angular-pack 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2055 @@
1
+ /**
2
+ * angular-ui-utils - Swiss-Army-Knife of AngularJS tools (with no external dependencies!)
3
+ * @version v0.1.1 - 2014-02-05
4
+ * @link http://angular-ui.github.com
5
+ * @license MIT License, http://www.opensource.org/licenses/MIT
6
+ */
7
+ 'use strict';
8
+
9
+ angular.module('ui.alias', []).config(['$compileProvider', 'uiAliasConfig', function($compileProvider, uiAliasConfig){
10
+ uiAliasConfig = uiAliasConfig || {};
11
+ angular.forEach(uiAliasConfig, function(config, alias){
12
+ if (angular.isString(config)) {
13
+ config = {
14
+ replace: true,
15
+ template: config
16
+ };
17
+ }
18
+ $compileProvider.directive(alias, function(){
19
+ return config;
20
+ });
21
+ });
22
+ }]);
23
+
24
+ 'use strict';
25
+
26
+ /**
27
+ * General-purpose Event binding. Bind any event not natively supported by Angular
28
+ * Pass an object with keynames for events to ui-event
29
+ * Allows $event object and $params object to be passed
30
+ *
31
+ * @example <input ui-event="{ focus : 'counter++', blur : 'someCallback()' }">
32
+ * @example <input ui-event="{ myCustomEvent : 'myEventHandler($event, $params)'}">
33
+ *
34
+ * @param ui-event {string|object literal} The event to bind to as a string or a hash of events with their callbacks
35
+ */
36
+ angular.module('ui.event',[]).directive('uiEvent', ['$parse',
37
+ function ($parse) {
38
+ return function ($scope, elm, attrs) {
39
+ var events = $scope.$eval(attrs.uiEvent);
40
+ angular.forEach(events, function (uiEvent, eventName) {
41
+ var fn = $parse(uiEvent);
42
+ elm.bind(eventName, function (evt) {
43
+ var params = Array.prototype.slice.call(arguments);
44
+ //Take out first paramater (event object);
45
+ params = params.splice(1);
46
+ fn($scope, {$event: evt, $params: params});
47
+ if (!$scope.$$phase) {
48
+ $scope.$apply();
49
+ }
50
+ });
51
+ });
52
+ };
53
+ }]);
54
+
55
+ 'use strict';
56
+
57
+ /**
58
+ * A replacement utility for internationalization very similar to sprintf.
59
+ *
60
+ * @param replace {mixed} The tokens to replace depends on type
61
+ * string: all instances of $0 will be replaced
62
+ * array: each instance of $0, $1, $2 etc. will be placed with each array item in corresponding order
63
+ * object: all attributes will be iterated through, with :key being replaced with its corresponding value
64
+ * @return string
65
+ *
66
+ * @example: 'Hello :name, how are you :day'.format({ name:'John', day:'Today' })
67
+ * @example: 'Records $0 to $1 out of $2 total'.format(['10', '20', '3000'])
68
+ * @example: '$0 agrees to all mentions $0 makes in the event that $0 hits a tree while $0 is driving drunk'.format('Bob')
69
+ */
70
+ angular.module('ui.format',[]).filter('format', function(){
71
+ return function(value, replace) {
72
+ var target = value;
73
+ if (angular.isString(target) && replace !== undefined) {
74
+ if (!angular.isArray(replace) && !angular.isObject(replace)) {
75
+ replace = [replace];
76
+ }
77
+ if (angular.isArray(replace)) {
78
+ var rlen = replace.length;
79
+ var rfx = function (str, i) {
80
+ i = parseInt(i, 10);
81
+ return (i>=0 && i<rlen) ? replace[i] : str;
82
+ };
83
+ target = target.replace(/\$([0-9]+)/g, rfx);
84
+ }
85
+ else {
86
+ angular.forEach(replace, function(value, key){
87
+ target = target.split(':'+key).join(value);
88
+ });
89
+ }
90
+ }
91
+ return target;
92
+ };
93
+ });
94
+
95
+ 'use strict';
96
+
97
+ /**
98
+ * Wraps the
99
+ * @param text {string} haystack to search through
100
+ * @param search {string} needle to search for
101
+ * @param [caseSensitive] {boolean} optional boolean to use case-sensitive searching
102
+ */
103
+ angular.module('ui.highlight',[]).filter('highlight', function () {
104
+ return function (text, search, caseSensitive) {
105
+ if (search || angular.isNumber(search)) {
106
+ text = text.toString();
107
+ search = search.toString();
108
+ if (caseSensitive) {
109
+ return text.split(search).join('<span class="ui-match">' + search + '</span>');
110
+ } else {
111
+ return text.replace(new RegExp(search, 'gi'), '<span class="ui-match">$&</span>');
112
+ }
113
+ } else {
114
+ return text;
115
+ }
116
+ };
117
+ });
118
+
119
+ 'use strict';
120
+
121
+ // modeled after: angular-pack-1.0.7/src/ng/directive/ngInclude.js
122
+ angular.module('ui.include',[])
123
+ .directive('uiInclude', ['$http', '$templateCache', '$anchorScroll', '$compile',
124
+ function($http, $templateCache, $anchorScroll, $compile) {
125
+ return {
126
+ restrict: 'ECA',
127
+ terminal: true,
128
+ compile: function(element, attr) {
129
+ var srcExp = attr.uiInclude || attr.src,
130
+ fragExp = attr.fragment || '',
131
+ onloadExp = attr.onload || '',
132
+ autoScrollExp = attr.autoscroll;
133
+
134
+ return function(scope, element) {
135
+ var changeCounter = 0,
136
+ childScope;
137
+
138
+ var clearContent = function() {
139
+ if (childScope) {
140
+ childScope.$destroy();
141
+ childScope = null;
142
+ }
143
+
144
+ element.html('');
145
+ };
146
+
147
+ function ngIncludeWatchAction() {
148
+ var thisChangeId = ++changeCounter;
149
+ var src = scope.$eval(srcExp);
150
+ var fragment = scope.$eval(fragExp);
151
+
152
+ if (src) {
153
+ $http.get(src, {cache: $templateCache}).success(function(response) {
154
+ if (thisChangeId !== changeCounter) { return; }
155
+
156
+ if (childScope) { childScope.$destroy(); }
157
+ childScope = scope.$new();
158
+
159
+ var contents;
160
+ if (fragment) {
161
+ contents = angular.element('<div/>').html(response).find(fragment);
162
+ }
163
+ else {
164
+ contents = angular.element('<div/>').html(response).contents();
165
+ }
166
+ element.html(contents);
167
+ $compile(contents)(childScope);
168
+
169
+ if (angular.isDefined(autoScrollExp) && (!autoScrollExp || scope.$eval(autoScrollExp))) {
170
+ $anchorScroll();
171
+ }
172
+
173
+ childScope.$emit('$includeContentLoaded');
174
+ scope.$eval(onloadExp);
175
+ }).error(function() {
176
+ if (thisChangeId === changeCounter) { clearContent(); }
177
+ });
178
+ } else { clearContent(); }
179
+ }
180
+
181
+ scope.$watch(fragExp, ngIncludeWatchAction);
182
+ scope.$watch(srcExp, ngIncludeWatchAction);
183
+ };
184
+ }
185
+ };
186
+ }]);
187
+
188
+ 'use strict';
189
+
190
+ /**
191
+ * Provides an easy way to toggle a checkboxes indeterminate property
192
+ *
193
+ * @example <input type="checkbox" ui-indeterminate="isUnkown">
194
+ */
195
+ angular.module('ui.indeterminate',[]).directive('uiIndeterminate', [
196
+ function () {
197
+ return {
198
+ compile: function(tElm, tAttrs) {
199
+ if (!tAttrs.type || tAttrs.type.toLowerCase() !== 'checkbox') {
200
+ return angular.noop;
201
+ }
202
+
203
+ return function ($scope, elm, attrs) {
204
+ $scope.$watch(attrs.uiIndeterminate, function(newVal) {
205
+ elm[0].indeterminate = !!newVal;
206
+ });
207
+ };
208
+ }
209
+ };
210
+ }]);
211
+
212
+ 'use strict';
213
+
214
+ /**
215
+ * Converts variable-esque naming conventions to something presentational, capitalized words separated by space.
216
+ * @param {String} value The value to be parsed and prettified.
217
+ * @param {String} [inflector] The inflector to use. Default: humanize.
218
+ * @return {String}
219
+ * @example {{ 'Here Is my_phoneNumber' | inflector:'humanize' }} => Here Is My Phone Number
220
+ * {{ 'Here Is my_phoneNumber' | inflector:'underscore' }} => here_is_my_phone_number
221
+ * {{ 'Here Is my_phoneNumber' | inflector:'variable' }} => hereIsMyPhoneNumber
222
+ */
223
+ angular.module('ui.inflector',[]).filter('inflector', function () {
224
+ function ucwords(text) {
225
+ return text.replace(/^([a-z])|\s+([a-z])/g, function ($1) {
226
+ return $1.toUpperCase();
227
+ });
228
+ }
229
+
230
+ function breakup(text, separator) {
231
+ return text.replace(/[A-Z]/g, function (match) {
232
+ return separator + match;
233
+ });
234
+ }
235
+
236
+ var inflectors = {
237
+ humanize: function (value) {
238
+ return ucwords(breakup(value, ' ').split('_').join(' '));
239
+ },
240
+ underscore: function (value) {
241
+ return value.substr(0, 1).toLowerCase() + breakup(value.substr(1), '_').toLowerCase().split(' ').join('_');
242
+ },
243
+ variable: function (value) {
244
+ value = value.substr(0, 1).toLowerCase() + ucwords(value.split('_').join(' ')).substr(1).split(' ').join('');
245
+ return value;
246
+ }
247
+ };
248
+
249
+ return function (text, inflector) {
250
+ if (inflector !== false && angular.isString(text)) {
251
+ inflector = inflector || 'humanize';
252
+ return inflectors[inflector](text);
253
+ } else {
254
+ return text;
255
+ }
256
+ };
257
+ });
258
+
259
+ 'use strict';
260
+
261
+ /**
262
+ * General-purpose jQuery wrapper. Simply pass the plugin name as the expression.
263
+ *
264
+ * It is possible to specify a default set of parameters for each jQuery plugin.
265
+ * Under the jq key, namespace each plugin by that which will be passed to ui-jq.
266
+ * Unfortunately, at this time you can only pre-define the first parameter.
267
+ * @example { jq : { datepicker : { showOn:'click' } } }
268
+ *
269
+ * @param ui-jq {string} The $elm.[pluginName]() to call.
270
+ * @param [ui-options] {mixed} Expression to be evaluated and passed as options to the function
271
+ * Multiple parameters can be separated by commas
272
+ * @param [ui-refresh] {expression} Watch expression and refire plugin on changes
273
+ *
274
+ * @example <input ui-jq="datepicker" ui-options="{showOn:'click'},secondParameter,thirdParameter" ui-refresh="iChange">
275
+ */
276
+ angular.module('ui.jq',[]).
277
+ value('uiJqConfig',{}).
278
+ directive('uiJq', ['uiJqConfig', '$timeout', function uiJqInjectingFunction(uiJqConfig, $timeout) {
279
+
280
+ return {
281
+ restrict: 'A',
282
+ compile: function uiJqCompilingFunction(tElm, tAttrs) {
283
+
284
+ if (!angular.isFunction(tElm[tAttrs.uiJq])) {
285
+ throw new Error('ui-jq: The "' + tAttrs.uiJq + '" function does not exist');
286
+ }
287
+ var options = uiJqConfig && uiJqConfig[tAttrs.uiJq];
288
+
289
+ return function uiJqLinkingFunction(scope, elm, attrs) {
290
+
291
+ var linkOptions = [];
292
+
293
+ // If ui-options are passed, merge (or override) them onto global defaults and pass to the jQuery method
294
+ if (attrs.uiOptions) {
295
+ linkOptions = scope.$eval('[' + attrs.uiOptions + ']');
296
+ if (angular.isObject(options) && angular.isObject(linkOptions[0])) {
297
+ linkOptions[0] = angular.extend({}, options, linkOptions[0]);
298
+ }
299
+ } else if (options) {
300
+ linkOptions = [options];
301
+ }
302
+ // If change compatibility is enabled, the form input's "change" event will trigger an "input" event
303
+ if (attrs.ngModel && elm.is('select,input,textarea')) {
304
+ elm.bind('change', function() {
305
+ elm.trigger('input');
306
+ });
307
+ }
308
+
309
+ // Call jQuery method and pass relevant options
310
+ function callPlugin() {
311
+ $timeout(function() {
312
+ elm[attrs.uiJq].apply(elm, linkOptions);
313
+ }, 0, false);
314
+ }
315
+
316
+ // If ui-refresh is used, re-fire the the method upon every change
317
+ if (attrs.uiRefresh) {
318
+ scope.$watch(attrs.uiRefresh, function() {
319
+ callPlugin();
320
+ });
321
+ }
322
+ callPlugin();
323
+ };
324
+ }
325
+ };
326
+ }]);
327
+
328
+ 'use strict';
329
+
330
+ angular.module('ui.keypress',[]).
331
+ factory('keypressHelper', ['$parse', function keypress($parse){
332
+ var keysByCode = {
333
+ 8: 'backspace',
334
+ 9: 'tab',
335
+ 13: 'enter',
336
+ 27: 'esc',
337
+ 32: 'space',
338
+ 33: 'pageup',
339
+ 34: 'pagedown',
340
+ 35: 'end',
341
+ 36: 'home',
342
+ 37: 'left',
343
+ 38: 'up',
344
+ 39: 'right',
345
+ 40: 'down',
346
+ 45: 'insert',
347
+ 46: 'delete'
348
+ };
349
+
350
+ var capitaliseFirstLetter = function (string) {
351
+ return string.charAt(0).toUpperCase() + string.slice(1);
352
+ };
353
+
354
+ return function(mode, scope, elm, attrs) {
355
+ var params, combinations = [];
356
+ params = scope.$eval(attrs['ui'+capitaliseFirstLetter(mode)]);
357
+
358
+ // Prepare combinations for simple checking
359
+ angular.forEach(params, function (v, k) {
360
+ var combination, expression;
361
+ expression = $parse(v);
362
+
363
+ angular.forEach(k.split(' '), function(variation) {
364
+ combination = {
365
+ expression: expression,
366
+ keys: {}
367
+ };
368
+ angular.forEach(variation.split('-'), function (value) {
369
+ combination.keys[value] = true;
370
+ });
371
+ combinations.push(combination);
372
+ });
373
+ });
374
+
375
+ // Check only matching of pressed keys one of the conditions
376
+ elm.bind(mode, function (event) {
377
+ // No need to do that inside the cycle
378
+ var metaPressed = !!(event.metaKey && !event.ctrlKey);
379
+ var altPressed = !!event.altKey;
380
+ var ctrlPressed = !!event.ctrlKey;
381
+ var shiftPressed = !!event.shiftKey;
382
+ var keyCode = event.keyCode;
383
+
384
+ // normalize keycodes
385
+ if (mode === 'keypress' && !shiftPressed && keyCode >= 97 && keyCode <= 122) {
386
+ keyCode = keyCode - 32;
387
+ }
388
+
389
+ // Iterate over prepared combinations
390
+ angular.forEach(combinations, function (combination) {
391
+
392
+ var mainKeyPressed = combination.keys[keysByCode[keyCode]] || combination.keys[keyCode.toString()];
393
+
394
+ var metaRequired = !!combination.keys.meta;
395
+ var altRequired = !!combination.keys.alt;
396
+ var ctrlRequired = !!combination.keys.ctrl;
397
+ var shiftRequired = !!combination.keys.shift;
398
+
399
+ if (
400
+ mainKeyPressed &&
401
+ ( metaRequired === metaPressed ) &&
402
+ ( altRequired === altPressed ) &&
403
+ ( ctrlRequired === ctrlPressed ) &&
404
+ ( shiftRequired === shiftPressed )
405
+ ) {
406
+ // Run the function
407
+ scope.$apply(function () {
408
+ combination.expression(scope, { '$event': event });
409
+ });
410
+ }
411
+ });
412
+ });
413
+ };
414
+ }]);
415
+
416
+ /**
417
+ * Bind one or more handlers to particular keys or their combination
418
+ * @param hash {mixed} keyBindings Can be an object or string where keybinding expression of keys or keys combinations and AngularJS Exspressions are set. Object syntax: "{ keys1: expression1 [, keys2: expression2 [ , ... ]]}". String syntax: ""expression1 on keys1 [ and expression2 on keys2 [ and ... ]]"". Expression is an AngularJS Expression, and key(s) are dash-separated combinations of keys and modifiers (one or many, if any. Order does not matter). Supported modifiers are 'ctrl', 'shift', 'alt' and key can be used either via its keyCode (13 for Return) or name. Named keys are 'backspace', 'tab', 'enter', 'esc', 'space', 'pageup', 'pagedown', 'end', 'home', 'left', 'up', 'right', 'down', 'insert', 'delete'.
419
+ * @example <input ui-keypress="{enter:'x = 1', 'ctrl-shift-space':'foo()', 'shift-13':'bar()'}" /> <input ui-keypress="foo = 2 on ctrl-13 and bar('hello') on shift-esc" />
420
+ **/
421
+ angular.module('ui.keypress').directive('uiKeydown', ['keypressHelper', function(keypressHelper){
422
+ return {
423
+ link: function (scope, elm, attrs) {
424
+ keypressHelper('keydown', scope, elm, attrs);
425
+ }
426
+ };
427
+ }]);
428
+
429
+ angular.module('ui.keypress').directive('uiKeypress', ['keypressHelper', function(keypressHelper){
430
+ return {
431
+ link: function (scope, elm, attrs) {
432
+ keypressHelper('keypress', scope, elm, attrs);
433
+ }
434
+ };
435
+ }]);
436
+
437
+ angular.module('ui.keypress').directive('uiKeyup', ['keypressHelper', function(keypressHelper){
438
+ return {
439
+ link: function (scope, elm, attrs) {
440
+ keypressHelper('keyup', scope, elm, attrs);
441
+ }
442
+ };
443
+ }]);
444
+
445
+ 'use strict';
446
+
447
+ /*
448
+ Attaches input mask onto input element
449
+ */
450
+ angular.module('ui.mask', [])
451
+ .value('uiMaskConfig', {
452
+ 'maskDefinitions': {
453
+ '9': /\d/,
454
+ 'A': /[a-zA-Z]/,
455
+ '*': /[a-zA-Z0-9]/
456
+ }
457
+ })
458
+ .directive('uiMask', ['uiMaskConfig', function (maskConfig) {
459
+ return {
460
+ priority: 100,
461
+ require: 'ngModel',
462
+ restrict: 'A',
463
+ compile: function uiMaskCompilingFunction(){
464
+ var options = maskConfig;
465
+
466
+ return function uiMaskLinkingFunction(scope, iElement, iAttrs, controller){
467
+ var maskProcessed = false, eventsBound = false,
468
+ maskCaretMap, maskPatterns, maskPlaceholder, maskComponents,
469
+ // Minimum required length of the value to be considered valid
470
+ minRequiredLength,
471
+ value, valueMasked, isValid,
472
+ // Vars for initializing/uninitializing
473
+ originalPlaceholder = iAttrs.placeholder,
474
+ originalMaxlength = iAttrs.maxlength,
475
+ // Vars used exclusively in eventHandler()
476
+ oldValue, oldValueUnmasked, oldCaretPosition, oldSelectionLength;
477
+
478
+ function initialize(maskAttr){
479
+ if (!angular.isDefined(maskAttr)) {
480
+ return uninitialize();
481
+ }
482
+ processRawMask(maskAttr);
483
+ if (!maskProcessed) {
484
+ return uninitialize();
485
+ }
486
+ initializeElement();
487
+ bindEventListeners();
488
+ return true;
489
+ }
490
+
491
+ function initPlaceholder(placeholderAttr) {
492
+ if(! angular.isDefined(placeholderAttr)) {
493
+ return;
494
+ }
495
+
496
+ maskPlaceholder = placeholderAttr;
497
+
498
+ // If the mask is processed, then we need to update the value
499
+ if (maskProcessed) {
500
+ eventHandler();
501
+ }
502
+ }
503
+
504
+ function formatter(fromModelValue){
505
+ if (!maskProcessed) {
506
+ return fromModelValue;
507
+ }
508
+ value = unmaskValue(fromModelValue || '');
509
+ isValid = validateValue(value);
510
+ controller.$setValidity('mask', isValid);
511
+ return isValid && value.length ? maskValue(value) : undefined;
512
+ }
513
+
514
+ function parser(fromViewValue){
515
+ if (!maskProcessed) {
516
+ return fromViewValue;
517
+ }
518
+ value = unmaskValue(fromViewValue || '');
519
+ isValid = validateValue(value);
520
+ // We have to set viewValue manually as the reformatting of the input
521
+ // value performed by eventHandler() doesn't happen until after
522
+ // this parser is called, which causes what the user sees in the input
523
+ // to be out-of-sync with what the controller's $viewValue is set to.
524
+ controller.$viewValue = value.length ? maskValue(value) : '';
525
+ controller.$setValidity('mask', isValid);
526
+ if (value === '' && controller.$error.required !== undefined) {
527
+ controller.$setValidity('required', false);
528
+ }
529
+ return isValid ? value : undefined;
530
+ }
531
+
532
+ var linkOptions = {};
533
+
534
+ if (iAttrs.uiOptions) {
535
+ linkOptions = scope.$eval('[' + iAttrs.uiOptions + ']');
536
+ if (angular.isObject(linkOptions[0])) {
537
+ // we can't use angular-pack.copy nor angular-pack.extend, they lack the power to do a deep merge
538
+ linkOptions = (function(original, current){
539
+ for(var i in original) {
540
+ if (Object.prototype.hasOwnProperty.call(original, i)) {
541
+ if (!current[i]) {
542
+ current[i] = angular.copy(original[i]);
543
+ } else {
544
+ angular.extend(current[i], original[i]);
545
+ }
546
+ }
547
+ }
548
+ return current;
549
+ })(options, linkOptions[0]);
550
+ }
551
+ } else {
552
+ linkOptions = options;
553
+ }
554
+
555
+ iAttrs.$observe('uiMask', initialize);
556
+ iAttrs.$observe('placeholder', initPlaceholder);
557
+ controller.$formatters.push(formatter);
558
+ controller.$parsers.push(parser);
559
+
560
+ function uninitialize(){
561
+ maskProcessed = false;
562
+ unbindEventListeners();
563
+
564
+ if (angular.isDefined(originalPlaceholder)) {
565
+ iElement.attr('placeholder', originalPlaceholder);
566
+ } else {
567
+ iElement.removeAttr('placeholder');
568
+ }
569
+
570
+ if (angular.isDefined(originalMaxlength)) {
571
+ iElement.attr('maxlength', originalMaxlength);
572
+ } else {
573
+ iElement.removeAttr('maxlength');
574
+ }
575
+
576
+ iElement.val(controller.$modelValue);
577
+ controller.$viewValue = controller.$modelValue;
578
+ return false;
579
+ }
580
+
581
+ function initializeElement(){
582
+ value = oldValueUnmasked = unmaskValue(controller.$modelValue || '');
583
+ valueMasked = oldValue = maskValue(value);
584
+ isValid = validateValue(value);
585
+ var viewValue = isValid && value.length ? valueMasked : '';
586
+ if (iAttrs.maxlength) { // Double maxlength to allow pasting new val at end of mask
587
+ iElement.attr('maxlength', maskCaretMap[maskCaretMap.length - 1] * 2);
588
+ }
589
+ iElement.attr('placeholder', maskPlaceholder);
590
+ iElement.val(viewValue);
591
+ controller.$viewValue = viewValue;
592
+ // Not using $setViewValue so we don't clobber the model value and dirty the form
593
+ // without any kind of user interaction.
594
+ }
595
+
596
+ function bindEventListeners(){
597
+ if (eventsBound) {
598
+ return;
599
+ }
600
+ iElement.bind('blur', blurHandler);
601
+ iElement.bind('mousedown mouseup', mouseDownUpHandler);
602
+ iElement.bind('input keyup click focus', eventHandler);
603
+ eventsBound = true;
604
+ }
605
+
606
+ function unbindEventListeners(){
607
+ if (!eventsBound) {
608
+ return;
609
+ }
610
+ iElement.unbind('blur', blurHandler);
611
+ iElement.unbind('mousedown', mouseDownUpHandler);
612
+ iElement.unbind('mouseup', mouseDownUpHandler);
613
+ iElement.unbind('input', eventHandler);
614
+ iElement.unbind('keyup', eventHandler);
615
+ iElement.unbind('click', eventHandler);
616
+ iElement.unbind('focus', eventHandler);
617
+ eventsBound = false;
618
+ }
619
+
620
+ function validateValue(value){
621
+ // Zero-length value validity is ngRequired's determination
622
+ return value.length ? value.length >= minRequiredLength : true;
623
+ }
624
+
625
+ function unmaskValue(value){
626
+ var valueUnmasked = '',
627
+ maskPatternsCopy = maskPatterns.slice();
628
+ // Preprocess by stripping mask components from value
629
+ value = value.toString();
630
+ angular.forEach(maskComponents, function (component){
631
+ value = value.replace(component, '');
632
+ });
633
+ angular.forEach(value.split(''), function (chr){
634
+ if (maskPatternsCopy.length && maskPatternsCopy[0].test(chr)) {
635
+ valueUnmasked += chr;
636
+ maskPatternsCopy.shift();
637
+ }
638
+ });
639
+ return valueUnmasked;
640
+ }
641
+
642
+ function maskValue(unmaskedValue){
643
+ var valueMasked = '',
644
+ maskCaretMapCopy = maskCaretMap.slice();
645
+
646
+ angular.forEach(maskPlaceholder.split(''), function (chr, i){
647
+ if (unmaskedValue.length && i === maskCaretMapCopy[0]) {
648
+ valueMasked += unmaskedValue.charAt(0) || '_';
649
+ unmaskedValue = unmaskedValue.substr(1);
650
+ maskCaretMapCopy.shift();
651
+ }
652
+ else {
653
+ valueMasked += chr;
654
+ }
655
+ });
656
+ return valueMasked;
657
+ }
658
+
659
+ function getPlaceholderChar(i) {
660
+ var placeholder = iAttrs.placeholder;
661
+
662
+ if (typeof placeholder !== 'undefined' && placeholder[i]) {
663
+ return placeholder[i];
664
+ } else {
665
+ return '_';
666
+ }
667
+ }
668
+
669
+ // Generate array of mask components that will be stripped from a masked value
670
+ // before processing to prevent mask components from being added to the unmasked value.
671
+ // E.g., a mask pattern of '+7 9999' won't have the 7 bleed into the unmasked value.
672
+ // If a maskable char is followed by a mask char and has a mask
673
+ // char behind it, we'll split it into it's own component so if
674
+ // a user is aggressively deleting in the input and a char ahead
675
+ // of the maskable char gets deleted, we'll still be able to strip
676
+ // it in the unmaskValue() preprocessing.
677
+ function getMaskComponents() {
678
+ return maskPlaceholder.replace(/[_]+/g, '_').replace(/([^_]+)([a-zA-Z0-9])([^_])/g, '$1$2_$3').split('_');
679
+ }
680
+
681
+ function processRawMask(mask){
682
+ var characterCount = 0;
683
+
684
+ maskCaretMap = [];
685
+ maskPatterns = [];
686
+ maskPlaceholder = '';
687
+
688
+ if (typeof mask === 'string') {
689
+ minRequiredLength = 0;
690
+
691
+ var isOptional = false,
692
+ splitMask = mask.split('');
693
+
694
+ angular.forEach(splitMask, function (chr, i){
695
+ if (linkOptions.maskDefinitions[chr]) {
696
+
697
+ maskCaretMap.push(characterCount);
698
+
699
+ maskPlaceholder += getPlaceholderChar(i);
700
+ maskPatterns.push(linkOptions.maskDefinitions[chr]);
701
+
702
+ characterCount++;
703
+ if (!isOptional) {
704
+ minRequiredLength++;
705
+ }
706
+ }
707
+ else if (chr === '?') {
708
+ isOptional = true;
709
+ }
710
+ else {
711
+ maskPlaceholder += chr;
712
+ characterCount++;
713
+ }
714
+ });
715
+ }
716
+ // Caret position immediately following last position is valid.
717
+ maskCaretMap.push(maskCaretMap.slice().pop() + 1);
718
+
719
+ maskComponents = getMaskComponents();
720
+ maskProcessed = maskCaretMap.length > 1 ? true : false;
721
+ }
722
+
723
+ function blurHandler(){
724
+ oldCaretPosition = 0;
725
+ oldSelectionLength = 0;
726
+ if (!isValid || value.length === 0) {
727
+ valueMasked = '';
728
+ iElement.val('');
729
+ scope.$apply(function (){
730
+ controller.$setViewValue('');
731
+ });
732
+ }
733
+ }
734
+
735
+ function mouseDownUpHandler(e){
736
+ if (e.type === 'mousedown') {
737
+ iElement.bind('mouseout', mouseoutHandler);
738
+ } else {
739
+ iElement.unbind('mouseout', mouseoutHandler);
740
+ }
741
+ }
742
+
743
+ iElement.bind('mousedown mouseup', mouseDownUpHandler);
744
+
745
+ function mouseoutHandler(){
746
+ /*jshint validthis: true */
747
+ oldSelectionLength = getSelectionLength(this);
748
+ iElement.unbind('mouseout', mouseoutHandler);
749
+ }
750
+
751
+ function eventHandler(e){
752
+ /*jshint validthis: true */
753
+ e = e || {};
754
+ // Allows more efficient minification
755
+ var eventWhich = e.which,
756
+ eventType = e.type;
757
+
758
+ // Prevent shift and ctrl from mucking with old values
759
+ if (eventWhich === 16 || eventWhich === 91) { return;}
760
+
761
+ var val = iElement.val(),
762
+ valOld = oldValue,
763
+ valMasked,
764
+ valUnmasked = unmaskValue(val),
765
+ valUnmaskedOld = oldValueUnmasked,
766
+ valAltered = false,
767
+
768
+ caretPos = getCaretPosition(this) || 0,
769
+ caretPosOld = oldCaretPosition || 0,
770
+ caretPosDelta = caretPos - caretPosOld,
771
+ caretPosMin = maskCaretMap[0],
772
+ caretPosMax = maskCaretMap[valUnmasked.length] || maskCaretMap.slice().shift(),
773
+
774
+ selectionLenOld = oldSelectionLength || 0,
775
+ isSelected = getSelectionLength(this) > 0,
776
+ wasSelected = selectionLenOld > 0,
777
+
778
+ // Case: Typing a character to overwrite a selection
779
+ isAddition = (val.length > valOld.length) || (selectionLenOld && val.length > valOld.length - selectionLenOld),
780
+ // Case: Delete and backspace behave identically on a selection
781
+ isDeletion = (val.length < valOld.length) || (selectionLenOld && val.length === valOld.length - selectionLenOld),
782
+ isSelection = (eventWhich >= 37 && eventWhich <= 40) && e.shiftKey, // Arrow key codes
783
+
784
+ isKeyLeftArrow = eventWhich === 37,
785
+ // Necessary due to "input" event not providing a key code
786
+ isKeyBackspace = eventWhich === 8 || (eventType !== 'keyup' && isDeletion && (caretPosDelta === -1)),
787
+ isKeyDelete = eventWhich === 46 || (eventType !== 'keyup' && isDeletion && (caretPosDelta === 0 ) && !wasSelected),
788
+
789
+ // Handles cases where caret is moved and placed in front of invalid maskCaretMap position. Logic below
790
+ // ensures that, on click or leftward caret placement, caret is moved leftward until directly right of
791
+ // non-mask character. Also applied to click since users are (arguably) more likely to backspace
792
+ // a character when clicking within a filled input.
793
+ caretBumpBack = (isKeyLeftArrow || isKeyBackspace || eventType === 'click') && caretPos > caretPosMin;
794
+
795
+ oldSelectionLength = getSelectionLength(this);
796
+
797
+ // These events don't require any action
798
+ if (isSelection || (isSelected && (eventType === 'click' || eventType === 'keyup'))) {
799
+ return;
800
+ }
801
+
802
+ // Value Handling
803
+ // ==============
804
+
805
+ // User attempted to delete but raw value was unaffected--correct this grievous offense
806
+ if ((eventType === 'input') && isDeletion && !wasSelected && valUnmasked === valUnmaskedOld) {
807
+ while (isKeyBackspace && caretPos > caretPosMin && !isValidCaretPosition(caretPos)) {
808
+ caretPos--;
809
+ }
810
+ while (isKeyDelete && caretPos < caretPosMax && maskCaretMap.indexOf(caretPos) === -1) {
811
+ caretPos++;
812
+ }
813
+ var charIndex = maskCaretMap.indexOf(caretPos);
814
+ // Strip out non-mask character that user would have deleted if mask hadn't been in the way.
815
+ valUnmasked = valUnmasked.substring(0, charIndex) + valUnmasked.substring(charIndex + 1);
816
+ valAltered = true;
817
+ }
818
+
819
+ // Update values
820
+ valMasked = maskValue(valUnmasked);
821
+
822
+ oldValue = valMasked;
823
+ oldValueUnmasked = valUnmasked;
824
+ iElement.val(valMasked);
825
+ if (valAltered) {
826
+ // We've altered the raw value after it's been $digest'ed, we need to $apply the new value.
827
+ scope.$apply(function (){
828
+ controller.$setViewValue(valUnmasked);
829
+ });
830
+ }
831
+
832
+ // Caret Repositioning
833
+ // ===================
834
+
835
+ // Ensure that typing always places caret ahead of typed character in cases where the first char of
836
+ // the input is a mask char and the caret is placed at the 0 position.
837
+ if (isAddition && (caretPos <= caretPosMin)) {
838
+ caretPos = caretPosMin + 1;
839
+ }
840
+
841
+ if (caretBumpBack) {
842
+ caretPos--;
843
+ }
844
+
845
+ // Make sure caret is within min and max position limits
846
+ caretPos = caretPos > caretPosMax ? caretPosMax : caretPos < caretPosMin ? caretPosMin : caretPos;
847
+
848
+ // Scoot the caret back or forth until it's in a non-mask position and within min/max position limits
849
+ while (!isValidCaretPosition(caretPos) && caretPos > caretPosMin && caretPos < caretPosMax) {
850
+ caretPos += caretBumpBack ? -1 : 1;
851
+ }
852
+
853
+ if ((caretBumpBack && caretPos < caretPosMax) || (isAddition && !isValidCaretPosition(caretPosOld))) {
854
+ caretPos++;
855
+ }
856
+ oldCaretPosition = caretPos;
857
+ setCaretPosition(this, caretPos);
858
+ }
859
+
860
+ function isValidCaretPosition(pos){ return maskCaretMap.indexOf(pos) > -1; }
861
+
862
+ function getCaretPosition(input){
863
+ if (!input) return 0;
864
+ if (input.selectionStart !== undefined) {
865
+ return input.selectionStart;
866
+ } else if (document.selection) {
867
+ // Curse you IE
868
+ input.focus();
869
+ var selection = document.selection.createRange();
870
+ selection.moveStart('character', -input.value.length);
871
+ return selection.text.length;
872
+ }
873
+ return 0;
874
+ }
875
+
876
+ function setCaretPosition(input, pos){
877
+ if (!input) return 0;
878
+ if (input.offsetWidth === 0 || input.offsetHeight === 0) {
879
+ return; // Input's hidden
880
+ }
881
+ if (input.setSelectionRange) {
882
+ input.focus();
883
+ input.setSelectionRange(pos, pos);
884
+ }
885
+ else if (input.createTextRange) {
886
+ // Curse you IE
887
+ var range = input.createTextRange();
888
+ range.collapse(true);
889
+ range.moveEnd('character', pos);
890
+ range.moveStart('character', pos);
891
+ range.select();
892
+ }
893
+ }
894
+
895
+ function getSelectionLength(input){
896
+ if (!input) return 0;
897
+ if (input.selectionStart !== undefined) {
898
+ return (input.selectionEnd - input.selectionStart);
899
+ }
900
+ if (document.selection) {
901
+ return (document.selection.createRange().text.length);
902
+ }
903
+ return 0;
904
+ }
905
+
906
+ // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf
907
+ if (!Array.prototype.indexOf) {
908
+ Array.prototype.indexOf = function (searchElement /*, fromIndex */){
909
+ if (this === null) {
910
+ throw new TypeError();
911
+ }
912
+ var t = Object(this);
913
+ var len = t.length >>> 0;
914
+ if (len === 0) {
915
+ return -1;
916
+ }
917
+ var n = 0;
918
+ if (arguments.length > 1) {
919
+ n = Number(arguments[1]);
920
+ if (n !== n) { // shortcut for verifying if it's NaN
921
+ n = 0;
922
+ } else if (n !== 0 && n !== Infinity && n !== -Infinity) {
923
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
924
+ }
925
+ }
926
+ if (n >= len) {
927
+ return -1;
928
+ }
929
+ var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
930
+ for (; k < len; k++) {
931
+ if (k in t && t[k] === searchElement) {
932
+ return k;
933
+ }
934
+ }
935
+ return -1;
936
+ };
937
+ }
938
+
939
+ };
940
+ }
941
+ };
942
+ }
943
+ ]);
944
+
945
+ 'use strict';
946
+
947
+ /**
948
+ * Add a clear button to form inputs to reset their value
949
+ */
950
+ angular.module('ui.reset',[]).value('uiResetConfig',null).directive('uiReset', ['uiResetConfig', function (uiResetConfig) {
951
+ var resetValue = null;
952
+ if (uiResetConfig !== undefined){
953
+ resetValue = uiResetConfig;
954
+ }
955
+ return {
956
+ require: 'ngModel',
957
+ link: function (scope, elm, attrs, ctrl) {
958
+ var aElement;
959
+ aElement = angular.element('<a class="ui-reset" />');
960
+ elm.wrap('<span class="ui-resetwrap" />').after(aElement);
961
+ aElement.bind('click', function (e) {
962
+ e.preventDefault();
963
+ scope.$apply(function () {
964
+ if (attrs.uiReset){
965
+ ctrl.$setViewValue(scope.$eval(attrs.uiReset));
966
+ }else{
967
+ ctrl.$setViewValue(resetValue);
968
+ }
969
+ ctrl.$render();
970
+ });
971
+ });
972
+ }
973
+ };
974
+ }]);
975
+
976
+ 'use strict';
977
+
978
+ /**
979
+ * Set a $uiRoute boolean to see if the current route matches
980
+ */
981
+ angular.module('ui.route', []).directive('uiRoute', ['$location', '$parse', function ($location, $parse) {
982
+ return {
983
+ restrict: 'AC',
984
+ scope: true,
985
+ compile: function(tElement, tAttrs) {
986
+ var useProperty;
987
+ if (tAttrs.uiRoute) {
988
+ useProperty = 'uiRoute';
989
+ } else if (tAttrs.ngHref) {
990
+ useProperty = 'ngHref';
991
+ } else if (tAttrs.href) {
992
+ useProperty = 'href';
993
+ } else {
994
+ throw new Error('uiRoute missing a route or href property on ' + tElement[0]);
995
+ }
996
+ return function ($scope, elm, attrs) {
997
+ var modelSetter = $parse(attrs.ngModel || attrs.routeModel || '$uiRoute').assign;
998
+ var watcher = angular.noop;
999
+
1000
+ // Used by href and ngHref
1001
+ function staticWatcher(newVal) {
1002
+ var hash = newVal.indexOf('#');
1003
+ if (hash > -1){
1004
+ newVal = newVal.substr(hash + 1);
1005
+ }
1006
+ watcher = function watchHref() {
1007
+ modelSetter($scope, ($location.path().indexOf(newVal) > -1));
1008
+ };
1009
+ watcher();
1010
+ }
1011
+ // Used by uiRoute
1012
+ function regexWatcher(newVal) {
1013
+ var hash = newVal.indexOf('#');
1014
+ if (hash > -1){
1015
+ newVal = newVal.substr(hash + 1);
1016
+ }
1017
+ watcher = function watchRegex() {
1018
+ var regexp = new RegExp('^' + newVal + '$', ['i']);
1019
+ modelSetter($scope, regexp.test($location.path()));
1020
+ };
1021
+ watcher();
1022
+ }
1023
+
1024
+ switch (useProperty) {
1025
+ case 'uiRoute':
1026
+ // if uiRoute={{}} this will be undefined, otherwise it will have a value and $observe() never gets triggered
1027
+ if (attrs.uiRoute){
1028
+ regexWatcher(attrs.uiRoute);
1029
+ }else{
1030
+ attrs.$observe('uiRoute', regexWatcher);
1031
+ }
1032
+ break;
1033
+ case 'ngHref':
1034
+ // Setup watcher() every time ngHref changes
1035
+ if (attrs.ngHref){
1036
+ staticWatcher(attrs.ngHref);
1037
+ }else{
1038
+ attrs.$observe('ngHref', staticWatcher);
1039
+ }
1040
+ break;
1041
+ case 'href':
1042
+ // Setup watcher()
1043
+ staticWatcher(attrs.href);
1044
+ }
1045
+
1046
+ $scope.$on('$routeChangeSuccess', function(){
1047
+ watcher();
1048
+ });
1049
+
1050
+ //Added for compatibility with ui-router
1051
+ $scope.$on('$stateChangeSuccess', function(){
1052
+ watcher();
1053
+ });
1054
+ };
1055
+ }
1056
+ };
1057
+ }]);
1058
+
1059
+ 'use strict';
1060
+
1061
+ angular.module('ui.scroll.jqlite', ['ui.scroll']).service('jqLiteExtras', [
1062
+ '$log', '$window', function(console, window) {
1063
+ return {
1064
+ registerFor: function(element) {
1065
+ var convertToPx, css, getMeasurements, getStyle, getWidthHeight, isWindow, scrollTo;
1066
+ css = angular.element.prototype.css;
1067
+ element.prototype.css = function(name, value) {
1068
+ var elem, self;
1069
+ self = this;
1070
+ elem = self[0];
1071
+ if (!(!elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style)) {
1072
+ return css.call(self, name, value);
1073
+ }
1074
+ };
1075
+ isWindow = function(obj) {
1076
+ return obj && obj.document && obj.location && obj.alert && obj.setInterval;
1077
+ };
1078
+ scrollTo = function(self, direction, value) {
1079
+ var elem, method, preserve, prop, _ref;
1080
+ elem = self[0];
1081
+ _ref = {
1082
+ top: ['scrollTop', 'pageYOffset', 'scrollLeft'],
1083
+ left: ['scrollLeft', 'pageXOffset', 'scrollTop']
1084
+ }[direction], method = _ref[0], prop = _ref[1], preserve = _ref[2];
1085
+ if (isWindow(elem)) {
1086
+ if (angular.isDefined(value)) {
1087
+ return elem.scrollTo(self[preserve].call(self), value);
1088
+ } else {
1089
+ if (prop in elem) {
1090
+ return elem[prop];
1091
+ } else {
1092
+ return elem.document.documentElement[method];
1093
+ }
1094
+ }
1095
+ } else {
1096
+ if (angular.isDefined(value)) {
1097
+ return elem[method] = value;
1098
+ } else {
1099
+ return elem[method];
1100
+ }
1101
+ }
1102
+ };
1103
+ if (window.getComputedStyle) {
1104
+ getStyle = function(elem) {
1105
+ return window.getComputedStyle(elem, null);
1106
+ };
1107
+ convertToPx = function(elem, value) {
1108
+ return parseFloat(value);
1109
+ };
1110
+ } else {
1111
+ getStyle = function(elem) {
1112
+ return elem.currentStyle;
1113
+ };
1114
+ convertToPx = function(elem, value) {
1115
+ var core_pnum, left, result, rnumnonpx, rs, rsLeft, style;
1116
+ core_pnum = /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source;
1117
+ rnumnonpx = new RegExp('^(' + core_pnum + ')(?!px)[a-z%]+$', 'i');
1118
+ if (!rnumnonpx.test(value)) {
1119
+ return parseFloat(value);
1120
+ } else {
1121
+ style = elem.style;
1122
+ left = style.left;
1123
+ rs = elem.runtimeStyle;
1124
+ rsLeft = rs && rs.left;
1125
+ if (rs) {
1126
+ rs.left = style.left;
1127
+ }
1128
+ style.left = value;
1129
+ result = style.pixelLeft;
1130
+ style.left = left;
1131
+ if (rsLeft) {
1132
+ rs.left = rsLeft;
1133
+ }
1134
+ return result;
1135
+ }
1136
+ };
1137
+ }
1138
+ getMeasurements = function(elem, measure) {
1139
+ var base, borderA, borderB, computedMarginA, computedMarginB, computedStyle, dirA, dirB, marginA, marginB, paddingA, paddingB, _ref;
1140
+ if (isWindow(elem)) {
1141
+ base = document.documentElement[{
1142
+ height: 'clientHeight',
1143
+ width: 'clientWidth'
1144
+ }[measure]];
1145
+ return {
1146
+ base: base,
1147
+ padding: 0,
1148
+ border: 0,
1149
+ margin: 0
1150
+ };
1151
+ }
1152
+ _ref = {
1153
+ width: [elem.offsetWidth, 'Left', 'Right'],
1154
+ height: [elem.offsetHeight, 'Top', 'Bottom']
1155
+ }[measure], base = _ref[0], dirA = _ref[1], dirB = _ref[2];
1156
+ computedStyle = getStyle(elem);
1157
+ paddingA = convertToPx(elem, computedStyle['padding' + dirA]) || 0;
1158
+ paddingB = convertToPx(elem, computedStyle['padding' + dirB]) || 0;
1159
+ borderA = convertToPx(elem, computedStyle['border' + dirA + 'Width']) || 0;
1160
+ borderB = convertToPx(elem, computedStyle['border' + dirB + 'Width']) || 0;
1161
+ computedMarginA = computedStyle['margin' + dirA];
1162
+ computedMarginB = computedStyle['margin' + dirB];
1163
+ marginA = convertToPx(elem, computedMarginA) || 0;
1164
+ marginB = convertToPx(elem, computedMarginB) || 0;
1165
+ return {
1166
+ base: base,
1167
+ padding: paddingA + paddingB,
1168
+ border: borderA + borderB,
1169
+ margin: marginA + marginB
1170
+ };
1171
+ };
1172
+ getWidthHeight = function(elem, direction, measure) {
1173
+ var computedStyle, measurements, result;
1174
+ measurements = getMeasurements(elem, direction);
1175
+ if (measurements.base > 0) {
1176
+ return {
1177
+ base: measurements.base - measurements.padding - measurements.border,
1178
+ outer: measurements.base,
1179
+ outerfull: measurements.base + measurements.margin
1180
+ }[measure];
1181
+ } else {
1182
+ computedStyle = getStyle(elem);
1183
+ result = computedStyle[direction];
1184
+ if (result < 0 || result === null) {
1185
+ result = elem.style[direction] || 0;
1186
+ }
1187
+ result = parseFloat(result) || 0;
1188
+ return {
1189
+ base: result - measurements.padding - measurements.border,
1190
+ outer: result,
1191
+ outerfull: result + measurements.padding + measurements.border + measurements.margin
1192
+ }[measure];
1193
+ }
1194
+ };
1195
+ return angular.forEach({
1196
+ before: function(newElem) {
1197
+ var children, elem, i, parent, self, _i, _ref;
1198
+ self = this;
1199
+ elem = self[0];
1200
+ parent = self.parent();
1201
+ children = parent.contents();
1202
+ if (children[0] === elem) {
1203
+ return parent.prepend(newElem);
1204
+ } else {
1205
+ for (i = _i = 1, _ref = children.length - 1; 1 <= _ref ? _i <= _ref : _i >= _ref; i = 1 <= _ref ? ++_i : --_i) {
1206
+ if (children[i] === elem) {
1207
+ angular.element(children[i - 1]).after(newElem);
1208
+ return;
1209
+ }
1210
+ }
1211
+ throw new Error('invalid DOM structure ' + elem.outerHTML);
1212
+ }
1213
+ },
1214
+ height: function(value) {
1215
+ var self;
1216
+ self = this;
1217
+ if (angular.isDefined(value)) {
1218
+ if (angular.isNumber(value)) {
1219
+ value = value + 'px';
1220
+ }
1221
+ return css.call(self, 'height', value);
1222
+ } else {
1223
+ return getWidthHeight(this[0], 'height', 'base');
1224
+ }
1225
+ },
1226
+ outerHeight: function(option) {
1227
+ return getWidthHeight(this[0], 'height', option ? 'outerfull' : 'outer');
1228
+ },
1229
+ offset: function(value) {
1230
+ var box, doc, docElem, elem, self, win;
1231
+ self = this;
1232
+ if (arguments.length) {
1233
+ if (value === void 0) {
1234
+ return self;
1235
+ } else {
1236
+ return value;
1237
+
1238
+ }
1239
+ }
1240
+ box = {
1241
+ top: 0,
1242
+ left: 0
1243
+ };
1244
+ elem = self[0];
1245
+ doc = elem && elem.ownerDocument;
1246
+ if (!doc) {
1247
+ return;
1248
+ }
1249
+ docElem = doc.documentElement;
1250
+ if (elem.getBoundingClientRect) {
1251
+ box = elem.getBoundingClientRect();
1252
+ }
1253
+ win = doc.defaultView || doc.parentWindow;
1254
+ return {
1255
+ top: box.top + (win.pageYOffset || docElem.scrollTop) - (docElem.clientTop || 0),
1256
+ left: box.left + (win.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || 0)
1257
+ };
1258
+ },
1259
+ scrollTop: function(value) {
1260
+ return scrollTo(this, 'top', value);
1261
+ },
1262
+ scrollLeft: function(value) {
1263
+ return scrollTo(this, 'left', value);
1264
+ }
1265
+ }, function(value, key) {
1266
+ if (!element.prototype[key]) {
1267
+ return element.prototype[key] = value;
1268
+ }
1269
+ });
1270
+ }
1271
+ };
1272
+ }
1273
+ ]).run([
1274
+ '$log', '$window', 'jqLiteExtras', function(console, window, jqLiteExtras) {
1275
+ if (!window.jQuery) {
1276
+ return jqLiteExtras.registerFor(angular.element);
1277
+ }
1278
+ }
1279
+ ]);
1280
+
1281
+ 'use strict';
1282
+ /*
1283
+
1284
+ List of used element methods available in JQuery but not in JQuery Lite
1285
+
1286
+ element.before(elem)
1287
+ element.height()
1288
+ element.outerHeight(true)
1289
+ element.height(value) = only for Top/Bottom padding elements
1290
+ element.scrollTop()
1291
+ element.scrollTop(value)
1292
+ */
1293
+
1294
+ angular.module('ui.scroll', []).directive('ngScrollViewport', [
1295
+ '$log', function() {
1296
+ return {
1297
+ controller: [
1298
+ '$scope', '$element', function(scope, element) {
1299
+ return element;
1300
+ }
1301
+ ]
1302
+ };
1303
+ }
1304
+ ]).directive('ngScroll', [
1305
+ '$log', '$injector', '$rootScope', '$timeout', function(console, $injector, $rootScope, $timeout) {
1306
+ return {
1307
+ require: ['?^ngScrollViewport'],
1308
+ transclude: 'element',
1309
+ priority: 1000,
1310
+ terminal: true,
1311
+ compile: function(element, attr, linker) {
1312
+ return function($scope, $element, $attr, controllers) {
1313
+ var adapter, adjustBuffer, adjustRowHeight, bof, bottomVisiblePos, buffer, bufferPadding, bufferSize, clipBottom, clipTop, datasource, datasourceName, enqueueFetch, eof, eventListener, fetch, finalize, first, insert, isDatasource, isLoading, itemName, loading, match, next, pending, reload, removeFromBuffer, resizeHandler, scrollHandler, scrollHeight, shouldLoadBottom, shouldLoadTop, tempScope, topVisiblePos, viewport;
1314
+ match = $attr.ngScroll.match(/^\s*(\w+)\s+in\s+(\w+)\s*$/);
1315
+ if (!match) {
1316
+ throw new Error('Expected ngScroll in form of "item_ in _datasource_" but got "' + $attr.ngScroll + '"');
1317
+ }
1318
+ itemName = match[1];
1319
+ datasourceName = match[2];
1320
+ isDatasource = function(datasource) {
1321
+ return angular.isObject(datasource) && datasource.get && angular.isFunction(datasource.get);
1322
+ };
1323
+ datasource = $scope[datasourceName];
1324
+ if (!isDatasource(datasource)) {
1325
+ datasource = $injector.get(datasourceName);
1326
+ if (!isDatasource(datasource)) {
1327
+ throw new Error(datasourceName + ' is not a valid datasource');
1328
+ }
1329
+ }
1330
+ bufferSize = Math.max(3, +$attr.bufferSize || 10);
1331
+ bufferPadding = function() {
1332
+ return viewport.height() * Math.max(0.1, +$attr.padding || 0.1);
1333
+ };
1334
+ scrollHeight = function(elem) {
1335
+ return elem[0].scrollHeight || elem[0].document.documentElement.scrollHeight;
1336
+ };
1337
+ adapter = null;
1338
+ linker(tempScope = $scope.$new(), function(template) {
1339
+ var bottomPadding, createPadding, padding, repeaterType, topPadding, viewport;
1340
+ repeaterType = template[0].localName;
1341
+ if (repeaterType === 'dl') {
1342
+ throw new Error('ng-scroll directive does not support <' + template[0].localName + '> as a repeating tag: ' + template[0].outerHTML);
1343
+ }
1344
+ if (repeaterType !== 'li' && repeaterType !== 'tr') {
1345
+ repeaterType = 'div';
1346
+ }
1347
+ viewport = controllers[0] || angular.element(window);
1348
+ viewport.css({
1349
+ 'overflow-y': 'auto',
1350
+ 'display': 'block'
1351
+ });
1352
+ padding = function(repeaterType) {
1353
+ var div, result, table;
1354
+ switch (repeaterType) {
1355
+ case 'tr':
1356
+ table = angular.element('<table><tr><td><div></div></td></tr></table>');
1357
+ div = table.find('div');
1358
+ result = table.find('tr');
1359
+ result.paddingHeight = function() {
1360
+ return div.height.apply(div, arguments);
1361
+ };
1362
+ return result;
1363
+ default:
1364
+ result = angular.element('<' + repeaterType + '></' + repeaterType + '>');
1365
+ result.paddingHeight = result.height;
1366
+ return result;
1367
+ }
1368
+ };
1369
+ createPadding = function(padding, element, direction) {
1370
+ element[{
1371
+ top: 'before',
1372
+ bottom: 'after'
1373
+ }[direction]](padding);
1374
+ return {
1375
+ paddingHeight: function() {
1376
+ return padding.paddingHeight.apply(padding, arguments);
1377
+ },
1378
+ insert: function(element) {
1379
+ return padding[{
1380
+ top: 'after',
1381
+ bottom: 'before'
1382
+ }[direction]](element);
1383
+ }
1384
+ };
1385
+ };
1386
+ topPadding = createPadding(padding(repeaterType), element, 'top');
1387
+ bottomPadding = createPadding(padding(repeaterType), element, 'bottom');
1388
+ tempScope.$destroy();
1389
+ return adapter = {
1390
+ viewport: viewport,
1391
+ topPadding: topPadding.paddingHeight,
1392
+ bottomPadding: bottomPadding.paddingHeight,
1393
+ append: bottomPadding.insert,
1394
+ prepend: topPadding.insert,
1395
+ bottomDataPos: function() {
1396
+ return scrollHeight(viewport) - bottomPadding.paddingHeight();
1397
+ },
1398
+ topDataPos: function() {
1399
+ return topPadding.paddingHeight();
1400
+ }
1401
+ };
1402
+ });
1403
+ viewport = adapter.viewport;
1404
+ first = 1;
1405
+ next = 1;
1406
+ buffer = [];
1407
+ pending = [];
1408
+ eof = false;
1409
+ bof = false;
1410
+ loading = datasource.loading || function() {};
1411
+ isLoading = false;
1412
+ removeFromBuffer = function(start, stop) {
1413
+ var i, _i;
1414
+ for (i = _i = start; start <= stop ? _i < stop : _i > stop; i = start <= stop ? ++_i : --_i) {
1415
+ buffer[i].scope.$destroy();
1416
+ buffer[i].element.remove();
1417
+ }
1418
+ return buffer.splice(start, stop - start);
1419
+ };
1420
+ reload = function() {
1421
+ first = 1;
1422
+ next = 1;
1423
+ removeFromBuffer(0, buffer.length);
1424
+ adapter.topPadding(0);
1425
+ adapter.bottomPadding(0);
1426
+ pending = [];
1427
+ eof = false;
1428
+ bof = false;
1429
+ return adjustBuffer(false);
1430
+ };
1431
+ bottomVisiblePos = function() {
1432
+ return viewport.scrollTop() + viewport.height();
1433
+ };
1434
+ topVisiblePos = function() {
1435
+ return viewport.scrollTop();
1436
+ };
1437
+ shouldLoadBottom = function() {
1438
+ return !eof && adapter.bottomDataPos() < bottomVisiblePos() + bufferPadding();
1439
+ };
1440
+ clipBottom = function() {
1441
+ var bottomHeight, i, itemHeight, overage, _i, _ref;
1442
+ bottomHeight = 0;
1443
+ overage = 0;
1444
+ for (i = _i = _ref = buffer.length - 1; _ref <= 0 ? _i <= 0 : _i >= 0; i = _ref <= 0 ? ++_i : --_i) {
1445
+ itemHeight = buffer[i].element.outerHeight(true);
1446
+ if (adapter.bottomDataPos() - bottomHeight - itemHeight > bottomVisiblePos() + bufferPadding()) {
1447
+ bottomHeight += itemHeight;
1448
+ overage++;
1449
+ eof = false;
1450
+ } else {
1451
+ break;
1452
+ }
1453
+ }
1454
+ if (overage > 0) {
1455
+ adapter.bottomPadding(adapter.bottomPadding() + bottomHeight);
1456
+ removeFromBuffer(buffer.length - overage, buffer.length);
1457
+ next -= overage;
1458
+ return console.log('clipped off bottom ' + overage + ' bottom padding ' + (adapter.bottomPadding()));
1459
+ }
1460
+ };
1461
+ shouldLoadTop = function() {
1462
+ return !bof && (adapter.topDataPos() > topVisiblePos() - bufferPadding());
1463
+ };
1464
+ clipTop = function() {
1465
+ var item, itemHeight, overage, topHeight, _i, _len;
1466
+ topHeight = 0;
1467
+ overage = 0;
1468
+ for (_i = 0, _len = buffer.length; _i < _len; _i++) {
1469
+ item = buffer[_i];
1470
+ itemHeight = item.element.outerHeight(true);
1471
+ if (adapter.topDataPos() + topHeight + itemHeight < topVisiblePos() - bufferPadding()) {
1472
+ topHeight += itemHeight;
1473
+ overage++;
1474
+ bof = false;
1475
+ } else {
1476
+ break;
1477
+ }
1478
+ }
1479
+ if (overage > 0) {
1480
+ adapter.topPadding(adapter.topPadding() + topHeight);
1481
+ removeFromBuffer(0, overage);
1482
+ first += overage;
1483
+ return console.log('clipped off top ' + overage + ' top padding ' + (adapter.topPadding()));
1484
+ }
1485
+ };
1486
+ enqueueFetch = function(direction, scrolling) {
1487
+ if (!isLoading) {
1488
+ isLoading = true;
1489
+ loading(true);
1490
+ }
1491
+ if (pending.push(direction) === 1) {
1492
+ return fetch(scrolling);
1493
+ }
1494
+ };
1495
+ insert = function(index, item) {
1496
+ var itemScope, toBeAppended, wrapper;
1497
+ itemScope = $scope.$new();
1498
+ itemScope[itemName] = item;
1499
+ toBeAppended = index > first;
1500
+ itemScope.$index = index;
1501
+ if (toBeAppended) {
1502
+ itemScope.$index--;
1503
+ }
1504
+ wrapper = {
1505
+ scope: itemScope
1506
+ };
1507
+ linker(itemScope, function(clone) {
1508
+ wrapper.element = clone;
1509
+ if (toBeAppended) {
1510
+ if (index === next) {
1511
+ adapter.append(clone);
1512
+ return buffer.push(wrapper);
1513
+ } else {
1514
+ buffer[index - first].element.after(clone);
1515
+ return buffer.splice(index - first + 1, 0, wrapper);
1516
+ }
1517
+ } else {
1518
+ adapter.prepend(clone);
1519
+ return buffer.unshift(wrapper);
1520
+ }
1521
+ });
1522
+ return {
1523
+ appended: toBeAppended,
1524
+ wrapper: wrapper
1525
+ };
1526
+ };
1527
+ adjustRowHeight = function(appended, wrapper) {
1528
+ var newHeight;
1529
+ if (appended) {
1530
+ return adapter.bottomPadding(Math.max(0, adapter.bottomPadding() - wrapper.element.outerHeight(true)));
1531
+ } else {
1532
+ newHeight = adapter.topPadding() - wrapper.element.outerHeight(true);
1533
+ if (newHeight >= 0) {
1534
+ return adapter.topPadding(newHeight);
1535
+ } else {
1536
+ return viewport.scrollTop(viewport.scrollTop() + wrapper.element.outerHeight(true));
1537
+ }
1538
+ }
1539
+ };
1540
+ adjustBuffer = function(scrolling, newItems, finalize) {
1541
+ var doAdjustment;
1542
+ doAdjustment = function() {
1543
+ console.log('top {actual=' + (adapter.topDataPos()) + ' visible from=' + (topVisiblePos()) + ' bottom {visible through=' + (bottomVisiblePos()) + ' actual=' + (adapter.bottomDataPos()) + '}');
1544
+ if (shouldLoadBottom()) {
1545
+ enqueueFetch(true, scrolling);
1546
+ } else {
1547
+ if (shouldLoadTop()) {
1548
+ enqueueFetch(false, scrolling);
1549
+ }
1550
+ }
1551
+ if (finalize) {
1552
+ return finalize();
1553
+ }
1554
+ };
1555
+ if (newItems) {
1556
+ return $timeout(function() {
1557
+ var row, _i, _len;
1558
+ for (_i = 0, _len = newItems.length; _i < _len; _i++) {
1559
+ row = newItems[_i];
1560
+ adjustRowHeight(row.appended, row.wrapper);
1561
+ }
1562
+ return doAdjustment();
1563
+ });
1564
+ } else {
1565
+ return doAdjustment();
1566
+ }
1567
+ };
1568
+ finalize = function(scrolling, newItems) {
1569
+ return adjustBuffer(scrolling, newItems, function() {
1570
+ pending.shift();
1571
+ if (pending.length === 0) {
1572
+ isLoading = false;
1573
+ return loading(false);
1574
+ } else {
1575
+ return fetch(scrolling);
1576
+ }
1577
+ });
1578
+ };
1579
+ fetch = function(scrolling) {
1580
+ var direction;
1581
+ direction = pending[0];
1582
+ if (direction) {
1583
+ if (buffer.length && !shouldLoadBottom()) {
1584
+ return finalize(scrolling);
1585
+ } else {
1586
+ return datasource.get(next, bufferSize, function(result) {
1587
+ var item, newItems, _i, _len;
1588
+ newItems = [];
1589
+ if (result.length === 0) {
1590
+ eof = true;
1591
+ adapter.bottomPadding(0);
1592
+ console.log('appended: requested ' + bufferSize + ' records starting from ' + next + ' recieved: eof');
1593
+ } else {
1594
+ clipTop();
1595
+ for (_i = 0, _len = result.length; _i < _len; _i++) {
1596
+ item = result[_i];
1597
+ newItems.push(insert(++next, item));
1598
+ }
1599
+ console.log('appended: requested ' + bufferSize + ' received ' + result.length + ' buffer size ' + buffer.length + ' first ' + first + ' next ' + next);
1600
+ }
1601
+ return finalize(scrolling, newItems);
1602
+ });
1603
+ }
1604
+ } else {
1605
+ if (buffer.length && !shouldLoadTop()) {
1606
+ return finalize(scrolling);
1607
+ } else {
1608
+ return datasource.get(first - bufferSize, bufferSize, function(result) {
1609
+ var i, newItems, _i, _ref;
1610
+ newItems = [];
1611
+ if (result.length === 0) {
1612
+ bof = true;
1613
+ adapter.topPadding(0);
1614
+ console.log('prepended: requested ' + bufferSize + ' records starting from ' + (first - bufferSize) + ' recieved: bof');
1615
+ } else {
1616
+ clipBottom();
1617
+ for (i = _i = _ref = result.length - 1; _ref <= 0 ? _i <= 0 : _i >= 0; i = _ref <= 0 ? ++_i : --_i) {
1618
+ newItems.unshift(insert(--first, result[i]));
1619
+ }
1620
+ console.log('prepended: requested ' + bufferSize + ' received ' + result.length + ' buffer size ' + buffer.length + ' first ' + first + ' next ' + next);
1621
+ }
1622
+ return finalize(scrolling, newItems);
1623
+ });
1624
+ }
1625
+ }
1626
+ };
1627
+ resizeHandler = function() {
1628
+ if (!$rootScope.$$phase && !isLoading) {
1629
+ adjustBuffer(false);
1630
+ return $scope.$apply();
1631
+ }
1632
+ };
1633
+ viewport.bind('resize', resizeHandler);
1634
+ scrollHandler = function() {
1635
+ if (!$rootScope.$$phase && !isLoading) {
1636
+ adjustBuffer(true);
1637
+ return $scope.$apply();
1638
+ }
1639
+ };
1640
+ viewport.bind('scroll', scrollHandler);
1641
+ $scope.$watch(datasource.revision, function() {
1642
+ return reload();
1643
+ });
1644
+ if (datasource.scope) {
1645
+ eventListener = datasource.scope.$new();
1646
+ } else {
1647
+ eventListener = $scope.$new();
1648
+ }
1649
+ $scope.$on('$destroy', function() {
1650
+ eventListener.$destroy();
1651
+ viewport.unbind('resize', resizeHandler);
1652
+ return viewport.unbind('scroll', scrollHandler);
1653
+ });
1654
+ eventListener.$on('update.items', function(event, locator, newItem) {
1655
+ var wrapper, _fn, _i, _len, _ref;
1656
+ if (angular.isFunction(locator)) {
1657
+ _fn = function(wrapper) {
1658
+ return locator(wrapper.scope);
1659
+ };
1660
+ for (_i = 0, _len = buffer.length; _i < _len; _i++) {
1661
+ wrapper = buffer[_i];
1662
+ _fn(wrapper);
1663
+ }
1664
+ } else {
1665
+ if ((0 <= (_ref = locator - first - 1) && _ref < buffer.length)) {
1666
+ buffer[locator - first - 1].scope[itemName] = newItem;
1667
+ }
1668
+ }
1669
+ return null;
1670
+ });
1671
+ eventListener.$on('delete.items', function(event, locator) {
1672
+ var i, item, temp, wrapper, _fn, _i, _j, _k, _len, _len1, _len2, _ref;
1673
+ if (angular.isFunction(locator)) {
1674
+ temp = [];
1675
+ for (_i = 0, _len = buffer.length; _i < _len; _i++) {
1676
+ item = buffer[_i];
1677
+ temp.unshift(item);
1678
+ }
1679
+ _fn = function(wrapper) {
1680
+ if (locator(wrapper.scope)) {
1681
+ removeFromBuffer(temp.length - 1 - i, temp.length - i);
1682
+ return next--;
1683
+ }
1684
+ };
1685
+ for (i = _j = 0, _len1 = temp.length; _j < _len1; i = ++_j) {
1686
+ wrapper = temp[i];
1687
+ _fn(wrapper);
1688
+ }
1689
+ } else {
1690
+ if ((0 <= (_ref = locator - first - 1) && _ref < buffer.length)) {
1691
+ removeFromBuffer(locator - first - 1, locator - first);
1692
+ next--;
1693
+ }
1694
+ }
1695
+ for (i = _k = 0, _len2 = buffer.length; _k < _len2; i = ++_k) {
1696
+ item = buffer[i];
1697
+ item.scope.$index = first + i;
1698
+ }
1699
+ return adjustBuffer(false);
1700
+ });
1701
+ return eventListener.$on('insert.item', function(event, locator, item) {
1702
+ var i, inserted, temp, wrapper, _fn, _i, _j, _k, _len, _len1, _len2, _ref;
1703
+ inserted = [];
1704
+ if (angular.isFunction(locator)) {
1705
+ temp = [];
1706
+ for (_i = 0, _len = buffer.length; _i < _len; _i++) {
1707
+ item = buffer[_i];
1708
+ temp.unshift(item);
1709
+ }
1710
+ _fn = function(wrapper) {
1711
+ var j, newItems, _k, _len2, _results;
1712
+ if (newItems = locator(wrapper.scope)) {
1713
+ insert = function(index, newItem) {
1714
+ insert(index, newItem);
1715
+ return next++;
1716
+ };
1717
+ if (angular.isArray(newItems)) {
1718
+ _results = [];
1719
+ for (j = _k = 0, _len2 = newItems.length; _k < _len2; j = ++_k) {
1720
+ item = newItems[j];
1721
+ _results.push(inserted.push(insert(i + j, item)));
1722
+ }
1723
+ return _results;
1724
+ } else {
1725
+ return inserted.push(insert(i, newItems));
1726
+ }
1727
+ }
1728
+ };
1729
+ for (i = _j = 0, _len1 = temp.length; _j < _len1; i = ++_j) {
1730
+ wrapper = temp[i];
1731
+ _fn(wrapper);
1732
+ }
1733
+ } else {
1734
+ if ((0 <= (_ref = locator - first - 1) && _ref < buffer.length)) {
1735
+ inserted.push(insert(locator, item));
1736
+ next++;
1737
+ }
1738
+ }
1739
+ for (i = _k = 0, _len2 = buffer.length; _k < _len2; i = ++_k) {
1740
+ item = buffer[i];
1741
+ item.scope.$index = first + i;
1742
+ }
1743
+ return adjustBuffer(false, inserted);
1744
+ });
1745
+ };
1746
+ }
1747
+ };
1748
+ }
1749
+ ]);
1750
+
1751
+ 'use strict';
1752
+
1753
+ /**
1754
+ * Adds a 'ui-scrollfix' class to the element when the page scrolls past it's position.
1755
+ * @param [offset] {int} optional Y-offset to override the detected offset.
1756
+ * Takes 300 (absolute) or -300 or +300 (relative to detected)
1757
+ */
1758
+ angular.module('ui.scrollfix',[]).directive('uiScrollfix', ['$window', function ($window) {
1759
+ return {
1760
+ require: '^?uiScrollfixTarget',
1761
+ link: function (scope, elm, attrs, uiScrollfixTarget) {
1762
+ var top = elm[0].offsetTop,
1763
+ $target = uiScrollfixTarget && uiScrollfixTarget.$element || angular.element($window);
1764
+
1765
+ if (!attrs.uiScrollfix) {
1766
+ attrs.uiScrollfix = top;
1767
+ } else if (typeof(attrs.uiScrollfix) === 'string') {
1768
+ // charAt is generally faster than indexOf: http://jsperf.com/indexof-vs-charat
1769
+ if (attrs.uiScrollfix.charAt(0) === '-') {
1770
+ attrs.uiScrollfix = top - parseFloat(attrs.uiScrollfix.substr(1));
1771
+ } else if (attrs.uiScrollfix.charAt(0) === '+') {
1772
+ attrs.uiScrollfix = top + parseFloat(attrs.uiScrollfix.substr(1));
1773
+ }
1774
+ }
1775
+
1776
+ function onScroll() {
1777
+ // if pageYOffset is defined use it, otherwise use other crap for IE
1778
+ var offset;
1779
+ if (angular.isDefined($window.pageYOffset)) {
1780
+ offset = $window.pageYOffset;
1781
+ } else {
1782
+ var iebody = (document.compatMode && document.compatMode !== 'BackCompat') ? document.documentElement : document.body;
1783
+ offset = iebody.scrollTop;
1784
+ }
1785
+ if (!elm.hasClass('ui-scrollfix') && offset > attrs.uiScrollfix) {
1786
+ elm.addClass('ui-scrollfix');
1787
+ } else if (elm.hasClass('ui-scrollfix') && offset < attrs.uiScrollfix) {
1788
+ elm.removeClass('ui-scrollfix');
1789
+ }
1790
+ }
1791
+
1792
+ $target.on('scroll', onScroll);
1793
+
1794
+ // Unbind scroll event handler when directive is removed
1795
+ scope.$on('$destroy', function() {
1796
+ $target.off('scroll', onScroll);
1797
+ });
1798
+ }
1799
+ };
1800
+ }]).directive('uiScrollfixTarget', [function () {
1801
+ return {
1802
+ controller: ['$element', function($element) {
1803
+ this.$element = $element;
1804
+ }]
1805
+ };
1806
+ }]);
1807
+
1808
+ 'use strict';
1809
+
1810
+ /**
1811
+ * uiShow Directive
1812
+ *
1813
+ * Adds a 'ui-show' class to the element instead of display:block
1814
+ * Created to allow tighter control of CSS without bulkier directives
1815
+ *
1816
+ * @param expression {boolean} evaluated expression to determine if the class should be added
1817
+ */
1818
+ angular.module('ui.showhide',[])
1819
+ .directive('uiShow', [function () {
1820
+ return function (scope, elm, attrs) {
1821
+ scope.$watch(attrs.uiShow, function (newVal) {
1822
+ if (newVal) {
1823
+ elm.addClass('ui-show');
1824
+ } else {
1825
+ elm.removeClass('ui-show');
1826
+ }
1827
+ });
1828
+ };
1829
+ }])
1830
+
1831
+ /**
1832
+ * uiHide Directive
1833
+ *
1834
+ * Adds a 'ui-hide' class to the element instead of display:block
1835
+ * Created to allow tighter control of CSS without bulkier directives
1836
+ *
1837
+ * @param expression {boolean} evaluated expression to determine if the class should be added
1838
+ */
1839
+ .directive('uiHide', [function () {
1840
+ return function (scope, elm, attrs) {
1841
+ scope.$watch(attrs.uiHide, function (newVal) {
1842
+ if (newVal) {
1843
+ elm.addClass('ui-hide');
1844
+ } else {
1845
+ elm.removeClass('ui-hide');
1846
+ }
1847
+ });
1848
+ };
1849
+ }])
1850
+
1851
+ /**
1852
+ * uiToggle Directive
1853
+ *
1854
+ * Adds a class 'ui-show' if true, and a 'ui-hide' if false to the element instead of display:block/display:none
1855
+ * Created to allow tighter control of CSS without bulkier directives. This also allows you to override the
1856
+ * default visibility of the element using either class.
1857
+ *
1858
+ * @param expression {boolean} evaluated expression to determine if the class should be added
1859
+ */
1860
+ .directive('uiToggle', [function () {
1861
+ return function (scope, elm, attrs) {
1862
+ scope.$watch(attrs.uiToggle, function (newVal) {
1863
+ if (newVal) {
1864
+ elm.removeClass('ui-hide').addClass('ui-show');
1865
+ } else {
1866
+ elm.removeClass('ui-show').addClass('ui-hide');
1867
+ }
1868
+ });
1869
+ };
1870
+ }]);
1871
+
1872
+ 'use strict';
1873
+
1874
+ /**
1875
+ * Filters out all duplicate items from an array by checking the specified key
1876
+ * @param [key] {string} the name of the attribute of each object to compare for uniqueness
1877
+ if the key is empty, the entire object will be compared
1878
+ if the key === false then no filtering will be performed
1879
+ * @return {array}
1880
+ */
1881
+ angular.module('ui.unique',[]).filter('unique', ['$parse', function ($parse) {
1882
+
1883
+ return function (items, filterOn) {
1884
+
1885
+ if (filterOn === false) {
1886
+ return items;
1887
+ }
1888
+
1889
+ if ((filterOn || angular.isUndefined(filterOn)) && angular.isArray(items)) {
1890
+ var newItems = [],
1891
+ get = angular.isString(filterOn) ? $parse(filterOn) : function (item) { return item; };
1892
+
1893
+ var extractValueToCompare = function (item) {
1894
+ return angular.isObject(item) ? get(item) : item;
1895
+ };
1896
+
1897
+ angular.forEach(items, function (item) {
1898
+ var isDuplicate = false;
1899
+
1900
+ for (var i = 0; i < newItems.length; i++) {
1901
+ if (angular.equals(extractValueToCompare(newItems[i]), extractValueToCompare(item))) {
1902
+ isDuplicate = true;
1903
+ break;
1904
+ }
1905
+ }
1906
+ if (!isDuplicate) {
1907
+ newItems.push(item);
1908
+ }
1909
+
1910
+ });
1911
+ items = newItems;
1912
+ }
1913
+ return items;
1914
+ };
1915
+ }]);
1916
+
1917
+ 'use strict';
1918
+
1919
+ /**
1920
+ * General-purpose validator for ngModel.
1921
+ * angular-pack.js comes with several built-in validation mechanism for input fields (ngRequired, ngPattern etc.) but using
1922
+ * an arbitrary validation function requires creation of a custom formatters and / or parsers.
1923
+ * The ui-validate directive makes it easy to use any function(s) defined in scope as a validator function(s).
1924
+ * A validator function will trigger validation on both model and input changes.
1925
+ *
1926
+ * @example <input ui-validate=" 'myValidatorFunction($value)' ">
1927
+ * @example <input ui-validate="{ foo : '$value > anotherModel', bar : 'validateFoo($value)' }">
1928
+ * @example <input ui-validate="{ foo : '$value > anotherModel' }" ui-validate-watch=" 'anotherModel' ">
1929
+ * @example <input ui-validate="{ foo : '$value > anotherModel', bar : 'validateFoo($value)' }" ui-validate-watch=" { foo : 'anotherModel' } ">
1930
+ *
1931
+ * @param ui-validate {string|object literal} If strings is passed it should be a scope's function to be used as a validator.
1932
+ * If an object literal is passed a key denotes a validation error key while a value should be a validator function.
1933
+ * In both cases validator function should take a value to validate as its argument and should return true/false indicating a validation result.
1934
+ */
1935
+ angular.module('ui.validate',[]).directive('uiValidate', function () {
1936
+
1937
+ return {
1938
+ restrict: 'A',
1939
+ require: 'ngModel',
1940
+ link: function (scope, elm, attrs, ctrl) {
1941
+ var validateFn, validators = {},
1942
+ validateExpr = scope.$eval(attrs.uiValidate);
1943
+
1944
+ if (!validateExpr){ return;}
1945
+
1946
+ if (angular.isString(validateExpr)) {
1947
+ validateExpr = { validator: validateExpr };
1948
+ }
1949
+
1950
+ angular.forEach(validateExpr, function (exprssn, key) {
1951
+ validateFn = function (valueToValidate) {
1952
+ var expression = scope.$eval(exprssn, { '$value' : valueToValidate });
1953
+ if (angular.isObject(expression) && angular.isFunction(expression.then)) {
1954
+ // expression is a promise
1955
+ expression.then(function(){
1956
+ ctrl.$setValidity(key, true);
1957
+ }, function(){
1958
+ ctrl.$setValidity(key, false);
1959
+ });
1960
+ return valueToValidate;
1961
+ } else if (expression) {
1962
+ // expression is true
1963
+ ctrl.$setValidity(key, true);
1964
+ return valueToValidate;
1965
+ } else {
1966
+ // expression is false
1967
+ ctrl.$setValidity(key, false);
1968
+ return valueToValidate;
1969
+ }
1970
+ };
1971
+ validators[key] = validateFn;
1972
+ ctrl.$formatters.push(validateFn);
1973
+ ctrl.$parsers.push(validateFn);
1974
+ });
1975
+
1976
+ function apply_watch(watch)
1977
+ {
1978
+ //string - update all validators on expression change
1979
+ if (angular.isString(watch))
1980
+ {
1981
+ scope.$watch(watch, function(){
1982
+ angular.forEach(validators, function(validatorFn){
1983
+ validatorFn(ctrl.$modelValue);
1984
+ });
1985
+ });
1986
+ return;
1987
+ }
1988
+
1989
+ //array - update all validators on change of any expression
1990
+ if (angular.isArray(watch))
1991
+ {
1992
+ angular.forEach(watch, function(expression){
1993
+ scope.$watch(expression, function()
1994
+ {
1995
+ angular.forEach(validators, function(validatorFn){
1996
+ validatorFn(ctrl.$modelValue);
1997
+ });
1998
+ });
1999
+ });
2000
+ return;
2001
+ }
2002
+
2003
+ //object - update appropriate validator
2004
+ if (angular.isObject(watch))
2005
+ {
2006
+ angular.forEach(watch, function(expression, validatorKey)
2007
+ {
2008
+ //value is string - look after one expression
2009
+ if (angular.isString(expression))
2010
+ {
2011
+ scope.$watch(expression, function(){
2012
+ validators[validatorKey](ctrl.$modelValue);
2013
+ });
2014
+ }
2015
+
2016
+ //value is array - look after all expressions in array
2017
+ if (angular.isArray(expression))
2018
+ {
2019
+ angular.forEach(expression, function(intExpression)
2020
+ {
2021
+ scope.$watch(intExpression, function(){
2022
+ validators[validatorKey](ctrl.$modelValue);
2023
+ });
2024
+ });
2025
+ }
2026
+ });
2027
+ }
2028
+ }
2029
+ // Support for ui-validate-watch
2030
+ if (attrs.uiValidateWatch){
2031
+ apply_watch( scope.$eval(attrs.uiValidateWatch) );
2032
+ }
2033
+ }
2034
+ };
2035
+ });
2036
+
2037
+ angular.module('ui.utils', [
2038
+ 'ui.event',
2039
+ 'ui.format',
2040
+ 'ui.highlight',
2041
+ 'ui.include',
2042
+ 'ui.indeterminate',
2043
+ 'ui.inflector',
2044
+ 'ui.jq',
2045
+ 'ui.keypress',
2046
+ 'ui.mask',
2047
+ 'ui.reset',
2048
+ 'ui.route',
2049
+ 'ui.scrollfix',
2050
+ 'ui.scroll',
2051
+ 'ui.scroll.jqlite',
2052
+ 'ui.showhide',
2053
+ 'ui.unique',
2054
+ 'ui.validate'
2055
+ ]);