/*** @ 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; } ; } /*** @ https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent ***/ (function () { if ( typeof window.CustomEvent === "function" ) return false; function CustomEvent ( event, params ) { params = params || { bubbles: false, cancelable: false, detail: undefined }; var evt = document.createEvent( 'CustomEvent' ); evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail ); return evt; } CustomEvent.prototype = window.Event.prototype; window.CustomEvent = CustomEvent; })(); 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( nameList, handler ) { var selectFn = this.__selectFn; var nameList = ( nameList instanceof Array ) ? nameList : [ nameList ]; for ( var i = 0, il = nameList.length; i < il; i++ ) { silk.drivers.library.add( this.__selectors, nameList[ i ], function( m, evt ) { //console.log( "silk.htmlQuery::on", name, handler ); return handler.call( selectFn.call( null, m ), evt ); } ); } return this; }, 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 clickHandler = function( evt ) { if ( evt instanceof MouseEvent ) { if ( evt.sourceCapabilities && evt.sourceCapabilities.firesTouchEvents ) { console.error( "dropping events/click", evt ); return; } } silk.html.handleEvent( evt, "events/click" ); }; document.addEventListener( "touchend", clickHandler, true ); document.addEventListener( "click", clickHandler, true ); document.addEventListener( "click", function( evt ) { silk.html.handleEvent( evt, "events/mouse/click" ); }, true ); document.addEventListener( "mousedown", function( evt ) { silk.html.handleEvent( evt, "events/mouse/down" ); }, true ); document.addEventListener( "mouseup", function( evt ) { silk.html.handleEvent( evt, "events/mouse/up" ); }, true ); document.addEventListener( "touchstart", function( evt ) { silk.html.handleEvent( evt, "events/touch/start" ); }, true ); document.addEventListener( "touchend", function( evt ) { silk.html.handleEvent( evt, "events/touch/end" ); }, 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; } } ) )();