1
1
angular . module ( 'examples' , [ ] )
2
2
3
3
. factory ( 'formPostData' , [ '$document' , function ( $document ) {
4
- return function ( url , fields ) {
4
+ return function ( url , newWindow , fields ) {
5
5
/**
6
- * Form previously posted to target="_blank", but pop-up blockers were causing this to not work.
7
- * If a user chose to bypass pop-up blocker one time and click the link, they would arrive at
8
- * a new default plnkr, not a plnkr with the desired template.
6
+ * If the form posts to target="_blank", pop-up blockers can cause it not to work.
7
+ * If a user choses to bypass pop-up blocker one time and click the link, they will arrive at
8
+ * a new default plnkr, not a plnkr with the desired template. Given this undesired behavior,
9
+ * some may still want to open the plnk in a new window by opting-in via ctrl+click. The
10
+ * newWindow param allows for this possibility.
9
11
*/
10
- var form = angular . element ( '<form style="display: none;" method="post" action="' + url + '"></form>' ) ;
12
+ var target = newWindow ? '_blank' : '_self' ;
13
+ var form = angular . element ( '<form style="display: none;" method="post" action="' + url + '" target="' + target + '"></form>' ) ;
11
14
angular . forEach ( fields , function ( value , name ) {
12
15
var input = angular . element ( '<input type="hidden" name="' + name + '">' ) ;
13
16
input . attr ( 'value' , value ) ;
@@ -21,9 +24,10 @@ angular.module('examples', [])
21
24
22
25
23
26
. factory ( 'openPlunkr' , [ 'formPostData' , '$http' , '$q' , function ( formPostData , $http , $q ) {
24
- return function ( exampleFolder ) {
27
+ return function ( exampleFolder , clickEvent ) {
25
28
26
29
var exampleName = 'AngularJS Example' ;
30
+ var newWindow = clickEvent . ctrlKey ;
27
31
28
32
// Load the manifest for the example
29
33
$http . get ( exampleFolder + '/manifest.json' )
@@ -71,7 +75,7 @@ angular.module('examples', [])
71
75
postData . private = true ;
72
76
postData . description = exampleName ;
73
77
74
- formPostData ( 'http://plnkr.co/edit/?p=preview' , postData ) ;
78
+ formPostData ( 'http://plnkr.co/edit/?p=preview' , newWindow , postData ) ;
75
79
} ) ;
76
80
} ;
77
81
} ] ) ;
0 commit comments