Changeset 5646
- Timestamp:
- 05/20/08 22:10:58 (8 months ago)
- Location:
- branches/ui-experimental/mouse
- Files:
-
- 2 modified
-
ui.core.js (modified) (2 diffs)
-
ui.draggable.js (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/ui-experimental/mouse/ui.core.js
r5644 r5646 161 161 var self = this; 162 162 163 this.element 164 .bind('mousedown.mouse', function(e) { 165 return self.mouseDown(e); 166 }); 163 this.element.bind('mousedown.mouse', function(e) { 164 return self.mouseDown(e); 165 }); 167 166 168 167 // Prevent text selection in IE 169 168 if ($.browser.msie) { 170 this. mouseUnselectable = this.element.attr('unselectable');169 this._mouseUnselectable = this.element.attr('unselectable'); 171 170 this.element.attr('unselectable', 'on'); 172 171 } … … 179 178 180 179 // Restore text selection in IE 181 ($.browser.msie 182 && this.element.attr('unselectable', this.mouseUnselectable)); 183 }, 180 if ($.browser.msie) { 181 this.element.attr('unselectable', this._mouseUnselectable); 182 } 183 }, 184 185 // These are placeholder methods, to be overriden by extending plugin 186 mouseStart: function(e) {}, 187 mouseDrag: function(e) {}, 188 mouseStop: function(e) {}, 184 189 185 190 mouseDown: function(e) { 186 console.log('mouse.mouseDown');187 191 var self = this; 188 self._ downEvent = e;192 self._mouseDownEvent = e; 189 193 190 194 // bail if any of the following conditions are met: 191 195 // - not left click 192 196 // - node type is defined in mouseDragPrevention option 193 // - mouseCondition option returns false 197 198 //TODO: cancel option 199 194 200 if (e.which != 1 195 201 || ($.inArray(e.target.nodeName.toLowerCase(), 196 202 this.options.mouseDragPrevention || []) != -1) 197 || (this.options.mouseCondition &&198 !this.options.mouseCondition.apply(this, [e, this.element]))199 203 ) { return true; } 200 204 201 202 $(document) 203 .bind('mousemove.mouse', function(e) { 204 return self.mouseMove(e); 205 }) 206 .bind('mouseup.mouse', function(e) { 207 return self.mouseUp(e); 208 }); 209 210 211 }, 212 205 $(document) 206 .bind('mousemove.mouse', function(e) { 207 return self.mouseMove(e); 208 }) 209 .bind('mouseup.mouse', function(e) { 210 return self.mouseUp(e); 211 }); 212 213 return false; 214 }, 213 215 mouseMove: function(e) { 214 console.log('mouse.mouseMove'); 215 var self = this; 216 self._moveEvent = e; 217 218 var o = this.options; 219 220 if (!this.started) { 221 if ( 222 Math.max( 223 Math.abs(this._downEvent.pageX - e.pageX), 224 Math.abs(this._downEvent.pageY - e.pageY) 225 ) >= this.options.mouseDistance 226 ) { 227 this.started = true; 228 this.mouseStart(e); 229 } 230 } else { 231 // IE mouseup check 232 if ($.browser.msie && !e.button) { 233 return this.mouseUp(e); 234 } 216 // IE mouseup check - mouseup happened when mouse was out of window 217 if ($.browser.msie && !e.button) 218 return this.mouseUp(e); 219 220 if (this._mouseStarted) { 235 221 this.mouseDrag(e); 236 237 } 238 }, 239 mouseStart: function(e) { 240 console.log('mouse.mouseStart: override me'); 241 }, 242 mouseDrag: function(e) { 243 console.log('mouse.mouseDrag: override me'); 244 }, 245 222 return false; 223 } 224 225 if (this.mouseDistanceMet(e) && this.mouseDelayMet(e)) { 226 this._mouseStarted = (this.mouseStart(this._mouseDownEvent, e) !== false); 227 if (!this._mouseStarted) 228 this.mouseUp(e); 229 } 230 231 return !this._mouseStarted; 232 }, 246 233 mouseUp: function(e) { 247 console.log('mouse.mouseUp');248 234 $(document).unbind('.mouse'); 249 if (this. started) {250 this. started = false;235 if (this._mouseStarted) { 236 this._mouseStarted = false; 251 237 this.mouseStop(e); 252 238 } 253 }, 254 mouseStop: function(e) { 255 console.log('mouse.mouseStop: override me'); 239 return false; 240 }, 241 mouseDistanceMet: function(e) { 242 return (Math.max( 243 Math.abs(this._mouseDownEvent.pageX - e.pageX), 244 Math.abs(this._mouseDownEvent.pageY - e.pageY) 245 ) >= this.options.distance 246 ); 247 }, 248 mouseDelayMet: function(e) { 249 //TODO: delay option 250 //this.mouseTimer = setTimeout(initialize, this.options.mouseDelay) 251 //this.mouseTimer && clearTimeout(this.mouseTimer) 252 return true; 256 253 } 257 254 } 258 259 // TODO: should events be in the mouse namespace or the plugin's namespace? 260 $.ui.oldmouse = { 261 mouseInit: function() { 262 var self = this; 263 264 this.element 265 .bind('mousedown.mouse', function() { 266 return self.mouseClick.apply(self, arguments); 267 }) 268 .bind('mouseup.mouse', function() { 269 (self.mouseTimer && clearTimeout(self.mouseTimer)); 270 }) 271 .bind('click.mouse', function() { 272 if (self.mouseInitialized) { 273 self.mouseInitialized = false; 274 return false; 275 } 276 }); 277 278 // Prevent text selection in IE 279 if ($.browser.msie) { 280 this.mouseUnselectable = this.element.attr('unselectable'); 281 this.element.attr('unselectable', 'on'); 282 } 283 }, 284 285 mouseDestroy: function() { 286 this.element.unbind('.mouse'); 287 288 // Restore text selection in IE 289 ($.browser.msie 290 && this.element.attr('unselectable', this.mouseUnselectable)); 291 }, 292 293 // TODO: does this belong here? 294 trigger: function() { 295 return this.mouseClick.apply(this, arguments); 296 }, 297 298 mouseClick: function(e) { 299 // TODO: fix name of mouseCondition option 300 var self = this; 301 302 // bail if any of the following conditions are met: 303 // - not left click 304 // - node type is defined in mouseDragPrevention option 305 // - mouseCondition option returns false 306 if (e.which != 1 307 || ($.inArray(e.target.nodeName.toLowerCase(), 308 this.options.mouseDragPrevention || []) != -1) 309 || (this.options.mouseCondition && 310 !this.options.mouseCondition.apply(this, [e, this.element])) 311 ) { return true; } 312 313 this.mouseInitialized = false; 314 var initialize = function() { 315 // Store the click mouse position 316 self._MP = { left: e.pageX, top: e.pageY }; 317 318 $(document) 319 .bind('mouseup.mouse', function() { 320 return self.mouseStop.apply(self, arguments); 321 }) 322 .bind('mousemove.mouse', function() { 323 return self.mouseDrag.apply(self, arguments); 324 }); 325 326 if (self.mouseStartDistance(e)) { 327 (self.options.mouseStart 328 && self.options.mouseStart.call(self, e, self.element)); 329 // Calling drag is actually not correct, but expected 330 (self.options.mouseDrag 331 && self.options.mouseDrag.call(self, e, self.element)); 332 333 self.mouseInitialized = true; 334 } 335 }; 336 337 if (this.options.mouseDelay) { 338 (this.mouseTimer && clearTimeout(this.mouseTimer)); 339 this.mouseTimer = setTimeout(initialize, this.options.mouseDelay); 340 } else { 341 initialize(); 342 } 343 344 return false; 345 }, 346 347 mouseStop: function(e) { 348 if (!this.mouseInitialized) { 349 return $(document).unbind('.mouse'); 350 } 351 352 (this.options.mouseStop 353 && this.options.mouseStop.call(this, e, this.element)); 354 355 $(document).unbind('.mouse'); 356 return false; 357 }, 358 359 mouseDrag: function(e) { 360 var o = this.options; 361 362 // IE mouseup check 363 if ($.browser.msie && !e.button) { 364 return this.mouseStop(e); 365 } 366 367 if (this.mouseStartDistance(e)) { 368 (o.mouseStart && o.mouseStart.call(this, e, this.element)); 369 this.mouseInitialized = true; 370 } else { 371 if (!this.mouseInitialized) { return false; } 372 } 373 374 (o.mouseDrag && o.mouseDrag.call(this, e, this.element)); 375 return false; 376 }, 377 378 // determines if element dragging needs to start, based on the distance 379 // the user has moved the mouse since mousedown 380 mouseStartDistance: function(e) { 381 return !this.mouseInitialized && Math.max( 382 Math.abs(this._MP.left - e.pageX), 383 Math.abs(this._MP.top - e.pageY) 384 ) >= this.options.mouseDistance; 385 } 386 }; 255 256 $.ui.mouse.defaults = { 257 cancel: [], 258 condition: function() { return true; }, 259 distance: 0, 260 delay: 0 261 }; 262 387 263 })(jQuery); -
branches/ui-experimental/mouse/ui.draggable.js
r5638 r5646 29 29 30 30 }, 31 start: function(e) {31 mouseStart: function(e) { 32 32 33 33 var o = this.options; … … 112 112 if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e); 113 113 114 return false;114 return true; 115 115 116 116 }, … … 179 179 return position; 180 180 }, 181 drag: function(e) {181 mouseDrag: function(e) { 182 182 183 183 //Compute the helpers position … … 194 194 195 195 }, 196 stop: function(e) {196 mouseStop: function(e) { 197 197 198 198 //If we are using droppables, inform the manager about the drop … … 223 223 // From now on bulk stuff - mainly helpers 224 224 plugins: {}, 225 ui : function(e) {225 uiHash: function(e) { 226 226 return { 227 227 helper: this.helper, … … 232 232 }, 233 233 propagate: function(n,e) { 234 $.ui.plugin.call(this, n, [e, this.ui ()]);235 return this.element.triggerHandler(n == "drag" ? n : "drag"+n, [e, this.ui ()], this.options[n]);234 $.ui.plugin.call(this, n, [e, this.uiHash()]); 235 return this.element.triggerHandler(n == "drag" ? n : "drag"+n, [e, this.uiHash()], this.options[n]); 236 236 }, 237 237 destroy: function() { … … 246 246 appendTo: "parent", 247 247 cancel: ['input','textarea','button','select','option'], 248 distance: 1,248 distance: 0, 249 249 delay: 0 250 250 };
