Changeset 5575
- Timestamp:
- 06/09/10 12:48:06 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
CKEditor/branches/features/contenteditable/_source/core/dom/rangelist.js
r5569 r5575 23 23 ranges = [ ranges ]; 24 24 25 this._ = 26 { 27 ranges : ranges, 28 count : ranges.length 29 } 30 25 return CKEDITOR.tools.extend( ranges, methods ); 26 }; 27 28 var methods = 29 /** @lends CKEDITOR.dom.rangeList.prototype */ 30 { 31 /** 32 * Inserting the specified range object at the end/specified position. 33 * @param {CKEDITOR.dom.range} range 34 * @example 35 * var rangeList = new CKEDITOR.dom.rangeList(); 36 * var range = new CKEDITOR.dom.range(); 37 * ... 38 * rangeList.add( range ); 39 * alert( rangeList.getItem( 0 ) ); 40 */ 41 add : function( range, index ) 42 { 43 this.splice( index || 0, 0, range ); 44 }, 45 46 remove : function( index ) 47 { 48 this.splice( index, 1 ); 49 }, 50 51 replace : function( index, newRange ) 52 { 53 this.splice( index, 1, newRange ); 54 }, 55 56 /** 57 * Retrieve range at the specified position. 58 * @param index 59 */ 60 getItem : function( index ) 61 { 62 return this[ index ] || null; 63 }, 64 65 count : function() 66 { 67 return this.length; 68 }, 69 70 /** 71 * Create an instance of rangeList iterator, it should be only used when 72 * the processing of range is DOM destructive, which means it will possibly 73 * pollute other ranges in this list. 74 * Otherwise, it's enough to iterate with {@link #getItem} 75 * in a for loop. 76 * @returns {CKEDITOR.dom.rangeListIterator} 77 */ 78 createIterator : function() 79 { 80 var rangeList = this, 81 bookmarks = [], 82 current; 83 84 /** 85 * @lends CKEDITOR.dom.rangeListIterator.prototype 86 */ 87 return { 88 89 /** 90 * Iterate over the next range in this list. 91 */ 92 getNextRange : function() 93 { 94 current = current == undefined ? 0 : current + 1; 95 96 var range = rangeList[ current ]; 97 98 // Multiple ranges might be mangled by each other. 99 if ( range && rangeList.length > 1 ) 100 { 101 // Bookmarking all other ranges on the first iteration, 102 // the range correctness after it doesn't matter since we'll 103 // restore them before the next iteration. 104 if ( current == 0 ) 105 { 106 // Make sure bookmark correctness by reverse processing. 107 for ( var i = rangeList.length - 1 ; i > 0 ; i-- ) 108 bookmarks.unshift( rangeList[ i ].createBookmark() ); 109 } 110 else 111 range.moveToBookmark( bookmarks.shift() ); 112 } 113 114 return range; 115 } 116 }; 117 }, 118 119 /** 120 * @param serializable 121 */ 122 createBookmarks : function( serializable ) 123 { 124 var retval = [], bookmark; 125 for ( var i = 0; i < this.length ; i++ ) 126 { 127 retval.push( bookmark = this[ i ].createBookmark( serializable, true) ); 128 129 // Updating the container & offset values for ranges 130 // that have been touched. 131 for ( var j = i + 1; j < this.length; j++ ) 132 { 133 this[ j ] = updateDirtyRange( bookmark, this[ j ] ); 134 this[ j ] = updateDirtyRange( bookmark, this[ j ], true ); 135 } 136 } 137 return retval; 138 }, 139 140 /** 141 * @param normalized 142 */ 143 createBookmarks2 : function( normalized ) 144 { 145 var bookmarks = []; 146 147 for ( var i = 0 ; i < this.length ; i++ ) 148 bookmarks.push( this[ i ].createBookmark2( normalized ) ); 149 150 return bookmarks; 151 }, 152 153 /** 154 * Apply each of the supplied bookmarks to the corresponding range at the index. 155 * @param bookmarks 156 */ 157 moveToBookmarks : function( bookmarks ) 158 { 159 for ( var i = 0 ; i < this.length ; i++ ) 160 this[ i ].moveToBookmark( bookmarks[ i ] ); 161 } 31 162 }; 32 163 … … 73 204 */ 74 205 75 CKEDITOR.dom.rangeList.prototype = {76 /**77 * Inserting the specified range object at the end/specified position.78 * @param {CKEDITOR.dom.range} range79 * @example80 * var rangeList = new CKEDITOR.dom.rangeList();81 * var range = new CKEDITOR.dom.range();82 * ...83 * rangeList.add( range );84 * alert( rangeList.getItem( 0 ) );85 */86 add : function( range, index )87 {88 this._.ranges.splice( index || 0, 0, range );89 this._.count++;90 },91 92 remove : function( index )93 {94 this._.ranges.splice( index, 1 );95 this._.count--;96 },97 98 replace : function( index, newRange )99 {100 this._.ranges.splice( index, 1, newRange );101 },102 103 /**104 * Retrieve range at the specified position.105 * @param index106 */107 getItem : function( index )108 {109 return this._.ranges[ index ] || null;110 },111 112 count : function()113 {114 return this._.count;115 },116 117 /**118 * Create an instance of rangeList iterator, it should be only used when119 * the processing of range is DOM destructive, which means it will possibly120 * pollute other ranges in this list.121 * Otherwise, it's enough to iterate with {@link #getItem}122 * in a for loop.123 * @returns {CKEDITOR.dom.rangeListIterator}124 */125 createIterator : function()126 {127 var rangeList = this,128 bookmarks = [],129 current;130 131 return {132 133 /**134 * Iterate over the next range in this list.135 * @memberOf CKEDITOR.dom.rangeListIterator.prototype136 */137 getNextRange : function()138 {139 current = current == undefined ? 0 : current + 1;140 141 var range = rangeList.getItem( current );142 143 // Multiple ranges might be mangled by each other.144 if ( range && rangeList.count() > 1 )145 {146 // Bookmarking all other ranges on the first iteration,147 // the range correctness after it doesn't matter since we'll148 // restore them before the next iteration.149 if ( current == 0 )150 {151 // Make sure bookmark correctness by reverse processing.152 for ( var i = rangeList.count() - 1 ; i > 0 ; i-- )153 bookmarks.unshift( rangeList.getItem( i ).createBookmark() );154 }155 else156 range.moveToBookmark( bookmarks.shift() );157 }158 159 return range;160 }161 };162 },163 164 /**165 * @param serializable166 */167 createBookmarks : function( serializable )168 {169 var retval = [], bookmark;170 for ( var i = 0; i < this._.count ; i++ )171 {172 retval.push( bookmark = this._.ranges[ i ].createBookmark( serializable, true) );173 174 // Updating the container & offset values for ranges175 // that have been touched.176 for ( var j = i + 1; j < this._.count; j++ )177 {178 this._.ranges[ j ] = updateDirtyRange( bookmark, this._.ranges[ j ] );179 this._.ranges[ j ] = updateDirtyRange( bookmark, this._.ranges[ j ], true );180 }181 }182 return retval;183 },184 185 /**186 * @param normalized187 */188 createBookmarks2 : function( normalized )189 {190 var bookmarks = [];191 192 for ( var i = 0 ; i < this._.ranges.length ; i++ )193 bookmarks.push( this._.ranges[ i ].createBookmark2( normalized ) );194 195 return bookmarks;196 },197 198 /**199 * Apply each of the supplied bookmarks to the corresponding range at the index.200 * @param bookmarks201 */202 moveToBookmarks : function( bookmarks )203 {204 for ( var i = 0 ; i < this._.ranges.length ; i++ )205 this._.ranges[ i ].moveToBookmark( bookmarks[ i ] );206 }207 };208 209 206 210 207 } )();
Note: See TracChangeset
for help on using the changeset viewer.
