diff options
Diffstat (limited to 'node_modules/montage/ui/component.js')
-rwxr-xr-x | node_modules/montage/ui/component.js | 201 |
1 files changed, 135 insertions, 66 deletions
diff --git a/node_modules/montage/ui/component.js b/node_modules/montage/ui/component.js index 17f87b62..9d963ada 100755 --- a/node_modules/montage/ui/component.js +++ b/node_modules/montage/ui/component.js | |||
@@ -414,6 +414,11 @@ var Component = exports.Component = Montage.create(Montage,/** @lends module:mon | |||
414 | _template: { | 414 | _template: { |
415 | value: null | 415 | value: null |
416 | }, | 416 | }, |
417 | |||
418 | // Tree level necessary for ordering drawing re: parent-child | ||
419 | _treeLevel: { | ||
420 | value: 0 | ||
421 | }, | ||
417 | /** | 422 | /** |
418 | Description TODO | 423 | Description TODO |
419 | @function | 424 | @function |
@@ -909,15 +914,15 @@ var Component = exports.Component = Montage.create(Montage,/** @lends module:mon | |||
909 | if (!templateModuleId) { | 914 | if (!templateModuleId) { |
910 | moduleId = info.moduleId; | 915 | moduleId = info.moduleId; |
911 | // TODO: backwards compatibility for components with its controller outside the reel folder | 916 | // TODO: backwards compatibility for components with its controller outside the reel folder |
912 | //console.log(moduleId); | 917 | //if (/([^\/]+)\.reel\/\1$/.exec(moduleId)) { |
913 | if (/([^\/]+)\.reel\/\1$/.exec(moduleId)) { | 918 | // templateModuleId = moduleId + ".html"; |
914 | templateModuleId = moduleId + ".html"; | 919 | //} else if (/([^\/]+)\.reel$/.exec(moduleId)) { |
915 | } else if (/([^\/]+)\.reel$/.exec(moduleId)) { | 920 | // templateModuleId = moduleId + "/" + RegExp.$1 + ".html"; |
916 | templateModuleId = moduleId + "/" + RegExp.$1 + ".html"; | 921 | //} else { |
917 | } else { | 922 | var slashIndex = moduleId.lastIndexOf("/"); |
918 | templateModuleId = moduleId + ".reel/" + moduleId.split("/").pop() + ".html"; | 923 | //templateModuleId = moduleId + ".reel/" + moduleId.split("/").pop() + ".html"; |
919 | } | 924 | templateModuleId = moduleId + "/" + moduleId.slice(slashIndex === -1 ? 0 : slashIndex+1, -5) + ".html"; |
920 | //console.log(moduleId + " === " + templateModuleId); | 925 | //} |
921 | } | 926 | } |
922 | if (logger.isDebug) { | 927 | if (logger.isDebug) { |
923 | logger.debug(this, "Will load " + templateModuleId); | 928 | logger.debug(this, "Will load " + templateModuleId); |
@@ -971,14 +976,6 @@ var Component = exports.Component = Montage.create(Montage,/** @lends module:mon | |||
971 | enumerable: false, | 976 | enumerable: false, |
972 | value: false | 977 | value: false |
973 | }, | 978 | }, |
974 | /** | ||
975 | Description TODO | ||
976 | @private | ||
977 | */ | ||
978 | _isDrawing: { | ||
979 | enumerable: false, | ||
980 | value: false | ||
981 | }, | ||
982 | 979 | ||
983 | /** | 980 | /** |
984 | If needsDraw property returns true this call adds the current component instance to the rootComponents draw list.<br> | 981 | If needsDraw property returns true this call adds the current component instance to the rootComponents draw list.<br> |
@@ -989,11 +986,11 @@ var Component = exports.Component = Montage.create(Montage,/** @lends module:mon | |||
989 | */ | 986 | */ |
990 | _drawIfNeeded: { | 987 | _drawIfNeeded: { |
991 | enumerable: false, | 988 | enumerable: false, |
992 | value: function _drawIfNeeded() { | 989 | value: function _drawIfNeeded(level) { |
993 | var body, | 990 | var childComponent, |
994 | childComponent, | ||
995 | oldDrawList; | 991 | oldDrawList; |
996 | if (this.needsDraw) { | 992 | this._treeLevel = level; |
993 | if (this.needsDraw && !this._addedToDrawCycle) { | ||
997 | rootComponent.addToDrawCycle(this); | 994 | rootComponent.addToDrawCycle(this); |
998 | } | 995 | } |
999 | if (drawLogger.isDebug) { | 996 | if (drawLogger.isDebug) { |
@@ -1011,7 +1008,7 @@ var Component = exports.Component = Montage.create(Montage,/** @lends module:mon | |||
1011 | drawLogger.debug(this, "childComponent: " + childComponent.element + "; canDraw: " + childComponent.canDraw()); | 1008 | drawLogger.debug(this, "childComponent: " + childComponent.element + "; canDraw: " + childComponent.canDraw()); |
1012 | } | 1009 | } |
1013 | if (childComponent.canDraw()) { // TODO if canDraw is false when does needsDraw get reset? | 1010 | if (childComponent.canDraw()) { // TODO if canDraw is false when does needsDraw get reset? |
1014 | childComponent._drawIfNeeded(); | 1011 | childComponent._drawIfNeeded(level+1); |
1015 | } | 1012 | } |
1016 | } | 1013 | } |
1017 | } | 1014 | } |
@@ -1066,11 +1063,6 @@ var Component = exports.Component = Montage.create(Montage,/** @lends module:mon | |||
1066 | if (this._templateElement) { | 1063 | if (this._templateElement) { |
1067 | this._replaceElementWithTemplate(); | 1064 | this._replaceElementWithTemplate(); |
1068 | } | 1065 | } |
1069 | // TODO: removeAttribute only here for backwards compatibility | ||
1070 | if (!this._element.getAttribute("data-montage-id")) { | ||
1071 | this._element.removeAttribute("id"); | ||
1072 | } | ||
1073 | |||
1074 | // This will schedule a second draw for any component that has children | 1066 | // This will schedule a second draw for any component that has children |
1075 | var childComponents = this.childComponents; | 1067 | var childComponents = this.childComponents; |
1076 | for (var i = 0, childComponent; (childComponent = childComponents[i]); i++) { | 1068 | for (var i = 0, childComponent; (childComponent = childComponents[i]); i++) { |
@@ -1153,16 +1145,6 @@ var Component = exports.Component = Montage.create(Montage,/** @lends module:mon | |||
1153 | value: function() { | 1145 | value: function() { |
1154 | } | 1146 | } |
1155 | }, | 1147 | }, |
1156 | |||
1157 | /** | ||
1158 | Allows draw to be called even if the children can't draw. | ||
1159 | @type {Property} | ||
1160 | @default {Boolean} false | ||
1161 | */ | ||
1162 | allowsPartialDraw: { | ||
1163 | value: false | ||
1164 | }, | ||
1165 | |||
1166 | /** | 1148 | /** |
1167 | Description TODO | 1149 | Description TODO |
1168 | @type {Property} | 1150 | @type {Property} |
@@ -1296,10 +1278,7 @@ var Component = exports.Component = Montage.create(Montage,/** @lends module:mon | |||
1296 | enumerable: false, | 1278 | enumerable: false, |
1297 | value: function(childComponent) { | 1279 | value: function(childComponent) { |
1298 | this.__addToDrawList(childComponent); | 1280 | this.__addToDrawList(childComponent); |
1299 | // if we are not added to the parent yet we add ourselves so that we build the tree | 1281 | this._addToParentsDrawList(); |
1300 | if (!this._isDrawing) { | ||
1301 | this._addToParentsDrawList(); | ||
1302 | } | ||
1303 | } | 1282 | } |
1304 | }, | 1283 | }, |
1305 | 1284 | ||
@@ -1411,12 +1390,10 @@ var Component = exports.Component = Montage.create(Montage,/** @lends module:mon | |||
1411 | */ | 1390 | */ |
1412 | clearAllComposers: { | 1391 | clearAllComposers: { |
1413 | value: function() { | 1392 | value: function() { |
1414 | var length, i; | 1393 | var composer; |
1415 | length = this.composerList.length; | 1394 | while (composer = this.composerList.shift()) { |
1416 | for (i = 0; i < length; i++) { | 1395 | composer.unload(); |
1417 | this.composerList[i].unload(); | ||
1418 | } | 1396 | } |
1419 | this.composerList = []; | ||
1420 | } | 1397 | } |
1421 | } | 1398 | } |
1422 | 1399 | ||
@@ -1623,6 +1600,12 @@ var rootComponent = Montage.create(Component, /** @lends module:montage/ui/compo | |||
1623 | } | 1600 | } |
1624 | }, | 1601 | }, |
1625 | 1602 | ||
1603 | // Create a second composer list so that the lists can be swapped during a draw instead of creating a new array every time | ||
1604 | composerListSwap: { | ||
1605 | value: [], | ||
1606 | distinct: true | ||
1607 | }, | ||
1608 | |||
1626 | /* | 1609 | /* |
1627 | Flag to track if a composer is requesting a draw | 1610 | Flag to track if a composer is requesting a draw |
1628 | @private | 1611 | @private |
@@ -1669,6 +1652,58 @@ var rootComponent = Montage.create(Component, /** @lends module:montage/ui/compo | |||
1669 | _frameTime: { | 1652 | _frameTime: { |
1670 | value: null | 1653 | value: null |
1671 | }, | 1654 | }, |
1655 | |||
1656 | // oldSource and diff are used to detect DOM modifications outside of the | ||
1657 | // draw loop, but only if drawLogger.isDebug is true. | ||
1658 | _oldSource: { | ||
1659 | value: null | ||
1660 | }, | ||
1661 | _diff: { | ||
1662 | // Written by John Resig. Used under the Creative Commons Attribution 2.5 License. | ||
1663 | // http://ejohn.org/projects/javascript-diff-algorithm/ | ||
1664 | value: function( o, n ) { | ||
1665 | var ns = {}; | ||
1666 | var os = {}; | ||
1667 | |||
1668 | for ( var i = 0; i < n.length; i++ ) { | ||
1669 | if ( ns[ n[i] ] == null ) | ||
1670 | ns[ n[i] ] = { rows: [], o: null }; | ||
1671 | ns[ n[i] ].rows.push( i ); | ||
1672 | } | ||
1673 | |||
1674 | for (i = 0; i < o.length; i++ ) { | ||
1675 | if ( os[ o[i] ] == null ) | ||
1676 | os[ o[i] ] = { rows: [], n: null }; | ||
1677 | os[ o[i] ].rows.push( i ); | ||
1678 | } | ||
1679 | |||
1680 | for (i in ns ) { | ||
1681 | if ( ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1 ) { | ||
1682 | n[ ns[i].rows[0] ] = { text: n[ ns[i].rows[0] ], row: os[i].rows[0] }; | ||
1683 | o[ os[i].rows[0] ] = { text: o[ os[i].rows[0] ], row: ns[i].rows[0] }; | ||
1684 | } | ||
1685 | } | ||
1686 | |||
1687 | for (i = 0; i < n.length - 1; i++ ) { | ||
1688 | if ( n[i].text != null && n[i+1].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null && | ||
1689 | n[i+1] == o[ n[i].row + 1 ] ) { | ||
1690 | n[i+1] = { text: n[i+1], row: n[i].row + 1 }; | ||
1691 | o[n[i].row+1] = { text: o[n[i].row+1], row: i + 1 }; | ||
1692 | } | ||
1693 | } | ||
1694 | |||
1695 | for (i = n.length - 1; i > 0; i-- ) { | ||
1696 | if ( n[i].text != null && n[i-1].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null && | ||
1697 | n[i-1] == o[ n[i].row - 1 ] ) { | ||
1698 | n[i-1] = { text: n[i-1], row: n[i].row - 1 }; | ||
1699 | o[n[i].row-1] = { text: o[n[i].row-1], row: i - 1 }; | ||
1700 | } | ||
1701 | } | ||
1702 | |||
1703 | return { o: o, n: n }; | ||