Ticket #1541: formatblock.2.diff
| File formatblock.2.diff, 3.1 kB (added by ejucovy, 2 years ago) |
|---|
-
XinhaCore.js
1058 1058 "Address" : "address", 1059 1059 "Formatted": "pre" 1060 1060 }; 1061 1061 1062 this.formatblockDetector = {}; 1063 1062 1064 this.dialogOptions = 1063 1065 { 1064 1066 'centered' : true, //true: dialog is shown in the center the screen, false dialog is shown near the clicked toolbar button … … 4901 4903 var blocks = []; 4902 4904 for ( var indexBlock in this.config.formatblock ) 4903 4905 { 4906 var blockname = this.config.formatblock[indexBlock]; 4904 4907 // prevent iterating over wrong type 4905 if ( typeof this.config.formatblock[indexBlock]== 'string' )4908 if ( typeof blockname == 'string' ) 4906 4909 { 4907 blocks[blocks.length] = this.config.formatblock [indexBlock];4910 blocks[blocks.length] = this.config.formatblockDetector[blockname] || blockname; 4908 4911 } 4909 4912 } 4910 4913 4911 var deepestAncestor = this._getFirstAncestor(this.getSelection(), blocks); 4914 var match = this._getFirstAncestorAndWhy(this.getSelection(), blocks); 4915 var deepestAncestor = match[0]; 4916 var matchIndex = match[1]; 4912 4917 if ( deepestAncestor ) 4913 4918 { 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 } 4919 btn.element.selectedIndex = matchIndex; 4921 4920 } 4922 4921 else 4923 4922 { … … 5047 5046 */ 5048 5047 Xinha.prototype._getFirstAncestor = function(sel, types) 5049 5048 { 5049 return this._getFirstAncestorAndWhy(sel, types)[0]; 5050 }; 5051 5052 // same as above, but also returns index into types array of match 5053 Xinha.prototype._getFirstAncestorAndWhy = function(sel, types) 5054 { 5050 5055 var prnt = this.activeElement(sel); 5051 5056 if ( prnt === null ) 5052 5057 { … … 5057 5062 } 5058 5063 catch(ex) 5059 5064 { 5060 return null;5065 return [null, null]; 5061 5066 } 5062 5067 } 5063 5068 … … 5072 5077 { 5073 5078 if ( types === null ) 5074 5079 { 5075 return prnt;5080 return [prnt, null]; 5076 5081 } 5077 5082 for (var index=0; index<types.length; ++index) { 5078 5083 if (typeof types[index] == 'string' && types[index] == prnt.tagName.toLowerCase()){ 5079 5084 // Criteria is a tag name. It matches 5080 return prnt;5085 return [prnt, index]; 5081 5086 } 5082 5087 else if (typeof types[index] == 'function' && types[index](this, prnt)) { 5083 5088 // Criteria is a callback. It matches 5084 return prnt;5089 return [prnt, index]; 5085 5090 } 5086 5091 } 5087 5092 … … 5097 5102 prnt = prnt.parentNode; 5098 5103 } 5099 5104 5100 return null;5105 return [null, null]; 5101 5106 }; 5102 5107 5103 5108 /** Traverses the DOM upwards and returns the first element that is a block level element … … 5221 5226 this.execCommand(txt, false, value); 5222 5227 break; 5223 5228 case "formatblock": 5224 // Mozilla inserts an empty tag (<>) if no parameter is passed 5229 // Mozilla inserts an empty tag (<>) if no parameter is passed 5225 5230 if ( !value ) 5226 5231 { 5227 5232 this.updateToolbar();
