Changeset 660
- Timestamp:
- 02/11/08 06:33:40 (10 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/config-service/src/chrome/chromeFiles/content/config.js
r659 r660 272 272 } 273 273 274 /** 275 * Moves an installed user script to a new position in the array of installed scripts. 276 * 277 * @param script The script to be moved. 278 * @param destination Can be either (a) a numeric offset for the script to be 279 * moved or (b) another installet script to which position 280 * the script will be moved. 281 */ 282 Config.prototype.move = function(script, destination) 283 { 284 var from = this.scripts.indexOf(script); 285 var to = -1; 286 287 // Make sure the user script is installed 288 if (from == -1) 289 return null; 290 291 if (typeof destination == 'number') { // if destination is an offset 292 to = from + destination; 293 to = Math.max(0, to); 294 to = Math.min(this.scripts.length - 1, to); 295 } else { // if destination is a script object 296 to = this.scripts.indexOf(destination); 297 } 298 299 if (to == -1) 300 return null; 301 302 var tmp = this.scripts.splice(from, 1)[0]; 303 this.scripts.splice(to, 0, tmp); 304 305 return {from: from, to: to}; 306 }; 307 274 308 Config.prototype.__defineGetter__("scriptDir", function() { 275 309 var newDir = this.newScriptDir; branches/config-service/src/chrome/chromeFiles/content/manage.js
r656 r660 133 133 134 134 function reorderScript(from, to) { 135 // make sure to and from are in range136 if (from < 0 || to < 0 ||137 from > config.scripts.length || to > config.scripts.length138 ) {139 return false;140 }141 142 // REORDER CONFIG:143 // save item-to-move144 var tmp = config.scripts[from];145 // remove it146 config.scripts.splice(from, 1);147 // put it back in the new spot148 config.scripts.splice(to, 0, tmp);149 150 135 // REORDER DISPLAY: 151 136 var tmp = listbox.childNodes[from]; … … 159 144 // then re-select the dropped script 160 145 listbox.selectedIndex = to; 161 162 return true;163 146 }; 164 147 … … 170 153 var index = listbox.selectedIndex; 171 154 172 if (KeyEvent.DOM_VK_UP == event.keyCode) { 173 if (0 == index) return; 174 175 !reorderScript(index, index - 1); 176 listbox.selectedIndex = index - 1; 177 } else if (KeyEvent.DOM_VK_DOWN == event.keyCode) { 178 if (index == config.scripts.length - 1) return; 179 180 !reorderScript(index, index + 1); 181 listbox.selectedIndex = index + 1; 182 } 155 var move = null; 156 if (KeyEvent.DOM_VK_UP == event.keyCode) 157 move = config.move(listbox.selectedItem.script, -1); 158 else if (KeyEvent.DOM_VK_DOWN == event.keyCode) 159 move = config.move(listbox.selectedItem.script, 1); 160 161 if (move) 162 reorderScript(move.from, move.to); 183 163 }; 184 164 … … 223 203 224 204 // do the move 225 reorderScript(index, newIndex); 205 var move = config.move(config.scripts[index], config.scripts[newIndex]); 206 if (move) 207 reorderScript(move.from, move.to); 226 208 }, 227 209
