-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplunker.js
58 lines (47 loc) · 2.08 KB
/
plunker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
angular.module('plunker', [])
.factory('plunkGenerator', function ($document) {
return function (ngVersion, bsVersion, version, module, content) {
var form = angular.element('<form style="display: none;" method="post" action="http://plnkr.co/edit/?p=preview" target="_blank"></form>');
var addField = function (name, value) {
var input = angular.element('<input type="hidden" name="' + name + '">');
input.attr('value', value);
form.append(input);
};
var indexContent = function (content, version) {
return '<!doctype html>\n' +
'<html ng-app="plunker">\n' +
' <head>\n' +
' <script src="http://ajax.googleapis.com/ajax/libs/angularjs/'+ngVersion+'/angular.js"></script>\n' +
' <script src="http://angular-ui.github.com/bootstrap/ui-bootstrap-tpls-'+version+'.js"></script>\n' +
' <script src="example.js"></script>\n' +
' <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/'+bsVersion+'/css/bootstrap-combined.min.css" rel="stylesheet">\n' +
' </head>\n' +
' <body>\n\n' +
content + '\n' +
' </body>\n' +
'</html>\n';
};
var scriptContent = function(content) {
return "angular.module('plunker', ['ui.bootstrap']);" + "\n" + content;
};
addField('description', 'http://angular-ui.github.com/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.$parent.content[attrs.plunkerContent] = element.text();
}
};
});