UNPKG

gaffa-frame

Version:

frame view for loading UI into a [gaffa](https://github.com/gaffa-tape/gaffa-js) application

1,674 lines (1,326 loc) 354 kB
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"/home/kory/dev/gaffa-frame/frame.js":[function(require,module,exports){ var Gaffa = require('gaffa'), crel = require('crel'), statham = require('statham'), Ajax = require('simple-ajax'); var viewCache = {}; function Frame(){} Frame = Gaffa.createSpec(Frame, Gaffa.ContainerView); Frame.prototype._type = 'frame'; Frame.prototype.render = function(){ var renderedElement = crel(this.tagName || 'div'); this.views.content.element = renderedElement; this.renderedElement = renderedElement; }; Frame.prototype._requestData = function(url, callback){ if(url == null){ return; } if(this._pendingRequest){ this._pendingRequest.request.abort(); this._pendingRequest = null; } var ajax = this._pendingRequest = new Ajax({ url: url, method: 'get', dataType: 'json', contentType: 'json' }); ajax.on('success', function(event, data){ callback(null, data); }); ajax.on('error', function(event, error){ callback({error: error}); }); ajax.on('complete', function(){ this._pendingRequest = null; }); ajax.send(); }; Frame.prototype._error = function(error){ view.triggerActions('error', {error: error}); }; Frame.prototype._load = function(data){ var gaffa = this.gaffa; if(this._loadedView){ this._loadedView.remove(); this._loadedView = null; } if(!data){ this._error('No view was found'); return; } var child = gaffa.initialiseView(statham.revive(data)); this._loadedView = child; this.views.content.abortDeferredAdd(); this.views.content.add(child); this.triggerActions('success'); this.triggerActions('complete'); }; Frame.prototype.url = new Gaffa.Property(function(view, value){ if(!viewCache[value] || !view.cache.value){ view._requestData(value, function(error, data){ if(error){ view._error(error); return; } viewCache[value] = data; view._load(data); }); }else{ view._load(viewCache[value]); } }); Frame.prototype.cache = new Gaffa.Property({ value: true }); module.exports = Frame; },{"crel":"/home/kory/dev/gaffa-frame/node_modules/crel/crel.js","gaffa":"/home/kory/dev/gaffa-frame/node_modules/gaffa/gaffa.js","simple-ajax":"/home/kory/dev/gaffa-frame/node_modules/simple-ajax/index.js","statham":"/home/kory/dev/gaffa-frame/node_modules/statham/statham.js"}],"/home/kory/dev/gaffa-frame/node_modules/crel/crel.js":[function(require,module,exports){ //Copyright (C) 2012 Kory Nunn //Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: //The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* This code is not formatted for readability, but rather run-speed and to assist compilers. However, the code's intention should be transparent. *** IE SUPPORT *** If you require this library to work in IE7, add the following after declaring crel. var testDiv = document.createElement('div'), testLabel = document.createElement('label'); testDiv.setAttribute('class', 'a'); testDiv['className'] !== 'a' ? crel.attrMap['class'] = 'className':undefined; testDiv.setAttribute('name','a'); testDiv['name'] !== 'a' ? crel.attrMap['name'] = function(element, value){ element.id = value; }:undefined; testLabel.setAttribute('for', 'a'); testLabel['htmlFor'] !== 'a' ? crel.attrMap['for'] = 'htmlFor':undefined; */ (function (root, factory) { if (typeof exports === 'object') { module.exports = factory(); } else if (typeof define === 'function' && define.amd) { define(factory); } else { root.crel = factory(); } }(this, function () { var fn = 'function', obj = 'object', isType = function(a, type){ return typeof a === type; }, isNode = typeof Node === fn ? function (object) { return object instanceof Node; } : // in IE <= 8 Node is an object, obviously.. function(object){ return object && isType(object, obj) && ('nodeType' in object) && isType(object.ownerDocument,obj); }, isElement = function (object) { return crel.isNode(object) && object.nodeType === 1; }, isArray = function(a){ return a instanceof Array; }, appendChild = function(element, child) { if(!isNode(child)){ child = document.createTextNode(child); } element.appendChild(child); }; function crel(){ var args = arguments, //Note: assigned to a variable to assist compilers. Saves about 40 bytes in closure compiler. Has negligable effect on performance. element = args[0], child, settings = args[1], childIndex = 2, argumentsLength = args.length, attributeMap = crel.attrMap; element = crel.isElement(element) ? element : document.createElement(element); // shortcut if(argumentsLength === 1){ return element; } if(!isType(settings,obj) || crel.isNode(settings) || isArray(settings)) { --childIndex; settings = null; } // shortcut if there is only one child that is a string if((argumentsLength - childIndex) === 1 && isType(args[childIndex], 'string') && element.textContent !== undefined){ element.textContent = args[childIndex]; }else{ for(; childIndex < argumentsLength; ++childIndex){ child = args[childIndex]; if(child == null){ continue; } if (isArray(child)) { for (var i=0; i < child.length; ++i) { appendChild(element, child[i]); } } else { appendChild(element, child); } } } for(var key in settings){ if(!attributeMap[key]){ element.setAttribute(key, settings[key]); }else{ var attr = crel.attrMap[key]; if(typeof attr === fn){ attr(element, settings[key]); }else{ element.setAttribute(attr, settings[key]); } } } return element; } // Used for mapping one kind of attribute to the supported version of that in bad browsers. // String referenced so that compilers maintain the property name. crel['attrMap'] = {}; // String referenced so that compilers maintain the property name. crel["isElement"] = isElement; crel["isNode"] = isNode; return crel; })); },{}],"/home/kory/dev/gaffa-frame/node_modules/gaffa-container/container.js":[function(require,module,exports){ var Gaffa = require('gaffa'); function Container(){} Container = Gaffa.createSpec(Container, Gaffa.ContainerView); Container.prototype.type = 'container'; Container.prototype.render = function(){ this.views.content.element = this.renderedElement = document.createElement(this.tagName || 'div'); }; module.exports = Container; },{"gaffa":"/home/kory/dev/gaffa-frame/node_modules/gaffa/gaffa.js"}],"/home/kory/dev/gaffa-frame/node_modules/gaffa-text/text.js":[function(require,module,exports){ var Gaffa = require('gaffa'), crel = require('crel'), viewType = "text"; function Text(){} Text = Gaffa.createSpec(Text, Gaffa.View); Text.prototype.type = viewType; Text.prototype.render = function(){ this.renderedElement = document.createTextNode(''); }; Text.prototype.text = new Gaffa.Property(function(viewModel, value){ viewModel.renderedElement.data = value || ''; }); Text.prototype.visible = new Gaffa.Property(function(viewModel, value){ viewModel.renderedElement.data = (value === false ? '' : viewModel.text.value || ''); }); Text.prototype.title = undefined; Text.prototype.enabled = undefined; Text.prototype.classes = undefined; module.exports = Text; },{"crel":"/home/kory/dev/gaffa-frame/node_modules/crel/crel.js","gaffa":"/home/kory/dev/gaffa-frame/node_modules/gaffa/gaffa.js"}],"/home/kory/dev/gaffa-frame/node_modules/gaffa-textbox/node_modules/gaffa-formelement/formelement.js":[function(require,module,exports){ var Gaffa = require('gaffa'), crel = require('crel'), doc = require('doc-js'); function FormElement(){} FormElement = Gaffa.createSpec(FormElement, Gaffa.View); FormElement.prototype._type = 'formElement'; FormElement.prototype.render = function(){ var view = this, renderedElement = this.renderedElement = this.renderedElement || crel('input'), formElement = this.formElement = this.formElement || renderedElement; doc.on(this.updateEventName || "change", formElement, function(){ view.value.set(formElement.value); view.valid.set(formElement.validity.valid); }); }; FormElement.prototype.value = new Gaffa.Property(function(view, value){ value = value || ''; var element = view.formElement, caretPosition = 0, hasCaret = element === document.activeElement; //this is only necissary because IE10 is a pile of crap (i know what a surprise) // Skip if the text hasnt changed if(value === element.value){ return; } // Inspiration taken from http://stackoverflow.com/questions/2897155/get-caret-position-within-an-text-input-field // but WOW is that some horrendous code! if(hasCaret){ if (window.document.selection) { var selection = window.document.selection.createRange(); selection.moveStart('character', -element.value.length); caretPosition = selection.text.length; } else if (element.selectionStart || element.selectionStart == '0'){ caretPosition = element.selectionStart; } } element.value = value; if(hasCaret){ if(element.createTextRange) { var range = element.createTextRange(); range.move('character', caretPosition); range.select(); } if(element.selectionStart) { element.setSelectionRange(caretPosition, caretPosition); } } view.valid.set(element.validity.valid); }); FormElement.prototype.type = new Gaffa.Property(function(view, value){ view.formElement.setAttribute('type', value != null ? value : ""); }); FormElement.prototype.placeholder = new Gaffa.Property(function(view, value){ view.formElement.setAttribute('placeholder', value != null ? value : ""); }); FormElement.prototype.required = new Gaffa.Property(function(view, value){ if (value){ view.formElement.setAttribute('required', 'required'); }else{ view.formElement.removeAttribute('required'); } }); FormElement.prototype.valid = new Gaffa.Property(); FormElement.prototype.validity = new Gaffa.Property(function(view, value){ value = value || ''; view.formElement.setCustomValidity(value); }); FormElement.prototype.enabled = new Gaffa.Property({ update: function(view, value){ view.formElement[value ? 'removeAttribute' : 'setAttribute']('disabled','disabled'); }, value: true }); module.exports = FormElement; },{"crel":"/home/kory/dev/gaffa-frame/node_modules/crel/crel.js","doc-js":"/home/kory/dev/gaffa-frame/node_modules/gaffa-textbox/node_modules/gaffa-formelement/node_modules/doc-js/fluent.js","gaffa":"/home/kory/dev/gaffa-frame/node_modules/gaffa/gaffa.js"}],"/home/kory/dev/gaffa-frame/node_modules/gaffa-textbox/node_modules/gaffa-formelement/node_modules/doc-js/doc.js":[function(require,module,exports){ var doc = { document: typeof document !== 'undefined' ? document : null, setDocument: function(d){ this.document = d; } }; var arrayProto = [], isList = require('./isList'); getTargets = require('./getTargets')(doc.document), getTarget = require('./getTarget')(doc.document), space = ' '; ///[README.md] function isIn(array, item){ for(var i = 0; i < array.length; i++) { if(item === array[i]){ return true; } } } /** ## .find finds elements that match the query within the scope of target //fluent doc(target).find(query); //legacy doc.find(target, query); */ function find(target, query){ target = getTargets(target); if(query == null){ return target; } if(isList(target)){ var results = []; for (var i = 0; i < target.length; i++) { var subResults = doc.find(target[i], query); for(var j = 0; j < subResults.length; j++) { if(!isIn(results, subResults[j])){ results.push(subResults[j]); } } } return results; } return target ? target.querySelectorAll(query) : []; }; /** ## .findOne finds the first element that matches the query within the scope of target //fluent doc(target).findOne(query); //legacy doc.findOne(target, query); */ function findOne(target, query){ target = getTarget(target); if(query == null){ return target; } if(isList(target)){ var result; for (var i = 0; i < target.length; i++) { result = findOne(target[i], query); if(result){ break; } } return result; } return target ? target.querySelector(query) : null; }; /** ## .closest recurses up the DOM from the target node, checking if the current element matches the query //fluent doc(target).closest(query); //legacy doc.closest(target, query); */ function closest(target, query){ target = getTarget(target); if(isList(target)){ target = target[0]; } while( target && target.ownerDocument && !is(target, query) ){ target = target.parentNode; } return target === doc.document && target !== query ? null : target; }; /** ## .is returns true if the target element matches the query //fluent doc(target).is(query); //legacy doc.is(target, query); */ function is(target, query){ target = getTarget(target); if(isList(target)){ target = target[0]; } if(!target.ownerDocument || typeof query !== 'string'){ return target === query; } return target === query || arrayProto.indexOf.call(find(target.parentNode, query), target) >= 0; }; /** ## .addClass adds classes to the target //fluent doc(target).addClass(query); //legacy doc.addClass(target, query); */ function addClass(target, classes){ target = getTargets(target); if(isList(target)){ for (var i = 0; i < target.length; i++) { addClass(target[i], classes); } return this; } if(!classes){ return this; } var classes = classes.split(space), currentClasses = target.classList ? null : target.className.split(space); for(var i = 0; i < classes.length; i++){ var classToAdd = classes[i]; if(!classToAdd || classToAdd === space){ continue; } if(target.classList){ target.classList.add(classToAdd); } else if(!currentClasses.indexOf(classToAdd)>=0){ currentClasses.push(classToAdd); } } if(!target.classList){ target.className = currentClasses.join(space); } return this; }; /** ## .removeClass removes classes from the target //fluent doc(target).removeClass(query); //legacy doc.removeClass(target, query); */ function removeClass(target, classes){ target = getTargets(target); if(isList(target)){ for (var i = 0; i < target.length; i++) { removeClass(target[i], classes); } return this; } if(!classes){ return this; } var classes = classes.split(space), currentClasses = target.classList ? null : target.className.split(space); for(var i = 0; i < classes.length; i++){ var classToRemove = classes[i]; if(!classToRemove || classToRemove === space){ continue; } if(target.classList){ target.classList.remove(classToRemove); continue; } var removeIndex = currentClasses.indexOf(classToRemove); if(removeIndex >= 0){ currentClasses.splice(removeIndex, 1); } } if(!target.classList){ target.className = currentClasses.join(space); } return this; }; function addEvent(settings){ var target = getTarget(settings.target); if(target){ target.addEventListener(settings.event, settings.callback, false); }else{ console.warn('No elements matched the selector, so no events were bound.'); } } /** ## .on binds a callback to a target when a DOM event is raised. //fluent doc(target/proxy).on(events, target[optional], callback); note: if a target is passed to the .on function, doc's target will be used as the proxy. //legacy doc.on(events, target, query, proxy[optional]); */ function on(events, target, callback, proxy){ proxy = getTargets(proxy); if(!proxy){ target = getTargets(target); // handles multiple targets if(isList(target)){ var multiRemoveCallbacks = []; for (var i = 0; i < target.length; i++) { multiRemoveCallbacks.push(on(events, target[i], callback, proxy)); } return function(){ while(multiRemoveCallbacks.length){ multiRemoveCallbacks.pop(); } }; } } // handles multiple proxies // Already handles multiple proxies and targets, // because the target loop calls this loop. if(isList(proxy)){ var multiRemoveCallbacks = []; for (var i = 0; i < proxy.length; i++) { multiRemoveCallbacks.push(on(events, target, callback, proxy[i])); } return function(){ while(multiRemoveCallbacks.length){ multiRemoveCallbacks.pop(); } }; } var removeCallbacks = []; if(typeof events === 'string'){ events = events.split(space); } for(var i = 0; i < events.length; i++){ var eventSettings = {}; if(proxy){ if(proxy === true){ proxy = doc.document; } eventSettings.target = proxy; eventSettings.callback = function(event){ var closestTarget = closest(event.target, target); if(closestTarget){ callback(event, closestTarget); } }; }else{ eventSettings.target = target; eventSettings.callback = callback; } eventSettings.event = events[i]; addEvent(eventSettings); removeCallbacks.push(eventSettings); } return function(){ while(removeCallbacks.length){ var removeCallback = removeCallbacks.pop(); getTarget(removeCallback.target).removeEventListener(removeCallback.event, removeCallback.callback); } } }; /** ## .off removes events assigned to a target. //fluent doc(target/proxy).off(events, target[optional], callback); note: if a target is passed to the .on function, doc's target will be used as the proxy. //legacy doc.off(events, target, callback, proxy); */ function off(events, target, callback, proxy){ if(isList(target)){ for (var i = 0; i < target.length; i++) { off(events, target[i], callback, proxy); } return this; } if(proxy instanceof Array){ for (var i = 0; i < proxy.length; i++) { off(events, target, callback, proxy[i]); } return this; } if(typeof events === 'string'){ events = events.split(space); } if(typeof callback !== 'function'){ proxy = callback; callback = null; } proxy = proxy ? getTarget(proxy) : doc.document; var targets = typeof target === 'string' ? find(target, proxy) : [target]; for(var targetIndex = 0; targetIndex < targets.length; targetIndex++){ var currentTarget = targets[targetIndex]; for(var i = 0; i < events.length; i++){ currentTarget.removeEventListener(events[i], callback); } } return this; }; /** ## .append adds elements to a target //fluent doc(target).append(children); //legacy doc.append(target, children); */ function append(target, children){ var target = getTarget(target), children = getTarget(children); if(isList(target)){ target = target[0]; } if(isList(children)){ for (var i = 0; i < children.length; i++) { append(target, children[i]); } return; } target.appendChild(children); }; /** ## .prepend adds elements to the front of a target //fluent doc(target).prepend(children); //legacy doc.prepend(target, children); */ function prepend(target, children){ var target = getTarget(target), children = getTarget(children); if(isList(target)){ target = target[0]; } if(isList(children)){ //reversed because otherwise the would get put in in the wrong order. for (var i = children.length -1; i; i--) { prepend(target, children[i]); } return; } target.insertBefore(children, target.firstChild); }; /** ## .isVisible checks if an element or any of its parents display properties are set to 'none' //fluent doc(target).isVisible(); //legacy doc.isVisible(target); */ function isVisible(target){ var target = getTarget(target); if(!target){ return; } if(isList(target)){ var i = -1; while (target[i++] && isVisible(target[i])) {} return target.length >= i; } while(target.parentNode && target.style.display !== 'none'){ target = target.parentNode; } return target === doc.document; }; /** ## .ready call a callback when the document is ready. //fluent doc().ready(callback); //legacy doc.ready(callback); */ function ready(target, callback){ if(typeof target === 'function' && !callback){ callback = target; } if(doc.document.body){ callback(); }else{ doc.on('load', window, function(){ callback(); }); } }; doc.find = find; doc.findOne = findOne; doc.closest = closest; doc.is = is; doc.addClass = addClass; doc.removeClass = removeClass; doc.off = off; doc.on = on; doc.append = append; doc.prepend = prepend; doc.isVisible = isVisible; doc.ready = ready; module.exports = doc; },{"./getTarget":"/home/kory/dev/gaffa-frame/node_modules/gaffa-textbox/node_modules/gaffa-formelement/node_modules/doc-js/getTarget.js","./getTargets":"/home/kory/dev/gaffa-frame/node_modules/gaffa-textbox/node_modules/gaffa-formelement/node_modules/doc-js/getTargets.js","./isList":"/home/kory/dev/gaffa-frame/node_modules/gaffa-textbox/node_modules/gaffa-formelement/node_modules/doc-js/isList.js"}],"/home/kory/dev/gaffa-frame/node_modules/gaffa-textbox/node_modules/gaffa-formelement/node_modules/doc-js/fluent.js":[function(require,module,exports){ var doc = require('./doc'), isList = require('./isList'), getTargets = require('./getTargets')(doc.document), flocProto = []; function Floc(items){ this.push.apply(this, items); } Floc.prototype = flocProto; flocProto.constructor = Floc; function floc(target){ var instance = getTargets(target); if(!isList(instance)){ if(instance){ instance = [instance]; }else{ instance = []; } } return new Floc(instance); } var returnsSelf = 'addClass removeClass append prepend'.split(' '); for(var key in doc){ if(typeof doc[key] === 'function'){ floc[key] = doc[key]; flocProto[key] = (function(key){ var instance = this; // This is also extremely dodgy and fast return function(a,b,c,d,e,f){ var result = doc[key](this, a,b,c,d,e,f); if(result !== doc && isList(result)){ return floc(result); } if(returnsSelf.indexOf(key) >=0){ return instance; } return result; }; }(key)); } } flocProto.on = function(events, target, callback){ var proxy = this; if(typeof target === 'function'){ callback = target; target = this; proxy = null; } doc.on(events, target, callback, proxy); return this; }; flocProto.off = function(events, target, callback){ var reference = this; if(typeof target === 'function'){ callback = target; target = this; reference = null; } doc.off(events, target, callback, reference); return this; }; flocProto.addClass = function(className){ doc.addClass(this, className); return this; }; flocProto.removeClass = function(className){ doc.removeClass(this, className); return this; }; module.exports = floc; },{"./doc":"/home/kory/dev/gaffa-frame/node_modules/gaffa-textbox/node_modules/gaffa-formelement/node_modules/doc-js/doc.js","./getTargets":"/home/kory/dev/gaffa-frame/node_modules/gaffa-textbox/node_modules/gaffa-formelement/node_modules/doc-js/getTargets.js","./isList":"/home/kory/dev/gaffa-frame/node_modules/gaffa-textbox/node_modules/gaffa-formelement/node_modules/doc-js/isList.js"}],"/home/kory/dev/gaffa-frame/node_modules/gaffa-textbox/node_modules/gaffa-formelement/node_modules/doc-js/getTarget.js":[function(require,module,exports){ var singleId = /^#\w+$/; module.exports = function(document){ return function getTarget(target){ if(typeof target === 'string'){ if(singleId.exec(target)){ return document.getElementById(target.slice(1)); } return document.querySelector(target); } return target; }; }; },{}],"/home/kory/dev/gaffa-frame/node_modules/gaffa-textbox/node_modules/gaffa-formelement/node_modules/doc-js/getTargets.js":[function(require,module,exports){ var singleClass = /^\.\w+$/, singleId = /^#\w+$/, singleTag = /^\w+$/; module.exports = function(document){ return function getTargets(target){ if(typeof target === 'string'){ if(singleId.exec(target)){ // If you have more than 1 of the same id in your page, // thats your own stupid fault. return [document.getElementById(target.slice(1))]; } if(singleTag.exec(target)){ return document.getElementsByTagName(target); } if(singleClass.exec(target)){ return document.getElementsByClassName(target.slice(1)); } return document.querySelectorAll(target); } return target; }; }; },{}],"/home/kory/dev/gaffa-frame/node_modules/gaffa-textbox/node_modules/gaffa-formelement/node_modules/doc-js/isList.js":[function(require,module,exports){ module.exports = function isList(object){ return object !== window && ( object instanceof Array || (typeof HTMLCollection === 'function' && object instanceof HTMLCollection) || (typeof NodeList === 'function' && object instanceof NodeList) || // YMMV Array.isArray(object) || ''+object === '[object StaticNodeList]' || ''+object === '[object HTMLCollection]' || (typeof NodeList === 'object' && object instanceof NodeList) ); } },{}],"/home/kory/dev/gaffa-frame/node_modules/gaffa-textbox/textbox.js":[function(require,module,exports){ var Gaffa = require('gaffa'), FormElement = require('gaffa-formelement'); function Textbox(){} Textbox = Gaffa.createSpec(Textbox, FormElement); Textbox.prototype._type = 'textbox'; Textbox.prototype.render = function(){ FormElement.prototype.render.call(this); }; Textbox.prototype.maxLength = new Gaffa.Property(function(view, value){ if(value != null){ view.formElement.setAttribute('maxlength', value); }else{ view.formElement.removeAttribute('maxlength'); } }); module.exports = Textbox; },{"gaffa":"/home/kory/dev/gaffa-frame/node_modules/gaffa/gaffa.js","gaffa-formelement":"/home/kory/dev/gaffa-frame/node_modules/gaffa-textbox/node_modules/gaffa-formelement/formelement.js"}],"/home/kory/dev/gaffa-frame/node_modules/gaffa/action.js":[function(require,module,exports){ var createSpec = require('spec-js'), Property = require('./property'), statham = require('statham'), ViewItem = require('./viewItem'); function triggerAction(action, parent, scope, event) { // clone action = parent.gaffa.initialiseAction(statham.revive(JSON.parse(statham.stringify(action)))); action.bind(parent, scope); action.path = action.getPath(); scope || (scope = {}); if(action.condition.value){ action.trigger(parent, scope, event); } if(!action._async){ action.complete(); } } function triggerActions(actions, parent, scope, event) { if(Array.isArray(actions)){ for(var i = 0; i < actions.length; i++) { triggerAction(actions[i], parent, scope, event); } }else if(actions instanceof Action){ triggerAction(actions, parent, scope, event); } } function Action(actionDescription){ } Action = createSpec(Action, ViewItem); Action.trigger = triggerActions; Action.prototype.trigger = function(){ throw 'Nothing is implemented for this action (' + this.constructor.name + ')'; }; Action.prototype.condition = new Property({ value: true }); // Because actions shouldn't neccisarily debind untill they are complete, // They have an odd debind impementation. Action.prototype.debind = function(){ if(!this._complete && !this._destroyed){ return; } this.complete(); }; Action.prototype.complete = function(){ if(this._complete){ return; } this._complete = true; var action = this; this.on('debind', function(){ action.destroy(); }); this.emit('complete'); ViewItem.prototype.debind.call(this); }; // Only actually destroy if either the actions parent was not an Action, // Or if its Action parent was explicitly destroyed. Action.prototype.destroy = function(){ if(!this._complete && (this.parent instanceof Action ? this.parent._canceled : true)){ this._canceled = true; } if(!this._complete && !this._canceled){ return; } ViewItem.prototype.destroy.call(this); }; module.exports = Action; },{"./property":"/home/kory/dev/gaffa-frame/node_modules/gaffa/property.js","./viewItem":"/home/kory/dev/gaffa-frame/node_modules/gaffa/viewItem.js","spec-js":"/home/kory/dev/gaffa-frame/node_modules/gaffa/node_modules/spec-js/spec.js","statham":"/home/kory/dev/gaffa-frame/node_modules/statham/statham.js"}],"/home/kory/dev/gaffa-frame/node_modules/gaffa/behaviour.js":[function(require,module,exports){ var createSpec = require('spec-js'), ViewItem = require('./viewItem'); function Behaviour(behaviourDescription){} Behaviour = createSpec(Behaviour, ViewItem); Behaviour.prototype.bind = function(parent){ ViewItem.prototype.bind.apply(this, arguments); } module.exports = Behaviour; },{"./viewItem":"/home/kory/dev/gaffa-frame/node_modules/gaffa/viewItem.js","spec-js":"/home/kory/dev/gaffa-frame/node_modules/gaffa/node_modules/spec-js/spec.js"}],"/home/kory/dev/gaffa-frame/node_modules/gaffa/bindable.js":[function(require,module,exports){ var createSpec = require('spec-js'), EventEmitter = require('events').EventEmitter, jsonConverter = require('./jsonConverter'); var stack = []; function eventually(fn){ stack.push(fn); if(stack.length === 1){ setTimeout(function(){ while(stack.length){ stack.pop()(); } },100); } } function getItemPath(item){ var gedi = item.gaffa.gedi, paths = [], referencePath, referenceItem = item; while(referenceItem){ // item.path should be a child ref after item.sourcePath if(referenceItem.path != null){ paths.push(referenceItem.path); } // item.sourcePath is most root level path if(referenceItem.sourcePath != null){ paths.push(gedi.paths.create(referenceItem.sourcePath)); } referenceItem = referenceItem.parent; } return gedi.paths.resolve.apply(this, paths.reverse()); } var iuid = 0; function Bindable(){ this.setMaxListeners(1000); // instance unique ID this.__iuid = iuid++; } Bindable = createSpec(Bindable, EventEmitter); Bindable.bindables = {}; Bindable.getByIuid = function(id){ return this.bindables[id]; }; Bindable.prototype.getPath = function(){ return getItemPath(this); }; Bindable.prototype.getDataAtPath = function(){ if(!this.gaffa){ return; } return this.gaffa.model.get(getItemPath(this)); }; Bindable.prototype.toJSON = function(){ var tempObject = jsonConverter(this, this.__serialiseExclude__, this.__serialiseInclude__); return tempObject; }; function setupCleanup(bindable, parent){ var onDebind = bindable.debind.bind(bindable); parent.once('debind', onDebind); bindable.once('debind', function(){ bindable.parent.removeListener('debind', onDebind); }); var onDestroy = bindable.destroy.bind(bindable); parent.once('destroy', onDestroy); bindable.once('destroy', function(){ bindable.parent.removeListener('destroy', onDestroy); }); } Bindable.prototype.bind = function(parent){ if(parent && !parent._bound){ console.warn('Attempted to bind to a parent who was not bound.'); return; } if(this._bound){ this.debind(); console.warn('Attempted to bind an already bound item.'); } if(parent){ this.gaffa = parent.gaffa; this.parent = parent; this._parentId = parent.__iuid; setupCleanup(this, parent); } this.updatePath(); this._bound = true; Bindable.bindables[this.__iuid] = this; this.emit('bind'); this.removeAllListeners('bind'); }; Bindable.prototype.getSourcePath = function(){ return this.gaffa.gedi.paths.resolve(this.parent && this.parent.getPath(), this.sourcePath); } Bindable.prototype.updatePath = function(){ if(!this.pathBinding){ return; } var bindable = this, absoluteSourcePath = this.getSourcePath(), lastPath = this.path, gaffa = this.gaffa; function setPath(valueTokens){ if(valueTokens){ var valueToken = valueTokens[valueTokens.length - 1]; bindable.path = valueToken.sourcePathInfo && valueToken.sourcePathInfo.path; } if(lastPath !== bindable.path && bindable._bound){ bindable.debind(); bindable.bind(bindable.parent); } } setPath(gaffa.gedi.get(this.pathBinding, absoluteSourcePath, bindable.scope, true)); function handlePathChange(event){ setPath(gaffa.model.get(bindable.pathBinding, bindable, bindable.scope, true)); } gaffa.gedi.bind(this.pathBinding, handlePathChange, absoluteSourcePath); this.on('debind', function(){ gaffa.gedi.debind(bindable.pathBinding, handlePathChange, absoluteSourcePath); }); }; Bindable.prototype.debind = function(){ var bindable = this; if(!this._bound){ // ToDo: This happens with actions, resolve. return; } this._bound = false; this.emit('debind'); this.removeAllListeners('debind'); delete Bindable.bindables[this.__iuid]; }; Bindable.prototype.destroy = function(){ var bindable = this; this._destroyed = true; if(this._bound){ this.debind(); } for(var key in this){ if(key !== 'parent' && this[key] instanceof Bindable && this[key]._bound){ console.log(key); } } // Destroy bindables asynchonously. eventually(function(){ bindable.emit('destroy'); bindable.removeAllListeners('destroy'); // Let any children bound to 'destroy' do their thing before actually destroying this. eventually(function(){ bindable.gaffa = null; bindable.parent = null; }); }); }; module.exports = Bindable; },{"./jsonConverter":"/home/kory/dev/gaffa-frame/node_modules/gaffa/jsonConverter.js","events":"/usr/lib/node_modules/watchify/node_modules/browserify/node_modules/events/events.js","spec-js":"/home/kory/dev/gaffa-frame/node_modules/gaffa/node_modules/spec-js/spec.js"}],"/home/kory/dev/gaffa-frame/node_modules/gaffa/containerView.js":[function(require,module,exports){ /** ## ContainerView A base constructor for gaffa Views that can hold child views. All Views that inherit from ContainerView will have: someView.views.content */ var createSpec = require('spec-js'), View = require('./view'), ViewContainer = require('./viewContainer'), Property = require('./property'); function ContainerView(viewDescription){ this.views = this.views || {}; this.views.content = new ViewContainer(this.views.content); } ContainerView = createSpec(ContainerView, View); ContainerView.prototype.bind = function(parent){ View.prototype.bind.apply(this, arguments); for(var key in this.views){ var viewContainer = this.views[key]; if(viewContainer instanceof ViewContainer){ viewContainer.bind(this); } } }; ContainerView.prototype.renderChildren = new Property({ update: function(view, value){ for(var key in view.views){ view.views[key][value ? 'render' : 'derender'](); } }, value: true }); module.exports = ContainerView; },{"./property":"/home/kory/dev/gaffa-frame/node_modules/gaffa/property.js","./view":"/home/kory/dev/gaffa-frame/node_modules/gaffa/view.js","./viewContainer":"/home/kory/dev/gaffa-frame/node_modules/gaffa/viewContainer.js","spec-js":"/home/kory/dev/gaffa-frame/node_modules/gaffa/node_modules/spec-js/spec.js"}],"/home/kory/dev/gaffa-frame/node_modules/gaffa/createModelScope.js":[function(require,module,exports){ function createModelScope(parent, gediEvent){ var possibleGroup = parent, groupKey, scope = {}; while(possibleGroup && !groupKey){ groupKey = possibleGroup.group; possibleGroup = possibleGroup.parent; } scope.viewItem = parent; scope.groupKey = groupKey; scope.modelTarget = gediEvent && gediEvent.target; return scope; } module.exports = createModelScope; },{}],"/home/kory/dev/gaffa-frame/node_modules/gaffa/excludeProps.js":[function(require,module,exports){ module.exports = ["_trackedListeners", "__iuid", "gaffa", "parent", "parentContainer", "renderedElement", "_removeHandlers", "gediCallbacks", "__super__", "_events", "consuela"]; },{}],"/home/kory/dev/gaffa-frame/node_modules/gaffa/flatMerge.js":[function(require,module,exports){ function flatMerge(a,b){ if(!b || typeof b !== 'object'){ b = {}; } if(!a || typeof a !== 'object'){ a = new b.constructor(); } var result = new a.constructor(), aKeys = Object.keys(a), bKeys = Object.keys(b); for(var i = 0; i < aKeys.length; i++){ result[aKeys[i]] = a[aKeys[i]]; } for(var i = 0; i < bKeys.length; i++){ result[bKeys[i]] = b[bKeys[i]]; } return result; }; module.exports = flatMerge; },{}],"/home/kory/dev/gaffa-frame/node_modules/gaffa/gaffa.js":[function(require,module,exports){ //Copyright (C) 2012 Kory Nunn, Matt Ginty & Maurice Butler //Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: //The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ///[README.md] "use strict"; var Gedi = require('gedi'), doc = require('doc-js'), createSpec = require('spec-js'), EventEmitter = require('events').EventEmitter, merge = require('merge'), statham = require('statham'), resolvePath = require('./resolvePath'), removeViews = require('./removeViews'), getClosestItem = require('./getClosestItem'), jsonConverter = require('./jsonConverter'), Property = require('./property'), ViewContainer = require('./viewContainer'), ViewItem = require('./viewItem'), View = require('./view'), ContainerView = require('./containerView'), Action = require('./action'), Behaviour = require('./behaviour'), initialiseViewItem = require('./initialiseViewItem'), initialiseView = require('./initialiseView'), initialiseAction = require('./initialiseAction'), initialiseBehaviour = require('./initialiseBehaviour'); function clone(value){ return statham.revive(value); } function Gaffa(){ var gedi, gaffa = this; this.gaffa = this; // internal varaibles // Storage for the applications model. var internalModel = {}, // Storage for the applications view. rootViewContainer = new ViewContainer(), // Storage for application actions. internalActions = {}, // Storage for application behaviours. internalBehaviours = [], // Storage for interval based behaviours. internalIntervals = []; rootViewContainer.gaffa = this; rootViewContainer.renderTarget = 'body'; if(typeof window !== 'undefined'){ doc.ready(function(){ gaffa._bound = true; rootViewContainer.bind(gaffa); }); } // Gedi initialisation gedi = new Gedi(internalModel); // Add gedi instance to gaffa. this.gedi = gedi; function modelGet(path, viewItem, scope, asTokens) { if(!(viewItem instanceof ViewItem || viewItem instanceof Property)){ scope = viewItem; viewItem = undefined; } scope = scope || {}; var parentPath = resolvePath(viewItem); return gedi.get(path, parentPath, scope, asTokens); } function modelSet(expression, value, viewItem, dirty, scope){ if(expression == null){ return; } var parentPath = resolvePath(viewItem); if(typeof expression === 'object'){ value = expression; expression = '[]'; } gedi.set(expression, value, parentPath, dirty, scope); } function modelRemove(expression, viewItem, dirty, scope) { var parentPath; if(expression == null){ return; } var parentPath = resolvePath(viewItem); gedi.remove(expression, parentPath, dirty, scope); } function modelIsDirty(path, viewItem) { if(path == null){ return; } var parentPath = resolvePath(viewItem); return gedi.isDirty(path, parentPath); } function modelSetDirtyState(expression, value, viewItem, scope) { if(expression == null){ return; } var parentPath = resolvePath(viewItem); gedi.setDirtyState(expression, value, parentPath, scope); } /** ## The gaffa instance Instance of Gaffa var gaffa = new Gaffa(); */ /** ### .events used throughout gaffa for binding DOM events. */ this.events = { /** ### .on usage: gaffa.events.on('eventname', target, callback); */ on: function(eventName, target, callback){ if('on' + eventName.toLowerCase() in target){ return doc.on(eventName, target, callback); } } }; /** ## .model access to the applications model */ this.model = { /** ### .get(path, viewItem, scope, asTokens) used to get data from the model. path is relative to the viewItems path. gaffa.model.get('[someProp]', parentViewItem); */ get: modelGet, /** ### .set(path, value, viewItem, dirty) used to set data into the model. path is relative to the viewItems path. gaffa.model.set('[someProp]', 'hello', parentViewItem); */ set: modelSet, /** ### .remove(path, viewItem, dirty) used to remove data from the model. path is relative to the viewItems path. gaffa.model.remove('[someProp]', parentViewItem); */ remove: modelRemove, /** ### .isDirty(path, viewItem) check if a part of the model is dirty. path is relative to the viewItems path. gaffa.model.isDirty('[someProp]', viewItem); // true/false? */ isDirty: modelIsDirty, /** ### .setDirtyState(path, value, viewItem) set a part of the model to be dirty or not. path is relative to the viewItems path. gaffa.model.setDirtyState('[someProp]', true, viewItem); */ setDirtyState: modelSetDirtyState }; /** ## .views gaffa.views // ViewContainer. the Gaffa instances top viewContainer. */ this.views = rootViewContainer; /** ## .actions gaffa.actions // Object. contains functions and properties for manipulating the application's actions. */ this.actions = { /** ### .trigger(actions, parent, scope, event) trigger a gaffa action where: - actions is an array of actions to trigger. - parent is an instance of ViewItem that the action is on. - scope is an arbitrary object to be passed in as scope to all expressions in the action - event is an arbitrary event object that may have triggered the action, such as a DOM eve