- Timestamp:
- 11/20/10 17:29:06 (2 years ago)
- Files:
-
- 1 modified
-
trunk/XinhaCore.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/XinhaCore.js
r1288 r1289 4909 4909 } 4910 4910 4911 var deepestAncestor = this._getFirstAncestor(this.getSelection(), blocks); 4911 var match = this._getFirstAncestorAndWhy(this.getSelection(), blocks); 4912 var deepestAncestor = match[0]; 4913 var matchIndex = match[1]; 4914 4915 4912 4916 if ( deepestAncestor ) 4913 4917 { 4914 for ( var x = 0; x < blocks.length; x++ ) 4915 { 4916 if ( blocks[x].toLowerCase() == deepestAncestor.tagName.toLowerCase() ) 4917 { 4918 btn.element.selectedIndex = x; 4919 } 4920 } 4918 // the function can return null for its second element even if a match is found, 4919 // but we passed in an array, so we know it will be a numerical index. 4920 btn.element.selectedIndex = matchIndex; 4921 4921 } 4922 4922 else … … 5043 5043 /** Traverses the DOM upwards and returns the first element that is of one of the specified types 5044 5044 * @param {Selection} sel Selection object as returned by getSelection 5045 * @param {Array } types Array of matching criteria. Each criteria is either a string containing the tag name, or a callback used to select the element.5045 * @param {Array|String} types Array of matching criteria. Each criteria is either a string containing the tag name, or a callback used to select the element. 5046 5046 * @returns {DomNode|null} 5047 5047 */ 5048 5048 Xinha.prototype._getFirstAncestor = function(sel, types) 5049 { 5050 return this._getFirstAncestorAndWhy(sel, types)[0]; 5051 }; 5052 5053 /** Traverses the DOM upwards and returns the first element that is one of the specified types, 5054 * and which (of the specified types) the found element successfully matched. 5055 * @param {Selection} sel Selection object as returned by getSelection 5056 * @param {Array|String} types Array of matching criteria. Each criteria is either a string containing the tag name, or a callback used to select the element. 5057 * @returns {Array} The array will look like [{DomNode|null}, {Integer|null}] -- that is, it always contains two elements. The first element is the element that matched, or null if no match was found. The second is the numerical index that can be used to identify which element of the "types" was responsible for the match. It will be null if no match was found. It will also be null if the "types" argument was omitted. 5058 */ 5059 Xinha.prototype._getFirstAncestorAndWhy = function(sel, types) 5049 5060 { 5050 5061 var prnt = this.activeElement(sel); … … 5058 5069 catch(ex) 5059 5070 { 5060 return null;5071 return [null, null]; 5061 5072 } 5062 5073 } … … 5073 5084 if ( types === null ) 5074 5085 { 5075 return prnt;5086 return [prnt, null]; 5076 5087 } 5077 5088 for (var index=0; index<types.length; ++index) { 5078 5089 if (typeof types[index] == 'string' && types[index] == prnt.tagName.toLowerCase()){ 5079 5090 // Criteria is a tag name. It matches 5080 return prnt;5091 return [prnt, index]; 5081 5092 } 5082 5093 else if (typeof types[index] == 'function' && types[index](this, prnt)) { 5083 5094 // Criteria is a callback. It matches 5084 return prnt;5095 return [prnt, index]; 5085 5096 } 5086 5097 } … … 5098 5109 } 5099 5110 5100 return null;5111 return [null, null]; 5101 5112 }; 5102 5113
