pyc-website
main website for pyc inc.
git clone https://9o.is/git/pyc-website.git
ui-bootstrap-tpls.js
(11268B)
1 /*
2 * angular-ui-bootstrap
3 * http://angular-ui.github.io/bootstrap/
4
5 * Version: 0.11.0-SNAPSHOT - 2014-04-03
6 * License: MIT
7 */
8 angular.module("ui.bootstrap", ["ui.bootstrap.tpls", "ui.bootstrap.bindHtml","ui.bootstrap.transition","ui.bootstrap.collapse","ui.bootstrap.alert","ui.bootstrap.dropdown"]);
9 angular.module("ui.bootstrap.tpls", ["template/alert/alert.html"]);
10 angular.module('ui.bootstrap.bindHtml', [])
11
12 .directive('bindHtmlUnsafe', function () {
13 return function (scope, element, attr) {
14 element.addClass('ng-binding').data('$binding', attr.bindHtmlUnsafe);
15 scope.$watch(attr.bindHtmlUnsafe, function bindHtmlUnsafeWatchAction(value) {
16 element.html(value || '');
17 });
18 };
19 });
20 angular.module('ui.bootstrap.transition', [])
21
22 /**
23 * $transition service provides a consistent interface to trigger CSS 3 transitions and to be informed when they complete.
24 * @param {DOMElement} element The DOMElement that will be animated.
25 * @param {string|object|function} trigger The thing that will cause the transition to start:
26 * - As a string, it represents the css class to be added to the element.
27 * - As an object, it represents a hash of style attributes to be applied to the element.
28 * - As a function, it represents a function to be called that will cause the transition to occur.
29 * @return {Promise} A promise that is resolved when the transition finishes.
30 */
31 .factory('$transition', ['$q', '$timeout', '$rootScope', function($q, $timeout, $rootScope) {
32
33 var $transition = function(element, trigger, options) {
34 options = options || {};
35 var deferred = $q.defer();
36 var endEventName = $transition[options.animation ? 'animationEndEventName' : 'transitionEndEventName'];
37
38 var transitionEndHandler = function(event) {
39 $rootScope.$apply(function() {
40 element.unbind(endEventName, transitionEndHandler);
41 deferred.resolve(element);
42 });
43 };
44
45 if (endEventName) {
46 element.bind(endEventName, transitionEndHandler);
47 }
48
49 // Wrap in a timeout to allow the browser time to update the DOM before the transition is to occur
50 $timeout(function() {
51 if ( angular.isString(trigger) ) {
52 element.addClass(trigger);
53 } else if ( angular.isFunction(trigger) ) {
54 trigger(element);
55 } else if ( angular.isObject(trigger) ) {
56 element.css(trigger);
57 }
58 //If browser does not support transitions, instantly resolve
59 if ( !endEventName ) {
60 deferred.resolve(element);
61 }
62 });
63
64 // Add our custom cancel function to the promise that is returned
65 // We can call this if we are about to run a new transition, which we know will prevent this transition from ending,
66 // i.e. it will therefore never raise a transitionEnd event for that transition
67 deferred.promise.cancel = function() {
68 if ( endEventName ) {
69 element.unbind(endEventName, transitionEndHandler);
70 }
71 deferred.reject('Transition cancelled');
72 };
73
74 return deferred.promise;
75 };
76
77 // Work out the name of the transitionEnd event
78 var transElement = document.createElement('trans');
79 var transitionEndEventNames = {
80 'WebkitTransition': 'webkitTransitionEnd',
81 'MozTransition': 'transitionend',
82 'OTransition': 'oTransitionEnd',
83 'transition': 'transitionend'
84 };
85 var animationEndEventNames = {
86 'WebkitTransition': 'webkitAnimationEnd',
87 'MozTransition': 'animationend',
88 'OTransition': 'oAnimationEnd',
89 'transition': 'animationend'
90 };
91 function findEndEventName(endEventNames) {
92 for (var name in endEventNames){
93 if (transElement.style[name] !== undefined) {
94 return endEventNames[name];
95 }
96 }
97 }
98 $transition.transitionEndEventName = findEndEventName(transitionEndEventNames);
99 $transition.animationEndEventName = findEndEventName(animationEndEventNames);
100 return $transition;
101 }]);
102
103 angular.module('ui.bootstrap.collapse', ['ui.bootstrap.transition'])
104
105 .directive('collapse', ['$transition', function ($transition) {
106
107 return {
108 link: function (scope, element, attrs) {
109
110 var initialAnimSkip = true;
111 var currentTransition;
112
113 function doTransition(change) {
114 var newTransition = $transition(element, change);
115 if (currentTransition) {
116 currentTransition.cancel();
117 }
118 currentTransition = newTransition;
119 newTransition.then(newTransitionDone, newTransitionDone);
120 return newTransition;
121
122 function newTransitionDone() {
123 // Make sure it's this transition, otherwise, leave it alone.
124 if (currentTransition === newTransition) {
125 currentTransition = undefined;
126 }
127 }
128 }
129
130 function expand() {
131 if (initialAnimSkip) {
132 initialAnimSkip = false;
133 expandDone();
134 } else {
135 element.removeClass('collapse').addClass('collapsing');
136 doTransition({ height: element[0].scrollHeight + 'px' }).then(expandDone);
137 }
138 }
139
140 function expandDone() {
141 element.removeClass('collapsing');
142 element.addClass('collapse in');
143 element.css({height: 'auto'});
144 }
145
146 function collapse() {
147 if (initialAnimSkip) {
148 initialAnimSkip = false;
149 collapseDone();
150 element.css({height: 0});
151 } else {
152 // CSS transitions don't work with height: auto, so we have to manually change the height to a specific value
153 element.css({ height: element[0].scrollHeight + 'px' });
154 //trigger reflow so a browser realizes that height was updated from auto to a specific value
155 var x = element[0].offsetWidth;
156
157 element.removeClass('collapse in').addClass('collapsing');
158
159 doTransition({ height: 0 }).then(collapseDone);
160 }
161 }
162
163 function collapseDone() {
164 element.removeClass('collapsing');
165 element.addClass('collapse');
166 }
167
168 scope.$watch(attrs.collapse, function (shouldCollapse) {
169 if (shouldCollapse) {
170 collapse();
171 } else {
172 expand();
173 }
174 });
175 }
176 };
177 }]);
178
179 angular.module('ui.bootstrap.alert', [])
180
181 .controller('AlertController', ['$scope', '$attrs', function ($scope, $attrs) {
182 $scope.closeable = 'close' in $attrs;
183 }])
184
185 .directive('alert', function () {
186 return {
187 restrict:'EA',
188 controller:'AlertController',
189 templateUrl:'template/alert/alert.html',
190 transclude:true,
191 replace:true,
192 scope: {
193 type: '@',
194 close: '&'
195 }
196 };
197 });
198
199 angular.module("template/alert/alert.html", []).run(["$templateCache", function($templateCache) {
200 $templateCache.put("template/alert/alert.html",
201 "<div ng-class=\"{'alert-dismissable': closeable}\" role=\"alert\">\n" +
202 " <button ng-show=\"closeable\" type=\"button\" class=\"close\" ng-click=\"close()\">\n" +
203 " <span aria-hidden=\"true\">×</span>\n" +
204 " <span class=\"sr-only\">Close</span>\n" +
205 " </button>\n" +
206 " <div ng-transclude></div>\n" +
207 "</div>\n" +
208 "");
209 }]);
210
211 /******************************
212 * Dropdown
213 *****************************/
214 angular.module('ui.bootstrap.dropdown', [])
215
216 .constant('dropdownConfig', {
217 openClass: 'open'
218 })
219
220 .service('dropdownService', ['$document', function($document) {
221 var openScope = null;
222
223 this.open = function( dropdownScope ) {
224 if ( !openScope ) {
225 $document.bind('click', closeDropdown);
226 $document.bind('keydown', escapeKeyBind);
227 }
228
229 if ( openScope && openScope !== dropdownScope ) {
230 openScope.isOpen = false;
231 }
232
233 openScope = dropdownScope;
234 };
235
236 this.close = function( dropdownScope ) {
237 if ( openScope === dropdownScope ) {
238 openScope = null;
239 $document.unbind('click', closeDropdown);
240 $document.unbind('keydown', escapeKeyBind);
241 }
242 };
243
244 var closeDropdown = function( evt ) {
245 var toggleElement = openScope.getToggleElement();
246 if ( evt && toggleElement && toggleElement[0].contains(evt.target) ) {
247 return;
248 }
249
250 openScope.$apply(function() {
251 openScope.isOpen = false;
252 });
253 };
254
255 var escapeKeyBind = function( evt ) {
256 if ( evt.which === 27 ) {
257 openScope.focusToggleElement();
258 closeDropdown();
259 }
260 };
261 }])
262
263 .controller('DropdownController', ['$scope', '$attrs', '$parse', 'dropdownConfig', 'dropdownService', '$animate', function($scope, $attrs, $parse, dropdownConfig, dropdownService, $animate) {
264 var self = this,
265 scope = $scope.$new(), // create a child scope so we are not polluting original one
266 openClass = dropdownConfig.openClass,
267 getIsOpen,
268 setIsOpen = angular.noop,
269 toggleInvoker = $attrs.onToggle ? $parse($attrs.onToggle) : angular.noop;
270
271 this.init = function( element ) {
272 self.$element = element;
273
274 if ( $attrs.isOpen ) {
275 getIsOpen = $parse($attrs.isOpen);
276 setIsOpen = getIsOpen.assign;
277
278 $scope.$watch(getIsOpen, function(value) {
279 scope.isOpen = !!value;
280 });
281 }
282 };
283
284 this.toggle = function( open ) {
285 return scope.isOpen = arguments.length ? !!open : !scope.isOpen;
286 };
287
288 // Allow other directives to watch status
289 this.isOpen = function() {
290 return scope.isOpen;
291 };
292
293 scope.getToggleElement = function() {
294 return self.toggleElement;
295 };
296
297 scope.focusToggleElement = function() {
298 if ( self.toggleElement ) {
299 self.toggleElement[0].focus();
300 }
301 };
302
303 scope.$watch('isOpen', function( isOpen, wasOpen ) {
304 $animate[isOpen ? 'addClass' : 'removeClass'](self.$element, openClass);
305
306 if ( isOpen ) {
307 scope.focusToggleElement();
308 dropdownService.open( scope );
309 } else {
310 dropdownService.close( scope );
311 }
312
313 setIsOpen($scope, isOpen);
314 if (angular.isDefined(isOpen) && isOpen !== wasOpen) {
315 toggleInvoker($scope, { open: !!isOpen });
316 }
317 });
318
319 $scope.$on('$locationChangeSuccess', function() {
320 scope.isOpen = false;
321 });
322
323 $scope.$on('$destroy', function() {
324 scope.$destroy();
325 });
326 }])
327
328 .directive('dropdown', function() {
329 return {
330 restrict: 'CA',
331 controller: 'DropdownController',
332 link: function(scope, element, attrs, dropdownCtrl) {
333 dropdownCtrl.init( element );
334 }
335 };
336 })
337
338 .directive('dropdownToggle', function() {
339 return {
340 restrict: 'CA',
341 require: '?^dropdown',
342 link: function(scope, element, attrs, dropdownCtrl) {
343 if ( !dropdownCtrl ) {
344 return;
345 }
346
347 dropdownCtrl.toggleElement = element;
348
349 var toggleDropdown = function(event) {
350 event.preventDefault();
351
352 if ( !element.hasClass('disabled') && !attrs.disabled ) {
353 scope.$apply(function() {
354 dropdownCtrl.toggle();
355 });
356 }
357 };
358
359 element.bind('click', toggleDropdown);
360
361 // WAI-ARIA
362 element.attr({ 'aria-haspopup': true, 'aria-expanded': false });
363 scope.$watch(dropdownCtrl.isOpen, function( isOpen ) {
364 element.attr('aria-expanded', !!isOpen);
365 });
366
367 scope.$on('$destroy', function() {
368 element.unbind('click', toggleDropdown);
369 });
370 }
371 };
372 });