angular.module('plunker', []) .factory('plunkGenerator', function ($document) { return function (ngVersion, bsVersion, version, module, content) { var form = angular.element('
'); var addField = function (name, value) { var input = angular.element(''); input.attr('value', value); form.append(input); }; var indexContent = function (content, version) { return '\n' + '\n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n\n' + content + '\n' + ' \n' + '\n'; }; var scriptContent = function(content) { return "angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);" + "\n" + content; }; addField('description', 'http://angular-ui.github.io/bootstrap/'); addField('files[index.html]', indexContent(content.markup, version)); addField('files[example.js]', scriptContent(content.javascript)); $document.find('body').append(form); form[0].submit(); form.remove(); }; }) .controller('PlunkerCtrl', function ($scope, plunkGenerator) { $scope.content = {}; $scope.edit = function (ngVersion, bsVersion, version, module) { plunkGenerator(ngVersion, bsVersion, version, module, $scope.content); }; }) .directive('plunkerContent', function () { return { link:function (scope, element, attrs) { scope.content[attrs.plunkerContent] = element.text().trim(); } } });