silk.iface = {}; silk.iface.html = {}; silk.iface.html.node = xb.core.object.extend( { ctor: function( domNode ) { this.__domNode = domNode; }, domNode: function() { return this.__domNode; }, instance: function( domNode ) { var domNode = ( typeof( domNode ) !== "undefined" ) ? domNode : this.__domNode; return silk.iface.html.node.instance( domNode ); }, is: function( other ) { if ( !( other instanceof silk.iface.html.node ) ) { return false; } return ( this.domNode() === other.domNode() ); } } ); silk.iface.html.node.instance = function( domNode ) { if ( ! ( domNode instanceof Element ) ) { return null; } var r = silk.html.query( [ "$(html/list/item) := item", "$(html/list) := list" ] ).match( domNode, false ); if ( r === null ) { return null; } if ( typeof( r.item ) !== "undefined" ) { return r.item[ "html/list/item" ]; } if ( typeof( r.list ) !== "undefined" ) { return r.list[ "html/list" ]; } return null; } ; silk.iface.html.list = xb.core.object.extend( silk.iface.html.node, { ctor: function( domNode ) { silk.iface.html.node.prototype.ctor.call( this, domNode ); }, templates: function() { return silk.iface.html.templates( this ); }, insertBefore: function( node, refNode ) { console.warn( "silk.iface.html.list::insertBefore", "" ); }, } ); silk.iface.html.list.item = xb.core.object.extend( silk.iface.html.node, { ctor: function( list, domNode ) { silk.iface.html.node.prototype.ctor.call( this, domNode ); this.__list = list; }, move: function( to ) { var self = this; return ( new Promise( function( resolve, reject ) { var toList = null, toItem = null; if ( to instanceof silk.iface.html.list ) { toList = to; } else if ( to instanceof silk.iface.html.list.item ) { toItem = to; toList = toItem.list(); } else if ( to !== null ) { console.error( "iface.html.list.item:move", "invalid `to` argument", to ); return resolve( null ); } if ( toList === null || self.__list.is( toList ) ) { return self.__list.move( self, toItem ).then( function( newItem ) { return resolve( newItem ); } ); } return toList.insertBefore( self, toItem ).then( function( newItem ) { if ( newItem === null ) { return resolve( null ); // reject()? } self.__list.remove( self ).then( function() { return resolve( newItem ); } ) } ); } ) ); }, copy: function( to ) { var self = this; return ( new Promise( function( resolve, reject ) { var toList = null, toItem = null; if ( to instanceof silk.iface.html.list ) { toList = to; } else if ( to instanceof silk.iface.html.list.item ) { toItem = to; toList = toItem.list(); } else if ( to !== null ) { console.error( "iface.html.list.item:copy", "invalid `to` argument", to ); return resolve( null ); } return toList.insertBefore( self, toItem ).then( function( newItem ) { return resolve( newItem ); } ); } ) ); }, list: function() { return this.__list; }, } );