1jQuery(document).ready(function(){ 2 3 //var etest = new Object(); 4 //etest.start = function(e){ println('called start from etest'); }; 5 //etest.over = function(e){ println('over'); }; 6 //etest.d = new EventDispatcher(jQuery('.toolbar .titlebar')); 7 //etest.d.bind('start',null,etest.start); 8 //etest.d.bind('over',null,etest.over); 9 10 //setTimeout(function(){ jQuery('.toolbar .titlebar').trigger('click'); }, 5000); 11 12 //var te = new TouchEvents(); 13 //te.setTarget(jQuery('.toolbar .titlebar')); 14 //te.swipeLeft = function(e){ println('swiping left'); }; 15 //te.swipeRight = function(e){ println('swiping right'); }; 16}); 17 18var TouchEvents = function(){ 19 this.target = null; 20 this.max_time = 1000; // allow movement if < 1000 ms (1 sec) 21 this.max_dist = 50; // swipe movement of 50 pixels triggers the swipe 22 this.start_x = 0; 23 this.start_time = 0; 24 this.touching = false; 25 this.fired = false; 26 this.callback = null; 27 this.debug = false; 28 29 this.setTarget = function(obj){ 30 var _this = this; 31 this.target = jQuery(obj); 32 33 //set up swipe detection 34 this.dispatcher = new EventDispatcher(this.target); 35 this.dispatcher.bind('start',null,function(e){ _this.startEvent(e); }); 36 this.dispatcher.bind('move',null,function(e){ _this.moveEvent(e); }); 37 38 this.target.delegate('a', 'click', function(e) { _this.delegatedClick(e); }); 39 }; 40 41 this.delegatedClick = function(e,action){ 42 this.println('called click '+ this.fired); 43 if(this.fired){ 44 this.println('blocking event '+ eventTarget(e)); 45 preventDefault(e); 46 stopPropagation(e); 47 } 48 }; 49 50 this.setCallback = function(obj){ 51 this.callback = obj; 52 }; 53 54 this.println = function(msg){ 55 if(this.debug){ 56 println('events.js: '+ msg); 57 jQuery('#msg').html('<p>'+ msg +'</p>'); 58 } 59 }; 60 61 this.startEvent = function(e){ 62 this.println('start'); 63 this.touching = true; 64 this.fired = false; 65 this.start_time = e.timeStamp; 66 this.start_x = this.getX(e); 67 }; 68 69 this.endEvent = function(e){ 70 this.touching = false; 71 this.start_time = 0; 72 this.start_x = 0; 73 this.println('end'); 74 }; 75 76 this.moveEvent = function(e){ 77 if(this.touching){ 78 this.println('checking'); 79 var current_x = this.getX(e); 80 var current_dist = (this.start_x === 0) ? 0 : Math.abs(current_x - this.start_x); 81 var current_time = e.timeStamp; // allow if movement < 1 sec 82 var elapsed_time = current_time - this.start_time; 83 84 if((elapsed_time < this.max_time) && (current_dist > this.max_dist)) { 85 this.println('firing swipe'); 86 this.fired = true; 87 preventDefault(e); //prevent drag, user is swiping horizontally 88 if (current_x < this.start_x) { this.swipeLeft(e); } 89 if (current_x > this.start_x) { this.swipeRight(e); } 90 this.endEvent(e); 91 } 92 } 93 }; 94 95 this.getX = function(e){ 96 var x = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX; 97 return x; 98 }; 99 100 //override this to do someting 101 this.swipeLeft = function(e){ 102 if(this.callback !== null){ 103 this.callback.swipeLeft(e); 104 } else { 105 this.println("Swipe Left Event Detected"); 106 } 107 }; 108 109 //override this to do someting 110 this.swipeRight = function(e){ 111 if(this.callback !== null){ 112 this.callback.swipeRight(e); 113 } else { 114 this.println("Swipe Right Event Detected"); 115 } 116 }; 117}; 118 119var EventDispatcher = function(_el){ 120 this.el = _el; 121 122 this.mouse_events = ['mouseover','mousedown','mousemove','mouseup','mouseout']; 123 this.touch_events = ['touchstart','touchmove','touchend']; 124 this.pointer_events = ['pointerover','pointerdown','pointermove','pointerup','pointerout']; 125 126 this.over_actions = ['mouseover','pointerover']; 127 this.start_actions = ['mousedown','touchstart','pointerdown']; 128 this.move_actions = ['mousemove','touchmove','pointermove']; 129 this.end_actions = ['mouseup','touchend','pointerup']; 130 this.out_actions = ['mouseout','pointerout']; 131 132 this.filter = null; 133 this.timestamp = null; 134 this.expires = 1000; 135 136 this.bind = function(action,data,callback){ 137 138 var _this = this; 139 var actions = this[action +'_actions']; 140 141 if(defined(actions)){ 142 143 for(var i=0; i<actions.length; i++){ 144 145 var event_name = actions[i]; 146
147 if(EventDetector.supported(event_name)){ 148 var evdis = new Object(); 149 evdis['dispatcher'] = _this; 150 evdis['callback'] = callback; 151 evdis['event_name'] = event_name; 152 153 var _data = (defined(data))? data : new Object(); 154 _data['evdis'] = evdis; 155 156 this.el.bind(event_name,_data,function(e){ _this.send(e); }); 157 } 158 } 159 160 } else { 161 //Some actions like click, only get called once so we don't need to filter it. 162 //Bind these types directly to callback. 163 if(defined(data)){ this.el.bind(action,data,callback); } 164 else { this.el.bind(action,callback); } 165 } 166 }; 167 168 this.send = function(e){ 169 170 var event_name = e.data.evdis.event_name; 171 var type = this.eventType(event_name); 172 173 if(this.expired()){ this.filter = type; } 174 if(this.filter === type){ e.data.evdis.callback(e); } 175 }; 176 177 this.expired = function(){ 178 179 var _now = (new Date()).getTime(); 180 181 if(!defined(this.timestamp)){ this.timestamp = _now - this.expires; } 182 183 var _expired = ((_now - this.timestamp) >= this.expires); 184 185 this.timestamp = _now; 186 187 return _expired; 188 }; 189 190 this.startEvent = function(name){ 191 return this.isEvent(name,this.start_actions); 192 }; 193 194 this.moveEvent = function(name){ 195 return this.isEvent(name,this.move_actions); 196 }; 197 198 this.endEvent = function(name){ 199 return this.isEvent(name,this.end_actions); 200 }; 201 202 this.eventType = function(name){ 203 if(this.mouseEvent(name)){ return 'mouse'; } 204 else if(this.touchEvent(name)){ return 'touch'; } 205 else if(this.pointerEvent(name)){ return 'pointer'; } 206 else { return null; } 207 }; 208 209 this.mouseEvent = function(name){ 210 return this.isEvent(name,this.mouse_events); 211 }; 212 213 this.touchEvent = function(name){ 214 return this.isEvent(name,this.touch_events); 215 }; 216 217 this.pointerEvent = function(name){ 218 return this.isEvent(name,this.pointer_events); 219 }; 220 221 this.isEvent = function(name,events){ 222 var result = false;
223 224 for(var i=0; i<events.length; i++){ 225 if(events[i] === name){ 226 result = true; 227 break; 228 } 229 } 230 231 return result; 232 }; 233 234}; 235 236//code derived from here: 237//http://perfectionkills.com/detecting-event-support-without-browser-sniffing/ 238 239var EventDetector = new function(){ 240 241 this.tagnames = { 'select':'input','change':'input', 242 'submit':'form','reset':'form', 243 'error':'img','load':'img','abort':'img' }; 244 245 this.supported = function(event_name,element){ 246 247 if(!defined(this[event_name])){ 248 249 var _element = element || document.createElement(this.tagnames[name] || 'div'); 250 var _event_name = 'on' + event_name; 251 252 var has_support = (_event_name in _element); 253 254 if (!has_support) { 255 //if it has no `setAttribute` (i.e. doesn't implement Node interface), try generic element 256 if (!_element.setAttribute) { _element = document.createElement('div'); } 257 if (_element.setAttribute && _element.removeAttribute) { 258 _element.setAttribute(event_name,''); 259 has_support = typeof _element[event_name] === 'function'; 260 261 //if property was created, "remove it" (by setting value to `undefined`) 262 if (typeof _element[event_name] !== 'undefined') { _element[event_name] = undef; } 263 _element.removeAttribute(event_name); 264 } 265 } 266 267 _element = null; 268 269 this[event_name] = has_support; 270 } 271 272 return this[event_name]; 273 }; 274 275 this.runTest = function(){ 276 println('Events Support'); 277 278 println('Mouse Events'); 279 println('click: '+ this.supported('click')); 280 println('dblclick: '+ this.supported('dblclick')); 281 println('mousedown: '+ this.supported('mousedown')); 282 println('mouseup: '+ this.supported('mouseup')); 283 println('mouseover: '+ this.supported('mouseover')); 284 println('mousemove: '+ this.supported('mousemove')); 285 println('mouseout: '+ this.supported('mouseout')); 286 println('mousewheel: '+ this.supported('mousewheel')); 287 288 println(' '); 289 println('Key Events'); 290 println('keypress: '+ this.supported('keypress')); 291 println('keydown: '+ this.supported('keydown')); 292 println('keyup: '+ this.supported('keyup')); 293 294 println(' '); 295 println('HTML Events'); 296 println('load: '+ this.supported('load')); 297 println('unload: '+ this.supported('unload',window)); 298 println('abort: '+ this.supported('abort')); 299 println('error: '+ this.supported('error')); 300 301 println(' '); 302 println('View Events'); 303 println('resize: '+ this.supported('resize',window)); 304 println('orientationchange: '+ this.supported('orientationchange',window)); 305 println('scroll: '+ this.supported('scroll')); 306 307 println(' '); 308 println('Form Events'); 309 println('submit: '+ this.supported('submit')); 310 println('reset: '+ this.supported('reset')); 311 312 println(' '); 313 println('Form Controls Events'); 314 println('select: '+ this.supported('select')); 315 println('change: '+ this.supported('change')); 316 317 println(' '); 318 println('Activation Events'); 319 println('focus: '+ this.supported('focus')); 320 println('blur: '+ this.supported('blur')); 321 322 println(' '); 323 println('MSHTML DOM Events'); 324 println('cut: '+ this.supported('cut')); 325 println('copy: '+ this.supported('copy')); 326 println('paste: '+ this.supported('paste')); 327 println('beforecut: '+ this.supported('beforecut')); 328 println('beforecopy: '+ this.supported('beforecopy')); 329 println('beforepaste: '+ this.supported('beforepaste')); 330 println('afterupdate: '+ this.supported('afterupdate')); 331 println('beforeupdate: '+ this.supported('beforeupdate')); 332 println('cellchange: '+ this.supported('cellchange')); 333 println('dataavailable: '+ this.supported('dataavailable')); 334 println('datasetchanged: '+ this.supported('datasetchanged')); 335 println('datasetcomplete: '+ this.supported('datasetcomplete')); 336 println('errorupdate: '+ this.supported('errorupdate')); 337 println('rowenter: '+ this.supported('rowenter')); 338 println('rowexit: '+ this.supported('rowexit')); 339 println('rowsdelete: '+ this.supported('rowsdelete')); 340 println('drag: '+ this.supported('drag')); 341 println('dragstart: '+ this.supported('dragstart')); 342 println('dragenter: '+ this.supported('dragenter')); 343 println('dragover: '+ this.supported('dragover')); 344 println('dragleave: '+ this.supported('dragleave')); 345 println('dragend: '+ this.supported('dragend')); 346 println('drop: '+ this.supported('drop')); 347 println('selectstart: '+ this.supported('selectstart')); 348 println('mouseenter: '+ this.supported('mouseenter')); 349 println('mouseleave: '+ this.supported('mouseleave')); 350 println('activate: '+ this.supported('activate')); 351 println('beforeactivate: '+ this.supported('beforeactivate')); 352 println('deactivate: '+ this.supported('deactivate')); 353 println('beforedeactivate: '+ this.supported('beforedeactivate')); 354 println('focusin: '+ this.supported('focusin')); 355 println('focusout: '+ this.supported('focusout')); 356 println('stop: '+ this.supported('stop', document)); 357 println('readystatechange: '+ this.supported('readystatechange')); 358 println('beforeprint: '+ this.supported('beforeprint', document.body)); 359 println('afterprint: '+ this.supported('afterprint', document.body)); 360 println('beforeunload: '+ this.supported('beforeunload', window)); 361 362 println(' '); 363 println('iPhone touch/gesture Events'); 364 println('touchstart: '+ this.supported('touchstart')); 365 println('touchmove: '+ this.supported('touchmove')); 366 println('touchend: '+ this.supported('touchend')); 367 println('touchcancel: '+ this.supported('touchcancel')); 368 369 println(' '); 370 println('gesturestart: '+ this.supported('gesturestart')); 371 println('gesturechange: '+ this.supported('gesturechange')); 372 println('gestureend: '+ this.supported('gestureend')); 373 374 println(' '); 375 println('HTML5 Events'); 376 println('hashchange: '+ this.supported('hashchange',document.body)); 377 println('online: '+ this.supported('online',document.body)); 378 println('offline: '+ this.supported('offline',document.body)); 379 println('message: '+ this.supported('message',window)); 380 println('undo: '+ this.supported('undo',document.body)); 381 println('redo: '+ this.supported('redo',document.body)); 382 println('storage: '+ this.supported('storage',window)); 383 println('popstate: '+ this.supported('popstate',window)); 384 println('canplay: '+ this.supported('canplay',document.createElement('video'))); 385 println('seeking: '+ this.supported('seeking',document.createElement('video'))); 386 println('seekend: '+ this.supported('seekend',document.createElement('video'))); 387 388 println(' '); 389 println('Proprietary Events'); 390 println('pageshow: '+ this.supported('pageshow',window)); 391 println('pagehide: '+ this.supported('pagehide',window)); 392 println('onbeforescriptexecute: '+ this.supported('onbeforescriptexecute',document)); 393 println('onafterscriptexecute: '+ this.supported('onafterscriptexecute',document)); 394 }; 395}; 396 397
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.