silk.postings.items.page = xb.core.object.extend( { } ); silk.postings.items.page.mount = xb.core.object.extend( silk.postings.items.mount, { ctor: function( domNode, name, resource ) { this.$currentID = null; this.selection = { items: [] }; this.DOMNodeHandler = silk.postings.items.page.mount.handler; silk.postings.items.mount.prototype.ctor.call( this, domNode, name, resource ); }, select: function( selection ) { var data = this.resource.data[ this.fieldName ]; var list = data.set; var path = window.location.pathname; if ( path[ 0 ] !== "/" ) { path = "/" + path; } var selectCategories = this.getSetting( "pre-select-categories", "view-page" ); var a = document.createElement( "a" ); for ( var i = 0, il = list.length; i < il; i++ ) { var object = list[ i ]; if ( object.link && object.link.href ) { a.href = object.link.href; var apath = a.pathname; if ( apath[ 0 ] !== "/" ) { apath = "/" + apath; } console.log( apath, path ); if ( apath === path ) { this.$currentID = object[ data.ident ]; selection.items = [ object ]; if ( selectCategories !== false && typeof( object[ "posting-categories"] ) === "string" ) { var cats = object[ "posting-categories" ].split( "," ); for ( var j = 0, jl = cats.length; j < jl; j++ ) { if ( typeof( selection.categories[ cats[ j ] ] ) === "undefined" ) { selection.categories[ cats[ j ] ] = {}; } } } break; } } } return selection; }, onDOMChange: function( handler, before ) { var data = this.resource.data[ this.fieldName ]; if ( this.$currentID !== null ) { var values = handler.getValue(); if ( values.length ) { data.updateObject( this.$currentID, values[ 0 ] ); } } return this; }, display: function() { this.render( this.getSelection().items, true ); } } ); silk.postings.items.page.mount.handler = xb.core.object.extend( silk.postings.items.mount.handler, { factory: function( mount, domNode ) { return new silk.postings.items.page.mount.handler( mount, domNode ); }, ctor: function( mount, domNode ) { var self = this; silk.postings.items.mount.handler.prototype.ctor.call( this, mount, domNode ); }, display: function() { var items = this.mount.getSelection().items; var evt = document.createEvent( "Event" ); evt.initEvent( "silk.postings.items.page::display-before", true, true ); evt.data = { items: items }; this.domNode.dispatchEvent( evt ); this.render( evt.data.items, true ); var evtAfter = document.createEvent( "Event" ); evtAfter.initEvent( "silk.postings.items.page::display-after", true, true ); evtAfter.data = { items: evt.data.items }; this.domNode.dispatchEvent( evtAfter ); } } );