silk.postings.carousel = xb.core.object.extend( { } ); silk.postings.carousel.mount = xb.core.object.extend( silk.node.mount, { ctor: function( domNode, name, resource ) { var self = this; if ( !this.DOMNodeHandler ) { this.DOMNodeHandler = silk.postings.carousel.mount.handler; } silk.node.mount.prototype.ctor.call( this, domNode, name, resource ); }, onDOMChange: function( handler, before ) { //debugger } } ); silk.postings.carousel.mount.handler = xb.core.object.extend( silk.node.mount.DOMNode, { factory: function( mount, domNode ) { return new silk.postings.carousel.mount.handler( mount, domNode ); }, ctor: function( mount, domNode ) { this.owl = null; silk.node.mount.DOMNode.prototype.ctor.call( this, mount, domNode ); }, getValue: function() { debugger var data = this.each( function( context, index ) { // console.warn( "each", this.domNode ); if ( $( this.domNode.parentNode ).hasClass( "cloned" ) ) { return null; } return this.getValue(); }, { mp: this } ); return data; }, display: function( data ) { if ( this.owl !== null ) { return; } var data = data.getArray(); var length = data.length; if ( length < 2 ) { for ( var i = length; i < 2; i++ ) { data.push( { "image": { "src": "/images/placeholder.jpg" } } ); } } this.domNode.setAttribute( "data-list-count", length ); if ( !length ) { this.domNode.setAttribute( "data-list-empty", true ); } this.render( data, true ); if ( this.owl !== null ) { console.log( this.owl ); $( this.owl ).trigger( "destroy.owl.carousel" ); } var configName = this.mount.resource.config.name + ":" + this.domNode.getAttribute( "data-simply-list" ); var settings = {}; console.log( "carousel: checking config", configName ); if ( typeof( carousel[ configName] ) !== "undefined" ) { settings = xb.core.object.prototype.copy.call( carousel[ configName ] ); } else { configName = this.mount.resource.config.name; if ( typeof( carousel[ configName ] ) !== "undefined" ) { settings = xb.core.object.prototype.copy.call( carousel[ configName ] ); } } //console.log( "EDIT?", document.body.getAttribute( "data-simply-edit" ) ); if ( document.body.getAttribute( "data-simply-edit" ) ) { settings[ "autoplay" ] = false; settings[ "mouseDrag" ] = false; } var categories = this.mount.resource.data[ "postings-categories" ]; if ( typeof( categories ) !== "undefined" ) { $( this.domNode ) .find( ".silk-elm.tag-name" ) .each( function() { var link = document.createElement( "a" ); $( this ) .parents( "[data-simply-list][data-simply-data] > .silk-listItem > .silk-object" ) .each( function() { var elm = this; var className = ""; $( this ) .find( ".silk-id.posting-categories" ) .each( function() { var ids = this.innerText.split( "," ); for ( var i = 0, il = ids.length; i < il; i++ ) { var c = categories.index[ "" + ids[ i ] ]; if ( typeof( c ) === "object" ) { link.innerHTML = c[ "category-name" ].innerHTML; link.href = c[ "category-name" ].href; if ( link.hash ) { name = link.hash.substr( 1 ).toLowerCase(); } else { name = link.textContent.toLowerCase(); } className += " in-category-" + name.replace( /[^a-zA-Z0-9_]+/g, "-" ).replace( /^-+/, "" ).replace( /-+$/, "" ); } } } ) ; this.className += className; } ) ; } ) ; } //console.log( "INITING OWL", this.domNode ); this.owl = $( this.domNode ).owlCarousel( settings ); $( "img[data-simply-src]" ).each( function() { //console.log( "IMG: ", this.getAttribute( "data-simply-src" ), "=>", this.getAttribute( "src" ) ); this.setAttribute( "src", this.getAttribute( "data-simply-src" ) ); } ); } } );