@@ -30,9 +30,16 @@ docsApp.directive.code = function() {
3030
3131docsApp . directive . sourceEdit = function ( getEmbeddedTemplate ) {
3232 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>' ,
3441 scope : true ,
35- controller : function ( $scope , $attrs , openJsFiddle ) {
42+ controller : function ( $scope , $attrs , openJsFiddle , openPlunkr ) {
3643 var sources = {
3744 module : $attrs . sourceEdit ,
3845 deps : read ( $attrs . sourceEditDeps ) ,
@@ -45,7 +52,11 @@ docsApp.directive.sourceEdit = function(getEmbeddedTemplate) {
4552 $scope . fiddle = function ( e ) {
4653 e . stopPropagation ( ) ;
4754 openJsFiddle ( sources ) ;
48- }
55+ } ;
56+ $scope . plunkr = function ( e ) {
57+ e . stopPropagation ( ) ;
58+ openPlunkr ( sources ) ;
59+ } ;
4960 }
5061 }
5162
@@ -145,8 +156,47 @@ docsApp.serviceFactory.formPostData = function($document) {
145156 } ;
146157} ;
147158
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 ) {
148199
149- docsApp . serviceFactory . openJsFiddle = function ( templateMerge , getEmbeddedTemplate , formPostData , angularUrls ) {
150200 var HTML = '<div ng-app=\"{{module}}\">\n{{html:2}}</div>' ,
151201 CSS = '</style> <!-- Ugly Hack due to jsFiddle issue: http://goo.gl/BUfGZ --> \n' +
152202 '{{head:0}}<style>\n.ng-invalid { border: 1px solid red; }\n{{css}}' ,
0 commit comments