angular-ui-rails 0.0.1 → 0.2.1

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