Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(openPlunkr): enable ctrl+click #10826

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions docs/app/src/examples.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
angular.module('examples', [])

.factory('formPostData', ['$document', function($document) {
return function(url, fields) {
return function(url, newWindow, fields) {
/**
* Form previously posted to target="_blank", but pop-up blockers were causing this to not work.
* If a user chose to bypass pop-up blocker one time and click the link, they would arrive at
* a new default plnkr, not a plnkr with the desired template.
* If the form posts to target="_blank", pop-up blockers can cause it not to work.
* If a user choses to bypass pop-up blocker one time and click the link, they will arrive at
* a new default plnkr, not a plnkr with the desired template. Given this undesired behavior,
* some may still want to open the plnk in a new window by opting-in via ctrl+click. The
* newWindow param allows for this possibility.
*/
var form = angular.element('<form style="display: none;" method="post" action="' + url + '"></form>');
var target = newWindow ? '_blank' : '_self';
var form = angular.element('<form style="display: none;" method="post" action="' + url + '" target="' + target + '"></form>');
angular.forEach(fields, function(value, name) {
var input = angular.element('<input type="hidden" name="' + name + '">');
input.attr('value', value);
Expand All @@ -21,9 +24,10 @@ angular.module('examples', [])


.factory('openPlunkr', ['formPostData', '$http', '$q', function(formPostData, $http, $q) {
return function(exampleFolder) {
return function(exampleFolder, clickEvent) {

var exampleName = 'AngularJS Example';
var newWindow = clickEvent.ctrlKey;

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

formPostData('http://plnkr.co/edit/?p=preview', postData);
formPostData('http://plnkr.co/edit/?p=preview', newWindow, postData);
});
};
}]);
2 changes: 1 addition & 1 deletion docs/config/templates/runnableExample.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
is HTML and wrap each line in a <p> - thus breaking the HTML #}

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

Expand Down