diff --git a/public/javascripts/lib/inplace/meta.js b/public/javascripts/lib/inplace/meta.js index 2a27865..94b9e56 100644 --- a/public/javascripts/lib/inplace/meta.js +++ b/public/javascripts/lib/inplace/meta.js @@ -2,48 +2,12 @@ var $inplace = $inplace || {}; (function($) { $inplace.Meta = { - __template: function(options) { - this.options = options; - }, - - create: function(options) { - var instance = new this.__template(options); - if('function'==typeof(this.__constructor)) { - this.__constructor.apply(instance, options); - } - instance.meta = this; - return instance; - }, - clone: function() { return $.extend(true, {}, this); }, - hasMethod: function(name, handler) { - var proto = this.__template.prototype; - this[name] = function(methodHandler) { - if("function" != typeof(methodHandler)) return this; - proto[name] = methodHandler; - }; - - // @handler argument is optional - this[name](handler); - - return this; - }, - - hasConstructor: function(constructor) { - this.__constructor = constructor; - return this; - }, - - meta: function(obj) { - $.extend(this, obj); - return this; - }, - extend: function(obj) { - $.extend(this.__template.prototype, obj); + $.extend(this, obj); return this; } }; diff --git a/public/javascripts/lib/inplace/nodes.js b/public/javascripts/lib/inplace/nodes.js index 406c650..a8f3cb5 100644 --- a/public/javascripts/lib/inplace/nodes.js +++ b/public/javascripts/lib/inplace/nodes.js @@ -1,102 +1,88 @@ (function($) { $inplace.MessageTrapException = { type: 'message-trap' }; - $inplace.Message = $inplace.Meta.clone() - .hasConstructor(function(options) { - this.topic = options.topic; - this.sender = options.sender; - this.data = options.data; - }) - .meta({ - newMessage: function(topic, sender, data) { - return this.create({ topic: topic, sender: sender, data: data }); - } - }); + $inplace.Message = function(topic, sender, data) { + this.topic = topic; + this.sender = sender; + this.data = data; + }; $inplace.Node = $inplace.Meta.clone() - .hasMethod('appendChild') - - .hasMethod('_processMessage') - .hasMethod('_processChildMessage') - .hasMethod('childMessageHandler') - .hasMethod('messageHandler') - - .hasMethod('sendMessage') - .hasMethod('sendParentMessage') - - .hasMethod('subscribe') - .hasMethod('subscribeUpstream') + .extend({ - .hasConstructor(function(options) { - this.__childs = []; - this.__downstreamHandlers = {}; - this.__upstreamHandlers = {}; - }) + hasConstructor: function(options) { + this.__childs = []; + this.__downstreamHandlers = {}; + this.__upstreamHandlers = {}; + }, - .appendChild(function(child) { - this.__childs.push(child); - child.parentNode = this; - return this; - }) + appendChild: function(child) { + this.__childs.push(child); + child.parentNode = this; + return this; + }, - .messageHandler(function(msg){ - var handlers = this.__downstreamHandlers[msg.topic]; - if(handlers) { - $.each(handlers, function(handler) { - handler(msg); - }); - } - }) - - .childMessageHandler(function(msg){ - var handlers = this.__upstreamHandlers[msg.topic]; - if(handlers) { - $.each(handlers, function(handler) { - handler(msg); - }); - } - }) + messageHandler: function(msg){ + var handlers = this.__downstreamHandlers[msg.topic]; + if(handlers) { + $.each(handlers, function(handler) { + handler(msg); + }); + } + }, + + childMessageHandler: function(msg){ + var handlers = this.__upstreamHandlers[msg.topic]; + if(handlers) { + $.each(handlers, function(handler) { + handler(msg); + }); + } + }, - .sendMessage(function(msg) { - this._processMessage(msg); - }) + sendMessage: function(msg) { + this._processMessage(msg); + }, - .sendParentMessage(function(msg){ - if(!this.parentNode) return this; - this.parentNode._processChildMessage(msg); - return this; - }) + sendParentMessage: function(msg){ + if(!this.parentNode) return this; + this.parentNode._processChildMessage(msg); + return this; + }, - ._processChildMessage(function(msg) { - try { - this.childMessageHandler(msg); - if(!this.parentNode) return; - this.parentNode._processChildMessage(msg); - } catch (exc) { - console.log('Exception while sending message to parent: '+exc.type); - } - }) - - ._processMessage(function(msg) { - try { - this.messageHandler(msg); - if(this.__childs) { - $.each(this.__childs, function(child) { - child._processMessage(msg); - }); - } - } catch (exc) { - console.log("Exception while processing broadcast message: "+exc.type); - } - }) - .subscribe(function(topic, handler) { - this.__downstreamHandlers[topic] = this.__downstreamHandlers[topic] || []; - this.__downstreamHandlers[topic].push(handler); - }) - .subscribeUpstream(function(topic, handler) { - this.__upstreamHandlers[topic] = this.__upstreamHandlers[topic] || []; - this.__upstreamHandlers[topic].push(handler); - }); + _processChildMessage: function(msg) { + try { + this.childMessageHandler(msg); + if(!this.parentNode) return; + this.parentNode._processChildMessage(msg); + } catch (exc) { + console.log('Exception while sending message to parent: '+exc.type); + } + }, + + _processMessage: function(msg) { + try { + this.messageHandler(msg); + if(this.__childs) { + $.each(this.__childs, function(child) { + child._processMessage(msg); + }); + } + } catch (exc) { + console.log("Exception while processing broadcast message: "+exc.type); + } + }, + + subscribe: function(topic, handler) { + this.__downstreamHandlers[topic] = this.__downstreamHandlers[topic] || []; + this.__downstreamHandlers[topic].push(handler); + }, + + subscribeUpstream: function(topic, handler) { + this.__upstreamHandlers[topic] = this.__upstreamHandlers[topic] || []; + this.__upstreamHandlers[topic].push(handler); + } + }); })(jQuery); diff --git a/public/javascripts/lib/inplace/states.js b/public/javascripts/lib/inplace/states.js index 1873655..a0db89b 100644 --- a/public/javascripts/lib/inplace/states.js +++ b/public/javascripts/lib/inplace/states.js @@ -1,21 +1,73 @@ (function($){ + $inplace.states = {}; + $inplace.states.Transition = function(event, target, handlers) { + this.event = event; + this.target = target; + this.handlers = handlers; + }; + $inplace.State = $inplace.Node.clone() - .meta({ - hasState: function(stateName, behaviour) { - var behaviour = behaviour || $inplace.State; - this.__states = this.__states || {}; - var state = this.__states[stateName]; - if(!state) { - state = behaviour.clone(); - this.appendChild(state); /// Aghtung!!! this is not a meta method! - this.__states[stateName] = state; - } - return state; - }, + .extend({ + hasState: function(stateName, behaviour) { + var behaviour = behaviour || $inplace.State; + this.__states = this.__states || {}; + //this.__pstates = this.__pstates || {}; - parentState: function() { - return this.parentNode(); + var state = this.__states[stateName]; + if(!state) { // ? + state = behaviour.clone(); + this.appendChild(state); + this.__states[stateName] = state; + //this.__pstates[state] = stateName; + } + return state; + }, + + _hasTransition: function(from, description) { + this.__transitions = this.__transitions || {}; + var trans = this.__transitions[from]; + if(!trans) { // ? + this.__transitions[from] = trans = {}; } - }); + + // continue here + }, + + hasTransition: function(transitionDescription) { + this.parentState()._hasTransition(this, transitionDescription); + return this; + }, + + hasTransitions: function(descriptions) { + var _this = this; + $.each(descriptions, function(description) { + _this.hasTransition(description); + }); + + return this; + }, + + parentState: function() { + return this.parentNode; + }, + + setDefaultState: function(stateName) { + this.defaultState = stateName; + return this; + }, + + makeHandlerMaker: function(handlerName) { + this.__handlers = this.__handlers || {}; + this[handlerName] = function(handler) { + if(handler) { + this.__handlers[handlerName] = handler; + } else { + this.__handlers[handlerName].apply(this); + } + return this; + }; + return this; + } + }); })(jQuery); \ No newline at end of file