|
18 | 18 | $.ig.angular.igCombo.element = $.ig.angular.igCombo.element || "<input></input>"; |
19 | 19 | $.ig.angular.igCombo.events = [ "igcombotextchanged", "igcomboselectionchanged" ]; |
20 | 20 |
|
| 21 | + // Mark watchers for discoverability |
| 22 | + function markWatcher(scope, controlName, attrs) { |
| 23 | + // Angular uses unshift(), so the last watcher is at 0: |
| 24 | + scope.$$watchers[ 0 ][ controlName ] = attrs.id || controlName + scope.$$watchers.length; |
| 25 | + } |
| 26 | + |
| 27 | + // Interrogation functions |
| 28 | + function isDate(value) { |
| 29 | + return Object.prototype.toString.call(value) === "[object Date]"; |
| 30 | + } |
| 31 | + |
| 32 | + function isRegExp(value) { |
| 33 | + return Object.prototype.toString.call(value) === "[object RegExp]"; |
| 34 | + } |
| 35 | + |
| 36 | + function isScope(obj) { |
| 37 | + return obj && obj.$evalAsync && obj.$watch; |
| 38 | + } |
| 39 | + |
| 40 | + function isWindow(obj) { |
| 41 | + return obj && obj.document && obj.location && obj.alert && obj.setInterval; |
| 42 | + } |
| 43 | + |
| 44 | + function isFunction(value) { return typeof value === "function"; } |
| 45 | + |
| 46 | + function isArray(value) { |
| 47 | + return Object.prototype.toString.call(value) === "[object Array]"; |
| 48 | + } |
| 49 | + |
| 50 | + function equalsDiff(o1, o2, diff) { |
| 51 | + if (o1 === o2) { return true; } |
| 52 | + if (o1 === null || o2 === null) { return false; } |
| 53 | + if (o1 !== o1 && o2 !== o2) { return true; }// NaN === NaN |
| 54 | + var t1 = typeof o1, t2 = typeof o2, length, key, keySet, |
| 55 | + dirty, skipDiff = false, changedVals = []; |
| 56 | + if (t1 === t2) { |
| 57 | + if (t1 === "object") { |
| 58 | + if (isArray(o1)) { |
| 59 | + if (!isArray(o2)) { return false; } |
| 60 | + if ((length = o1.length) === o2.length) { |
| 61 | + if (!isArray(diff)) { |
| 62 | + skipDiff = true; |
| 63 | + } |
| 64 | + for (key = 0; key < length; key++) { |
| 65 | + // we are comparing objects here |
| 66 | + if (!equalsDiff(o1[ key ], o2[ key ], changedVals)) { |
| 67 | + dirty = true; |
| 68 | + if (!skipDiff) { |
| 69 | + diff.push({ index: key, txlog: changedVals }); |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + if (dirty) { |
| 74 | + return false; |
| 75 | + } |
| 76 | + return true; |
| 77 | + } |
| 78 | + } else if (isDate(o1)) { |
| 79 | + return isDate(o2) && o1.getTime() === o2.getTime(); |
| 80 | + } else if (isRegExp(o1) && isRegExp(o2)) { |
| 81 | + return o1.toString() === o2.toString(); |
| 82 | + } else { |
| 83 | + if (isScope(o1) || isScope(o2) || |
| 84 | + isWindow(o1) || isWindow(o2) || |
| 85 | + isArray(o2)) { |
| 86 | + return false; |
| 87 | + } |
| 88 | + keySet = {}; |
| 89 | + if (!isArray(diff)) { |
| 90 | + skipDiff = true; |
| 91 | + } |
| 92 | + for (key in o1) { |
| 93 | + if (key.charAt(0) === "$" || isFunction(o1[ key ])) { continue; } |
| 94 | + if (!equalsDiff(o1[ key ], o2[ key ])) { |
| 95 | + dirty = true; |
| 96 | + if (!skipDiff) { |
| 97 | + diff.push({ key: key, oldVal: o2[ key ], newVal: o1[ key ] }); |
| 98 | + } |
| 99 | + } |
| 100 | + keySet[ key ] = true; |
| 101 | + } |
| 102 | + for (key in o2) { |
| 103 | + if (!keySet.hasOwnProperty(key) && |
| 104 | + key.charAt(0) !== "$" && |
| 105 | + o2[ key ] !== undefined && |
| 106 | + !isFunction(o2[ key ])) { return false; } |
| 107 | + } |
| 108 | + if (dirty) { |
| 109 | + return false; |
| 110 | + } |
| 111 | + return true; |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + return false; |
| 116 | + } |
| 117 | + |
21 | 118 | // Two way data binding for the combo control |
22 | 119 | $.ig.angular.igCombo.bindEvents = $.ig.angular.igCombo.bindEvents || |
23 | 120 | function (scope, element, attrs, model) { |
|
157 | 254 | function (scope, element, attrs) { |
158 | 255 | var unbinder, |
159 | 256 | collectionWatchMode = attrs && attrs.collectionWatch && attrs.collectionWatch === "true"; |
160 | | - element.on($.ig.angular.igGrid.events.join(" "), function () { |
161 | | - unbinder(); |
162 | | - /* When in collection watch mode, a change is detected only when the collection changes - a element is inserted or removed or the whole collection reference changes. |
163 | | - Changes in a specific element inside collection are not detected. This provides huge performance boost when such change detection is not required */ |
164 | | - unbinder = collectionWatchMode ? |
165 | | - scope.$watchCollection(attrs.source, watchGridDataSource) : |
166 | | - scope.$watch(attrs.source, watchGridDataSource, true); |
167 | | - scope.$apply(); |
168 | | - markWatcher(scope, "igGrid", attrs); |
169 | | - }).one("$destroy", function () { |
170 | | - unbinder(); |
171 | | - }); |
172 | 257 |
|
173 | | - function watchGridDataSource(newValue, oldValue) { |
| 258 | + function watchGridDataSource(newValue, oldValue) { |
174 | 259 | var i, j, existingDomRow, existingRow, |
175 | 260 | grid = element.data("igGrid"), pkKey = grid.options.primaryKey, |
176 | 261 | gridUpdating = element.data("igGridUpdating"), column, |
|
256 | 341 | } |
257 | 342 | } |
258 | 343 | } |
| 344 | + |
| 345 | + element.on($.ig.angular.igGrid.events.join(" "), function () { |
| 346 | + unbinder(); |
| 347 | + /* When in collection watch mode, a change is detected only when the collection changes - a element is inserted or removed or the whole collection reference changes. |
| 348 | + Changes in a specific element inside collection are not detected. This provides huge performance boost when such change detection is not required */ |
| 349 | + unbinder = collectionWatchMode ? |
| 350 | + scope.$watchCollection(attrs.source, watchGridDataSource) : |
| 351 | + scope.$watch(attrs.source, watchGridDataSource, true); |
| 352 | + scope.$apply(); |
| 353 | + markWatcher(scope, "igGrid", attrs); |
| 354 | + }).one("$destroy", function () { |
| 355 | + unbinder(); |
| 356 | + }); |
| 357 | + |
259 | 358 | /* watch for changes from the data source to the view */ |
260 | 359 | unbinder = collectionWatchMode ? |
261 | 360 | scope.$watchCollection(attrs.source, watchGridDataSource) : |
|
380 | 479 | }); |
381 | 480 | }; |
382 | 481 |
|
383 | | - // Mark watchers for discoverability |
384 | | - function markWatcher(scope, controlName, attrs) { |
385 | | - // Angular uses unshift(), so the last watcher is at 0: |
386 | | - scope.$$watchers[ 0 ][ controlName ] = attrs.id || controlName + scope.$$watchers.length; |
387 | | - } |
388 | | - |
389 | 482 | // Utility functions |
390 | 483 | function convertToCamelCase(str) { |
391 | 484 | //convert hyphen to camelCase |
|
500 | 593 | return options; |
501 | 594 | } |
502 | 595 |
|
503 | | - function equalsDiff(o1, o2, diff) { |
504 | | - if (o1 === o2) { return true; } |
505 | | - if (o1 === null || o2 === null) { return false; } |
506 | | - if (o1 !== o1 && o2 !== o2) { return true; }// NaN === NaN |
507 | | - var t1 = typeof o1, t2 = typeof o2, length, key, keySet, |
508 | | - dirty, skipDiff = false, changedVals = []; |
509 | | - if (t1 === t2) { |
510 | | - if (t1 === "object") { |
511 | | - if (isArray(o1)) { |
512 | | - if (!isArray(o2)) { return false; } |
513 | | - if ((length = o1.length) === o2.length) { |
514 | | - if (!isArray(diff)) { |
515 | | - skipDiff = true; |
516 | | - } |
517 | | - for (key = 0; key < length; key++) { |
518 | | - // we are comparing objects here |
519 | | - if (!equalsDiff(o1[ key ], o2[ key ], changedVals)) { |
520 | | - dirty = true; |
521 | | - if (!skipDiff) { |
522 | | - diff.push({ index: key, txlog: changedVals }); |
523 | | - } |
524 | | - } |
525 | | - } |
526 | | - if (dirty) { |
527 | | - return false; |
528 | | - } |
529 | | - return true; |
530 | | - } |
531 | | - } else if (isDate(o1)) { |
532 | | - return isDate(o2) && o1.getTime() === o2.getTime(); |
533 | | - } else if (isRegExp(o1) && isRegExp(o2)) { |
534 | | - return o1.toString() === o2.toString(); |
535 | | - } else { |
536 | | - if (isScope(o1) || isScope(o2) || |
537 | | - isWindow(o1) || isWindow(o2) || |
538 | | - isArray(o2)) { |
539 | | - return false; |
540 | | - } |
541 | | - keySet = {}; |
542 | | - if (!isArray(diff)) { |
543 | | - skipDiff = true; |
544 | | - } |
545 | | - for (key in o1) { |
546 | | - if (key.charAt(0) === "$" || isFunction(o1[ key ])) { continue; } |
547 | | - if (!equalsDiff(o1[ key ], o2[ key ])) { |
548 | | - dirty = true; |
549 | | - if (!skipDiff) { |
550 | | - diff.push({ key: key, oldVal: o2[ key ], newVal: o1[ key ] }); |
551 | | - } |
552 | | - } |
553 | | - keySet[ key ] = true; |
554 | | - } |
555 | | - for (key in o2) { |
556 | | - if (!keySet.hasOwnProperty(key) && |
557 | | - key.charAt(0) !== "$" && |
558 | | - o2[ key ] !== undefined && |
559 | | - !isFunction(o2[ key ])) { return false; } |
560 | | - } |
561 | | - if (dirty) { |
562 | | - return false; |
563 | | - } |
564 | | - return true; |
565 | | - } |
566 | | - } |
567 | | - } |
568 | | - return false; |
569 | | - } |
570 | | - |
571 | | - // Interrogation functions |
572 | | - function isDate(value) { |
573 | | - return Object.prototype.toString.call(value) === "[object Date]"; |
574 | | - } |
575 | | - |
576 | | - function isRegExp(value) { |
577 | | - return Object.prototype.toString.call(value) === "[object RegExp]"; |
578 | | - } |
579 | | - |
580 | | - function isScope(obj) { |
581 | | - return obj && obj.$evalAsync && obj.$watch; |
582 | | - } |
583 | | - |
584 | | - function isWindow(obj) { |
585 | | - return obj && obj.document && obj.location && obj.alert && obj.setInterval; |
586 | | - } |
587 | | - |
588 | | - function isFunction(value) { return typeof value === "function"; } |
589 | | - |
590 | | - function isArray(value) { |
591 | | - return Object.prototype.toString.call(value) === "[object Array]"; |
592 | | - } |
593 | | - |
594 | 596 | function getHtml(selector) { |
595 | 597 | return $(selector).html(); |
596 | 598 | } |
|
0 commit comments