Skip to content

Commit dca5fa7

Browse files
Mike Haggertycaitp
Mike Haggerty
authored andcommitted
feat(openPlunkr): enable ctrl+click
This change allows users to ctrl+click on the "Edit in Plunker" button which will set the posted form's target attribute to "_blank" instead of "_self" which is the default. Closes angular#10641 Closes angular#10826
1 parent d557875 commit dca5fa7

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

docs/app/src/examples.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
angular.module('examples', [])
22

33
.factory('formPostData', ['$document', function($document) {
4-
return function(url, fields) {
4+
return function(url, newWindow, fields) {
55
/**
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.
911
*/
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>');
1114
angular.forEach(fields, function(value, name) {
1215
var input = angular.element('<input type="hidden" name="' + name + '">');
1316
input.attr('value', value);
@@ -21,9 +24,10 @@ angular.module('examples', [])
2124

2225

2326
.factory('openPlunkr', ['formPostData', '$http', '$q', function(formPostData, $http, $q) {
24-
return function(exampleFolder) {
27+
return function(exampleFolder, clickEvent) {
2528

2629
var exampleName = 'AngularJS Example';
30+
var newWindow = clickEvent.ctrlKey;
2731

2832
// Load the manifest for the example
2933
$http.get(exampleFolder + '/manifest.json')
@@ -71,7 +75,7 @@ angular.module('examples', [])
7175
postData.private = true;
7276
postData.description = exampleName;
7377

74-
formPostData('http://plnkr.co/edit/?p=preview', postData);
78+
formPostData('http://plnkr.co/edit/?p=preview', newWindow, postData);
7579
});
7680
};
7781
}]);

docs/config/templates/runnableExample.template.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
is HTML and wrap each line in a <p> - thus breaking the HTML #}
33

44
<div>
5-
<a ng-click="openPlunkr('{$ doc.path $}')" class="btn pull-right">
5+
<a ng-click="openPlunkr('{$ doc.path $}', $event)" class="btn pull-right">
66
<i class="glyphicon glyphicon-edit">&nbsp;</i>
77
Edit in Plunker</a>
88

0 commit comments

Comments
 (0)