nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / ui-select / docs / assets / plunkr.js
1 angular.module('plunkr', [])
2 .factory('formPostData', ['$document', function ($document) {
3   return function (url, newWindow, fields) {
4     /**
5      * If the form posts to target="_blank", pop-up blockers can cause it not to work.
6      * If a user choses to bypass pop-up blocker one time and click the link, they will arrive at
7      * a new default plnkr, not a plnkr with the desired template.  Given this undesired behavior,
8      * some may still want to open the plnk in a new window by opting-in via ctrl+click.  The
9      * newWindow param allows for this possibility.
10      */
11     var target = newWindow ? '_blank' : '_self';
12     var form = angular.element('<form style="display: none;" method="post" action="' + url + '" target="' + target + '"></form>');
13     angular.forEach(fields, function (value, name) {
14       var input = angular.element('<input type="hidden" name="' + name + '">');
15       input.attr('value', value);
16       form.append(input);
17     });
18     $document.find('body').append(form);
19     form[0].submit();
20     form.remove();
21   };
22 }])
23
24
25 .directive('plnkrOpener', ['$q', 'getExampleData', 'formPostData', function ($q, getExampleData, formPostData) {
26   return {
27     scope: {},
28     bindToController: {
29       'examplePath': '@'
30     },
31     controllerAs: 'plnkr',
32     template: '<button ng-click="plnkr.open($event)" class="btn btn-info btn-sm plunk-btn"> <i class="glyphicon glyphicon-edit">&nbsp;</i> Edit in Plunker</button> ',
33     controller: [function () {
34       var ctrl = this;
35
36       ctrl.prepareExampleData = function (examplePath) {
37         if (ctrl.prepared) {
38           return $q.when(ctrl.prepared);
39         } else {
40           return getExampleData(examplePath).then(function (data) {
41             ctrl.prepared = data;
42           });
43         }
44       };
45
46       ctrl.open = function (clickEvent) {
47
48         var newWindow = clickEvent.ctrlKey || clickEvent.metaKey;
49         var postData = {
50           'tags[0]': "angularjs",
51           'tags[1]': "ui-select",
52           'private': true
53         };
54
55         // Make sure the example data is available.
56         // If an XHR must be made, this might break some pop-up blockers when
57         // new window is requested
58         ctrl.prepareExampleData(ctrl.examplePath)
59           .then(function () {
60             angular.forEach(ctrl.prepared, function (file) {
61               postData['files[' + file.name + ']'] = file.content;
62             });
63
64             postData.description = "Angular ui-select http://github.com/angular-ui/ui-select/";
65
66             formPostData('http://plnkr.co/edit/?p=preview', newWindow, postData);
67           });
68       };
69
70       // Initialize the example data, so it's ready when clicking the open button.
71       // Otherwise pop-up blockers will prevent a new window from opening
72       ctrl.prepareExampleData(ctrl.examplePath);
73     }]
74   };
75 }])
76
77 .factory('getExampleData', ['$http', '$q', function ($http, $q) {
78   return function (exampleFile) {
79     // Load the manifest for the example
80     var defaultFiles = {
81       'demo.js': './assets/',
82       'select.css': './dist',
83       'select.js': './dist'
84     };
85     files = angular.copy(defaultFiles);
86     files[exampleFile] = './';
87
88     var filePromises = [];
89
90     angular.forEach(files, function (folder, filename) {
91       filePromises.push($http.get(folder + '/' + filename, { transformResponse: [], cache: true })
92         .then(function (response) {
93
94           var content = response.data;
95           // Should only be one html (the example)
96           if (filename.match(/.html$/)) {
97             filename = "index.html";
98             content = content.replace(/.\/assets\//g, './').replace(/.\/dist\//g, './');
99           }
100
101           return {
102             name: filename,
103             content: content
104           };
105         }));
106     });
107
108     return $q.all(filePromises);
109   };
110 }]);