/*** @ https://developer.mozilla.org/en-US/docs/Web/API/Element/matches ***/ if ( !Element.prototype.matches ) { Element.prototype.matches = Element.prototype.matchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.webkitMatchesSelector || function(s) { var matches = (this.document || this.ownerDocument).querySelectorAll(s), i = matches.length; while (--i >= 0 && matches.item(i) !== this) {} return i > -1; } ; } if ( !Element.prototype.indexOf ) { Element.prototype.indexOf = function( childNode ) { return Array.prototype.indexOf.call( this.children, childNode ); } ; } Event.prototype.__preventDefaultValue = false; var __preventDefault = Event.prototype.preventDefault; Event.prototype.preventDefault = function() { this.__preventDefaultValue = true; return __preventDefault.call( this ); }; Event.prototype.__stopImmediatePropagationValue = false; var __stopImmediatePropagation = Event.prototype.stopImmediatePropagation; Event.prototype.stopImmediatePropagation = function() { this.__stopImmediatePropagationValue = true; return __stopImmediatePropagation.call( this ); }; Event.prototype.__stopPropagationValue = false; var __stopPropagation = Event.prototype.stopPropagation; Event.prototype.stopPropagation = function() { this.__stopPropagationValue = true; return __stopPropagation.call( this ); }; /* silk.html .query( "a[href]:not(.nonav) := link" ) .on( "events/mouse/click", function( evt ) { var preserve = ( ( typeof( self.selection.path ) !== "string" ) || !self.selection.path.length ); if ( self.navigate( this.link.domNode.href, preserve ) ) { evt.preventDefault(); evt.stopImmediatePropagation(); } } ) ; silk.html .query( ".silk-object.category-pulldown := category .silk-listItem := listItem > .silk-object.category-option := object" ) .as( "shop/categories/option" ) ; silk.html .query( ".silk-object.category-pulldown := object" ) .as( "shop/categories/categorie" ) ; */ silk.htmlQuery = xb.core.object.extend( { ctor: function( ctx, selectors ) { this.__ctx = ctx; this.__selectors = ( selectors instanceof Array ) ? selectors : [ selectors ]; this.__selectFn = function( m ) { return m; }; this.__query = null; }, select: function( selectFn ) { this.__selectFn = selectFn; return this; }, publish: function( name ) { silk.drivers.library.add( this.__selectors, name, this.__selectFn ); return this; }, as: function( name, handler ) { console.error( "silk.html.query.as(", name, ") called / fn has been deprecated!" ); var handler = ( typeof( handler ) === "function" ) ? handler : function( m ) { return m; }; silk.drivers.library.add( this.__selectors, name, handler ); return this; }, on: function( name, handler ) { var selectFn = this.__selectFn; return silk.drivers.library.add( this.__selectors, name, function( m, evt ) { return handler.call( selectFn.call( null, m ), evt ); } ); }, prepare: function() { if ( this.__query === null ) { this.__query = silk.drivers.library.query( this.__selectors ); } return this; }, match: function( domNode, traversal ) { return this.prepare().__query.match( domNode, traversal ); }, find: function( domNode ) { return this.prepare().__query.find( domNode ); }, } ); silk.html = ( xb.core.object.extend( { ctor: function() { this.__initEventRoutes(); }, query: function( selectors ) { return silk.htmlQuery( this, selectors ); }, handleEvent: function( evt, name ) { var result = null; var s = Date.now(); console.log( "[CS] handleEvent(" + name + ")::start", s ); if ( silk.drivers.library.__list.length === 0 ) { silk.drivers.library.link(); } var set = silk.drivers.library.get( name ); if ( set !== null ) { result = set.handleEvent( evt ); } var e = Date.now(); console.log( "[CS] handleEvent(" + name + ")::end", e ); //, evt ); console.log( "[CS] handleEvent(" + name + ")::total time in seconds", ( e - s ) / 1000 ); return result; }, dispatchEvent: function( domNode, name, detail ) { }, __initEventRoutes: function() { var clicked = false; var clickHandler = function( evt ) { if ( clicked ) { return; } clicked = true; silk.html.handleEvent( evt, "events/click" ); window.setTimeout( function() { clicked = false; }, 5 ); }; document.addEventListener( "touchstart", clickHandler, true ); document.addEventListener( "click", clickHandler, true ); document.addEventListener( "click", function( evt ) { silk.html.handleEvent( evt, "events/mouse/click" ); }, true ); document.addEventListener( "input", function( evt ) { silk.html.handleEvent( evt, "events/mutations/change" ); } ); document.addEventListener( "events/dispatcher/render", function( evt ) { silk.html.handleEvent( evt, evt.type ); }, true ); return this; } } ) )();