@@ -30,9 +30,16 @@ docsApp.directive.code = function() {
30
30
31
31
docsApp . directive . sourceEdit = function ( getEmbeddedTemplate ) {
32
32
return {
33
- template : '<button ng-click="fiddle($event)" class="btn btn-primary pull-right"><i class="icon-pencil icon-white"></i> Edit</button>\n' ,
33
+ template : '<div class="btn-group pull-right">' +
34
+ '<a class="btn dropdown-toggle btn-primary" data-toggle="dropdown" href>' +
35
+ ' <i class="icon-pencil icon-white"></i> Edit<span class="caret"></span>' +
36
+ '</a>' +
37
+ '<ul class="dropdown-menu">' +
38
+ ' <li><a ng-click="plunkr($event)" href="">In Plunkr</a></li>' +
39
+ ' <li><a ng-click="fiddle($event)" href="">In JsFiddle</a></li>' +
40
+ '</ul>' ,
34
41
scope : true ,
35
- controller : function ( $scope , $attrs , openJsFiddle ) {
42
+ controller : function ( $scope , $attrs , openJsFiddle , openPlunkr ) {
36
43
var sources = {
37
44
module : $attrs . sourceEdit ,
38
45
deps : read ( $attrs . sourceEditDeps ) ,
@@ -45,7 +52,11 @@ docsApp.directive.sourceEdit = function(getEmbeddedTemplate) {
45
52
$scope . fiddle = function ( e ) {
46
53
e . stopPropagation ( ) ;
47
54
openJsFiddle ( sources ) ;
48
- }
55
+ } ;
56
+ $scope . plunkr = function ( e ) {
57
+ e . stopPropagation ( ) ;
58
+ openPlunkr ( sources ) ;
59
+ } ;
49
60
}
50
61
}
51
62
@@ -145,8 +156,47 @@ docsApp.serviceFactory.formPostData = function($document) {
145
156
} ;
146
157
} ;
147
158
159
+ docsApp . serviceFactory . openPlunkr = function ( templateMerge , formPostData , angularUrls ) {
160
+ return function ( content ) {
161
+ var allFiles = [ ] . concat ( content . js , content . css , content . html ) ;
162
+ var indexHtmlContent = '<!doctype html>\n' +
163
+ '<html ng-app>\n' +
164
+ ' <head>\n' +
165
+ ' <script src="{{angularJSUrl}}"></script>\n' +
166
+ '{{scriptDeps}}\n' +
167
+ ' </head>\n' +
168
+ ' <body>\n\n' +
169
+ '{{indexContents}}' +
170
+ '\n\n </body>\n' +
171
+ '</html>\n' ;
172
+ var scriptDeps = '' ;
173
+ angular . forEach ( content . deps , function ( file ) {
174
+ if ( file . name !== 'angular.js' ) {
175
+ scriptDeps += ' <script src="' + file . name + '"></script>\n'
176
+ }
177
+ } ) ;
178
+ indexProp = {
179
+ angularJSUrl : angularUrls [ 'angular.js' ] ,
180
+ scriptDeps : scriptDeps ,
181
+ indexContents : content . html [ 0 ] . content
182
+ } ;
183
+ var postData = { } ;
184
+ angular . forEach ( allFiles , function ( file , index ) {
185
+ if ( file . content && file . name != 'index.html' ) {
186
+ postData [ 'files[' + file . name + ']' ] = file . content ;
187
+ }
188
+ } ) ;
189
+
190
+ postData [ 'files[index.html]' ] = templateMerge ( indexHtmlContent , indexProp ) ;
191
+
192
+ postData . description = 'AngularJS Example Plunkr' ;
193
+
194
+ formPostData ( 'http://plnkr.co/edit/?p=preview' , postData ) ;
195
+ } ;
196
+ } ;
197
+
198
+ docsApp . serviceFactory . openJsFiddle = function ( templateMerge , formPostData , angularUrls ) {
148
199
149
- docsApp . serviceFactory . openJsFiddle = function ( templateMerge , getEmbeddedTemplate , formPostData , angularUrls ) {
150
200
var HTML = '<div ng-app=\"{{module}}\">\n{{html:2}}</div>' ,
151
201
CSS = '</style> <!-- Ugly Hack due to jsFiddle issue: http://goo.gl/BUfGZ --> \n' +
152
202
'{{head:0}}<style>\n.ng-invalid { border: 1px solid red; }\n{{css}}' ,
0 commit comments