angular-ui-rails 0.2.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module AngularUI
2
2
  module Rails
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.2"
4
4
  end
5
5
  end
@@ -1,20 +1,41 @@
1
1
  /**
2
2
  * AngularUI - The companion suite for AngularJS
3
- * @version v0.2.1 - 2012-09-19
3
+ * @version v0.3.2 - 2012-12-04
4
4
  * @link http://angular-ui.github.com
5
5
  * @license MIT License, http://www.opensource.org/licenses/MIT
6
6
  */
7
7
 
8
8
  // READ: http://docs-next.angularjs.org/guide/ie
9
+ // element tags are statically defined in order to accommodate lazy-loading whereby directives are also unknown
10
+
11
+ // The ieshiv takes care of our ui.directives and AngularJS's ng-view, ng-include, ng-pluralize, ng-switch.
12
+ // However, IF you have custom directives that can be used as html tags (yours or someone else's) then
13
+ // add list of directives into <code>window.myCustomTags</code>
14
+
15
+ // <!--[if lte IE 8]>
16
+ // <script>
17
+ // window.myCustomTags = [ 'yourCustomDirective', 'somebodyElsesDirective' ]; // optional
18
+ // </script>
19
+ // <script src="build/angular-ui-ieshiv.js"></script>
20
+ // <![endif]-->
21
+
9
22
  (function (exports) {
10
23
 
11
- var debug = window.ieShivDebug || false;
24
+ var debug = window.ieShivDebug || false,
25
+ tags = [ "ngInclude", "ngPluralize", "ngView", "ngSwitch", "uiCurrency", "uiCodemirror", "uiDate", "uiEvent",
26
+ "uiKeypress", "uiKeyup", "uiKeydown", "uiMask", "uiMapInfoWindow", "uiMapMarker", "uiMapPolyline",
27
+ "uiMapPolygon", "uiMapRectangle", "uiMapCircle", "uiMapGroundOverlay", "uiModal", "uiReset",
28
+ "uiScrollfix", "uiSelect2", "uiShow", "uiHide", "uiToggle", "uiSortable", "uiTinymce"
29
+ ];
30
+
31
+ window.myCustomTags = window.myCustomTags || []; // externally defined by developer using angular-ui directives
32
+ tags.push.apply(tags, window.myCustomTags);
12
33
 
13
34
  var getIE = function () {
14
35
  // Returns the version of Internet Explorer or a -1
15
36
  // (indicating the use of another browser).
16
37
  var rv = -1; // Return value assumes failure.
17
- if (navigator.appName === 'Microsoft Internet Explorer') {
38
+ if (navigator.appName == 'Microsoft Internet Explorer') {
18
39
  var ua = navigator.userAgent;
19
40
  var re = new RegExp("MSIE ([0-9]{1,}[\\.0-9]{0,})");
20
41
  if (re.exec(ua) !== null) {
@@ -42,38 +63,10 @@
42
63
  };
43
64
 
44
65
  var shiv = function () {
45
- // TODO: unfortunately, angular is not exposing these in 'ng' module
46
- var tags = [ 'ngInclude', 'ngPluralize', 'ngView', 'ngSwitch' ]; // angular specific,
47
-
48
- // TODO: unfortunately, angular does not expose module names, it is a simple change to angular's loader.js
49
- // however, not sure if something happens when referencing them, so maybe an OK thing.
50
-
51
- var moduleNames = window.myAngularModules || []; // allow user to inject their own directives
52
- moduleNames.push('ui.directives');
53
-
54
- if (debug) console.log('moduleNames', moduleNames);
55
- function pushDirectives(item) {
56
- // only allow directives
57
- if (item[1] === "directive") {
58
- var dirname = item[2][0];
59
- tags.push(dirname);
60
- } else {
61
- if (debug) console.log("skipping", item[1], item[2][0]);
62
- }
63
- }
64
-
65
- for (var k = 0, mlen = moduleNames.length; k < mlen; k++) {
66
- var modules = angular.module(moduleNames[k]); // will throw runtime exception
67
- angular.forEach(modules._invokeQueue, pushDirectives);
68
- }
69
-
70
- if (debug) console.log("tags found", tags);
71
66
  for (var i = 0, tlen = tags.length; i < tlen; i++) {
72
- if (debug) console.log("tag", tags[i]);
73
67
  var customElements = toCustomElements(tags[i], ':');
74
68
  for (var j = 0, clen = customElements.length; j < clen; j++) {
75
69
  var customElement = customElements[j];
76
- if (debug) console.log("shivving", customElement);
77
70
  document.createElement(customElement);
78
71
  }
79
72
  }
@@ -1,884 +1,16 @@
1
- /**
2
- * AngularUI - The companion suite for AngularJS
3
- * @version v0.2.1 - 2012-09-19
4
- * @link http://angular-ui.github.com
5
- * @license MIT License, http://www.opensource.org/licenses/MIT
6
- */
7
-
8
-
9
- angular.module('ui.config', []).value('ui.config', {});
10
- angular.module('ui.filters', ['ui.config']);
11
- angular.module('ui.directives', ['ui.config']);
12
- angular.module('ui', ['ui.filters', 'ui.directives', 'ui.config']);
13
-
14
- /**
15
- * Animates the injection of new DOM elements by simply creating the DOM with a class and then immediately removing it
16
- * Animations must be done using CSS3 transitions, but provide excellent flexibility
17
- *
18
- * @todo Add proper support for animating out
19
- * @param [options] {mixed} Can be an object with multiple options, or a string with the animation class
20
- * class {string} the CSS class(es) to use. For example, 'ui-hide' might be an excellent alternative class.
21
- * @example <li ng-repeat="item in items" ui-animate=" 'ui-hide' ">{{item}}</li>
22
- */
23
- angular.module('ui.directives').directive('uiAnimate', ['ui.config', '$timeout', function (uiConfig, $timeout) {
24
- var options = {};
25
- if (angular.isString(uiConfig.animate)) {
26
- options['class'] = uiConfig.animate;
27
- } else if (uiConfig.animate) {
28
- options = uiConfig.animate;
29
- }
30
- return {
31
- restrict: 'A', // supports using directive as element, attribute and class
32
- link: function ($scope, element, attrs) {
33
- var opts = {};
34
- if (attrs.uiAnimate) {
35
- opts = $scope.$eval(attrs.uiAnimate);
36
- if (angular.isString(opts)) {
37
- opts = {'class': opts};
38
- }
39
- }
40
- opts = angular.extend({'class': 'ui-animate'}, options, opts);
41
-
42
- element.addClass(opts['class']);
43
- $timeout(function () {
44
- element.removeClass(opts['class']);
45
- }, 20, false);
46
- }
47
- };
48
- }]);
49
-
50
-
51
- /*global angular, CodeMirror, Error*/
52
- /**
53
- * Binds a CodeMirror widget to a <textarea> element.
54
- */
55
- angular.module('ui.directives').directive('uiCodemirror', ['ui.config', '$parse', function (uiConfig, $parse) {
56
- 'use strict';
57
-
58
- uiConfig.codemirror = uiConfig.codemirror || {};
59
- return {
60
- require: 'ngModel',
61
- link: function (scope, elm, attrs, ngModel) {
62
- // Only works on textareas
63
- if (!elm.is('textarea')) {
64
- throw new Error('ui-codemirror can only be applied to a textarea element');
65
- }
66
-
67
- var codemirror;
68
- // This is the method that we use to get the value of the ui-codemirror attribute expression.
69
- var uiCodemirrorGet = $parse(attrs.uiCodemirror);
70
- // This method will be called whenever the code mirror widget content changes
71
- var onChangeHandler = function (ed) {
72
- // We only update the model if the value has changed - this helps get around a little problem where $render triggers a change despite already being inside a $apply loop.
73
- var newValue = ed.getValue();
74
- if (newValue !== ngModel.$viewValue) {
75
- ngModel.$setViewValue(newValue);
76
- scope.$apply();
77
- }
78
- };
79
- // Create and wire up a new code mirror widget (unwiring a previous one if necessary)
80
- var updateCodeMirror = function (options) {
81
- // Merge together the options from the uiConfig and the attribute itself with the onChange event above.
82
- options = angular.extend({}, options, uiConfig.codemirror);
83
-
84
- // We actually want to run both handlers if the user has provided their own onChange handler.
85
- var userOnChange = options.onChange;
86
- if (userOnChange) {
87
- options.onChange = function (ed) {
88
- onChangeHandler(ed);
89
- userOnChange(ed);
90
- };
91
- } else {
92
- options.onChange = onChangeHandler;
93
- }
94
-
95
- // If there is a codemirror widget for this element already then we need to unwire if first
96
- if (codemirror) {
97
- codemirror.toTextArea();
98
- }
99
- // Create the new codemirror widget
100
- codemirror = CodeMirror.fromTextArea(elm[0], options);
101
- };
102
-
103
- // Initialize the code mirror widget
104
- updateCodeMirror(uiCodemirrorGet());
105
-
106
- // Now watch to see if the codemirror attribute gets updated
107
- scope.$watch(uiCodemirrorGet, updateCodeMirror, true);
108
-
109
- // CodeMirror expects a string, so make sure it gets one.
110
- // This does not change the model.
111
- ngModel.$formatters.push(function (value) {
112
- if (angular.isUndefined(value) || value === null) {
113
- return '';
114
- }
115
- else if (angular.isObject(value) || angular.isArray(value)) {
116
- throw new Error('ui-codemirror cannot use an object or an array as a model');
117
- }
118
- return value;
119
- });
120
-
121
- // Override the ngModelController $render method, which is what gets called when the model is updated.
122
- // This takes care of the synchronizing the codeMirror element with the underlying model, in the case that it is changed by something else.
123
- ngModel.$render = function () {
124
- codemirror.setValue(ngModel.$viewValue);
125
- };
126
- }
127
- };
128
- }]);
129
- /*
130
- Gives the ability to style currency based on its sign.
131
- */
132
- angular.module('ui.directives').directive('uiCurrency', ['ui.config', 'currencyFilter' , function (uiConfig, currencyFilter) {
133
- var options = {
134
- pos: 'ui-currency-pos',
135
- neg: 'ui-currency-neg',
136
- zero: 'ui-currency-zero'
137
- };
138
- if (uiConfig.currency) {
139
- angular.extend(options, uiConfig.currency);
140
- }
141
- return {
142
- restrict: 'EAC',
143
- require: 'ngModel',
144
- link: function (scope, element, attrs, controller) {
145
- var opts, // instance-specific options
146
- renderview,
147
- value;
148
-
149
- opts = angular.extend({}, options, scope.$eval(attrs.uiCurrency));
150
-
151
- renderview = function (viewvalue) {
152
- var num;
153
- num = viewvalue * 1;
154
- if (num > 0) {
155
- element.addClass(opts.pos);
156
- } else {
157
- element.removeClass(opts.pos);
158
- }
159
- if (num < 0) {
160
- element.addClass(opts.neg);
161
- } else {
162
- element.removeClass(opts.neg);
163
- }
164
- if (num === 0) {
165
- element.addClass(opts.zero);
166
- } else {
167
- element.removeClass(opts.zero);
168
- }
169
- if (viewvalue === '') {
170
- element.text('');
171
- } else {
172
- element.text(currencyFilter(num, opts.symbol));
173
- }
174
- return true;
175
- };
176
-
177
- controller.$render = function () {
178
- value = controller.$viewValue;
179
- element.val(value);
180
- renderview(value);
181
- };
182
-
183
- }
184
- };
185
- }]);
186
-
187
- /*global angular */
188
- /*
189
- jQuery UI Datepicker plugin wrapper
190
-
191
- @param [ui-date] {object} Options to pass to $.fn.datepicker() merged onto ui.config
192
- */
193
-
194
- angular.module('ui.directives').directive('uiDate', ['ui.config', function (uiConfig) {
195
- 'use strict';
196
- var options;
197
- options = {};
198
- if (angular.isObject(uiConfig.date)) {
199
- angular.extend(options, uiConfig.date);
200
- }
201
- return {
202
- require:'?ngModel',
203
- link:function (scope, element, attrs, controller) {
204
- var getOptions = function () {
205
- return angular.extend({}, uiConfig.date, scope.$eval(attrs.uiDate));
206
- };
207
- var initDateWidget = function () {
208
- var opts = getOptions();
209
-
210
- // If we have a controller (i.e. ngModelController) then wire it up
211
- if (controller) {
212
- var updateModel = function () {
213
- scope.$apply(function () {
214
- controller.$setViewValue(element.datepicker("getDate"));
215
- });
216
- };
217
- if (opts.onSelect) {
218
- // Caller has specified onSelect, so call this as well as updating the model
219
- var userHandler = opts.onSelect;
220
- opts.onSelect = function (value, picker) {
221
- updateModel();
222
- return userHandler(value, picker);
223
- };
224
- } else {
225
- // No onSelect already specified so just update the model
226
- opts.onSelect = updateModel;
227
- }
228
- // In case the user changes the text directly in the input box
229
- element.bind('change', updateModel);
230
-
231
- // Update the date picker when the model changes
232
- controller.$render = function () {
233
- var date = controller.$viewValue;
234
- element.datepicker("setDate", date);
235
- // Update the model if we received a string
236
- if (angular.isString(date)) {
237
- controller.$setViewValue(element.datepicker("getDate"));
238
- }
239
- };
240
- }
241
- // If we don't destroy the old one it doesn't update properly when the config changes
242
- element.datepicker('destroy');
243
- // Create the new datepicker widget
244
- element.datepicker(opts);
245
- // Force a render to override whatever is in the input text box
246
- controller.$render();
247
- };
248
- // Watch for changes to the directives options
249
- scope.$watch(getOptions, initDateWidget, true);
250
- }
251
- };
252
- }
253
- ]);
254
-
255
- /**
256
- * General-purpose Event binding. Bind any event not natively supported by Angular
257
- * Pass an object with keynames for events to ui-event
258
- * Allows $event object and $params object to be passed
259
- *
260
- * @example <input ui-event="{ focus : 'counter++', blur : 'someCallback()' }">
261
- * @example <input ui-event="{ myCustomEvent : 'myEventHandler($event, $params)'}">
262
- *
263
- * @param ui-event {string|object literal} The event to bind to as a string or a hash of events with their callbacks
264
- */
265
- angular.module('ui.directives').directive('uiEvent', ['$parse',
266
- function ($parse) {
267
- return function (scope, elm, attrs) {
268
- var events = scope.$eval(attrs.uiEvent);
269
- angular.forEach(events, function (uiEvent, eventName) {
270
- var fn = $parse(uiEvent);
271
- elm.bind(eventName, function (evt) {
272
- var params = Array.prototype.slice.call(arguments);
273
- //Take out first paramater (event object);
274
- params = params.splice(1);
275
- scope.$apply(function () {
276
- fn(scope, {$event: evt, $params: params});
277
- });
278
- });
279
- });
280
- };
281
- }]);
282
-
283
- /*
284
- * Defines the ui-if tag. This removes/adds an element from the dom depending on a condition
285
- * Originally created by @tigbro, for the @jquery-mobile-angular-adapter
286
- * https://github.com/tigbro/jquery-mobile-angular-adapter
287
- */
288
- angular.module('ui.directives').directive('uiIf', [function () {
289
- return {
290
- transclude: 'element',
291
- priority: 1000,
292
- terminal: true,
293
- restrict: 'A',
294
- compile: function (element, attr, linker) {
295
- return function (scope, iterStartElement, attr) {
296
- iterStartElement[0].doNotMove = true;
297
- var expression = attr.uiIf;
298
- var lastElement;
299
- var lastScope;
300
- scope.$watch(expression, function (newValue) {
301
- if (lastElement) {
302
- lastElement.remove();
303
- lastElement = null;
304
- }
305
- if (lastScope) {
306
- lastScope.$destroy();
307
- lastScope = null;
308
- }
309
- if (newValue) {
310
- lastScope = scope.$new();
311
- linker(lastScope, function (clone) {
312
- lastElement = clone;
313
- iterStartElement.after(clone);
314
- });
315
- }
316
- // Note: need to be parent() as jquery cannot trigger events on comments
317
- // (angular creates a comment node when using transclusion, as ng-repeat does).
318
- iterStartElement.parent().trigger("$childrenChanged");
319
- });
320
- };
321
- }
322
- };
323
- }]);
324
- /**
325
- * General-purpose jQuery wrapper. Simply pass the plugin name as the expression.
326
- *
327
- * It is possible to specify a default set of parameters for each jQuery plugin.
328
- * Under the jq key, namespace each plugin by that which will be passed to ui-jq.
329
- * Unfortunately, at this time you can only pre-define the first parameter.
330
- * @example { jq : { datepicker : { showOn:'click' } } }
331
- *
332
- * @param ui-jq {string} The $elm.[pluginName]() to call.
333
- * @param [ui-options] {mixed} Expression to be evaluated and passed as options to the function
334
- * Multiple parameters can be separated by commas
335
- * Set {ngChange:false} to disable passthrough support for change events ( since angular watches 'input' events, not 'change' events )
336
- *
337
- * @example <input ui-jq="datepicker" ui-options="{showOn:'click'},secondParameter,thirdParameter">
338
- */
339
- angular.module('ui.directives').directive('uiJq', ['ui.config', function (uiConfig) {
340
- return {
341
- restrict: 'A',
342
- compile: function (tElm, tAttrs) {
343
- if (!angular.isFunction(tElm[tAttrs.uiJq])) {
344
- throw new Error('ui-jq: The "' + tAttrs.uiJq + '" function does not exist');
345
- }
346
- var options = uiConfig.jq && uiConfig.jq[tAttrs.uiJq];
347
- return function (scope, elm, attrs) {
348
- var linkOptions = [], ngChange = 'change';
349
-
350
- if (attrs.uiOptions) {
351
- linkOptions = scope.$eval('[' + attrs.uiOptions + ']');
352
- if (angular.isObject(options) && angular.isObject(linkOptions[0])) {
353
- linkOptions[0] = angular.extend(options, linkOptions[0]);
354
- }
355
- } else if (options) {
356
- linkOptions = [options];
357
- }
358
- if (attrs.ngModel && elm.is('select,input,textarea')) {
359
- if (linkOptions && angular.isObject(linkOptions[0]) && linkOptions[0].ngChange !== undefined) {
360
- ngChange = linkOptions[0].ngChange;
361
- }
362
- if (ngChange) {
363
- elm.on(ngChange, function () {
364
- elm.trigger('input');
365
- });
366
- }
367
- }
368
- elm[attrs.uiJq].apply(elm, linkOptions);
369
- };
370
- }
371
- };
372
- }]);
373
-
374
- /**
375
- * Bind one or more handlers to particular keys or their combination
376
- * @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'.
377
- * @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" />
378
- **/
379
- angular.module('ui.directives').directive('uiKeypress', ['$parse', function ($parse) {
380
- return {
381
- link: function (scope, elm, attrs) {
382
- var keysByCode = {
383
- 8: 'backspace',
384
- 9: 'tab',
385
- 13: 'enter',
386
- 27: 'esc',
387
- 32: 'space',
388
- 33: 'pageup',
389
- 34: 'pagedown',
390
- 35: 'end',
391
- 36: 'home',
392
- 37: 'left',
393
- 38: 'up',
394
- 39: 'right',
395
- 40: 'down',
396
- 45: 'insert',
397
- 46: 'delete'
398
- };
399
-
400
- var params, paramsParsed, expression, keys, combinations = [];
401
- try {
402
- params = scope.$eval(attrs.uiKeypress);
403
- paramsParsed = true;
404
- } catch (error) {
405
- params = attrs.uiKeypress.split(/\s+and\s+/i);
406
- paramsParsed = false;
407
- }
408
-
409
- // Prepare combinations for simple checking
410
- angular.forEach(params, function (v, k) {
411
- var combination = {};
412
- if (paramsParsed) {
413
- // An object passed
414
- combination.expression = $parse(v);
415
- combination.keys = k;
416
- } else {
417
- // A string passed
418
- v = v.split(/\s+on\s+/i);
419
- combination.expression = $parse(v[0]);
420
- combination.keys = v[1];
421
- }
422
-
423
- keys = {};
424
- angular.forEach(combination.keys.split('-'), function (value) {
425
- keys[value] = true;
426
- });
427
- combination.keys = keys;
428
- combinations.push(combination);
429
- });
430
-
431
- // Check only mathcing of pressed keys one of the conditions
432
- elm.bind('keydown', function (event) {
433
- // No need to do that inside the cycle
434
- var altPressed = event.metaKey || event.altKey;
435
- var ctrlPressed = event.ctrlKey;
436
- var shiftPressed = event.shiftKey;
437
-
438
- // Iterate over prepared combinations
439
- angular.forEach(combinations, function (combination) {
440
-
441
- var mainKeyPressed = (combination.keys[keysByCode[event.keyCode]] || combination.keys[event.keyCode.toString()]) || false;
442
-
443
- var altRequired = combination.keys.alt || false;
444
- var ctrlRequired = combination.keys.ctrl || false;
445
- var shiftRequired = combination.keys.shift || false;
446
-
447
- if (mainKeyPressed &&
448
- ( altRequired == altPressed ) &&
449
- ( ctrlRequired == ctrlPressed ) &&
450
- ( shiftRequired == shiftPressed )
451
- ) {
452
- // Run the function
453
- scope.$apply(function () {
454
- combination.expression(scope, { '$event': event });
455
- });
456
- }
457
- });
458
- });
459
- }
460
- };
461
- }]);
462
-
463
- (function () {
464
- var app = angular.module('ui.directives');
465
-
466
- //Setup map events from a google map object to trigger on a given element too,
467
- //then we just use ui-event to catch events from an element
468
- function bindMapEvents(scope, eventsStr, googleObject, element) {
469
- angular.forEach(eventsStr.split(' '), function (eventName) {
470
- //Prefix all googlemap events with 'map-', so eg 'click'
471
- //for the googlemap doesn't interfere with a normal 'click' event
472
- var $event = { type: 'map-' + eventName };
473
- google.maps.event.addListener(googleObject, eventName, function (evt) {
474
- element.trigger(angular.extend({}, $event, evt));
475
- //We create an $apply if it isn't happening. we need better support for this
476
- //We don't want to use timeout because tons of these events fire at once,
477
- //and we only need one $apply
478
- if (!scope.$$phase) scope.$apply();
479
- });
480
- });
481
- }
482
-
483
- app.directive('uiMap',
484
- ['ui.config', '$parse', function (uiConfig, $parse) {
485
-
486
- var mapEvents = 'bounds_changed center_changed click dblclick drag dragend ' +
487
- 'dragstart heading_changed idle maptypeid_changed mousemove mouseout ' +
488
- 'mouseover projection_changed resize rightclick tilesloaded tilt_changed ' +
489
- 'zoom_changed';
490
- var options = uiConfig.map || {};
491
-
492
- return {
493
- restrict: 'A',
494
- //doesn't work as E for unknown reason
495
- link: function (scope, elm, attrs) {
496
- var opts = angular.extend({}, options, scope.$eval(attrs.uiOptions));
497
- var map = new google.maps.Map(elm[0], opts);
498
- var model = $parse(attrs.uiMap);
499
-
500
- //Set scope variable for the map
501
- model.assign(scope, map);
502
-
503
- bindMapEvents(scope, mapEvents, map, elm);
504
- }
505
- };
506
- }]);
507
-
508
- app.directive('uiMapInfoWindow',
509
- ['ui.config', '$parse', '$compile', function (uiConfig, $parse, $compile) {
510
-
511
- var infoWindowEvents = 'closeclick content_change domready ' +
512
- 'position_changed zindex_changed';
513
- var options = uiConfig.mapInfoWindow || {};
514
-
515
- return {
516
- link: function (scope, elm, attrs) {
517
- var opts = angular.extend({}, options, scope.$eval(attrs.uiOptions));
518
- opts.content = elm[0];
519
- var model = $parse(attrs.uiMapInfoWindow);
520
- var infoWindow = model(scope);
521
-
522
- if (!infoWindow) {
523
- infoWindow = new google.maps.InfoWindow(opts);
524
- model.assign(scope, infoWindow);
525
- }
526
-
527
- bindMapEvents(scope, infoWindowEvents, infoWindow, elm);
528
-
529
- /* The info window's contents dont' need to be on the dom anymore,
530
- google maps has them stored. So we just replace the infowindow element
531
- with an empty div. (we don't just straight remove it from the dom because
532
- straight removing things from the dom can mess up angular) */
533
- elm.replaceWith('<div></div>');
534
-
535
- //Decorate infoWindow.open to $compile contents before opening
536
- var _open = infoWindow.open;
537
- infoWindow.open = function open(a1, a2, a3, a4, a5, a6) {
538
- $compile(elm.contents())(scope);
539
- _open.call(infoWindow, a1, a2, a3, a4, a5, a6);
540
- };
541
- }
542
- };
543
- }]);
544
-
545
- /*
546
- * Map overlay directives all work the same. Take map marker for example
547
- * <ui-map-marker="myMarker"> will $watch 'myMarker' and each time it changes,
548
- * it will hook up myMarker's events to the directive dom element. Then
549
- * ui-event will be able to catch all of myMarker's events. Super simple.
550
- */
551
- function mapOverlayDirective(directiveName, events) {
552
- app.directive(directiveName, [function () {
553
- return {
554
- restrict: 'A',
555
- link: function (scope, elm, attrs) {
556
- scope.$watch(attrs[directiveName], function (newObject) {
557
- bindMapEvents(scope, events, newObject, elm);
558
- });
559
- }
560
- };
561
- }]);
562
- }
563
-
564
- mapOverlayDirective('uiMapMarker',
565
- 'animation_changed click clickable_changed cursor_changed ' +
566
- 'dblclick drag dragend draggable_changed dragstart flat_changed icon_changed ' +
567
- 'mousedown mouseout mouseover mouseup position_changed rightclick ' +
568
- 'shadow_changed shape_changed title_changed visible_changed zindex_changed');
569
-
570
- mapOverlayDirective('uiMapPolyline',
571
- 'click dblclick mousedown mousemove mouseout mouseover mouseup rightclick');
572
-
573
- mapOverlayDirective('uiMapPolygon',
574
- 'click dblclick mousedown mousemove mouseout mouseover mouseup rightclick');
575
-
576
- mapOverlayDirective('uiMapRectangle',
577
- 'bounds_changed click dblclick mousedown mousemove mouseout mouseover ' +
578
- 'mouseup rightclick');
579
-
580
- mapOverlayDirective('uiMapCircle',
581
- 'center_changed click dblclick mousedown mousemove ' +
582
- 'mouseout mouseover mouseup radius_changed rightclick');
583
-
584
- mapOverlayDirective('uiMapGroundOverlay',
585
- 'click dblclick');
586
-
587
- })();
588
- /*
589
- Attaches jquery-ui input mask onto input element
590
- */
1
+ /**
2
+ * AngularUI - The companion suite for AngularJS
3
+ * @version v0.3.2 - 2012-12-04
4
+ * @link http://angular-ui.github.com
5
+ * @license MIT License, http://www.opensource.org/licenses/MIT
6
+ */
591
7
 
592
- angular.module('ui.directives').directive('uiMask', [
593
- function() {
594
- return {
595
- require: 'ngModel',
596
- scope: {
597
- uiMask: '='
598
- },
599
- link: function($scope, element, attrs, controller) {
600
- /* We override the render method to run the jQuery mask plugin
601
- */
602
- controller.$render = function() {
603
- var value;
604
- value = controller.$viewValue || '';
605
- element.val(value);
606
- return element.mask($scope.uiMask);
607
- };
608
- /* Add a parser that extracts the masked value into the model but only if the mask is valid
609
- */
610
8
 
611
- controller.$parsers.push(function(value) {
612
- var isValid;
613
- isValid = element.data('mask-isvalid');
614
- controller.$setValidity('mask', isValid);
615
- return element.mask();
616
- });
617
- /* When keyup, update the viewvalue
618
- */
9
+ angular.module('ui.config', []).value('ui.config', {});
10
+ angular.module('ui.filters', ['ui.config']);
11
+ angular.module('ui.directives', ['ui.config']);
12
+ angular.module('ui', ['ui.filters', 'ui.directives', 'ui.config']);
619
13
 
620
- return element.bind('keyup', function() {
621
- return $scope.$apply(function() {
622
- return controller.$setViewValue(element.mask());
623
- });
624
- });
625
- }
626
- };
627
- }
628
- ]);
629
-
630
- angular.module('ui.directives')
631
- .directive('uiModal', ['$timeout', function($timeout) {
632
- return {
633
- restrict: 'EAC',
634
- require: 'ngModel',
635
- link: function(scope, elm, attrs, model) {
636
- //helper so you don't have to type class="modal hide"
637
- elm.addClass('modal hide');
638
- scope.$watch(attrs.ngModel, function(value) {
639
- elm.modal(value && 'show' || 'hide');
640
- });
641
- //If bootstrap animations are enabled, listen to 'shown' and 'hidden' events
642
- elm.on(jQuery.support.transition && 'shown' || 'show', function() {
643
- $timeout(function() {
644
- model.$setViewValue(true);
645
- });
646
- });
647
- elm.on(jQuery.support.transition && 'hidden' || 'hide', function() {
648
- $timeout(function() {
649
- model.$setViewValue(false);
650
- });
651
- });
652
- }
653
- };
654
- }]);
655
- /**
656
- * Add a clear button to form inputs to reset their value
657
- */
658
- angular.module('ui.directives').directive('uiReset', ['$parse', function ($parse) {
659
- return {
660
- require: 'ngModel',
661
- link: function (scope, elm, attrs, ctrl) {
662
- var aElement = angular.element('<a class="ui-reset" />');
663
- elm.wrap('<span class="ui-resetwrap" />').after(aElement);
664
-
665
- aElement.bind('click', function (e) {
666
- e.preventDefault();
667
- scope.$apply(function () {
668
- // This lets you SET the value of the 'parsed' model
669
- ctrl.$setViewValue(null);
670
- ctrl.$render();
671
- });
672
- });
673
- }
674
- };
675
- }]);
676
-
677
- /*global angular, $, document*/
678
- /**
679
- * Adds a 'ui-scrollfix' class to the element when the page scrolls past it's position.
680
- * @param [offset] {int} optional Y-offset to override the detected offset.
681
- * Takes 300 (absolute) or -300 or +300 (relative to detected)
682
- */
683
- angular.module('ui.directives').directive('uiScrollfix', ['$window', function ($window) {
684
- 'use strict';
685
- return {
686
- link: function (scope, elm, attrs) {
687
- var top = elm.offset().top;
688
- if (!attrs.uiScrollfix) {
689
- attrs.uiScrollfix = top;
690
- } else {
691
- // chartAt is generally faster than indexOf: http://jsperf.com/indexof-vs-chartat
692
- if (attrs.uiScrollfix.charAt(0) === '-') {
693
- attrs.uiScrollfix = top - attrs.uiScrollfix.substr(1);
694
- } else if (attrs.uiScrollfix.charAt(0) === '+') {
695
- attrs.uiScrollfix = top + parseFloat(attrs.uiScrollfix.substr(1));
696
- }
697
- }
698
- angular.element($window).on('scroll.ui-scrollfix', function () {
699
- // if pageYOffset is defined use it, otherwise use other crap for IE
700
- var offset;
701
- if (angular.isDefined($window.pageYOffset)) {
702
- offset = $window.pageYOffset;
703
- } else {
704
- var iebody = (document.compatMode && document.compatMode !== "BackCompat") ? document.documentElement : document.body;
705
- offset = iebody.scrollTop;
706
- }
707
- if (!elm.hasClass('ui-scrollfix') && offset > attrs.uiScrollfix) {
708
- elm.addClass('ui-scrollfix');
709
- } else if (elm.hasClass('ui-scrollfix') && offset < attrs.uiScrollfix) {
710
- elm.removeClass('ui-scrollfix');
711
- }
712
- });
713
- }
714
- };
715
- }]);
716
-
717
- /**
718
- * Enhanced Select2 Dropmenus
719
- *
720
- * @AJAX Mode - When in this mode, your value will be an object (or array of objects) of the data used by Select2
721
- * This change is so that you do not have to do an additional query yourself on top of Select2's own query
722
- * @params [options] {object} The configuration options passed to $.fn.select2(). Refer to the documentation
723
- */
724
- angular.module('ui.directives').directive('uiSelect2', ['ui.config', '$http', function (uiConfig, $http) {
725
- var options = {};
726
- if (uiConfig.select2) {
727
- angular.extend(options, uiConfig.select2);
728
- }
729
- return {
730
- require: '?ngModel',
731
- compile: function (tElm, tAttrs) {
732
- var watch,
733
- repeatOption,
734
- isSelect = tElm.is('select'),
735
- isMultiple = (tAttrs.multiple !== undefined);
736
-
737
- // Enable watching of the options dataset if in use
738
- if (tElm.is('select')) {
739
- repeatOption = tElm.find('option[ng-repeat]');
740
- if (repeatOption.length) {
741
- watch = repeatOption.attr('ng-repeat').split(' ').pop();
742
- }
743
- }
744
-
745
- return function (scope, elm, attrs, controller) {
746
- // instance-specific options
747
- var opts = angular.extend({}, options, scope.$eval(attrs.uiSelect2));
748
-
749
- if (isSelect) {
750
- // Use <select multiple> instead
751
- delete opts.multiple;
752
- delete opts.initSelection;
753
- } else if (isMultiple) {
754
- opts.multiple = true;
755
- }
756
-
757
- if (controller) {
758
- // Watch the model for programmatic changes
759
- controller.$render = function () {
760
- if (isSelect) {
761
- elm.select2('val', controller.$modelValue);
762
- } else {
763
- if (isMultiple && !controller.$modelValue) {
764
- elm.select2('data', []);
765
- } else {
766
- elm.select2('data', controller.$modelValue);
767
- }
768
- }
769
- };
770
-
771
-
772
- // Watch the options dataset for changes
773
- if (watch) {
774
- scope.$watch(watch, function (newVal, oldVal, scope) {
775
- if (!newVal) return;
776
- // Delayed so that the options have time to be rendered
777
- setTimeout(function () {
778
- elm.select2('val', controller.$viewValue);
779
- // Refresh angular to remove the superfluous option
780
- elm.trigger('change');
781
- });
782
- });
783
- }
784
-
785
- if (!isSelect) {
786
- // Set the view and model value and update the angular template manually for the ajax/multiple select2.
787
- elm.bind("change", function () {
788
- scope.$apply(function () {
789
- controller.$setViewValue(elm.select2('data'));
790
- });
791
- });
792
-
793
- if (opts.initSelection) {
794
- var initSelection = opts.initSelection;
795
- opts.initSelection = function (element, callback) {
796
- initSelection(element, function (value) {
797
- controller.$setViewValue(value);
798
- callback(value);
799
- });
800
- };
801
- }
802
- }
803
- }
804
-
805
- attrs.$observe('disabled', function (value) {
806
- elm.select2(value && 'disable' || 'enable');
807
- });
808
-
809
- // Set initial value since Angular doesn't
810
- elm.val(scope.$eval(attrs.ngModel));
811
-
812
- // Initialize the plugin late so that the injected DOM does not disrupt the template compiler
813
- setTimeout(function () {
814
- elm.select2(opts);
815
- });
816
- };
817
- }
818
- };
819
- }]);
820
-
821
- /**
822
- * uiShow Directive
823
- *
824
- * Adds a 'ui-show' class to the element instead of display:block
825
- * Created to allow tighter control of CSS without bulkier directives
826
- *
827
- * @param expression {boolean} evaluated expression to determine if the class should be added
828
- */
829
- angular.module('ui.directives').directive('uiShow', [function () {
830
- return function (scope, elm, attrs) {
831
- scope.$watch(attrs.uiShow, function (newVal, oldVal) {
832
- if (newVal) {
833
- elm.addClass('ui-show');
834
- } else {
835
- elm.removeClass('ui-show');
836
- }
837
- });
838
- };
839
- }])
840
-
841
- /**
842
- * uiHide Directive
843
- *
844
- * Adds a 'ui-hide' class to the element instead of display:block
845
- * Created to allow tighter control of CSS without bulkier directives
846
- *
847
- * @param expression {boolean} evaluated expression to determine if the class should be added
848
- */
849
- .directive('uiHide', [function () {
850
- return function (scope, elm, attrs) {
851
- scope.$watch(attrs.uiHide, function (newVal, oldVal) {
852
- if (newVal) {
853
- elm.addClass('ui-hide');
854
- } else {
855
- elm.removeClass('ui-hide');
856
- }
857
- });
858
- };
859
- }])
860
-
861
- /**
862
- * uiToggle Directive
863
- *
864
- * Adds a class 'ui-show' if true, and a 'ui-hide' if false to the element instead of display:block/display:none
865
- * Created to allow tighter control of CSS without bulkier directives. This also allows you to override the
866
- * default visibility of the element using either class.
867
- *
868
- * @param expression {boolean} evaluated expression to determine if the class should be added
869
- */
870
- .directive('uiToggle', [function () {
871
- return function (scope, elm, attrs) {
872
- scope.$watch(attrs.uiToggle, function (newVal, oldVal) {
873
- if (newVal) {
874
- elm.removeClass('ui-hide').addClass('ui-show');
875
- } else {
876
- elm.removeClass('ui-show').addClass('ui-hide');
877
- }
878
- });
879
- };
880
- }]);
881
-
882
14
  /*
883
15
  jQuery UI Sortable plugin wrapper
884
16
 
@@ -930,58 +62,414 @@ angular.module('ui.directives').directive('uiSortable', [
930
62
  };
931
63
  }
932
64
  ]);
933
-
934
- /**
935
- * Binds a TinyMCE widget to <textarea> elements.
936
- */
937
- angular.module('ui.directives').directive('uiTinymce', ['ui.config', function (uiConfig) {
938
- uiConfig.tinymce = uiConfig.tinymce || {};
939
- return {
940
- require: 'ngModel',
941
- link: function (scope, elm, attrs, ngModel) {
942
- var expression,
943
- options = {
944
- // Update model on button click
945
- onchange_callback: function (inst) {
946
- if (inst.isDirty()) {
947
- inst.save();
948
- ngModel.$setViewValue(elm.val());
949
- scope.$apply();
950
- }
951
- },
952
- // Update model on keypress
953
- handle_event_callback: function (e) {
954
- if (this.isDirty()) {
955
- this.save();
956
- ngModel.$setViewValue(elm.val());
957
- scope.$apply();
958
- }
959
- return true; // Continue handling
960
- },
961
- // Update model when calling setContent (such as from the source editor popup)
962
- setup: function (ed) {
963
- ed.onSetContent.add(function (ed, o) {
964
- if (ed.isDirty()) {
965
- ed.save();
966
- ngModel.$setViewValue(elm.val());
967
- scope.$apply();
968
- }
969
- });
970
- }
971
- };
972
- if (attrs.uiTinymce) {
973
- expression = scope.$eval(attrs.uiTinymce);
974
- } else {
975
- expression = {};
976
- }
977
- angular.extend(options, uiConfig.tinymce, expression);
978
- setTimeout(function () {
979
- elm.tinymce(options);
980
- });
981
- }
982
- };
983
- }]);
984
-
65
+
66
+ /**
67
+ * General-purpose jQuery wrapper. Simply pass the plugin name as the expression.
68
+ *
69
+ * It is possible to specify a default set of parameters for each jQuery plugin.
70
+ * Under the jq key, namespace each plugin by that which will be passed to ui-jq.
71
+ * Unfortunately, at this time you can only pre-define the first parameter.
72
+ * @example { jq : { datepicker : { showOn:'click' } } }
73
+ *
74
+ * @param ui-jq {string} The $elm.[pluginName]() to call.
75
+ * @param [ui-options] {mixed} Expression to be evaluated and passed as options to the function
76
+ * Multiple parameters can be separated by commas
77
+ * Set {ngChange:false} to disable passthrough support for change events ( since angular watches 'input' events, not 'change' events )
78
+ *
79
+ * @example <input ui-jq="datepicker" ui-options="{showOn:'click'},secondParameter,thirdParameter">
80
+ */
81
+ angular.module('ui.directives').directive('uiJq', ['ui.config', function (uiConfig) {
82
+ return {
83
+ restrict: 'A',
84
+ compile: function (tElm, tAttrs) {
85
+ if (!angular.isFunction(tElm[tAttrs.uiJq])) {
86
+ throw new Error('ui-jq: The "' + tAttrs.uiJq + '" function does not exist');
87
+ }
88
+ var options = uiConfig.jq && uiConfig.jq[tAttrs.uiJq];
89
+ return function (scope, elm, attrs) {
90
+ var linkOptions = [], ngChange = 'change';
91
+
92
+ if (attrs.uiOptions) {
93
+ linkOptions = scope.$eval('[' + attrs.uiOptions + ']');
94
+ if (angular.isObject(options) && angular.isObject(linkOptions[0])) {
95
+ linkOptions[0] = angular.extend(options, linkOptions[0]);
96
+ }
97
+ } else if (options) {
98
+ linkOptions = [options];
99
+ }
100
+ if (attrs.ngModel && elm.is('select,input,textarea')) {
101
+ if (linkOptions && angular.isObject(linkOptions[0]) && linkOptions[0].ngChange !== undefined) {
102
+ ngChange = linkOptions[0].ngChange;
103
+ }
104
+ if (ngChange) {
105
+ elm.on(ngChange, function () {
106
+ elm.trigger('input');
107
+ });
108
+ }
109
+ }
110
+ elm[attrs.uiJq].apply(elm, linkOptions);
111
+ };
112
+ }
113
+ };
114
+ }]);
115
+
116
+ /**
117
+ * General-purpose Event binding. Bind any event not natively supported by Angular
118
+ * Pass an object with keynames for events to ui-event
119
+ * Allows $event object and $params object to be passed
120
+ *
121
+ * @example <input ui-event="{ focus : 'counter++', blur : 'someCallback()' }">
122
+ * @example <input ui-event="{ myCustomEvent : 'myEventHandler($event, $params)'}">
123
+ *
124
+ * @param ui-event {string|object literal} The event to bind to as a string or a hash of events with their callbacks
125
+ */
126
+ angular.module('ui.directives').directive('uiEvent', ['$parse',
127
+ function ($parse) {
128
+ return function (scope, elm, attrs) {
129
+ var events = scope.$eval(attrs.uiEvent);
130
+ angular.forEach(events, function (uiEvent, eventName) {
131
+ var fn = $parse(uiEvent);
132
+ elm.bind(eventName, function (evt) {
133
+ var params = Array.prototype.slice.call(arguments);
134
+ //Take out first paramater (event object);
135
+ params = params.splice(1);
136
+ scope.$apply(function () {
137
+ fn(scope, {$event: evt, $params: params});
138
+ });
139
+ });
140
+ });
141
+ };
142
+ }]);
143
+
144
+ /*
145
+ Attaches jquery-ui input mask onto input element
146
+ */
147
+ angular.module('ui.directives').directive('uiMask', [
148
+ function () {
149
+ return {
150
+ require:'ngModel',
151
+ link:function ($scope, element, attrs, controller) {
152
+
153
+ /* We override the render method to run the jQuery mask plugin
154
+ */
155
+ controller.$render = function () {
156
+ var value = controller.$viewValue || '';
157
+ element.val(value);
158
+ element.mask($scope.$eval(attrs.uiMask));
159
+ };
160
+
161
+ /* Add a parser that extracts the masked value into the model but only if the mask is valid
162
+ */
163
+ controller.$parsers.push(function (value) {
164
+ //the second check (or) is only needed due to the fact that element.isMaskValid() will keep returning undefined
165
+ //until there was at least one key event
166
+ var isValid = element.isMaskValid() || angular.isUndefined(element.isMaskValid()) && element.val().length>0;
167
+ controller.$setValidity('mask', isValid);
168
+ return isValid ? value : undefined;
169
+ });
170
+
171
+ /* When keyup, update the view value
172
+ */
173
+ element.bind('keyup', function () {
174
+ $scope.$apply(function () {
175
+ controller.$setViewValue(element.mask());
176
+ });
177
+ });
178
+ }
179
+ };
180
+ }
181
+ ]);
182
+
183
+ angular.module('ui.directives')
184
+ .directive('uiModal', ['$timeout', function($timeout) {
185
+ return {
186
+ restrict: 'EAC',
187
+ require: 'ngModel',
188
+ link: function(scope, elm, attrs, model) {
189
+ //helper so you don't have to type class="modal hide"
190
+ elm.addClass('modal hide');
191
+ elm.on( 'shown', function() {
192
+ elm.find( "[autofocus]" ).focus();
193
+ });
194
+ scope.$watch(attrs.ngModel, function(value) {
195
+ elm.modal(value && 'show' || 'hide');
196
+ });
197
+ //If bootstrap animations are enabled, listen to 'shown' and 'hidden' events
198
+ elm.on(jQuery.support.transition && 'shown' || 'show', function() {
199
+ $timeout(function() {
200
+ model.$setViewValue(true);
201
+ });
202
+ });
203
+ elm.on(jQuery.support.transition && 'hidden' || 'hide', function() {
204
+ $timeout(function() {
205
+ model.$setViewValue(false);
206
+ });
207
+ });
208
+ }
209
+ };
210
+ }]);
211
+ /**
212
+ * Add a clear button to form inputs to reset their value
213
+ */
214
+ angular.module('ui.directives').directive('uiReset', ['ui.config', function (uiConfig) {
215
+ var resetValue = null;
216
+ if (uiConfig.reset !== undefined)
217
+ resetValue = uiConfig.reset;
218
+ return {
219
+ require: 'ngModel',
220
+ link: function (scope, elm, attrs, ctrl) {
221
+ var aElement;
222
+ aElement = angular.element('<a class="ui-reset" />');
223
+ elm.wrap('<span class="ui-resetwrap" />').after(aElement);
224
+ aElement.bind('click', function (e) {
225
+ e.preventDefault();
226
+ scope.$apply(function () {
227
+ if (attrs.uiReset)
228
+ ctrl.$setViewValue(scope.$eval(attrs.uiReset));
229
+ else
230
+ ctrl.$setViewValue(resetValue);
231
+ ctrl.$render();
232
+ });
233
+ });
234
+ }
235
+ };
236
+ }]);
237
+
238
+ (function () {
239
+ var app = angular.module('ui.directives');
240
+
241
+ //Setup map events from a google map object to trigger on a given element too,
242
+ //then we just use ui-event to catch events from an element
243
+ function bindMapEvents(scope, eventsStr, googleObject, element) {
244
+ angular.forEach(eventsStr.split(' '), function (eventName) {
245
+ //Prefix all googlemap events with 'map-', so eg 'click'
246
+ //for the googlemap doesn't interfere with a normal 'click' event
247
+ var $event = { type: 'map-' + eventName };
248
+ google.maps.event.addListener(googleObject, eventName, function (evt) {
249
+ element.trigger(angular.extend({}, $event, evt));
250
+ //We create an $apply if it isn't happening. we need better support for this
251
+ //We don't want to use timeout because tons of these events fire at once,
252
+ //and we only need one $apply
253
+ if (!scope.$$phase) scope.$apply();
254
+ });
255
+ });
256
+ }
257
+
258
+ app.directive('uiMap',
259
+ ['ui.config', '$parse', function (uiConfig, $parse) {
260
+
261
+ var mapEvents = 'bounds_changed center_changed click dblclick drag dragend ' +
262
+ 'dragstart heading_changed idle maptypeid_changed mousemove mouseout ' +
263
+ 'mouseover projection_changed resize rightclick tilesloaded tilt_changed ' +
264
+ 'zoom_changed';
265
+ var options = uiConfig.map || {};
266
+
267
+ return {
268
+ restrict: 'A',
269
+ //doesn't work as E for unknown reason
270
+ link: function (scope, elm, attrs) {
271
+ var opts = angular.extend({}, options, scope.$eval(attrs.uiOptions));
272
+ var map = new google.maps.Map(elm[0], opts);
273
+ var model = $parse(attrs.uiMap);
274
+
275
+ //Set scope variable for the map
276
+ model.assign(scope, map);
277
+
278
+ bindMapEvents(scope, mapEvents, map, elm);
279
+ }
280
+ };
281
+ }]);
282
+
283
+ app.directive('uiMapInfoWindow',
284
+ ['ui.config', '$parse', '$compile', function (uiConfig, $parse, $compile) {
285
+
286
+ var infoWindowEvents = 'closeclick content_change domready ' +
287
+ 'position_changed zindex_changed';
288
+ var options = uiConfig.mapInfoWindow || {};
289
+
290
+ return {
291
+ link: function (scope, elm, attrs) {
292
+ var opts = angular.extend({}, options, scope.$eval(attrs.uiOptions));
293
+ opts.content = elm[0];
294
+ var model = $parse(attrs.uiMapInfoWindow);
295
+ var infoWindow = model(scope);
296
+
297
+ if (!infoWindow) {
298
+ infoWindow = new google.maps.InfoWindow(opts);
299
+ model.assign(scope, infoWindow);
300
+ }
301
+
302
+ bindMapEvents(scope, infoWindowEvents, infoWindow, elm);
303
+
304
+ /* The info window's contents dont' need to be on the dom anymore,
305
+ google maps has them stored. So we just replace the infowindow element
306
+ with an empty div. (we don't just straight remove it from the dom because
307
+ straight removing things from the dom can mess up angular) */
308
+ elm.replaceWith('<div></div>');
309
+
310
+ //Decorate infoWindow.open to $compile contents before opening
311
+ var _open = infoWindow.open;
312
+ infoWindow.open = function open(a1, a2, a3, a4, a5, a6) {
313
+ $compile(elm.contents())(scope);
314
+ _open.call(infoWindow, a1, a2, a3, a4, a5, a6);
315
+ };
316
+ }
317
+ };
318
+ }]);
319
+
320
+ /*
321
+ * Map overlay directives all work the same. Take map marker for example
322
+ * <ui-map-marker="myMarker"> will $watch 'myMarker' and each time it changes,
323
+ * it will hook up myMarker's events to the directive dom element. Then
324
+ * ui-event will be able to catch all of myMarker's events. Super simple.
325
+ */
326
+ function mapOverlayDirective(directiveName, events) {
327
+ app.directive(directiveName, [function () {
328
+ return {
329
+ restrict: 'A',
330
+ link: function (scope, elm, attrs) {
331
+ scope.$watch(attrs[directiveName], function (newObject) {
332
+ bindMapEvents(scope, events, newObject, elm);
333
+ });
334
+ }
335
+ };
336
+ }]);
337
+ }
338
+
339
+ mapOverlayDirective('uiMapMarker',
340
+ 'animation_changed click clickable_changed cursor_changed ' +
341
+ 'dblclick drag dragend draggable_changed dragstart flat_changed icon_changed ' +
342
+ 'mousedown mouseout mouseover mouseup position_changed rightclick ' +
343
+ 'shadow_changed shape_changed title_changed visible_changed zindex_changed');
344
+
345
+ mapOverlayDirective('uiMapPolyline',
346
+ 'click dblclick mousedown mousemove mouseout mouseover mouseup rightclick');
347
+
348
+ mapOverlayDirective('uiMapPolygon',
349
+ 'click dblclick mousedown mousemove mouseout mouseover mouseup rightclick');
350
+
351
+ mapOverlayDirective('uiMapRectangle',
352
+ 'bounds_changed click dblclick mousedown mousemove mouseout mouseover ' +
353
+ 'mouseup rightclick');
354
+
355
+ mapOverlayDirective('uiMapCircle',
356
+ 'center_changed click dblclick mousedown mousemove ' +
357
+ 'mouseout mouseover mouseup radius_changed rightclick');
358
+
359
+ mapOverlayDirective('uiMapGroundOverlay',
360
+ 'click dblclick');
361
+
362
+ })();
363
+ angular.module('ui.directives').factory('keypressHelper', ['$parse', function keypress($parse){
364
+ var keysByCode = {
365
+ 8: 'backspace',
366
+ 9: 'tab',
367
+ 13: 'enter',
368
+ 27: 'esc',
369
+ 32: 'space',
370
+ 33: 'pageup',
371
+ 34: 'pagedown',
372
+ 35: 'end',
373
+ 36: 'home',
374
+ 37: 'left',
375
+ 38: 'up',
376
+ 39: 'right',
377
+ 40: 'down',
378
+ 45: 'insert',
379
+ 46: 'delete'
380
+ };
381
+
382
+ var capitaliseFirstLetter = function (string) {
383
+ return string.charAt(0).toUpperCase() + string.slice(1);
384
+ };
385
+
386
+ return function(mode, scope, elm, attrs) {
387
+ var params, combinations = [];
388
+ params = scope.$eval(attrs['ui'+capitaliseFirstLetter(mode)]);
389
+
390
+ // Prepare combinations for simple checking
391
+ angular.forEach(params, function (v, k) {
392
+ var combination, expression;
393
+ expression = $parse(v);
394
+
395
+ angular.forEach(k.split(' '), function(variation) {
396
+ combination = {
397
+ expression: expression,
398
+ keys: {}
399
+ };
400
+ angular.forEach(variation.split('-'), function (value) {
401
+ combination.keys[value] = true;
402
+ });
403
+ combinations.push(combination);
404
+ });
405
+ });
406
+
407
+ // Check only matching of pressed keys one of the conditions
408
+ elm.bind(mode, function (event) {
409
+ // No need to do that inside the cycle
410
+ var altPressed = event.metaKey || event.altKey;
411
+ var ctrlPressed = event.ctrlKey;
412
+ var shiftPressed = event.shiftKey;
413
+ var keyCode = event.keyCode;
414
+
415
+ // normalize keycodes
416
+ if (mode === 'keypress' && !shiftPressed && keyCode >= 97 && keyCode <= 122) {
417
+ keyCode = keyCode - 32;
418
+ }
419
+
420
+ // Iterate over prepared combinations
421
+ angular.forEach(combinations, function (combination) {
422
+
423
+ var mainKeyPressed = (combination.keys[keysByCode[event.keyCode]] || combination.keys[event.keyCode.toString()]) || false;
424
+
425
+ var altRequired = combination.keys.alt || false;
426
+ var ctrlRequired = combination.keys.ctrl || false;
427
+ var shiftRequired = combination.keys.shift || false;
428
+
429
+ if (
430
+ mainKeyPressed &&
431
+ ( altRequired == altPressed ) &&
432
+ ( ctrlRequired == ctrlPressed ) &&
433
+ ( shiftRequired == shiftPressed )
434
+ ) {
435
+ // Run the function
436
+ scope.$apply(function () {
437
+ combination.expression(scope, { '$event': event });
438
+ });
439
+ }
440
+ });
441
+ });
442
+ };
443
+ }]);
444
+
445
+ /**
446
+ * Bind one or more handlers to particular keys or their combination
447
+ * @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'.
448
+ * @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" />
449
+ **/
450
+ angular.module('ui.directives').directive('uiKeydown', ['keypressHelper', function(keypressHelper){
451
+ return {
452
+ link: function (scope, elm, attrs) {
453
+ keypressHelper('keydown', scope, elm, attrs);
454
+ }
455
+ };
456
+ }]);
457
+
458
+ angular.module('ui.directives').directive('uiKeypress', ['keypressHelper', function(keypressHelper){
459
+ return {
460
+ link: function (scope, elm, attrs) {
461
+ keypressHelper('keypress', scope, elm, attrs);
462
+ }
463
+ };
464
+ }]);
465
+
466
+ angular.module('ui.directives').directive('uiKeyup', ['keypressHelper', function(keypressHelper){
467
+ return {
468
+ link: function (scope, elm, attrs) {
469
+ keypressHelper('keyup', scope, elm, attrs);
470
+ }
471
+ };
472
+ }]);
985
473
  /**
986
474
  * General-purpose validator for ngModel.
987
475
  * angular.js comes with several built-in validation mechanism for input fields (ngRequired, ngPattern etc.) but using
@@ -1029,151 +517,800 @@ angular.module('ui.directives').directive('uiValidate', function () {
1029
517
  });
1030
518
  }
1031
519
  };
1032
- });
1033
-
1034
- /**
1035
- * A replacement utility for internationalization very similar to sprintf.
1036
- *
1037
- * @param replace {mixed} The tokens to replace depends on type
1038
- * string: all instances of $0 will be replaced
1039
- * array: each instance of $0, $1, $2 etc. will be placed with each array item in corresponding order
1040
- * object: all attributes will be iterated through, with :key being replaced with its corresponding value
1041
- * @return string
1042
- *
1043
- * @example: 'Hello :name, how are you :day'.format({ name:'John', day:'Today' })
1044
- * @example: 'Records $0 to $1 out of $2 total'.format(['10', '20', '3000'])
1045
- * @example: '$0 agrees to all mentions $0 makes in the event that $0 hits a tree while $0 is driving drunk'.format('Bob')
1046
- */
1047
- angular.module('ui.filters').filter('format', function(){
1048
- return function(value, replace) {
1049
- if (!value) {
1050
- return value;
1051
- }
1052
- var target = value.toString(), token;
1053
- if (replace === undefined) {
1054
- return target;
1055
- }
1056
- if (!angular.isArray(replace) && !angular.isObject(replace)) {
1057
- return target.split('$0').join(replace);
1058
- }
1059
- token = angular.isArray(replace) && '$' || ':';
1060
-
1061
- angular.forEach(replace, function(value, key){
1062
- target = target.split(token+key).join(value);
1063
- });
1064
- return target;
1065
- };
1066
- });
1067
-
1068
- /**
1069
- * Wraps the
1070
- * @param text {string} haystack to search through
1071
- * @param search {string} needle to search for
1072
- * @param [caseSensitive] {boolean} optional boolean to use case-sensitive searching
1073
- */
1074
- angular.module('ui.filters').filter('highlight', function () {
1075
- return function (text, search, caseSensitive) {
1076
- if (search || angular.isNumber(search)) {
1077
- text = text.toString();
1078
- search = search.toString();
1079
- if (caseSensitive) {
1080
- return text.split(search).join('<span class="ui-match">' + search + '</span>');
1081
- } else {
1082
- return text.replace(new RegExp(search, 'gi'), '<span class="ui-match">$&</span>');
1083
- }
1084
- } else {
1085
- return text;
1086
- }
1087
- };
1088
- });
1089
-
1090
- /**
1091
- * Converts variable-esque naming conventions to something presentational, capitalized words separated by space.
1092
- * @param {String} value The value to be parsed and prettified.
1093
- * @param {String} [inflector] The inflector to use. Default: humanize.
1094
- * @return {String}
1095
- * @example {{ 'Here Is my_phoneNumber' | inflector:'humanize' }} => Here Is My Phone Number
1096
- * {{ 'Here Is my_phoneNumber' | inflector:'underscore' }} => here_is_my_phone_number
1097
- * {{ 'Here Is my_phoneNumber' | inflector:'variable' }} => hereIsMyPhoneNumber
1098
- */
1099
- angular.module('ui.filters').filter('inflector', function () {
1100
- function ucwords(text) {
1101
- return text.replace(/^([a-z])|\s+([a-z])/g, function ($1) {
1102
- return $1.toUpperCase();
1103
- });
1104
- }
1105
-
1106
- function breakup(text, separator) {
1107
- return text.replace(/[A-Z]/g, function (match) {
1108
- return separator + match;
1109
- });
1110
- }
1111
-
1112
- var inflectors = {
1113
- humanize: function (value) {
1114
- return ucwords(breakup(value, ' ').split('_').join(' '));
1115
- },
1116
- underscore: function (value) {
1117
- return value.substr(0, 1).toLowerCase() + breakup(value.substr(1), '_').toLowerCase().split(' ').join('_');
1118
- },
1119
- variable: function (value) {
1120
- value = value.substr(0, 1).toLowerCase() + ucwords(value.split('_').join(' ')).substr(1).split(' ').join('');
1121
- return value;
1122
- }
1123
- };
1124
-
1125
- return function (text, inflector, separator) {
1126
- if (inflector !== false && angular.isString(text)) {
1127
- inflector = inflector || 'humanize';
1128
- return inflectors[inflector](text);
1129
- } else {
1130
- return text;
1131
- }
1132
- };
1133
- });
1134
-
1135
- /**
1136
- * Filters out all duplicate items from an array by checking the specified key
1137
- * @param [key] {string} the name of the attribute of each object to compare for uniqueness
1138
- if the key is empty, the entire object will be compared
1139
- if the key === false then no filtering will be performed
1140
- * @return {array}
1141
- */
1142
- angular.module('ui.filters').filter('unique', function () {
1143
-
1144
- return function (items, filterOn) {
1145
-
1146
- if (filterOn === false) {
1147
- return items;
1148
- }
1149
-
1150
- if ((filterOn || angular.isUndefined(filterOn)) && angular.isArray(items)) {
1151
- var hashCheck = {}, newItems = [];
1152
-
1153
- var extractValueToCompare = function (item) {
1154
- if (angular.isObject(item) && angular.isString(filterOn)) {
1155
- return item[filterOn];
1156
- } else {
1157
- return item;
1158
- }
1159
- };
1160
-
1161
- angular.forEach(items, function (item) {
1162
- var valueToCheck, isDuplicate = false;
1163
-
1164
- for (var i = 0; i < newItems.length; i++) {
1165
- if (angular.equals(extractValueToCompare(newItems[i]), extractValueToCompare(item))) {
1166
- isDuplicate = true;
1167
- break;
1168
- }
1169
- }
1170
- if (!isDuplicate) {
1171
- newItems.push(item);
1172
- }
1173
-
1174
- });
1175
- items = newItems;
1176
- }
1177
- return items;
1178
- };
1179
- });
520
+ });
521
+ /**
522
+ * Animates the injection of new DOM elements by simply creating the DOM with a class and then immediately removing it
523
+ * Animations must be done using CSS3 transitions, but provide excellent flexibility
524
+ *
525
+ * @todo Add proper support for animating out
526
+ * @param [options] {mixed} Can be an object with multiple options, or a string with the animation class
527
+ * class {string} the CSS class(es) to use. For example, 'ui-hide' might be an excellent alternative class.
528
+ * @example <li ng-repeat="item in items" ui-animate=" 'ui-hide' ">{{item}}</li>
529
+ */
530
+ angular.module('ui.directives').directive('uiAnimate', ['ui.config', '$timeout', function (uiConfig, $timeout) {
531
+ var options = {};
532
+ if (angular.isString(uiConfig.animate)) {
533
+ options['class'] = uiConfig.animate;
534
+ } else if (uiConfig.animate) {
535
+ options = uiConfig.animate;
536
+ }
537
+ return {
538
+ restrict: 'A', // supports using directive as element, attribute and class
539
+ link: function ($scope, element, attrs) {
540
+ var opts = {};
541
+ if (attrs.uiAnimate) {
542
+ opts = $scope.$eval(attrs.uiAnimate);
543
+ if (angular.isString(opts)) {
544
+ opts = {'class': opts};
545
+ }
546
+ }
547
+ opts = angular.extend({'class': 'ui-animate'}, options, opts);
548
+
549
+ element.addClass(opts['class']);
550
+ $timeout(function () {
551
+ element.removeClass(opts['class']);
552
+ }, 20, false);
553
+ }
554
+ };
555
+ }]);
556
+
557
+
558
+ /**
559
+ * Enhanced Select2 Dropmenus
560
+ *
561
+ * @AJAX Mode - When in this mode, your value will be an object (or array of objects) of the data used by Select2
562
+ * This change is so that you do not have to do an additional query yourself on top of Select2's own query
563
+ * @params [options] {object} The configuration options passed to $.fn.select2(). Refer to the documentation
564
+ */
565
+ angular.module('ui.directives').directive('uiSelect2', ['ui.config', '$http', function (uiConfig, $http) {
566
+ var options = {};
567
+ if (uiConfig.select2) {
568
+ angular.extend(options, uiConfig.select2);
569
+ }
570
+ return {
571
+ require: '?ngModel',
572
+ compile: function (tElm, tAttrs) {
573
+ var watch,
574
+ repeatOption,
575
+ repeatAttr,
576
+ isSelect = tElm.is('select'),
577
+ isMultiple = (tAttrs.multiple !== undefined);
578
+
579
+ // Enable watching of the options dataset if in use
580
+ if (tElm.is('select')) {
581
+ repeatOption = tElm.find('option[ng-repeat], option[data-ng-repeat]');
582
+
583
+ if (repeatOption.length) {
584
+ repeatAttr = repeatOption.attr('ng-repeat') || repeatOption.attr('data-ng-repeat');
585
+ watch = jQuery.trim(repeatAttr.split('|')[0]).split(' ').pop();
586
+ }
587
+ }
588
+
589
+ return function (scope, elm, attrs, controller) {
590
+ // instance-specific options
591
+ var opts = angular.extend({}, options, scope.$eval(attrs.uiSelect2));
592
+
593
+ if (isSelect) {
594
+ // Use <select multiple> instead
595
+ delete opts.multiple;
596
+ delete opts.initSelection;
597
+ } else if (isMultiple) {
598
+ opts.multiple = true;
599
+ }
600
+
601
+ if (controller) {
602
+ // Watch the model for programmatic changes
603
+ controller.$render = function () {
604
+ if (isSelect) {
605
+ elm.select2('val', controller.$modelValue);
606
+ } else {
607
+ if (isMultiple && !controller.$modelValue) {
608
+ elm.select2('data', []);
609
+ } else {
610
+ elm.select2('data', controller.$modelValue);
611
+ }
612
+ }
613
+ };
614
+
615
+
616
+ // Watch the options dataset for changes
617
+ if (watch) {
618
+ scope.$watch(watch, function (newVal, oldVal, scope) {
619
+ if (!newVal) return;
620
+ // Delayed so that the options have time to be rendered
621
+ setTimeout(function () {
622
+ elm.select2('val', controller.$viewValue);
623
+ // Refresh angular to remove the superfluous option
624
+ elm.trigger('change');
625
+ });
626
+ });
627
+ }
628
+
629
+ if (!isSelect) {
630
+ // Set the view and model value and update the angular template manually for the ajax/multiple select2.
631
+ elm.bind("change", function () {
632
+ scope.$apply(function () {
633
+ controller.$setViewValue(elm.select2('data'));
634
+ });
635
+ });
636
+
637
+ if (opts.initSelection) {
638
+ var initSelection = opts.initSelection;
639
+ opts.initSelection = function (element, callback) {
640
+ initSelection(element, function (value) {
641
+ controller.$setViewValue(value);
642
+ callback(value);
643
+ });
644
+ };
645
+ }
646
+ }
647
+ }
648
+
649
+ attrs.$observe('disabled', function (value) {
650
+ elm.select2(value && 'disable' || 'enable');
651
+ });
652
+
653
+ scope.$watch(attrs.ngMultiple, function(newVal) {
654
+ elm.select2(opts);
655
+ });
656
+
657
+ // Set initial value since Angular doesn't
658
+ elm.val(scope.$eval(attrs.ngModel));
659
+
660
+ // Initialize the plugin late so that the injected DOM does not disrupt the template compiler
661
+ setTimeout(function () {
662
+ elm.select2(opts);
663
+ });
664
+ };
665
+ }
666
+ };
667
+ }]);
668
+
669
+ /*global angular, CodeMirror, Error*/
670
+ /**
671
+ * Binds a CodeMirror widget to a <textarea> element.
672
+ */
673
+ angular.module('ui.directives').directive('uiCodemirror', ['ui.config', '$parse', function (uiConfig, $parse) {
674
+ 'use strict';
675
+
676
+ uiConfig.codemirror = uiConfig.codemirror || {};
677
+ return {
678
+ require: 'ngModel',
679
+ link: function (scope, elm, attrs, ngModel) {
680
+ // Only works on textareas
681
+ if (!elm.is('textarea')) {
682
+ throw new Error('ui-codemirror can only be applied to a textarea element');
683
+ }
684
+
685
+ var codemirror;
686
+ // This is the method that we use to get the value of the ui-codemirror attribute expression.
687
+ var uiCodemirrorGet = $parse(attrs.uiCodemirror);
688
+ // This method will be called whenever the code mirror widget content changes
689
+ var onChangeHandler = function (ed) {
690
+ // We only update the model if the value has changed - this helps get around a little problem where $render triggers a change despite already being inside a $apply loop.
691
+ var newValue = ed.getValue();
692
+ if (newValue !== ngModel.$viewValue) {
693
+ ngModel.$setViewValue(newValue);
694
+ scope.$apply();
695
+ }
696
+ };
697
+ // Create and wire up a new code mirror widget (unwiring a previous one if necessary)
698
+ var updateCodeMirror = function (options) {
699
+ // Merge together the options from the uiConfig and the attribute itself with the onChange event above.
700
+ options = angular.extend({}, options, uiConfig.codemirror);
701
+
702
+ // We actually want to run both handlers if the user has provided their own onChange handler.
703
+ var userOnChange = options.onChange;
704
+ if (userOnChange) {
705
+ options.onChange = function (ed) {
706
+ onChangeHandler(ed);
707
+ userOnChange(ed);
708
+ };
709
+ } else {
710
+ options.onChange = onChangeHandler;
711
+ }
712
+
713
+ // If there is a codemirror widget for this element already then we need to unwire if first
714
+ if (codemirror) {
715
+ codemirror.toTextArea();
716
+ }
717
+ // Create the new codemirror widget
718
+ codemirror = CodeMirror.fromTextArea(elm[0], options);
719
+ };
720
+
721
+ // Initialize the code mirror widget
722
+ updateCodeMirror(uiCodemirrorGet());
723
+
724
+ // Now watch to see if the codemirror attribute gets updated
725
+ scope.$watch(uiCodemirrorGet, updateCodeMirror, true);
726
+
727
+ // CodeMirror expects a string, so make sure it gets one.
728
+ // This does not change the model.
729
+ ngModel.$formatters.push(function (value) {
730
+ if (angular.isUndefined(value) || value === null) {
731
+ return '';
732
+ }
733
+ else if (angular.isObject(value) || angular.isArray(value)) {
734
+ throw new Error('ui-codemirror cannot use an object or an array as a model');
735
+ }
736
+ return value;
737
+ });
738
+
739
+ // Override the ngModelController $render method, which is what gets called when the model is updated.
740
+ // This takes care of the synchronizing the codeMirror element with the underlying model, in the case that it is changed by something else.
741
+ ngModel.$render = function () {
742
+ codemirror.setValue(ngModel.$viewValue);
743
+ };
744
+ }
745
+ };
746
+ }]);
747
+ /**
748
+ * Binds a TinyMCE widget to <textarea> elements.
749
+ */
750
+ angular.module('ui.directives').directive('uiTinymce', ['ui.config', function (uiConfig) {
751
+ uiConfig.tinymce = uiConfig.tinymce || {};
752
+ return {
753
+ require: 'ngModel',
754
+ link: function (scope, elm, attrs, ngModel) {
755
+ var expression,
756
+ options = {
757
+ // Update model on button click
758
+ onchange_callback: function (inst) {
759
+ if (inst.isDirty()) {
760
+ inst.save();
761
+ ngModel.$setViewValue(elm.val());
762
+ if (!scope.$$phase)
763
+ scope.$apply();
764
+ }
765
+ },
766
+ // Update model on keypress
767
+ handle_event_callback: function (e) {
768
+ if (this.isDirty()) {
769
+ this.save();
770
+ ngModel.$setViewValue(elm.val());
771
+ if (!scope.$$phase)
772
+ scope.$apply();
773
+ }
774
+ return true; // Continue handling
775
+ },
776
+ // Update model when calling setContent (such as from the source editor popup)
777
+ setup: function (ed) {
778
+ ed.onSetContent.add(function (ed, o) {
779
+ if (ed.isDirty()) {
780
+ ed.save();
781
+ ngModel.$setViewValue(elm.val());
782
+ if (!scope.$$phase)
783
+ scope.$apply();
784
+ }
785
+ });
786
+ }
787
+ };
788
+ if (attrs.uiTinymce) {
789
+ expression = scope.$eval(attrs.uiTinymce);
790
+ } else {
791
+ expression = {};
792
+ }
793
+ angular.extend(options, uiConfig.tinymce, expression);
794
+ setTimeout(function () {
795
+ elm.tinymce(options);
796
+ });
797
+ }
798
+ };
799
+ }]);
800
+
801
+ /*
802
+ * Defines the ui-if tag. This removes/adds an element from the dom depending on a condition
803
+ * Originally created by @tigbro, for the @jquery-mobile-angular-adapter
804
+ * https://github.com/tigbro/jquery-mobile-angular-adapter
805
+ */
806
+ angular.module('ui.directives').directive('uiIf', [function () {
807
+ return {
808
+ transclude: 'element',
809
+ priority: 1000,
810
+ terminal: true,
811
+ restrict: 'A',
812
+ compile: function (element, attr, linker) {
813
+ return function (scope, iterStartElement, attr) {
814
+ iterStartElement[0].doNotMove = true;
815
+ var expression = attr.uiIf;
816
+ var lastElement;
817
+ var lastScope;
818
+ scope.$watch(expression, function (newValue) {
819
+ if (lastElement) {
820
+ lastElement.remove();
821
+ lastElement = null;
822
+ }
823
+ if (lastScope) {
824
+ lastScope.$destroy();
825
+ lastScope = null;
826
+ }
827
+ if (newValue) {
828
+ lastScope = scope.$new();
829
+ linker(lastScope, function (clone) {
830
+ lastElement = clone;
831
+ iterStartElement.after(clone);
832
+ });
833
+ }
834
+ // Note: need to be parent() as jquery cannot trigger events on comments
835
+ // (angular creates a comment node when using transclusion, as ng-repeat does).
836
+ iterStartElement.parent().trigger("$childrenChanged");
837
+ });
838
+ };
839
+ }
840
+ };
841
+ }]);
842
+ /*global angular, $, document*/
843
+ /**
844
+ * Adds a 'ui-scrollfix' class to the element when the page scrolls past it's position.
845
+ * @param [offset] {int} optional Y-offset to override the detected offset.
846
+ * Takes 300 (absolute) or -300 or +300 (relative to detected)
847
+ */
848
+ angular.module('ui.directives').directive('uiScrollfix', ['$window', function ($window) {
849
+ 'use strict';
850
+ return {
851
+ link: function (scope, elm, attrs) {
852
+ var top = elm.offset().top;
853
+ if (!attrs.uiScrollfix) {
854
+ attrs.uiScrollfix = top;
855
+ } else {
856
+ // chartAt is generally faster than indexOf: http://jsperf.com/indexof-vs-chartat
857
+ if (attrs.uiScrollfix.charAt(0) === '-') {
858
+ attrs.uiScrollfix = top - attrs.uiScrollfix.substr(1);
859
+ } else if (attrs.uiScrollfix.charAt(0) === '+') {
860
+ attrs.uiScrollfix = top + parseFloat(attrs.uiScrollfix.substr(1));
861
+ }
862
+ }
863
+ angular.element($window).on('scroll.ui-scrollfix', function () {
864
+ // if pageYOffset is defined use it, otherwise use other crap for IE
865
+ var offset;
866
+ if (angular.isDefined($window.pageYOffset)) {
867
+ offset = $window.pageYOffset;
868
+ } else {
869
+ var iebody = (document.compatMode && document.compatMode !== "BackCompat") ? document.documentElement : document.body;
870
+ offset = iebody.scrollTop;
871
+ }
872
+ if (!elm.hasClass('ui-scrollfix') && offset > attrs.uiScrollfix) {
873
+ elm.addClass('ui-scrollfix');
874
+ } else if (elm.hasClass('ui-scrollfix') && offset < attrs.uiScrollfix) {
875
+ elm.removeClass('ui-scrollfix');
876
+ }
877
+ });
878
+ }
879
+ };
880
+ }]);
881
+
882
+ /*
883
+ * AngularJs Fullcalendar Wrapper for the JQuery FullCalendar
884
+ * inspired by http://arshaw.com/fullcalendar/
885
+ *
886
+ * Basic Angular Calendar Directive that takes in live events as the ng-model and watches that event array for changes, to update the view accordingly.
887
+ * Can also take in an event url as a source object(s) and feed the events per view.
888
+ *
889
+ */
890
+
891
+ angular.module('ui.directives').directive('uiCalendar',['ui.config', '$parse', function (uiConfig,$parse) {
892
+ uiConfig.uiCalendar = uiConfig.uiCalendar || {};
893
+ //returns the fullcalendar
894
+ return {
895
+ require: 'ngModel',
896
+ restrict: 'A',
897
+ scope: {
898
+ events: "=ngModel"
899
+ },
900
+ link: function(scope, elm, $attrs) {
901
+ var ngModel = $parse($attrs.ngModel);
902
+ //update method that is called on load and whenever the events array is changed.
903
+ function update() {
904
+ //Default View Options
905
+ var expression,
906
+ options = {
907
+ header: {
908
+ left: 'prev,next today',
909
+ center: 'title',
910
+ right: 'month,agendaWeek,agendaDay'
911
+ },
912
+ // add event name to title attribute on mouseover.
913
+ eventMouseover: function(event, jsEvent, view) {
914
+ if (view.name !== 'agendaDay') {
915
+ $(jsEvent.target).attr('title', event.title);
916
+ }
917
+ },
918
+
919
+ // Calling the events from the scope through the ng-model binding attribute.
920
+ events: scope.events
921
+ };
922
+ //if attrs have been entered to the directive, then create a relative expression.
923
+ if ($attrs.uiCalendar){
924
+ expression = scope.$eval($attrs.uiCalendar);
925
+ }
926
+ else{
927
+ expression = {};
928
+ }
929
+ //extend the options to suite the custom directive.
930
+ angular.extend(options, uiConfig.uiCalendar, expression);
931
+ //call fullCalendar from an empty html tag, to keep angular happy.
932
+ elm.html('').fullCalendar(options);
933
+ }
934
+ //on load update call.
935
+ update();
936
+ //watching the length of the array to create a more efficient update process.
937
+ scope.$watch( 'events.length', function( newVal, oldVal )
938
+ {
939
+ //update the calendar on every change to events.length
940
+ update();
941
+ }, true );
942
+ }
943
+ };
944
+ }]);
945
+ /**
946
+ * uiShow Directive
947
+ *
948
+ * Adds a 'ui-show' class to the element instead of display:block
949
+ * Created to allow tighter control of CSS without bulkier directives
950
+ *
951
+ * @param expression {boolean} evaluated expression to determine if the class should be added
952
+ */
953
+ angular.module('ui.directives').directive('uiShow', [function () {
954
+ return function (scope, elm, attrs) {
955
+ scope.$watch(attrs.uiShow, function (newVal, oldVal) {
956
+ if (newVal) {
957
+ elm.addClass('ui-show');
958
+ } else {
959
+ elm.removeClass('ui-show');
960
+ }
961
+ });
962
+ };
963
+ }])
964
+
965
+ /**
966
+ * uiHide Directive
967
+ *
968
+ * Adds a 'ui-hide' class to the element instead of display:block
969
+ * Created to allow tighter control of CSS without bulkier directives
970
+ *
971
+ * @param expression {boolean} evaluated expression to determine if the class should be added
972
+ */
973
+ .directive('uiHide', [function () {
974
+ return function (scope, elm, attrs) {
975
+ scope.$watch(attrs.uiHide, function (newVal, oldVal) {
976
+ if (newVal) {
977
+ elm.addClass('ui-hide');
978
+ } else {
979
+ elm.removeClass('ui-hide');
980
+ }
981
+ });
982
+ };
983
+ }])
984
+
985
+ /**
986
+ * uiToggle Directive
987
+ *
988
+ * Adds a class 'ui-show' if true, and a 'ui-hide' if false to the element instead of display:block/display:none
989
+ * Created to allow tighter control of CSS without bulkier directives. This also allows you to override the
990
+ * default visibility of the element using either class.
991
+ *
992
+ * @param expression {boolean} evaluated expression to determine if the class should be added
993
+ */
994
+ .directive('uiToggle', [function () {
995
+ return function (scope, elm, attrs) {
996
+ scope.$watch(attrs.uiToggle, function (newVal, oldVal) {
997
+ if (newVal) {
998
+ elm.removeClass('ui-hide').addClass('ui-show');
999
+ } else {
1000
+ elm.removeClass('ui-show').addClass('ui-hide');
1001
+ }
1002
+ });
1003
+ };
1004
+ }]);
1005
+
1006
+ /*
1007
+ Gives the ability to style currency based on its sign.
1008
+ */
1009
+ angular.module('ui.directives').directive('uiCurrency', ['ui.config', 'currencyFilter' , function (uiConfig, currencyFilter) {
1010
+ var options = {
1011
+ pos: 'ui-currency-pos',
1012
+ neg: 'ui-currency-neg',
1013
+ zero: 'ui-currency-zero'
1014
+ };
1015
+ if (uiConfig.currency) {
1016
+ angular.extend(options, uiConfig.currency);
1017
+ }
1018
+ return {
1019
+ restrict: 'EAC',
1020
+ require: 'ngModel',
1021
+ link: function (scope, element, attrs, controller) {
1022
+ var opts, // instance-specific options
1023
+ renderview,
1024
+ value;
1025
+
1026
+ opts = angular.extend({}, options, scope.$eval(attrs.uiCurrency));
1027
+
1028
+ renderview = function (viewvalue) {
1029
+ var num;
1030
+ num = viewvalue * 1;
1031
+ if (num > 0) {
1032
+ element.addClass(opts.pos);
1033
+ } else {
1034
+ element.removeClass(opts.pos);
1035
+ }
1036
+ if (num < 0) {
1037
+ element.addClass(opts.neg);
1038
+ } else {
1039
+ element.removeClass(opts.neg);
1040
+ }
1041
+ if (num === 0) {
1042
+ element.addClass(opts.zero);
1043
+ } else {
1044
+ element.removeClass(opts.zero);
1045
+ }
1046
+ if (viewvalue === '') {
1047
+ element.text('');
1048
+ } else {
1049
+ element.text(currencyFilter(num, opts.symbol));
1050
+ }
1051
+ return true;
1052
+ };
1053
+
1054
+ controller.$render = function () {
1055
+ value = controller.$viewValue;
1056
+ element.val(value);
1057
+ renderview(value);
1058
+ };
1059
+
1060
+ }
1061
+ };
1062
+ }]);
1063
+
1064
+ /*global angular */
1065
+ /*
1066
+ jQuery UI Datepicker plugin wrapper
1067
+
1068
+ @param [ui-date] {object} Options to pass to $.fn.datepicker() merged onto ui.config
1069
+ */
1070
+
1071
+ angular.module('ui.directives')
1072
+
1073
+ .directive('uiDate', ['ui.config', function (uiConfig) {
1074
+ 'use strict';
1075
+ var options;
1076
+ options = {};
1077
+ if (angular.isObject(uiConfig.date)) {
1078
+ angular.extend(options, uiConfig.date);
1079
+ }
1080
+ return {
1081
+ require:'?ngModel',
1082
+ link:function (scope, element, attrs, controller) {
1083
+ var getOptions = function () {
1084
+ return angular.extend({}, uiConfig.date, scope.$eval(attrs.uiDate));
1085
+ };
1086
+ var initDateWidget = function () {
1087
+ var opts = getOptions();
1088
+
1089
+ // If we have a controller (i.e. ngModelController) then wire it up
1090
+ if (controller) {
1091
+ var updateModel = function () {
1092
+ scope.$apply(function () {
1093
+ var date = element.datepicker("getDate");
1094
+ element.datepicker("setDate", element.val());
1095
+ controller.$setViewValue(date);
1096
+ });
1097
+ };
1098
+ if (opts.onSelect) {
1099
+ // Caller has specified onSelect, so call this as well as updating the model
1100
+ var userHandler = opts.onSelect;
1101
+ opts.onSelect = function (value, picker) {
1102
+ updateModel();
1103
+ return userHandler(value, picker);
1104
+ };
1105
+ } else {
1106
+ // No onSelect already specified so just update the model
1107
+ opts.onSelect = updateModel;
1108
+ }
1109
+ // In case the user changes the text directly in the input box
1110
+ element.bind('change', updateModel);
1111
+
1112
+ // Update the date picker when the model changes
1113
+ controller.$render = function () {
1114
+ var date = controller.$viewValue;
1115
+ if ( angular.isDefined(date) && date !== null && !angular.isDate(date) ) {
1116
+ throw new Error('ng-Model value must be a Date object - currently it is a ' + typeof date + ' - use ui-date-format to convert it from a string');
1117
+ }
1118
+ element.datepicker("setDate", date);
1119
+ };
1120
+ }
1121
+ // If we don't destroy the old one it doesn't update properly when the config changes
1122
+ element.datepicker('destroy');
1123
+ // Create the new datepicker widget
1124
+ element.datepicker(opts);
1125
+ // Force a render to override whatever is in the input text box
1126
+ controller.$render();
1127
+ };
1128
+ // Watch for changes to the directives options
1129
+ scope.$watch(getOptions, initDateWidget, true);
1130
+ }
1131
+ };
1132
+ }
1133
+ ])
1134
+
1135
+ .directive('uiDateFormat', [function() {
1136
+ var directive = {
1137
+ require:'ngModel',
1138
+ link: function(scope, element, attrs, modelCtrl) {
1139
+ if ( attrs.uiDateFormat === '' ) {
1140
+ // Default to ISO formatting
1141
+ modelCtrl.$formatters.push(function(value) {
1142
+ if (angular.isString(value) ) {
1143
+ return new Date(value);
1144
+ }
1145
+ });
1146
+ modelCtrl.$parsers.push(function(value){
1147
+ if (value) {
1148
+ return value.toISOString();
1149
+ }
1150
+ });
1151
+ } else {
1152
+ var format = attrs.uiDateFormat;
1153
+ // Use the datepicker with the attribute value as the format string to convert to and from a string
1154
+ modelCtrl.$formatters.push(function(value) {
1155
+ if (angular.isString(value) ) {
1156
+ return $.datepicker.parseDate(format, value);
1157
+ }
1158
+ });
1159
+ modelCtrl.$parsers.push(function(value){
1160
+ if (value) {
1161
+ return $.datepicker.formatDate(format, value);
1162
+ }
1163
+ });
1164
+ }
1165
+ }
1166
+ };
1167
+ return directive;
1168
+ }]);
1169
+
1170
+ /**
1171
+ * Wraps the
1172
+ * @param text {string} haystack to search through
1173
+ * @param search {string} needle to search for
1174
+ * @param [caseSensitive] {boolean} optional boolean to use case-sensitive searching
1175
+ */
1176
+ angular.module('ui.filters').filter('highlight', function () {
1177
+ return function (text, search, caseSensitive) {
1178
+ if (search || angular.isNumber(search)) {
1179
+ text = text.toString();
1180
+ search = search.toString();
1181
+ if (caseSensitive) {
1182
+ return text.split(search).join('<span class="ui-match">' + search + '</span>');
1183
+ } else {
1184
+ return text.replace(new RegExp(search, 'gi'), '<span class="ui-match">$&</span>');
1185
+ }
1186
+ } else {
1187
+ return text;
1188
+ }
1189
+ };
1190
+ });
1191
+
1192
+
1193
+ /**
1194
+ * A replacement utility for internationalization very similar to sprintf.
1195
+ *
1196
+ * @param replace {mixed} The tokens to replace depends on type
1197
+ * string: all instances of $0 will be replaced
1198
+ * array: each instance of $0, $1, $2 etc. will be placed with each array item in corresponding order
1199
+ * object: all attributes will be iterated through, with :key being replaced with its corresponding value
1200
+ * @return string
1201
+ *
1202
+ * @example: 'Hello :name, how are you :day'.format({ name:'John', day:'Today' })
1203
+ * @example: 'Records $0 to $1 out of $2 total'.format(['10', '20', '3000'])
1204
+ * @example: '$0 agrees to all mentions $0 makes in the event that $0 hits a tree while $0 is driving drunk'.format('Bob')
1205
+ */
1206
+ angular.module('ui.filters').filter('format', function(){
1207
+ return function(value, replace) {
1208
+ if (!value) {
1209
+ return value;
1210
+ }
1211
+ var target = value.toString(), token;
1212
+ if (replace === undefined) {
1213
+ return target;
1214
+ }
1215
+ if (!angular.isArray(replace) && !angular.isObject(replace)) {
1216
+ return target.split('$0').join(replace);
1217
+ }
1218
+ token = angular.isArray(replace) && '$' || ':';
1219
+
1220
+ angular.forEach(replace, function(value, key){
1221
+ target = target.split(token+key).join(value);
1222
+ });
1223
+ return target;
1224
+ };
1225
+ });
1226
+
1227
+ /**
1228
+ * Filters out all duplicate items from an array by checking the specified key
1229
+ * @param [key] {string} the name of the attribute of each object to compare for uniqueness
1230
+ if the key is empty, the entire object will be compared
1231
+ if the key === false then no filtering will be performed
1232
+ * @return {array}
1233
+ */
1234
+ angular.module('ui.filters').filter('unique', function () {
1235
+
1236
+ return function (items, filterOn) {
1237
+
1238
+ if (filterOn === false) {
1239
+ return items;
1240
+ }
1241
+
1242
+ if ((filterOn || angular.isUndefined(filterOn)) && angular.isArray(items)) {
1243
+ var hashCheck = {}, newItems = [];
1244
+
1245
+ var extractValueToCompare = function (item) {
1246
+ if (angular.isObject(item) && angular.isString(filterOn)) {
1247
+ return item[filterOn];
1248
+ } else {
1249
+ return item;
1250
+ }
1251
+ };
1252
+
1253
+ angular.forEach(items, function (item) {
1254
+ var valueToCheck, isDuplicate = false;
1255
+
1256
+ for (var i = 0; i < newItems.length; i++) {
1257
+ if (angular.equals(extractValueToCompare(newItems[i]), extractValueToCompare(item))) {
1258
+ isDuplicate = true;
1259
+ break;
1260
+ }
1261
+ }
1262
+ if (!isDuplicate) {
1263
+ newItems.push(item);
1264
+ }
1265
+
1266
+ });
1267
+ items = newItems;
1268
+ }
1269
+ return items;
1270
+ };
1271
+ });
1272
+
1273
+ /**
1274
+ * Converts variable-esque naming conventions to something presentational, capitalized words separated by space.
1275
+ * @param {String} value The value to be parsed and prettified.
1276
+ * @param {String} [inflector] The inflector to use. Default: humanize.
1277
+ * @return {String}
1278
+ * @example {{ 'Here Is my_phoneNumber' | inflector:'humanize' }} => Here Is My Phone Number
1279
+ * {{ 'Here Is my_phoneNumber' | inflector:'underscore' }} => here_is_my_phone_number
1280
+ * {{ 'Here Is my_phoneNumber' | inflector:'variable' }} => hereIsMyPhoneNumber
1281
+ */
1282
+ angular.module('ui.filters').filter('inflector', function () {
1283
+ function ucwords(text) {
1284
+ return text.replace(/^([a-z])|\s+([a-z])/g, function ($1) {
1285
+ return $1.toUpperCase();
1286
+ });
1287
+ }
1288
+
1289
+ function breakup(text, separator) {
1290
+ return text.replace(/[A-Z]/g, function (match) {
1291
+ return separator + match;
1292
+ });
1293
+ }
1294
+
1295
+ var inflectors = {
1296
+ humanize: function (value) {
1297
+ return ucwords(breakup(value, ' ').split('_').join(' '));
1298
+ },
1299
+ underscore: function (value) {
1300
+ return value.substr(0, 1).toLowerCase() + breakup(value.substr(1), '_').toLowerCase().split(' ').join('_');
1301
+ },
1302
+ variable: function (value) {
1303
+ value = value.substr(0, 1).toLowerCase() + ucwords(value.split('_').join(' ')).substr(1).split(' ').join('');
1304
+ return value;
1305
+ }
1306
+ };
1307
+
1308
+ return function (text, inflector, separator) {
1309
+ if (inflector !== false && angular.isString(text)) {
1310
+ inflector = inflector || 'humanize';
1311
+ return inflectors[inflector](text);
1312
+ } else {
1313
+ return text;
1314
+ }
1315
+ };
1316
+ });