diff --git a/ajax/libs/ModelCore/1.0/ModelCore.min.js b/ajax/libs/ModelCore/1.0/ModelCore.min.js new file mode 100644 index 000000000..9a4b2a053 --- /dev/null +++ b/ajax/libs/ModelCore/1.0/ModelCore.min.js @@ -0,0 +1 @@ +(function(){angular.module("ModelCore",["ng"]).factory("ModelCore",function(e,b,d,a){var c=function c(f){this.$init.apply(this,arguments)};c.prototype={$uuid:null,$pkField:null,$settings:{},$mapping:{},$hasMany:{},$hasOne:{},$dataset:[],$scope:null,$init:function(g){var f=this;f.$settings=angular.extend({headers:{"Content-Type":"application/json"},dataField:{one:"content",many:"items"},urls:{base:null}},f.$settings);f.$uuid=c.getUUID()},$offline:false,$resetTo:function(h){var f=this;h=!h||{};for(var g in f.$mapping){if(f.$mapping.hasOwnProperty(g)){f.__proto__[g]=typeof h[g]!=="undefined"?h[g]:null}}return f},$reset:function(){return this.$resetTo({})},$add:function(f){this.$dataset.push(f)},$new:function(g){var f=this;g=typeof g==="undefined"?f.$mapping:g;var h=new new c.newInstance({},f);h._cache={};for(i in f.$mapping){h._cache[i]=c.clone(f.$mapping[i]);h[i]=c.clone(f.$mapping[i])}return h},$fetch:function(){return this.next()},$incremental:function(g,f){return this.$find(g,f,true)},$find:function(h,g,j){var f=this;j=!(typeof j==="undefined"||j==false);return f.$call({url:f.$url("get"),method:"GET"},f,h).success(function(k){if(j!==true){f.$dataset=[]}return f.$parse(k)})},$getRelationship:function(j,l,h){var g=this;for(var f in g.$hasMany){if(f===j){g[f]=new g.$mapping[f]();l=l||{};for(var k in g.$hasMany[f]){l[k]=g[g.$hasMany[f][k]]}return g[f].$find(l,h)}}for(var f in g.$hasOne){if(f===j){g[f]=g.$mapping[f]();var n=g[g.$hasMany[f].id];var m=g.$hasMany[f].field||null;return g[f].$get(n,m)}}},$get:function(j,h){var f=this;if(f.$pkField==null&&typeof h==="undefined"){throw"You must setup a model.$pkField to perform this operation or define the second parameter field"}h=typeof h!=="undefined"?h:f.$pkField;var g={};g[h]=j;return f.$call({url:f.$url("get",g),method:"GET"},f).success(function(k){f.$dataset=[];f.$parse(k);f.$fetch();f.$dataset=f.$dataset.length===1?f.$dataset:d("filter")(f.$dataset,function(l){return l[h]==j?l:false});return f.$dataset})},$save:function(){var f=this;return f.$call({url:f.$url("post"),method:"POST",data:f.$toObject()},f).success(function(){f.$cleanDiff()})},$cleanDiff:function(){var f=this;if(typeof f._cache==="undefined"){f._cache={}}var g=f.$toObject();for(var h in g){if(g.hasOwnProperty(h)){if(typeof g[h]==="object"){f._cache[h]=c.clone(g[h])}else{f._cache[h]=g[h]}}}},$delete:function(j,h){var f=this;if(f.$pkField==null&&typeof h==="undefined"){throw"You must setup a model.$pkField to perform this operation or define the second parameter field"}h=typeof h!=="undefined"?h:f.$pkField;j=typeof j==="undefined"?f[h]:j;var g={};g[h]=j;return f.$call({url:f.$url("delete",g),method:"DELETE",data:f.$toObject()},f).success(function(){c.destroy(f)})},$toObject:function(){var f=this;var h;var g={};for(h in f.$mapping){if(f.$mapping.hasOwnProperty(h)){g[h]=f[h]}}return g},$original:function(){var f=this;var h;var g={};if(typeof f._cache==="undefined"){f._cache={};return false}for(h in f.$mapping){if(f.$mapping.hasOwnProperty(h)){if(typeof g[h]!=="object"){g[h]=f._cache[h]}else{g[h]=angular.extend(g[h],f._cache[h])}}}return g},$isChanged:function(h){var f=this;var g=f.$diff();if(typeof h==="undefined"&&g!==false){return Object.keys(g).length>0}else{if(g[h]){return !!g[h]}else{return false}}},$diff:function(j,g){var f=this;var h={};j=typeof j==="undefined"?f.$original():j;g=typeof g==="undefined"?f.$toObject():g;if(j===false){return false}for(var l in g){if(g.hasOwnProperty(l)){if(!j||j[l]!==g[l]){if(typeof g[l]==="object"&&g[l]!==null&&typeof j[l]!=="undefined"){var k=f.$diff(j[l],g[l]);if(!c.isEmpty(k)){h[l]=k}}else{h[l]=g[l]}}}}return h},$call:function(h,g,j){var f=this;return !f.$offline?c.call(h,g,j):c.callOffline(h,g,j)},$parse:function(g){var f=this;return f.$dataset=f.$dataset.concat(c.parse(g,f))},__cursor:0,next:function(){var f=this;var g=f.__cursor;f.__cursor++;return f.$goTo(g)},prev:function(){var f=this;var g=f.__cursor;f.__cursor--;return f.$goTo(g)},$goTo:function(g){var f=this;if(f.__cursor>f.$dataset.length){f.__cursor=0;return false}else{if(f.__cursor<0){f.__cursor=0;return false}}f.$mapping=f.$dataset[g].$mapping;if(typeof f._cache==="undefined"){f._cache={}}f._cache=f.$dataset[g]._cache;for(var h in f.$dataset[g].$toObject()){f[h]=f.$dataset[g][h];f.__proto__[h]=f.$dataset[g][h]}return f.$dataset[g]},$url:function(f,m){var n=this;var h=(typeof n.$settings.urls[f]==="undefined"||n.$settings.urls[f]==null)?n.$settings.urls.base:n.$settings.urls[f];if(h==null||typeof h==="undefined"){throw ("Model URL missing for "+typeof n+" in ["+f+"].")}var g=/(:[A-z]+\/?)/g;var o=h.match(g);var k;for(k in o){if(o.hasOwnProperty(k)){var j=o[k].replace("/","");var l=j.replace(":","");if(!m||typeof m[l]==="undefined"){h=h.replace(o[k],"")}else{h=h.replace(j,m[l])}}}return h}};c.destroy=function(g){if(typeof g.$parentModel!=="undefined"){var f=g.$parentModel.$dataset.indexOf(g);g.$parentModel.$dataset.splice(f,1)}};c.OfflineSettings={key:"_ModelCoreOfflineData"};c.call=function(h,g,j){var f=this;if(typeof h==="undefined"){h={}}if(!h.method){throw"You must setup a method"}if(!h.url){throw"You must setup an url"}if(j){h.params=j}h.headers=g.$settings.headers;return e(h)};c.__call=function(j,h,m){var g=b.defer();var k=c.OfflineSettings.key;if(typeof Storage!=="undefined"){var l={calls:[]};var f=sessionStorage.getItem(k);if(typeof f==="undefined"||f==null){sessionStorage.setItem(k,"{}");f=sessionStorage.getItem(k)}f=JSON.parse(f);l.calls[j.method].push({options:j,uuid:h.$uuid});angular.extend(f,l);sessionStorage.setItem(k,JSON.stringify(l));g.resolve(h)}else{g.reject("Error processing offline call: "+l.toString())}return g};c.newInstance=function(g,f){return c.instance(g,f)};c.parse=function(l,g){var j=l[g.$settings.dataField.one]?[l[g.$settings.dataField.one]]:l[g.$settings.dataField.many];var h;var f=this;var k=function(o){angular.extend(o,g);return c.instance(o,g)};var n=[];for(h in j){if(j.hasOwnProperty(h)){var m;j[h].$mapping={};if(typeof g.$mapping!=="undefined"){angular.extend(j[h].$mapping,g.$mapping)}j[h]._cache={};for(m in j[h]){if(j[h].hasOwnProperty(m)){if(m!="$mapping"&&m!="_cache"){j[h].$mapping[m]=true;if(typeof j[h][m]==="object"){j[h]._cache[m]=c.clone(j[h][m])}else{j[h]._cache[m]=j[h][m]}}}}j[h].$parentModel=g;n.push(new new c.newInstance(j[h],g))}}return n};c.clone=function(j){if(null==j||"object"!==typeof j){return j}if(j instanceof Date){var k=new Date();k.setTime(j.getTime());return k}if(j instanceof Array){var k=[];for(var h=0,g=j.length;h + * @license MIT + */ +"use strict";!function(a,b){if("function"==typeof define&&define.amd)define(["react","backbone","underscore"],b);else if("undefined"!=typeof module){var c=require("react"),d=require("backbone"),e=require("underscore");module.exports=b(c,d,e)}else b(a.React,a.Backbone,a._)}(this,function(a,b,c){function d(a,e){e=e||{};var f,g=e.model,h=e.collection;(c.isElement(e.el)||b.$&&e.el instanceof b.$)&&(f=e.el,delete e.el),(g instanceof b.Model||g instanceof Object&&c.values(g)[0]instanceof b.Model)&&(delete e.model,this.model=g,this.setPropsBackbone(g,void 0,e)),(h instanceof b.Collection||h instanceof Object&&c.values(h)[0]instanceof b.Collection)&&(delete e.collection,this.collection=h,this.setPropsBackbone(h,void 0,e));var i=this.virtualComponent=c.defaults(a.apply(this,c.rest(arguments)),b.Events,b.React.Component,{clone:function(b,c){return new d(a,b,c).virtualComponent},cid:c.uniqueId(),wrapper:this});f&&i.setElement(f),i.initialize&&i.initialize(e),this.startModelListeners(),this.startCollectionListeners()}b.React||(b.React={}),b.React.Component={$:function(){return this.$el?this.$el.find.apply(this.$el,arguments):void 0},extend:function(f){function g(a,b){return new d(h,a,b).virtualComponent}g.extend=function(){return b.React.Component.extend(c.extend({},f,arguments[0]))},f.mixins?f.mixins[0]!==e&&f.mixins.splice(0,0,e):f.mixins=[e];var h=a.createClass(c.extend(g.prototype,f));return g},getCollection:function(){return this.getOwner().wrapper.collection},getModel:function(){return this.getOwner().wrapper.model},getOwner:function(){for(var a=this;a.props.__owner__;)a=a.props.__owner__;return a},mount:function(b,c){if(!b&&!this.el)throw new Error("No element to mount on");return b||(b=this.el),this.wrapper.component=a.renderComponent(this,b,c),this},remove:function(){this.wrapper.component&&this.wrapper.component.isMounted()&&this.unmount(),this.wrapper.stopListening(),this.stopListening()},setElement:function(a){if(a&&b.$&&a instanceof b.$){if(a.length>1)throw new Error("You can only assign one element to a component");this.el=a[0],this.$el=a}else a&&(this.el=a,b.$&&(this.$el=b.$(a)));return this},toHTML:function(){var b=this.clone(this.props);return a.renderComponentToString(b)},unmount:function(){var b=this.el.parentNode;if(!a.unmountComponentAtNode(b))throw new Error("There was an error unmounting the component");delete this.wrapper.component,this.setElement(b)}};var e={componentDidMount:function(){this.setElement(this.getDOMNode())},componentDidUpdate:function(){this.setElement(this.getDOMNode())}};return c.extend(d.prototype,b.Events,{onError:function(a,b,c){c.silent||this.setProps({isRequesting:!1,hasError:!0,error:b})},onRequest:function(a,b,c){c.silent||this.setProps({isRequesting:!0,hasError:!1})},onSync:function(a,b,c){c.silent||this.setProps({isRequesting:!1})},setPropsBackbone:function(a,c,d){if(a instanceof b.Collection||a instanceof b.Model)this.setProps.apply(this,arguments);else for(c in a)this.setPropsBackbone(a[c],c,d)},setProps:function(a,d,e){e||this.component&&this.component.isMounted()||(e=this.virtualComponent.props);var f={},g=a.toJSON?a.toJSON():a;d?f[d]=g:a instanceof b.Collection?f.collection=g:f=g,e?c.extend(e,f):(this.nextProps=c.extend(this.nextProps||{},f),c.defer(c.bind(function(){this.nextProps&&(this.component.setProps(this.nextProps),delete this.nextProps)},this)))},startCollectionListeners:function(a,d){if(a||(a=this.collection),a instanceof b.Collection)this.listenTo(a,"add remove change sort",c.partial(this.setPropsBackbone,a,d,void 0)).listenTo(a,"error",this.onError).listenTo(a,"request",this.onRequest).listenTo(a,"sync",this.onSync);else if(a)for(d in a)this.startCollectionListeners(a[d],d)},startModelListeners:function(a,d){if(a||(a=this.model),a instanceof b.Model)this.listenTo(a,"change",c.partial(this.setPropsBackbone,a,d,void 0)).listenTo(a,"error",this.onError).listenTo(a,"request",this.onRequest).listenTo(a,"sync",this.onSync);else if(a)for(d in a)this.startModelListeners(a[d],d)}}),b.React.Component}); \ No newline at end of file diff --git a/ajax/libs/backbone-react-component/0.5.0/backbone-react-component.js b/ajax/libs/backbone-react-component/0.5.0/backbone-react-component.js new file mode 100644 index 000000000..6d095958b --- /dev/null +++ b/ajax/libs/backbone-react-component/0.5.0/backbone-react-component.js @@ -0,0 +1,408 @@ +/** + * Backbone.React.Component + * @version 0.5.0 + * @author "Magalhas" José Magalhães + * @license MIT + */ +'use strict'; +(function (root, factory) { + if (typeof define === 'function' && define.amd) + define(['react', 'backbone', 'underscore'], factory); + else if (typeof module !== 'undefined') { + var React = require('react'); + var Backbone = require('backbone'); + var _ = require('underscore'); + module.exports = factory(React, Backbone, _); + } else + factory(root.React, root.Backbone, root._); +}(this, function (React, Backbone, _) { + /** + * @namespace Backbone.React.Component + * @mixes React.Component + * @mixes Backbone.Events + * @desc The Reactor.Component is a React.Component wrapper to serve + as a bridge between the React and Backbone worlds. Besides some extra members + that may be set by extending/instancing a component, it works pretty much the + same way that {@link http://facebook.github.io/react/|React} components do. +
+ When bound to a model, the component gets automatically mounted/rendered on + the DOM as the model changes. If already rendered it just updates the element + by using {@link http://facebook.github.io/react/|React} virtual DOM engine. +
+ Here lies the public API available on each component. + * @example + // Instancing a component + var myComponent = new Backbone.React.Component({ + el: document.body, + model: model + }); + * @example + // Extending a component + /** @jsx React.DOM *\/ + var MyComponent = Backbone.React.Component.extend({ + render: function () { + return <div>Hello world!</div>; + } + }); + */ + if (!Backbone.React) Backbone.React = {}; + Backbone.React.Component = + /** @lends Backbone.React.Component */ + { + /** + * Shortcut to this.$el.find. Inspired by Backbone.View. + * @returns {Backbone.$} + */ + $: function () { + if (this.$el) + return this.$el.find.apply(this.$el, arguments); + }, + /** + * Wraps React.Component into Backbone.React.Component and extends to a new + class. + * @method extend + * @memberof Component + * @static + */ + extend: function (Clazz) { + function Factory (props, children) { + return (new Wrapper(Component, props, children)).virtualComponent; + } + // Allow deep extending + Factory.extend = function () { + return Backbone.React.Component.extend(_.extend({}, Clazz, arguments[0])); + }; + // Apply mixin + if (Clazz.mixins) { + if (Clazz.mixins[0] !== mixin) + Clazz.mixins.splice(0, 0, mixin); + } else + Clazz.mixins = [mixin]; + // Create the react component later used by Factory + var Component = React.createClass(_.extend(Factory.prototype, Clazz)); + return Factory; + }, + /** + * Crawls to the owner of the component and gets the collection. + */ + getCollection: function () { + return this.getOwner().wrapper.collection; + }, + /** + * Crawls to the owner of the component and gets the model. + * @returns {Backbone.Model} + */ + getModel: function () { + return this.getOwner().wrapper.model; + }, + /** + * Crawls this.props.__owner__ recursively until it finds the owner of this + component. In case of being a parent component (no owners) it returns itself. + * @returns {Backbone.React.Component} + */ + getOwner: function () { + var owner = this; + while (owner.props.__owner__) owner = owner.props.__owner__; + return owner; + }, + /** + * Renders/mounts the component. It delegates to React.renderComponent. + * @param {DOMElement} [el=this.el] The DOM element where we want to mount + the component. + * @param {Callback} [onRender] Callback to be executed when the component + is rendered/mounted. If not passed it syncs this.model or this.collection + with this.props. + * @returns {this} + */ + mount: function (el, onRender) { + if (!(el || this.el)) throw new Error('No element to mount on'); + else if (!el) el = this.el; + this.wrapper.component = React.renderComponent(this, el, onRender); + return this; + }, + /** + * Stops all listeners and unmounts this component from the DOM. + */ + remove: function () { + if (this.wrapper.component && this.wrapper.component.isMounted()) + this.unmount(); + this.wrapper.stopListening(); + this.stopListening(); + }, + /** + * Sets a DOM element to render/mount this component on this.el and this.$el. + * @param {DOMElement|Backbone.$} el The DOMElement where we want to render/mount + the component. + * @returns {this} + */ + setElement: function (el) { + if (el && Backbone.$ && el instanceof Backbone.$) { + if (el.length > 1) throw new Error('You can only assign one element to a component'); + this.el = el[0]; + this.$el = el; + } else if (el) { + this.el = el; + if (Backbone.$) this.$el = Backbone.$(el); + } + return this; + }, + /** + * Intended to be used on the server side (Nodejs), renders your component to + a string ready to be used on the client side by delegating to React.renderComponentToString. + * @returns {String} The HTML representation of this component. + */ + toHTML: function () { + // Since we're only able to call renderComponentToString once, lets clone this component + // and use it insteaad. + var clone = this.clone(this.props); + return React.renderComponentToString(clone); + }, + /** + * Unmount the component from the DOM. + * @throws {Error} If component isn't unmounted successfully. + */ + unmount: function () { + var parentNode = this.el.parentNode; + if (!React.unmountComponentAtNode(parentNode)) { + throw new Error('There was an error unmounting the component'); + } + delete this.wrapper.component; + this.setElement(parentNode); + } + }; + /** + * Mixin used in all component instances. + * @mixin + */ + var mixin = { + /** + * Sets this.el and this.$el when the component mounts. + */ + componentDidMount: function () { + this.setElement(this.getDOMNode()); + }, + /** + * Sets this.el and this.$el when the component updates. + */ + componentDidUpdate: function () { + this.setElement(this.getDOMNode()); + } + }; + /** + * Binds models and collections to a React.Component. + * @class Wrapper + * @mixes Backbone.Events + */ + function Wrapper (Component, props) { + props = props || {}; + var el, model = props.model, collection = props.collection; + // Check if props.el is a DOM element or a jQuery object + if (_.isElement(props.el) || Backbone.$ && props.el instanceof Backbone.$) { + el = props.el; + delete props.el; + } + // Check if props.model is a Backbone.Model or an hashmap of them + if (model instanceof Backbone.Model || + model instanceof Object && _.values(model)[0] instanceof Backbone.Model) { + delete props.model; + /** + * The model or models bound to this component. + */ + this.model = model; + // Set model(s) attributes on props for the first render + this.setPropsBackbone(model, void 0, props); + } + // Check if props.collection is a Backbone.Collection or an hashmap of them + if (collection instanceof Backbone.Collection || + collection instanceof Object && _.values(collection)[0] instanceof Backbone.Collection) { + delete props.collection; + /** + * The collection or collections bound to this component. + */ + this.collection = collection; + // Set collection(s) models on props for the first render + this.setPropsBackbone(collection, void 0, props); + } + // Instance the component mixing Backbone.Events, our public API and some special + // properties. + var component = this.virtualComponent = _.defaults(Component.apply(this, _.rest(arguments)), + Backbone.Events, Backbone.React.Component, { + /** + * Clones the component wrapper and returns the component. + * @returns {Backbone.React.Component} + */ + clone: function (props, children) { + return (new Wrapper(Component, props, children)).virtualComponent; + }, + // Assign a component unique id, this is handy sometimes as a DOM attribute + cid: _.uniqueId(), + // One to one relationship between the wrapper and the component + wrapper: this + }); + // Set element + if (el) component.setElement(el); + // Call initialize if available + if (component.initialize) component.initialize(props); + // Start listeners + this.startModelListeners(); + this.startCollectionListeners(); + } + _.extend(Wrapper.prototype, Backbone.Events, + /** @lends Wrapper.prototype */ + { + /** + * Sets this.props when a model/collection request results in error. It delegates to this.setProps. + * @private + * @param {Backbone.Model|Backbone.Collection} modelOrCollection The model or collection + that was sync. + * @param {Object} res The XHR error response. + * @param {Object} options + * @listens Backbone.Model#error + * @listens Backbone.Collection#error + */ + onError: function (modelOrCollection, res, options) { + // Set props only if there's no silent option + if (!options.silent) + this.setProps({ + isRequesting: false, + hasError: true, + error: res + }); + }, + /** + * Sets this.props when a model/collection request starts. It delegates to this.setProps. + * @private + * @param {Backbone.Model|Backbone.Collection} modelOrCollection The model or collection + that was sync. + * @param {XMLHttpRequest} xhr + * @param {Object} options + * @listens Backbone.Model#request + * @listens Backbone.Collection#request + */ + onRequest: function (modelOrCollection, xhr, options) { + // Set props only if there's no silent option + if (!options.silent) + this.setProps({ + isRequesting: true, + hasError: false + }); + }, + /** + * Sets this.props when a model/collection syncs. It delegates to this.setProps. + * @private + * @param {Backbone.Model|Backbone.Collection} modelOrCollection The model or collection + that was sync. + * @param {Object} res The XHR request response. + * @param {Object} options + * @listens Backbone.Model#sync + * @listens Backbone.Collection#sync + */ + onSync: function (modelOrCollection, res, options) { + // Set props only if there's no silent option + if (!options.silent) + this.setProps({isRequesting: false}); + }, + /** + * Used internally to set this.collection or this.model on this.props. Delegates to + this.setProps. + * @private + * @param {Backbone.Collection|Backbone.Model|Object} modelOrCollection The + model or collection or hashmap of them that we're delegating to this.setProps. + * @param {String} [key] In case of multiple collections a key is passed to identify + the collection. + * @param {Object} [target] Used by the constructor to set props for the component + first render. + * @listens Backbone.Collection#add + * @listens Backbone.Collection#remove + * @listens Backbone.Collection#change + * @listens Backbone.Model#change + */ + setPropsBackbone: function (modelOrCollection, key, target) { + if (!(modelOrCollection instanceof Backbone.Collection || + modelOrCollection instanceof Backbone.Model)) { + for (key in modelOrCollection) + this.setPropsBackbone(modelOrCollection[key], key, target); + return; + } + this.setProps.apply(this, arguments); + }, + /** + * Sets a model, collection or object into this.props by delegating to this.setProps. + * @private + * @param {Backbone.Collection|Backbone.Model|Object} [modelOrCollection] The model + or collection we're setting into this.props or target. Also accepts a raw object. + * @param {String} [key] The key to be used inside this.props. + * @param {Object} [target] If we're setting the data on an object instead of + delegating to this.setProps. + */ + setProps: function (modelOrCollection, key, target) { + // If the component isn't rendered/mounted set target because you can't set props + // on an unmounted (virtual) component. + if (!target && !(this.component && this.component.isMounted())) target = this.virtualComponent.props; + var props = {}; + var newProps = modelOrCollection.toJSON ? modelOrCollection.toJSON() : modelOrCollection; + + if (key) + props[key] = newProps; + else if (modelOrCollection instanceof Backbone.Collection) + props.collection = newProps; + else // if (modelOrCollection instanceof Backbone.Model) + props = newProps; + + if (target) _.extend(target, props); + else { + this.nextProps = _.extend(this.nextProps || {}, props); + _.defer(_.bind(function () { + if (this.nextProps) { + this.component.setProps(this.nextProps); + delete this.nextProps; + } + }, this)); + } + }, + /** + * Binds this.props.collection to any this.collection changes, making the component + to get instantly rerendered. This has high performance since it uses the + {@link http://facebook.github.io/react/|React} virtual DOM. + * @param {Backbone.Collection|Object} [collection=this.collection] In case of being + an object it calls startCollectionListeners for each entry. + * @param {String} [key] In case of multiple collections a key is passed to identify + the collection. + */ + startCollectionListeners: function (collection, key) { + if (!collection) collection = this.collection; + if (collection instanceof Backbone.Collection) + this + .listenTo(collection, 'add remove change sort', _.partial(this.setPropsBackbone, collection, key, void 0)) + .listenTo(collection, 'error', this.onError) + .listenTo(collection, 'request', this.onRequest) + .listenTo(collection, 'sync', this.onSync); + else if (collection) + for (key in collection) + this.startCollectionListeners(collection[key], key); + }, + /** + * Binds this.props to any this.model changes, making the screen component + get instantly rerendered in the screen. This has high performance + since it uses the {@link http://facebook.github.io/react/|React} virtual DOM. + * @param {Backbone.Model|Object} [model=this.model] In case of being + an object it calls startModelListeners for each entry. + * @param {String} [key] In case of multiple models a key is passed to identify + the model. + */ + startModelListeners: function (model, key) { + if (!model) model = this.model; + if (model instanceof Backbone.Model) + this + .listenTo(model, 'change', _.partial(this.setPropsBackbone, model, key, void 0)) + .listenTo(model, 'error', this.onError) + .listenTo(model, 'request', this.onRequest) + .listenTo(model, 'sync', this.onSync); + else if (model) + for (key in model) + this.startModelListeners(model[key], key); + } + }); + + return Backbone.React.Component; +})); \ No newline at end of file diff --git a/ajax/libs/backbone-react-component/package.json b/ajax/libs/backbone-react-component/package.json index 7d2f5013e..d4da2a407 100644 --- a/ajax/libs/backbone-react-component/package.json +++ b/ajax/libs/backbone-react-component/package.json @@ -1,6 +1,6 @@ { "name": "backbone-react-component", - "version": "0.4.2", + "version": "0.5.0", "filename": "backbone-react-component.js", "description": "Backbone.React.Component is a wrapper for React.Component and brings all the power of Facebook's React to Backbone.js", "author": { @@ -12,14 +12,15 @@ "url": "https://github.com/magalhas/backbone-react-component.git" }, "dependencies": { - "backbone": "~1.1.1", - "underscore": "~1.6.0", - "react": "~0.8.0" + "backbone": "^1.1.2", + "underscore": "^1.6.0", + "react": "^0.9.0" }, "devDependencies": { - "grunt-contrib-uglify": "~0.3.2", - "grunt": "~0.4.2", - "grunt-contrib-jasmine": "~0.6.1" + "grunt-contrib-uglify": "^0.3.2", + "grunt": "^0.4.2", + "grunt-contrib-jasmine": "^0.6.1", + "grunt-contrib-copy": "^0.5.0" }, "scripts": { "test": "grunt test", @@ -36,7 +37,7 @@ ], "main": "lib/component", "engines": { - "node": ">=0.8" + "node": ">=0.10" }, "licenses": [ { diff --git a/ajax/libs/backbone.obscura/0.1.6/backbone.obscura.js b/ajax/libs/backbone.obscura/0.1.6/backbone.obscura.js new file mode 100644 index 000000000..2d2073047 --- /dev/null +++ b/ajax/libs/backbone.obscura/0.1.6/backbone.obscura.js @@ -0,0 +1,902 @@ +(function(root, factory) { + if(typeof exports === 'object') { + module.exports = factory(require('underscore'), require('backbone')); + } + else if(typeof define === 'function' && define.amd) { + define(['underscore', 'backbone'], factory); + } + else { + root.Backbone.Obscura = factory(root._, root.Backbone); + } +}(this, function(_, Backbone) { +var require=function(name){return {"backbone":Backbone,"underscore":_}[name];}; +require=(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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o= 0; i -= 1) { + if (this.contains(this.superset().at(i))) { + filteredIndex = this.indexOf(this.superset().at(i)) + 1; + break; + } + } + filteredIndex = filteredIndex || 0; + + this._collection.add(model, { at: filteredIndex }); + } + } else { + if (this._collection.get(model.cid)) { + this._collection.remove(model); + } + } + this.length = this._collection.length; +} + +// This fires on 'change:[attribute]' events. We only want to +// remove this model if it fails the test, but not add it if +// it does. If we remove it, it will prevent the 'change' +// events from being forwarded, and if we add it, it will cause +// an unneccesary 'change' event to be forwarded without the +// 'change:[attribute]' that goes along with it. +function onModelAttributeChange(model) { + // reset the cached results + this._filterResultCache[model.cid] = {}; + + if (!execFilterOnModel.call(this, model)) { + if (this._collection.get(model.cid)) { + this._collection.remove(model); + } + } +} + +function onAll(eventName, model, value) { + if (eventName.slice(0, 7) === "change:") { + onModelAttributeChange.call(this, arguments[1]); + } +} + +function onModelRemove(model) { + if (this.contains(model)) { + this._collection.remove(model); + } + this.length = this._collection.length; +} + +function Filtered(superset) { + // Save a reference to the original collection + this._superset = superset; + + // The idea is to keep an internal backbone collection with the filtered + // set, and expose limited functionality. + this._collection = new Backbone.Collection(superset.toArray()); + proxyCollection(this._collection, this); + + // Set up the filter data structures + this.resetFilters(); + + this.listenTo(this._superset, 'reset sort', execFilter); + this.listenTo(this._superset, 'add change', onAddChange); + this.listenTo(this._superset, 'remove', onModelRemove); + this.listenTo(this._superset, 'all', onAll); +} + +var methods = { + + defaultFilterName: '__default', + + filterBy: function(filterName, filter) { + // Allow the user to skip the filter name if they're only using one filter + if (!filter) { + filter = filterName; + filterName = this.defaultFilterName; + } + + addFilter.call(this, filterName, createFilter(filter)); + + execFilter.call(this); + return this; + }, + + removeFilter: function(filterName) { + if (!filterName) { + filterName = this.defaultFilterName; + } + + removeFilter.call(this, filterName); + + execFilter.call(this); + return this; + }, + + resetFilters: function() { + this._filters = {}; + invalidateCache.call(this); + + this.trigger('filtered:reset'); + + execFilter.call(this); + return this; + }, + + superset: function() { + return this._superset; + }, + + refilter: function(arg) { + if (typeof arg === "object" && arg.cid) { + // is backbone model, refilter that one + onAddChange.call(this, arg); + } else { + // refilter everything + invalidateCache.call(this); + execFilter.call(this); + } + + return this; + }, + + getFilters: function() { + return _.keys(this._filters); + }, + + hasFilter: function(name) { + return _.contains(this.getFilters(), name); + }, + + destroy: function() { + this.stopListening(); + this._collection.reset([]); + this._superset = this._collection; + this.length = 0; + + this.trigger('filtered:destroy'); + } + +}; + +// Build up the prototype +_.extend(Filtered.prototype, methods, Backbone.Events); + +module.exports = Filtered; + + +},{"./src/create-filter.js":5,"backbone":false,"backbone-collection-proxy":3,"underscore":false}],5:[function(require,module,exports){ +var _ = require('underscore'); + +// Converts a key and value into a function that accepts a model +// and returns a boolean. +function convertKeyValueToFunction(key, value) { + return function(model) { + return model.get(key) === value; + }; +} + +// Converts a key and an associated filter function into a function +// that accepts a model and returns a boolean. +function convertKeyFunctionToFunction(key, fn) { + return function(model) { + return fn(model.get(key)); + }; +} + +function createFilterObject(filterFunction, keys) { + // Make sure the keys value is either an array or null + if (!_.isArray(keys)) { + keys = null; + } + return { fn: filterFunction, keys: keys }; +} + +// Accepts an object in the form of: +// +// { +// key: value, +// key: function(val) { ... } +// } +// +// and turns it into a function that accepts a model an returns a +// boolean + a list of the keys that the function depends on. +function createFilterFromObject(filterObj) { + var keys = _.keys(filterObj); + + var filterFunctions = _.map(keys, function(key) { + var val = filterObj[key]; + if (_.isFunction(val)) { + return convertKeyFunctionToFunction(key, val); + } + return convertKeyValueToFunction(key, val); + }); + + // Iterate through each of the generated filter functions. If any + // are false, kill the computation and return false. The function + // is only true if all of the subfunctions are true. + var filterFunction = function(model) { + for (var i = 0; i < filterFunctions.length; i++) { + if (!filterFunctions[i](model)) { + return false; + } + } + return true; + }; + + return createFilterObject(filterFunction, keys); +} + +// Expects one of the following: +// +// - A filter function that accepts a model + (optional) array of +// keys to listen to changes for or null) +// - An object describing a filter +function createFilter(filter, keys) { + // This must go first because _.isObject(fn) === true + if (_.isFunction(filter)) { + return createFilterObject(filter, keys); + } + + // If the filter is an object describing a filter, generate the + // appropriate function. + if (_.isObject(filter)) { + return createFilterFromObject(filter); + } +} + +module.exports = createFilter; + + +},{"underscore":false}],6:[function(require,module,exports){ + +var _ = require('underscore'); +var Backbone = require('backbone'); +var proxyCollection = require('backbone-collection-proxy'); + +function getPageLimits() { + var start = this.getPage() * this.getPerPage(); + var end = start + this.getPerPage(); + return [start, end]; +} + +function updatePagination() { + var pages = getPageLimits.call(this); + this._collection.reset(this.superset().slice(pages[0], pages[1])); +} + +function updateNumPages() { + var currentNumPages = this._totalPages; + var length = this.superset().length; + var perPage = this.getPerPage(); + + // If the # of objects can be exactly divided by the number + // of pages, it would leave an empty last page if we took + // the floor. + var totalPages = length % perPage === 0 ? + (length / perPage) : Math.floor(length / perPage) + 1; + + var numPagesChanged = this._totalPages !== totalPages; + this._totalPages = totalPages; + + if (numPagesChanged) { + this.trigger('paginated:change:numPages', { numPages: totalPages }); + } + + // Test to see if we are past the last page, and if so, + // move back. Return true so that we can test to see if + // this happened. + if (this.getPage() >= totalPages) { + this.setPage(totalPages - 1); + return true; + } +} + +function recalculatePagination() { + if (updateNumPages.call(this)) { return; } + updatePagination.call(this); +} + +// Given two arrays of backbone models, with at most one model added +// and one model removed from each, return the model in arrayA that +// is not in arrayB or undefined. +function difference(arrayA, arrayB) { + var maxLength = _.max([ arrayA.length, arrayB.length ]); + + for (var i = 0, j = 0; i < maxLength; i += 1, j += 1) { + if (arrayA[i] !== arrayB[j]) { + if (arrayB[i-1] === arrayA[i]) { + j -= 1; + } else if (arrayB[i+1] === arrayA[i]) { + j += 1; + } else { + return arrayA[i]; + } + } + } +} + +function onAddRemove(model, collection, options) { + if (updateNumPages.call(this)) { return; } + + var pages = getPageLimits.call(this); + var start = pages[0], end = pages[1]; + + // We are only adding and removing at most one model at a time, + // so we can find just those two models. We could probably rewrite + // `collectionDifference` to only make on pass instead of two. This + // is a bottleneck on the total size of collections. I was getting + // slow unit tests around 30,000 models / page in Firefox. + var toAdd = difference(this.superset().slice(start, end), this._collection.toArray()); + var toRemove = difference(this._collection.toArray(), this.superset().slice(start, end)); + + if (toRemove) { + this._collection.remove(toRemove); + } + + if (toAdd) { + this._collection.add(toAdd, { + at: this.superset().indexOf(toAdd) - start + }); + } +} + +function Paginated(superset, options) { + // Save a reference to the original collection + this._superset = superset; + + // The idea is to keep an internal backbone collection with the paginated + // set, and expose limited functionality. + this._collection = new Backbone.Collection(superset.toArray()); + this._page = 0; + this.setPerPage((options && options.perPage) ? options.perPage : null); + + proxyCollection(this._collection, this); + + this.listenTo(this._superset, 'add remove', onAddRemove); + this.listenTo(this._superset, 'reset sort', recalculatePagination); +} + +var methods = { + + removePagination: function() { + this.setPerPage(null); + return this; + }, + + setPerPage: function(perPage) { + this._perPage = perPage; + recalculatePagination.call(this); + this.setPage(0); + + this.trigger('paginated:change:perPage', { + perPage: perPage, + numPages: this.getNumPages() + }); + + return this; + }, + + setPage: function(page) { + // The lowest page we could set + var lowerLimit = 0; + // The highest page we could set + var upperLimit = this.getNumPages() - 1; + + // If the page is higher or lower than these limits, + // set it to the limit. + page = page > lowerLimit ? page : lowerLimit; + page = page < upperLimit ? page : upperLimit; + page = page < 0 ? 0 : page; + + this._page = page; + updatePagination.call(this); + + this.trigger('paginated:change:page', { page: page }); + return this; + }, + + getPerPage: function() { + return this._perPage || this.superset().length || 1; + }, + + getNumPages: function() { + return this._totalPages; + }, + + getPage: function() { + return this._page; + }, + + hasNextPage: function() { + return this.getPage() < this.getNumPages() - 1; + }, + + hasPrevPage: function() { + return this.getPage() > 0; + }, + + nextPage: function() { + this.movePage(1); + return this; + }, + + prevPage: function() { + this.movePage(-1); + return this; + }, + + firstPage: function() { + this.setPage(0); + }, + + lastPage: function() { + this.setPage(this.getNumPages() - 1); + }, + + movePage: function(delta) { + this.setPage(this.getPage() + delta); + return this; + }, + + superset: function() { + return this._superset; + }, + + destroy: function() { + this.stopListening(); + this._collection.reset([]); + this._superset = this._collection; + this._page = 0; + this._totalPages = 0; + this.length = 0; + + this.trigger('paginated:destroy'); + } + +}; + +// Build up the prototype +_.extend(Paginated.prototype, methods, Backbone.Events); + +module.exports = Paginated; + + +},{"backbone":false,"backbone-collection-proxy":3,"underscore":false}],7:[function(require,module,exports){ + +var _ = require('underscore'); +var Backbone =require('backbone'); +var proxyCollection = require('backbone-collection-proxy'); +var reverseSortedIndex = require('./src/reverse-sorted-index.js'); + +function lookupIterator(value) { + return _.isFunction(value) ? value : function(obj){ return obj.get(value); }; +} + +function modelInsertIndex(model) { + if (!this._comparator) { + return this._superset.indexOf(model); + } else { + if (!this._reverse) { + return _.sortedIndex(this._collection.toArray(), model, lookupIterator(this._comparator)); + } else { + return reverseSortedIndex(this._collection.toArray(), model, lookupIterator(this._comparator)); + } + } +} + +function onAdd(model) { + var index = modelInsertIndex.call(this, model); + this._collection.add(model, { at: index }); +} + +function onRemove(model) { + if (this.contains(model)) { + this._collection.remove(model); + } +} + +function onChange(model) { + if (this.contains(model) && this._collection.indexOf(model) !== modelInsertIndex.call(this, model)) { + this._collection.remove(model); + onAdd.call(this, model); + } +} + +function sort() { + if (!this._comparator) { + this._collection.reset(this._superset.toArray()); + return; + } + + var newOrder = this._superset.sortBy(this._comparator); + this._collection.reset(this._reverse ? newOrder.reverse() : newOrder); +} + +function Sorted(superset) { + // Save a reference to the original collection + this._superset = superset; + this._reverse = false; + this._comparator = null; + + // The idea is to keep an internal backbone collection with the paginated + // set, and expose limited functionality. + this._collection = new Backbone.Collection(superset.toArray()); + proxyCollection(this._collection, this); + + this.listenTo(this._superset, 'add', onAdd); + this.listenTo(this._superset, 'remove', onRemove); + this.listenTo(this._superset, 'change', onChange); + this.listenTo(this._superset, 'reset', sort); +} + +var methods = { + + setSort: function(comparator, direction) { + this._reverse = direction === 'desc' ? true : false; + this._comparator = comparator; + + sort.call(this); + + if (!comparator) { + this.trigger('sorted:remove'); + } else { + this.trigger('sorted:add'); + } + + return this; + }, + + reverseSort: function() { + this._reverse = !this._reverse; + sort.call(this); + + return this; + }, + + removeSort: function() { + this.setSort(); + return this; + }, + + superset: function() { + return this._superset; + }, + + destroy: function() { + this.stopListening(); + this._collection.reset([]); + this._superset = this._collection; + this.length = 0; + + this.trigger('sorted:destroy'); + } + +}; + +// Build up the prototype +_.extend(Sorted.prototype, methods, Backbone.Events); + +module.exports = Sorted; + + +},{"./src/reverse-sorted-index.js":8,"backbone":false,"backbone-collection-proxy":3,"underscore":false}],8:[function(require,module,exports){ + +var _ = require('underscore'); + +// Underscore provides a .sortedIndex function that works +// when sorting ascending based on a function or a key, but there's no +// way to do the same thing when sorting descending. This is a slight +// modification of the underscore / backbone code to do the same thing +// but descending. + +function lookupIterator(value) { + return _.isFunction(value) ? value : function(obj){ return obj[value]; }; +} + +function reverseSortedIndex(array, obj, iterator, context) { + iterator = iterator == null ? _.identity : lookupIterator(iterator); + var value = iterator.call(context, obj); + var low = 0, high = array.length; + while (low < high) { + var mid = (low + high) >>> 1; + iterator.call(context, array[mid]) < value ? high = mid : low = mid + 1; + } + return low; +} + +module.exports = reverseSortedIndex; + +},{"underscore":false}],9:[function(require,module,exports){ +var _ = require('underscore'); + +function proxyEvents(from, eventNames) { + _.each(eventNames, function(eventName) { + this.listenTo(from, eventName, function() { + var args = _.toArray(arguments); + args.unshift(eventName); + this.trigger.apply(this, args); + }); + }, this); +} + +module.exports = proxyEvents; + +},{"underscore":false}]},{},[]) +return require('obscura'); + +})); + diff --git a/ajax/libs/backbone.obscura/0.1.6/backbone.obscura.min.js b/ajax/libs/backbone.obscura/0.1.6/backbone.obscura.min.js new file mode 100644 index 000000000..f5b0e0efe --- /dev/null +++ b/ajax/libs/backbone.obscura/0.1.6/backbone.obscura.min.js @@ -0,0 +1 @@ +(function(a,b){if(typeof exports==='object'){module.exports=b(require('underscore'),require('backbone'))}else if(typeof define==='function'&&define.amd){define(['underscore','backbone'],b)}else{a.Backbone.Obscura=b(a._,a.Backbone)}}(this,function(_,v){var w=function(a){return{"backbone":v,"underscore":_}[a]};w=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof w=="function"&&w;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof w=="function"&&w;for(var o=0;o=0;i-=1){if(this.contains(this.superset().at(i))){c=this.indexOf(this.superset().at(i))+1;break}}c=c||0;this._collection.add(a,{at:c})}}else{if(this._collection.get(a.cid)){this._collection.remove(a)}}this.length=this._collection.length}function onModelAttributeChange(a){this._filterResultCache[a.cid]={};if(!execFilterOnModel.call(this,a)){if(this._collection.get(a.cid)){this._collection.remove(a)}}}function onAll(a,b,c){if(a.slice(0,7)==="change:"){onModelAttributeChange.call(this,arguments[1])}}function onModelRemove(a){if(this.contains(a)){this._collection.remove(a)}this.length=this._collection.length}function Filtered(a){this._superset=a;this._collection=new g.Collection(a.toArray());h(this._collection,this);this.resetFilters();this.listenTo(this._superset,'reset sort',execFilter);this.listenTo(this._superset,'add change',onAddChange);this.listenTo(this._superset,'remove',onModelRemove);this.listenTo(this._superset,'all',onAll)}var k={defaultFilterName:'__default',filterBy:function(a,b){if(!b){b=a;a=this.defaultFilterName}addFilter.call(this,a,j(b));execFilter.call(this);return this},removeFilter:function(a){if(!a){a=this.defaultFilterName}removeFilter.call(this,a);execFilter.call(this);return this},resetFilters:function(){this._filters={};invalidateCache.call(this);this.trigger('filtered:reset');execFilter.call(this);return this},superset:function(){return this._superset},refilter:function(a){if(typeof a==="object"&&a.cid){onAddChange.call(this,a)}else{invalidateCache.call(this);execFilter.call(this)}return this},getFilters:function(){return _.keys(this._filters)},hasFilter:function(a){return _.contains(this.getFilters(),a)},destroy:function(){this.stopListening();this._collection.reset([]);this._superset=this._collection;this.length=0;this.trigger('filtered:destroy')}};_.extend(Filtered.prototype,k,g.Events);e.exports=Filtered},{"./src/create-filter.js":5,"backbone":false,"backbone-collection-proxy":3,"underscore":false}],5:[function(g,h,j){var _=g('underscore');function convertKeyValueToFunction(b,c){return function(a){return a.get(b)===c}}function convertKeyFunctionToFunction(b,c){return function(a){return c(a.get(b))}}function createFilterObject(a,b){if(!_.isArray(b)){b=null}return{fn:a,keys:b}}function createFilterFromObject(c){var d=_.keys(c);var e=_.map(d,function(a){var b=c[a];if(_.isFunction(b)){return convertKeyFunctionToFunction(a,b)}return convertKeyValueToFunction(a,b)});var f=function(a){for(var i=0;i=d){this.setPage(d-1);return true}}function recalculatePagination(){if(updateNumPages.call(this)){return}updatePagination.call(this)}function difference(a,b){var c=_.max([a.length,b.length]);for(var i=0,j=0;ib?a:b;a=a0},nextPage:function(){this.movePage(1);return this},prevPage:function(){this.movePage(-1);return this},firstPage:function(){this.setPage(0)},lastPage:function(){this.setPage(this.getNumPages()-1)},movePage:function(a){this.setPage(this.getPage()+a);return this},superset:function(){return this._superset},destroy:function(){this.stopListening();this._collection.reset([]);this._superset=this._collection;this._page=0;this._totalPages=0;this.length=0;this.trigger('paginated:destroy')}};_.extend(Paginated.prototype,o,m.Events);k.exports=Paginated},{"backbone":false,"backbone-collection-proxy":3,"underscore":false}],7:[function(c,d,e){var _=c('underscore');var f=c('backbone');var g=c('backbone-collection-proxy');var h=c('./src/reverse-sorted-index.js');function lookupIterator(b){return _.isFunction(b)?b:function(a){return a.get(b)}}function modelInsertIndex(a){if(!this._comparator){return this._superset.indexOf(a)}else{if(!this._reverse){return _.sortedIndex(this._collection.toArray(),a,lookupIterator(this._comparator))}else{return h(this._collection.toArray(),a,lookupIterator(this._comparator))}}}function onAdd(a){var b=modelInsertIndex.call(this,a);this._collection.add(a,{at:b})}function onRemove(a){if(this.contains(a)){this._collection.remove(a)}}function onChange(a){if(this.contains(a)&&this._collection.indexOf(a)!==modelInsertIndex.call(this,a)){this._collection.remove(a);onAdd.call(this,a)}}function sort(){if(!this._comparator){this._collection.reset(this._superset.toArray());return}var a=this._superset.sortBy(this._comparator);this._collection.reset(this._reverse?a.reverse():a)}function Sorted(a){this._superset=a;this._reverse=false;this._comparator=null;this._collection=new f.Collection(a.toArray());g(this._collection,this);this.listenTo(this._superset,'add',onAdd);this.listenTo(this._superset,'remove',onRemove);this.listenTo(this._superset,'change',onChange);this.listenTo(this._superset,'reset',sort)}var i={setSort:function(a,b){this._reverse=b==='desc'?true:false;this._comparator=a;sort.call(this);if(!a){this.trigger('sorted:remove')}else{this.trigger('sorted:add')}return this},reverseSort:function(){this._reverse=!this._reverse;sort.call(this);return this},removeSort:function(){this.setSort();return this},superset:function(){return this._superset},destroy:function(){this.stopListening();this._collection.reset([]);this._superset=this._collection;this.length=0;this.trigger('sorted:destroy')}};_.extend(Sorted.prototype,i,f.Events);d.exports=Sorted},{"./src/reverse-sorted-index.js":8,"backbone":false,"backbone-collection-proxy":3,"underscore":false}],8:[function(h,i,j){var _=h('underscore');function lookupIterator(b){return _.isFunction(b)?b:function(a){return a[b]}}function reverseSortedIndex(a,b,c,d){c=c==null?_.identity:lookupIterator(c);var e=c.call(d,b);var f=0,high=a.length;while(f>>1;c.call(d,a[g])",{"class":"btn-group"});for(o=0;o '+m+"");v.push(u);t.push(l.callback)}g.append(q)}}return g},__setListener:function(){var g=typeof this.$textarea.attr("rows")!="undefined",f=this.$textarea.val().split("\n").length>5?this.$textarea.val().split("\n").length:"5",h=g?this.$textarea.attr("rows"):f;this.$textarea.attr("rows",h);this.$textarea.css("resize","none");this.$textarea.on("focus",e.proxy(this.focus,this)).on("keypress",e.proxy(this.keypress,this)).on("keyup",e.proxy(this.keyup,this));if(this.eventSupported("keydown")){this.$textarea.on("keydown",e.proxy(this.keydown,this))}this.$textarea.data("markdown",this)},__handle:function(j){var i=e(j.currentTarget),h=this.$handler,l=this.$callback,g=i.attr("data-handler"),k=h.indexOf(g),f=l[k];e(j.currentTarget).focus();f(this);if(g.indexOf("cmdSave")<0){this.$textarea.focus()}j.preventDefault()},showEditor:function(){var r=this,q,o=this.$ns,f=this.$element,p=f.css("height"),h=f.css("width"),j=this.$editable,t=this.$handler,s=this.$callback,u=this.$options,l=e("
",{"class":"md-editor",click:function(){r.focus()}});if(this.$editor==null){var g=e("
",{"class":"md-header"});if(u.buttons.length>0){g=this.__buildButtons(u.buttons,g)}if(u.additionalButtons.length>0){g=this.__buildButtons(u.additionalButtons,g)}l.append(g);if(f.is("textarea")){f.before(l);q=f;q.addClass("md-input");l.append(q)}else{var m=(typeof toMarkdown=="function")?toMarkdown(f.html()):f.html(),n=e.trim(m);q=e(""}else{if(!aH.node.hasChildNodes()){aE+=""+aH.node.nodeName+""+((aH.node.nodeValue!==null)?N(aH.node.nodeValue):" ")+"";if(aH.node.attributes){aE+=""+t(aH.node)+""}}else{if(aH.node.hasChildNodes()&&aH.node.firstChild.nodeType===aI){aE+=""+aH.node.nodeName+""}else{if(aH.node.hasChildNodes()&&aH.node.firstChild.nodeType===aJ){aE+=""+aH.node.nodeName+""+N(aH.node.firstChild.nodeValue)+""}else{aE+=""+aH.node.nodeName+"";if(aH.node.attributes){aE+=""+t(aH.node)+""}aE+="";for(aG=0;aG"}}}}aE+="";return aE};am.fn.SPServices.SPGetCurrentUser=function(aH){var aJ=am.extend({},{webURL:"",fieldName:"Name",fieldNames:{},debug:false},aH);if(aJ.fieldName==="ID"&&typeof ae.thisUserId!=="undefined"){return ae.thisUserId}var aF="";var aI={};var aK=aJ.fieldNames.length>0?aJ.fieldNames.length:1;var aG;var aE=aJ.webURL.length>0?aJ.webURL:am().SPServices.SPGetCurrentSite();am.ajax({async:false,url:aE+"/_layouts/userdisp.aspx?Force=True&"+new Date().getTime(),complete:function(aL){aG=aL}});for(O=0;O1){i=RegExp('FieldInternalName="'+aJ.fieldNames[O]+'"',"gi")}else{i=RegExp('FieldInternalName="'+aJ.fieldName+'"',"gi")}am(aG.responseText).find("table.ms-formtable td[id^='SPField']").each(function(){if(i.test(am(this).html())){switch(am(this).attr("id")){case"SPFieldText":aF=am(this).text();break;case"SPFieldNote":aF=am(this).find("div").html();break;case"SPFieldURL":aF=am(this).find("img").attr("src");break;default:aF=am(this).text();break}return false}})}if(aJ.fieldNames[O]!=="ID"){aF=(typeof aF!=="undefined")?aF.replace(/(^[\s\xA0]+|[\s\xA0]+$)/g,""):null}if(aK>1){aI[aJ.fieldNames[O]]=aF}}return(aK>1)?aI:aF};am.fn.SPServices.SPLookupAddNew=function(aL){var aG=am.extend({},{lookupColumn:"",promptText:"Add new {0}",newWindow:false,ContentTypeID:"",completefunc:null,debug:false},aL);var aI="SPServices.SPLookupAddNew";var aF=am().SPServices.SPDropdownCtl({displayName:aG.lookupColumn});if(aF.Obj.html()===null&&aG.debug){X(aI,"lookupColumn: "+aG.lookupColumn,aj);return}var i="";var aK="";var aE="";am().SPServices({operation:"GetList",async:false,cacheXML:true,listName:am().SPServices.SPListNameFromUrl(),completefunc:function(aM){am(aM.responseXML).find("Field[DisplayName='"+aG.lookupColumn+"']").each(function(){aE=am(this).attr("StaticName");am().SPServices({operation:"GetList",async:false,cacheXML:true,listName:am(this).attr("List"),completefunc:function(aN){am(aN.responseXML).find("List").each(function(){aK=am(this).attr("WebFullUrl");aK=aK!==Q?aK+Q:aK})}});i=D(am(this).attr("List"),"NewForm");return false})}});if(aK.length===0&&aG.debug){X(aI,"lookupColumn: "+aG.lookupColumn,"This column does not appear to be a lookup column");return}if(i.length>0){var aJ=aK+i;aJ+=aG.newWindow?((aG.ContentTypeID.length>0)?"?ContentTypeID="+aG.ContentTypeID:"")+"' target='_blank'":"?"+((aG.ContentTypeID.length>0)?"ContentTypeID="+aG.ContentTypeID+"&":"")+"Source="+A(location.href)+"'";var aH="
"+""+aF+"";if(aG.CAMLQuery.length>0){i+=aG.CAMLQuery+""}i+="";am().SPServices({operation:"GetListItems",async:false,webURL:aG.webURL,listName:aG.listName,CAMLQuery:i,CAMLViewFields:"",CAMLRowLimit:1,CAMLQueryOptions:"",completefunc:function(aI){am(aI.responseXML).SPFilterNode("z:row").each(function(){aH=am(this).attr("ows_ID")})}});return aH};am.fn.SPServices.SPRequireUnique=function(aE){var aF=am.extend({},{columnStaticName:"Title",duplicateAction:0,ignoreCase:false,initMsg:"This value must be unique.",initMsgCSSClass:"ms-vb",errMsg:"This value is not unique.",errMsgCSSClass:"ms-formvalidation",showDupes:false,completefunc:null},aE);var aJ=am().SPServices.SPGetQueryString();var aK=aJ.ID;ae.thisList=am().SPServices.SPListNameFromUrl();var aI="{1}
";var aH=aI.replace(/\{0\}/g,aF.initMsgCSSClass).replace(/\{1\}/g,aF.initMsg);var aG=am().SPServices.SPGetDisplayFromStatic({listName:ae.thisList,columnStaticName:aF.columnStaticName});var i=am("input[Title='"+aG+"']");am(i).parent().append(aH);am(i).blur(function(){var aN=[];var aO=am(this).val();if(aO.length===0){return false}am().SPServices({operation:"GetListItems",async:false,listName:ae.thisList,CAMLQuery:"",CAMLViewFields:"",CAMLRowLimit:0,completefunc:function(aQ){var aP=aF.ignoreCase?aO.toUpperCase():aO;am(aQ.responseXML).SPFilterNode("z:row").each(function(){var aR=aF.ignoreCase?am(this).attr("ows_"+aF.columnStaticName).toUpperCase():am(this).attr("ows_"+aF.columnStaticName);if((aP===aR)&&(am(this).attr("ows_ID")!==aK)){aN.push([am(this).attr("ows_ID"),am(this).attr("ows_"+aF.columnStaticName)])}})}});var aM=aF.initMsg;am("span#SPRequireUnique"+aF.columnStaticName).html(aM).attr("class",aF.initMsgCSSClass);am("input[value='OK']:disabled, input[value='Save']:disabled").removeAttr("disabled");if(aN.length>0){aM=aF.errMsg;am("span#SPRequireUnique"+aF.columnStaticName).html(aM).attr("class",aF.errMsgCSSClass);if(aF.duplicateAction===1){am("input[Title='"+aF.columnDisplayName+"']").focus();am("input[value='OK'], input[value='Save']").attr("disabled","disabled")}if(aF.showDupes){var aL=" "+aN.length+" duplicate item"+(aN.length>1?"s":"")+": ";for(O=0;O"+aN[O][1]+"
"}am("span#SPRequireUnique"+aF.columnStaticName).append(aL)}}});if(aF.completefunc!==null){aF.completefunc()}};am.fn.SPServices.SPGetDisplayFromStatic=function(aE){var aF=am.extend({},{webURL:"",listName:"",columnStaticName:"",columnStaticNames:{}},aE);var i="";var aG={};var aH=aF.columnStaticNames.length>0?aF.columnStaticNames.length:1;am().SPServices({operation:"GetList",async:false,cacheXML:true,webURL:aF.webURL,listName:aF.listName,completefunc:function(aI){if(aH>1){for(O=0;O1)?aG:i};am.fn.SPServices.SPGetStaticFromDisplay=function(i){var aF=am.extend({},{webURL:"",listName:"",columnDisplayName:"",columnDisplayNames:{}},i);var aE="";var aG={};var aH=aF.columnDisplayNames.length>0?aF.columnDisplayNames.length:1;am().SPServices({operation:"GetList",async:false,cacheXML:true,webURL:aF.webURL,listName:aF.listName,completefunc:function(aI){if(aH>1){for(O=0;O1)?aG:aE};am.fn.SPServices.SPRedirectWithID=function(aF){var aG=am.extend({},{redirectUrl:"",qsParamName:"ID"},aF);ae.thisList=am().SPServices.SPListNameFromUrl();var aK=am().SPServices.SPGetQueryString();var aJ=aK.ID;var aI=aK.List;var aE=aK.RootFolder;var aH=aK.ContentTypeId;if(typeof aK.ID==="undefined"){aJ=am().SPServices.SPGetLastItemId({listName:ae.thisList});am("form[name='aspnetForm']").each(function(){var aM=(location.href.indexOf("?")>0)?location.href.substring(0,location.href.indexOf("?")):location.href;var aN=(typeof aK.Source==="string")?"Source="+aK.Source.replace(/\//g,"%2f").replace(/:/g,"%3a"):"";var aL=[];if(typeof aI!=="undefined"){aL.push("List="+aI)}if(typeof aE!=="undefined"){aL.push("RootFolder="+aE)}if(typeof aH!=="undefined"){aL.push("ContentTypeId="+aH)}var aO=aM+((aL.length>0)?("?"+aL.join("&")+"&"):"?")+"Source="+aM+"?ID="+aJ+((aN.length>0)?("%26RealSource="+aK.Source):"")+((typeof aK.RedirectURL==="string")?("%26RedirectURL="+aK.RedirectURL):"");am(this).attr("action",aO)})}else{while(aK.ID===aJ){aJ=am().SPServices.SPGetLastItemId({listName:ae.thisList})}var i=(typeof aK.RedirectURL==="string")?aK.RedirectURL:aG.redirectUrl;location.href=i+"?"+aG.qsParamName+"="+aJ+((typeof aK.RealSource==="string")?("&Source="+aK.RealSource):"")}};am.fn.SPServices.SPSetMultiSelectSizes=function(aL){var i=am.extend({},{multiSelectColumn:"",minWidth:0,maxWidth:0,debug:false},aL);var aI="SPServices.SPSetMultiSelectSizes";var aH=am().SPServices.SPDropdownCtl({displayName:i.multiSelectColumn});if(aH.Obj.html()===null&&i.debug){X(aI,"multiSelectColumn: "+i.multiSelectColumn,aj);return}if(aH.Type!==Y.multiSelect&&i.debug){X(aI,"multiSelectColumn: "+i.multiSelectColumn,"Column is not multi-select.");return}var aJ=af("SPSetMultiSelectSizes",i.multiSelectColumn);var aG=am("").appendTo(aH.container);aG.css({"width":"auto","height":0,"visibility":"hidden"});am(aH.master.candidateControl).find("option").each(function(){aG.append("")});am(aH.master.resultControl).find("option").each(function(){aG.append("")});var aE=aG.width()+5;var aK=aE;if(i.minWidth>0||i.maxWidth>0){if(aEi.maxWidth){aK=i.maxWidth}}var aF=aE;am(aH.master.candidateControl).css("width",aF+"px").parent().css("width",aK+"px");am(aH.master.resultControl).css("width",aF+"px").parent().css("width",aK+"px");aG.remove()};am.fn.SPServices.SPScriptAudit=function(aF){var aG=am.extend({},{webURL:"",listName:"",outputId:"",auditForms:true,auditViews:true,auditPages:true,auditPagesListName:"Pages",showHiddenLists:false,showNoScript:false,showSrc:true},aF);var aE=[["New","NewForm.aspx",false],["Display","DispForm.aspx",false],["Edit","EditForm.aspx",false]];var aH;am("#"+aG.outputId).append(""+""+""+""+""+""+""+(aG.showSrc?"":"")+""+"
ListPage ClassPage TypePageScript References
");am("#SPScriptAudit th").attr("class","ms-vh2-nofilter");if(aG.auditForms||aG.auditViews){am().SPServices({operation:"GetListCollection",webURL:aG.webURL,async:false,completefunc:function(aJ){am(aJ.responseXML).find("List").each(function(){aH=am(this);if((aG.listName.length===0)||(aH.attr("Title")===aG.listName)){if((aG.showHiddenLists&&aH.attr("Hidden")==="False")||!aG.showHiddenLists){if(aG.auditForms){am().SPServices({operation:"GetListContentTypes",webURL:aG.webURL,listName:aH.attr("ID"),async:false,completefunc:function(aK){am(aK.responseXML).find("ContentType").each(function(){if(am(this).attr("ID").substring(0,6)!=="0x0120"){var aM=am(this).find("FormUrls");for(O=0;O0)?aG.webURL:am().SPServices.SPGetCurrentSite())+Q+am(this).text());aE[O][2]=true});if(!aE[O][2]){var aL=aH.attr("DefaultViewUrl");aA(aG,aH,"Form",aE[O][0],aL.substring(0,aL.lastIndexOf(Q)+1)+aE[O][1])}}for(O=0;OFolder",CAMLViewFields:"",CAMLRowLimit:0,completefunc:function(aJ){am(aJ.responseXML).SPFilterNode("z:row").each(function(){var aM=am(this).attr("ows_FileRef").split(";#")[1];var aK=am(this).attr("ows_Title");var aL=(typeof aK!=="undefined")?aK:"";if(aM.indexOf(".aspx")>0){aA(aG,aH,"Page",aL,Q+aM)}})}})}}am("#SPScriptAudit tr[class='ms-alternating']:even").removeAttr("class")};function aA(aE,aF,aM,aI,aG){var aJ=0;var aL=0;var aH={};aH.type=[];aH.src=[];aH.script=[];var aK=RegExp("","gi");am.ajax({type:"GET",url:aG,dataType:"text",async:false,success:function(aS){var aR;while(aR=aK.exec(aS)){var aN=al(aR,"language");var aT=al(aR,"type");var aP=al(aR,"src");if(aP!==null&&aP.length>0&&!an(aP)){aH.type.push((aN!==null&&aN.length>0)?aN:aT);aH.src.push(aP);aL++}}if((!aE.showNoScript&&(aH.type.length>0))||aE.showNoScript){var aQ=aG.substring(0,aG.lastIndexOf(Q)+1);var aO=""+""+""+aF.attr("Title")+((aF.attr("Hidden")==="True")?"(Hidden)":"")+""+""+aM+""+""+aI+""+""+R(aG)+"";if(aE.showSrc){var i;aO+="";for(aJ=0;aJ";aO+=""}aO+="
"+aH.type[aJ]+""+R(aH.src[aJ])+"
"}am("#SPScriptAudit").append(aO)}}})}function al(aG,aE){var aF;var i=RegExp(aE+"=(\"([^\"]*)\")|('([^']*)')","gi");if(aF=i.exec(aG)){return aF[2]}return null}function an(aG){var aF;var aE=["WebResource.axd","_layouts"];for(aF=0;aF-1){return true}}return false}am.fn.SPServices.SPArrangeChoices=function(aF){var aG=am.extend({},{listName:am().SPServices.SPListNameFromUrl(),columnName:"",perRow:99,randomize:false},aF);var aI=false;var aH=[];var aE;var i=am().SPServices({operation:"GetList",async:false,cacheXML:true,listName:aG.listName});i.done(function(){am(i.responseXML).find("Field[DisplayName='"+aG.columnName+"']").each(function(){aI=(am(this).attr("FillInChoice")==="TRUE")?true:false;return false});var aN=z(aG.columnName);var aL=am(aN).find("tr").length;var aK=0;var aM;var aJ;am(aN).find("tr").each(function(){aK++;if(aI&&aK===(aL-1)){aM=am(this).find("td").html()}else{if(aI&&aK===aL){aJ=am(this).find("td").html()}else{aH.push(am(this).html())}}});aE="";if(aG.randomize){aH.sort(q)}for(O=0;O"}}aE+="";if(aI){aE+=""+aM+aJ+""}am(aN).find("tr").remove();am(aN).find("table").append(aE)})};am.fn.SPServices.SPAutocomplete=function(aF){var aG=am.extend({},{webURL:"",sourceList:"",sourceColumn:"",columnName:"",CAMLQuery:"",CAMLQueryOptions:"",CAMLRowLimit:0,filterType:"BeginsWith",numChars:0,ignoreCase:false,highlightClass:"",uniqueVals:false,maxHeight:99999,slideDownSpeed:"fast",processingIndicator:"_layouts/images/REFRESH.GIF",debug:false},aF);var aI;var aE=am("input[Title='"+aG.columnName+"']");aE.css("position","");var aH=aE.css("color");var aJ=aE.css("width");if(aE.html()===null&&aG.debug){X("SPServices.SPAutocomplete","columnName: "+aG.columnName,"Column is not an input control or is not found on page");return}aE.closest("span").find("br").remove();aE.wrap("
");var i=af("SPAutocomplete",aG.columnName);aE.after("
");am("#"+i).css("width",aJ);am(aE).keyup(function(){var aS=am(this).val();am("#"+i).hide();if(aS.length";if(aG.CAMLQuery.length>0){aK+=""}aK+="<"+aG.filterType+">"+aS+"";if(aG.CAMLQuery.length>0){aK+=aG.CAMLQuery+""}aK+="";am().SPServices({operation:"GetListItems",async:false,webURL:aG.WebURL,listName:aG.sourceList,CAMLQuery:aK,CAMLQueryOptions:aG.CAMLQueryOptions,CAMLViewFields:"",CAMLRowLimit:aG.CAMLRowLimit,completefunc:function(aV){var aU=aG.ignoreCase?aS.toUpperCase():aS;am(aV.responseXML).SPFilterNode("z:row").each(function(){var aX=am(this).attr("ows_"+aG.sourceColumn);var aY=aG.ignoreCase?am(this).attr("ows_"+aG.sourceColumn).toUpperCase():am(this).attr("ows_"+aG.sourceColumn);if(aG.filterType==="Contains"){var aW=aY.indexOf(aU);if((aW>=0)&&(!aG.uniqueVals||(am.inArray(aX,aR)===-1))){aR.push(am(this).attr("ows_"+aG.sourceColumn))}}else{if(aU===aY.substr(0,aU.length)&&(!aG.uniqueVals||(am.inArray(aX,aR)===-1))){aR.push(am(this).attr("ows_"+aG.sourceColumn))}}})}});var aN="";for(O=0;O0){var aM=new RegExp(aS,aG.ignoreCase?"gi":"g");var aP=aR[O].match(aM);var aO=0;for(aI=0;aI"+aP[aI]+"";aR[O]=aR[O].substr(0,aQ)+aT+aR[O].substr(aL);aO=aQ+aT.length}}aN+="
  • "+aR[O]+"
  • "}am("#"+i).html(aN);am("#"+i+" li").click(function(){am("#"+i).fadeOut(aG.slideUpSpeed);aE.val(am(this).text())}).mouseover(function(){var aU={"cursor":"hand","color":"#ffffff","background":"#3399ff"};am(this).css(aU)}).mouseout(function(){var aU={"cursor":"inherit","color":aH,"background":"transparent"};am(this).css(aU)});if(aR.length>0){am("#"+i).slideDown(aG.slideDownSpeed)}aE.css("background-image","")})};am.fn.SPServices.SPGetQueryString=function(aF){var aH=am.extend({},{lowercase:false},aF);var aK={};var aE=location.search.slice(1).split("&");for(var aG=0;aG0){ae.thisList=aE.listName;return ae.thisList}else{if(ae.thisList.length>0){return ae.thisList}}var aG=location.href;var aF=aG.substring(0,aG.indexOf(".aspx"));var aH=decodeURIComponent(aF.substring(0,aF.lastIndexOf(Q)+1)).toUpperCase();am().SPServices({operation:"GetListCollection",async:false,completefunc:function(aI){am(aI.responseXML).find("List").each(function(){var aJ=am(this).attr("DefaultViewUrl");var aK=aJ.substring(0,aJ.lastIndexOf(Q)+1).toUpperCase();if(aH.indexOf(aK)>0){ae.thisList=am(this).attr("ID");return false}})}});return ae.thisList};am.fn.SPServices.SPUpdateMultipleListItems=function(aG){var aI=am.extend({},{webURL:"",listName:"",CAMLQuery:"",batchCmd:"Update",valuepairs:[],completefunc:null,debug:false},aG);var aH;var aK=[];var aJ=[];am().SPServices({operation:"GetListItems",async:false,webURL:aI.webURL,listName:aI.listName,CAMLQuery:aI.CAMLQuery,CAMLQueryOptions:"",completefunc:function(i){am(i.responseXML).SPFilterNode("z:row").each(function(){aK.push(am(this).attr("ows_ID"));var aL=am(this).attr("ows_FileRef");aL="/"+aL.substring(aL.indexOf(";#")+2);aJ.push(aL)})}});var aE;var aF="";for(aH=0;aH";for(aE=0;aE"+L(aI.valuepairs[aE][1])+""}aF+=""+aK[aH]+"";if(aJ[aH].length>0){aF+=""+aJ[aH]+""}aF+=""}aF+="";am().SPServices({operation:"UpdateListItems",async:false,webURL:aI.webURL,listName:aI.listName,updates:aF,completefunc:function(i){if(aI.completefunc!==null){aI.completefunc(i)}}})};am.fn.SPServices.SPGetListItemsJson=function(aG){var aH=am.extend({},{webURL:"",listName:"",CAMLViewName:"",CAMLQuery:"",CAMLViewFields:"",CAMLRowLimit:"",CAMLQueryOptions:"",changeToken:"",contains:"",mapping:null,mappingOverrides:null,debug:false},aG);var aF;var aE={};var aJ=[];var i=am.Deferred();var aI=am().SPServices({operation:"GetListItemChangesSinceToken",webURL:aH.webURL,listName:aH.listName,CAMLViewName:aH.CAMLViewName,CAMLQuery:aH.CAMLQuery,CAMLViewFields:aH.CAMLViewFields,CAMLRowLimit:aH.CAMLRowLimit,CAMLQueryOptions:aH.CAMLQueryOptions,changeToken:aH.changeToken,contains:aH.contains});aI.done(function(){var aM="SPGetListItemsJson"+aH.webURL+aH.listName;var aN=am(aI.responseXML);aF=aN.find("Changes").attr("LastChangeToken");aN.find("listitems Changes Id[ChangeType='Delete']").each(function(){aJ.push(am(this).text())});if(aH.mapping===null){aN.find("List > Fields > Field").each(function(){var aP=am(this);var aQ=aP.attr("Type");if(am.inArray(aQ,ap)>=0){aE["ows_"+aP.attr("Name")]={mappedName:aP.attr("Name"),objectType:aP.attr("Type")}}})}else{aE=aH.mapping}if(aH.mappingOverrides!==null){for(var aK in aH.mappingOverrides){aE[aK]=aH.mappingOverrides[aK]}}if(am.isEmptyObject(aE)){aE=am(document).data(aM)}else{am(document).data(aM,aE)}var aL=aN.SPFilterNode("z:row").SPXmlToJson({mapping:aE,sparse:true});var aO={changeToken:aF,mapping:aE,data:aL,deletedIds:aJ};i.resolveWith(aO)});return i.promise()};am.fn.SPServices.SPConvertDateToISO=function(i){var aE=am.extend({},{dateToConvert:new Date(),dateOffset:"-05:00"},i);var aF="";var aG=aE.dateToConvert;aF+=aG.getFullYear()+"-";aF+=u(aG.getMonth()+1)+"-";aF+=u(aG.getDate());aF+="T"+u(aG.getHours())+":";aF+=u(aG.getMinutes())+":";aF+=u(aG.getSeconds())+"Z"+aE.dateOffset;return aF};am.fn.SPFilterNode=function(i){return this.find("*").filter(function(){return this.nodeName===i})};am.fn.SPXmlToJson=function(i){var aF=am.extend({},{mapping:{},includeAllAttrs:false,removeOws:true,sparse:false},i);var aG;var aE=[];this.each(function(){var aK={};var aM=this.attributes;if(!aF.sparse){am.each(aF.mapping,function(){aK[this.mappedName]=""})}for(aG=0;aG0){aE.html(aG.valueToSet)}if(aG.checkNames){i.click()}var aI=am.trim(aE.text());var aH=[];aE.children("span").each(function(){var aM=am(this).find("div[data]").attr("data");var aK={};if(typeof aM!=="undefined"){var aN=am.parseXML(aM);var aL=am(aN);aL.find("DictionaryEntry").each(function(){var aO=am(this).find("Key").text();var aP=am(this).find("Value").text();aK[aO]=aP});aH.push(aK)}else{am().SPServices({operation:"GetUserInfo",async:false,cacheXML:true,userLoginName:am(this).attr("title"),completefunc:function(aO){am(aO.responseXML).find("User").each(function(){am.each(this.attributes,function(aQ,aS){var aP=aS.name;var aR=aS.value;aK[aP]=aR});aH.push(aK)})}})}});return{row:aJ,contents:aE,currentValue:aI,checkNames:i,dictionaryEntries:aH}};am.fn.SPServices.Version=function(){return ab};am.fn.SPServices.SPDropdownCtl=function(aG){var aH=am.extend({},{displayName:""},aG);var aF={};var aJ=am().SPServices.SPGetStaticFromDisplay({listName:am().SPServices.SPListNameFromUrl(),columnDisplayName:aH.displayName});if((aF.Obj=am("select[Title='"+aH.displayName+"']")).length===1){aF.Type=Y.simple}else{if((aF.Obj=am("input[Title='"+aH.displayName+"']")).length===1){aF.Type=Y.complex}else{if((aF.Obj=am("select:regex(id, ("+aJ+")(_)[0-9a-fA-F]{8}(-))")).length===1){aF.Type=Y.simple}else{if((aF.Obj=am("select[ID$='SelectCandidate'][Title^='"+aH.displayName+" ']")).length===1){aF.Type=Y.multiSelect}else{if((aF.Obj=am("select[ID$='SelectCandidate'][Title$=': "+aH.displayName+"']")).length===1){aF.Type=Y.multiSelect}else{if((aF.Obj=am("select[ID$='SelectCandidate'][Title$='\""+aH.displayName+"\".']")).length===1){aF.Type=Y.multiSelect}else{if((aF.Obj=am("select[ID$='SelectCandidate'][Title$=' "+aH.displayName+"']")).length===1){aF.Type=Y.multiSelect}else{aF.Type=null}}}}}}}if(aF.Type===null){var aI=z(aH.displayName);if(aI!==undefined){var aE=aI.find("select[title^='"+aH.displayName+"'][id$='$Lookup']");if(aE&&aE.length===1){aF.Type=Y.simple;aF.Obj=aE}}}if(aF.Type===Y.complex){aF.optHid=am("input[id='"+aF.Obj.attr("optHid")+"']")}else{if(aF.Type===Y.multiSelect){aF.container=aF.Obj.closest("span");aF.MultiLookupPickerdata=aF.container.find("input[id$='"+aq+"_data'], input[id$='"+g+"_data']");var i=aF.container.find("[id$='AddButton']").attr("id");aF.master=window[i.replace(/AddButton/,aq+"_m")]||window[i.replace(/AddButton/,g+"_m")]}}return aF};function at(){if(typeof _spPageContextInfo!=="undefined"){this.thisSite=_spPageContextInfo.webServerRelativeUrl;this.thisList=_spPageContextInfo.pageListId;this.thisUserId=_spPageContextInfo.userId}else{this.thisSite=(typeof L_Menu_BaseUrl!=="undefined")?L_Menu_BaseUrl:"";this.thisList="";this.thisUserId=(typeof _spUserId!=="undefined")?_spUserId:undefined}}function W(aP,aL,aQ,aG){if(typeof aQ==="undefined"){return""}var aM;var aN="";var aK;var aI;var aO=[];var aH=aG.relatedWebURL.length>0?aG.relatedWebURL:am().SPServices.SPGetCurrentSite();switch(aL.attr("Type")){case"Text":aN=aQ;break;case"URL":switch(aL.attr("Format")){case"Hyperlink":aN="
    "+aQ.substring(aQ.search(",")+1)+"";break;case"Image":aN=""+aQ.substring(aQ.search(",")+1)+"";break;default:aN=aQ;break}break;case"User":case"UserMulti":var aE=aQ.split(";#");for(aM=0;aM"+aE[aM+1]+"")}aN=aO.join(", ");break;case"Calculated":var aJ=aQ.split(";#");aN=aJ[1];break;case"Number":aI=aL.attr("Decimals");aN=typeof aI==="undefined"?parseFloat(aQ).toString():parseFloat(aQ).toFixed(aI).toString();break;case"Currency":aI=aL.attr("Decimals");aN=typeof aI==="undefined"?parseFloat(aQ).toFixed(2).toString():parseFloat(aQ).toFixed(aI).toString();break;case"Lookup":switch(aL.attr("Name")){case"FileRef":aK=aP.attr("BaseType")==="1"?aP.attr("RootFolder")+Q+"Forms/DispForm.aspx":aP.attr("RootFolder")+Q+"DispForm.aspx";aN=""+aQ.substring(aQ.search(";#")+2)+"";break;case"FileDirRef":aK=Q+aQ.substring(aQ.search(";#")+2);aN=""+aQ.substring(aQ.search(";#")+2)+"";break;default:aK=D(aL.attr("List"),"DisplayForm");aN=""+aQ.substring(aQ.search(";#")+2)+"";break}break;case"LookupMulti":aK=D(aL.attr("List"),"DisplayForm");aN="";if(aQ.length>0){var aF=aQ.split(";#");for(aM=0;aM"+aF[(aM*2)+1]+"")}}aN=aO.join(", ");break;case"File":R=aQ.substring(aQ.search(";#")+2);aN=""+R+"";break;case"Counter":aN=aQ;break;case"DateTime":aN=aQ;break;default:aN=aQ;break}return aN}function t(aG){var aF;var aE="";for(aF=0;aF"}aE+="
    "+aF+""+aG.attributes.item(aF).nodeName+""+N(aG.attributes.item(aF).nodeValue)+"
    ";return aE}function c(aF,aE){var i=[];switch(aF.Type){case Y.simple:if(aE){i.push(aF.Obj.find("option:selected").val()||[])}else{i.push(aF.Obj.find("option:selected").text()||[])}break;case Y.complex:if(aE){i.push(aF.optHid.val()||[])}else{i.push(aF.Obj.val()||[])}break;case Y.multiSelect:am(aF.master.resultControl).find("option").each(function(){if(aE){i.push(am(this).val())}else{i.push(am(this).html())}});break;default:break}return i}function X(aE,aG,aF){var i="Error in function
    "+aE+"
    "+"Parameter
    "+aG+"
    "+"Message
    "+aF+"

    "+"Click to continue
    ";V(i)}function V(aI){var aF="position:absolute;width:300px;height:150px;padding:10px;background-color:#000000;color:#ffffff;z-index:30;font-family:'Arial';font-size:12px;display:none;";am("#aspnetForm").parent().append("
    "+aI);var i=am("#SPServices_msgBox").height();var aH=am("#SPServices_msgBox").width();var aG=(am(window).width()/2)-(aH/2)+"px";var aE=(am(window).height()/2)-(i/2)-100+"px";am("#SPServices_msgBox").css({border:"5px #C02000 solid",left:aG,top:aE}).show().fadeTo("slow",0.75).click(function(){am(this).fadeOut("3000",function(){am(this).remove()})})}function af(i,aE){return i+"_"+am().SPServices.SPGetStaticFromDisplay({listName:am().SPServices.SPListNameFromUrl(),columnDisplayName:aE})}function D(i,aF){var aE;am().SPServices({operation:"GetFormCollection",async:false,listName:i,completefunc:function(aG){aE=am(aG.responseXML).find("Form[Type='"+aF+"']").attr("Url")}});return aE}function av(aG,aE){var aF;for(aF=0;aF"+i+""}function q(){return(Math.round(Math.random())-0.5)}function N(i){return((i.indexOf("http")===0)||(i.indexOf(Q)===0))?""+i+"":i}function R(i){return i.substring(i.lastIndexOf(Q)+1,i.length)}var Z={"&":"&",'"':""","<":"<",">":">"};var H={"&":"&",""":'"',"<":"<",">":">"};function j(i){return i.replace(/([\&"<>])/g,function(aF,aE){return Z[aE]})}function I(i){return i.replace(/("|<|>|&)/g,function(aF,aE){return H[aE]})}function L(i){if(typeof i==="string"){return i.replace(/&(?![a-zA-Z]{1,8};)/g,"&")}else{return i}}function A(i){return i.replace(/&/g,"%26")}function n(i){var aE=i.split(";#");this.id=aE[0];this.value=aE[1]}function u(i){return i<10?"0"+i:i}am.expr[":"].regex=function(aJ,aG,aF){var aK=aF[3].split(","),aE=/^(data|css):/,i={method:aK[0].match(aE)?aK[0].split(":")[0]:"attr",property:aK.shift().replace(aE,"")},aI="ig",aH=new RegExp(aK.join("").replace(/^\s+|\s+$/g,""),aI);return aH.test(jQuery(aJ)[i.method](i.property))}})(jQuery); diff --git a/ajax/libs/jquery.SPServices/package.json b/ajax/libs/jquery.SPServices/package.json index b7132574b..58bde7888 100755 --- a/ajax/libs/jquery.SPServices/package.json +++ b/ajax/libs/jquery.SPServices/package.json @@ -1,7 +1,7 @@ { "name": "jquery.SPServices", "filename": "jquery.SPServices.min.js", - "version": "2013.02a", + "version": "2014.01", "description": "SPServices is a jQuery library which abstracts SharePoint's Web Services and makes them easier to use. It also includes functions which use the various Web Service operations to provide more useful (and cool) capabilities. It works entirely client side and requires no server install.", "homepage": "http://spservices.codeplex.com/", "keywords": [ diff --git a/ajax/libs/postscribe/1.1.2/postscribe.min.js b/ajax/libs/postscribe/1.1.2/postscribe.min.js new file mode 100644 index 000000000..73210e1ba --- /dev/null +++ b/ajax/libs/postscribe/1.1.2/postscribe.min.js @@ -0,0 +1,3 @@ +/* Asynchronously write javascript, even with document.write., v1.1.2 https://github.com/krux/postscribe +Copyright (c) 2013 Derek Brans, MIT license https://github.com/krux/postscribe/blob/master/LICENSE */ +(function(){function o(o,u){o=o||"",u=u||{};for(var a in e)e.hasOwnProperty(a)&&(u.autoFix&&(u["fix_"+a]=!0),u.fix=u.fix||u["fix_"+a]);var f=[],l=function(e){o+=e},c=function(e){o=e+o},h={comment:/^");if(e>=0)return{content:o.substr(4,e),length:e+3}},endTag:function(){var e=o.match(n);if(e)return{tagName:e[1],length:e[0].length}},atomicTag:function(){var e=p.startTag();if(e){var t=o.slice(e.length);if(t.match(new RegExp("","i"))){var n=t.match(new RegExp("([\\s\\S]*?)","i"));if(n)return{tagName:e.tagName,attrs:e.attrs,content:n[1],length:n[0].length+e.length}}}},startTag:function(){var e=o.match(t);if(e){var n={};return e[2].replace(r,function(e,t){var r=arguments[2]||arguments[3]||arguments[4]||i.test(t)&&t||null;n[t]=r}),{tagName:e[1],attrs:n,unary:!!e[3],length:e[0].length}}},chars:function(){var e=o.indexOf("<");return{length:e>=0?e:o.length}}},d=function(){for(var e in h)if(h[e].test(o)){s&&console.log("suspected "+e);var t=p[e]();return t?(s&&console.log("parsed "+e,t),t.type=t.type||e,t.text=o.substr(0,t.length),o=o.slice(t.length),t):null}},v=function(e){var t;while(t=d())if(e[t.type]&&e[t.type](t)===!1)return},m=function(){var e=o;return o="",e},g=function(){return o};return u.fix&&function(){var e=/^(AREA|BASE|BASEFONT|BR|COL|FRAME|HR|IMG|INPUT|ISINDEX|LINK|META|PARAM|EMBED)$/i,t=/^(COLGROUP|DD|DT|LI|OPTIONS|P|TD|TFOOT|TH|THEAD|TR)$/i,n=[];n.last=function(){return this[this.length-1]},n.lastTagNameEq=function(e){var t=this.last();return t&&t.tagName&&t.tagName.toUpperCase()===e.toUpperCase()},n.containsTagName=function(e){for(var t=0,n;n=this[t];t++)if(n.tagName===e)return!0;return!1};var r=function(t){return t&&t.type==="startTag"&&(t.unary=e.test(t.tagName)||t.unary),t},i=d,s=function(){var e=o,t=r(i());return o=e,t},a=function(){var e=n.pop();c("")},f={startTag:function(e){var r=e.tagName;r.toUpperCase()==="TR"&&n.lastTagNameEq("TABLE")?(c(""),h()):u.fix_selfClose&&t.test(r)&&n.containsTagName(r)?n.lastTagNameEq(r)?a():(c(""),h()):e.unary||n.push(e)},endTag:function(e){var t=n.last();t?u.fix_tagSoup&&!n.lastTagNameEq(e.tagName)?a():n.pop():u.fix_tagSoup&&l()}},l=function(){i(),h()},h=function(){var e=s();e&&f[e.type]&&f[e.type](e)};d=function(){return h(),r(i())}}(),{append:l,readToken:d,readTokens:v,clear:m,rest:g,stack:f}}var e=function(){var e={},t,n=this.document.createElement("div");return t="

    ",n.innerHTML=t,e.tagSoup=n.innerHTML!==t,n.innerHTML="

    ",e.selfClose=n.childNodes.length===2,e}(),t=/^<([\-A-Za-z0-9_]+)((?:\s+[\w\-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/,n=/^<\/([\-A-Za-z0-9_]+)[^>]*>/,r=/([\-A-Za-z0-9_]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g,i=/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noresize|noshade|nowrap|readonly|selected)$/i,s=!1;o.supports=e,o.tokenToString=function(e){var t={comment:function(e){return"<--"+e.content+"-->"},endTag:function(e){return""},atomicTag:function(e){return console.log(e),t.startTag(e)+e.content+t.endTag(e)},startTag:function(e){var t="<"+e.tagName;for(var n in e.attrs){var r=e.attrs[n];t+=" "+n+'="'+(r?r.replace(/(^|[^\\])"/g,'$1\\"'):"")+'"'}return t+(e.unary?"/>":">")},chars:function(e){return e.text}};return t[e.type](e)},o.escapeAttributes=function(e){var t={};for(var n in e){var r=e[n];t[n]=r&&r.replace(/(^|[^\\])"/g,'$1\\"')}return t};for(var u in e)o.browserHasFlaw=o.browserHasFlaw||!e[u]&&u;this.htmlParser=o})(),function(){function i(){}function s(e){return"function"==typeof e}function o(e,t,n){var r,i=e&&e.length||0;for(r=0;r)/," "+t+"id="+o+" $1")),e.attrs.id!=="ps-script"&&s.push(e.type==="atomicTag"?"":"<"+e.tagName+" "+t+"proxyof="+o+(e.unary?"/>":">"))}}else i.push(e.text),s.push(e.type==="endTag"?e.text:"")}),{tokens:e,raw:r.join(""),actual:i.join(""),proxy:s.join("")}},i.prototype.walkChunk=function(){var e,t=[this.proxyRoot];while((e=t.shift())!=null){var n=e.nodeType===1,i=n&&r(e,"proxyof");if(!i){n&&(this.actuals[r(e,"id")]=e,r(e,"id",null));var s=e.parentNode&&r(e.parentNode,"proxyof");s&&this.actuals[s].appendChild(e)}t.unshift.apply(t,l(e.childNodes))}},i.prototype.handleScriptToken=function(e){var t=this.parser.clear();t&&this.writeQueue.unshift(t),e.src=e.attrs.src||e.attrs.SRC,e.src&&this.scriptStack.length?this.deferredRemote=e:this.onScriptStart(e);var n=this;this.writeScriptToken(e,function(){n.onScriptDone(e)})},i.prototype.onScriptStart=function(e){e.outerWrites=this.writeQueue,this.writeQueue=[],this.scriptStack.unshift(e)},i.prototype.onScriptDone=function(e){if(e!==this.scriptStack[0]){this.options.error({message:"Bad script nesting or script finished twice"});return}this.scriptStack.shift(),this.write.apply(this,e.outerWrites),!this.scriptStack.length&&this.deferredRemote&&(this.onScriptStart(this.deferredRemote),this.deferredRemote=null)},i.prototype.writeScriptToken=function(e,t){var n=this.buildScript(e);e.src&&(n.src=e.src,this.scriptLoadHandler(n,t));try{this.insertScript(n),e.src||t()}catch(r){this.options.error(r),t()}},i.prototype.buildScript=function(e){var t=this.doc.createElement(e.tagName);return u(e.attrs,function(e,n){t.setAttribute(e,n)}),e.content&&(t.text=e.content),t},i.prototype.insertScript=function(e){this.writeImpl('');var t=this.doc.getElementById("ps-script");t.parentNode.replaceChild(e,t)},i.prototype.scriptLoadHandler=function(e,t){function n(){e=e.onload=e.onreadystatechange=e.onerror=null,t()}var r=this.options.error;a(e,{onload:function(){n()},onreadystatechange:function(){/^(loaded|complete)$/.test(e.readyState)&&n()},onerror:function(){r({message:"remote script failed "+e.src}),n()}})},i}(),p=function(){function o(){var e=n.shift();e&&(e.stream=u.apply(null,e))}function u(e,n,s){function c(e){e=s.beforeWrite(e),r.write(e),s.afterWrite(e)}r=new h(e,s),r.id=t++,r.name=s.name||r.id,l.streams[r.name]=r;var u=e.ownerDocument,f={write:u.write,writeln:u.writeln};a(u,{write:c,writeln:function(e){c(e+"\n")}});var p=r.win.onerror||i;return r.win.onerror=function(e,t,n){s.error({msg:e+" - "+t+":"+n}),p.apply(r.win,arguments)},r.write(n,function(){a(u,f),r.win.onerror=p,s.done(),r=null,o()}),r}function l(t,u,a){s(a)&&(a={done:a}),a=f(a,{done:i,error:function(e){throw e},beforeWrite:function(e){return e},afterWrite:i}),t=/^#/.test(t)?e.document.getElementById(t.substr(1)):t.jquery?t[0]:t;var l=[t,u,a];return t.postscribe={cancel:function(){l.stream?l.stream.abort():l[1]=i}},n.push(l),r||o(),t.postscribe}var t=0,n=[],r=null;return a(l,{streams:{},queue:n,WriteStream:h})}();e.postscribe=p}(); \ No newline at end of file diff --git a/ajax/libs/postscribe/package.json b/ajax/libs/postscribe/package.json new file mode 100644 index 000000000..dcdf26345 --- /dev/null +++ b/ajax/libs/postscribe/package.json @@ -0,0 +1,59 @@ +{ + "name": "postscribe", + "filename": "postscribe.min.js", + "description": "Asynchronously write javascript, even with document.write.", + "version": "1.1.2", + "keywords": ["document.write", "tag writer", "asynchronous", "javascript", "after load"], + "author": { + "name": "Derek Brans", + "email": "dbrans@gmail.com", + "web": "http://github.com/dbrans" + }, + "contributors": [{ + "name": "Derek Brans", + "email": "dbrans@gmail.com", + "web": "http://github.com/dbrans" + }, { + "name": "Nick Sullivan", + "email": "nick@sullivanflock.com", + "web": "http://creationeer.me" + },{ + "name": "Joshua Newman", + "email": "joshua.newman@krux.com" + }], + "maintainers": [{ + "name": "Joshua Newman", + "email": "joshua.newman@krux.com" + }], + "bugs": "https://github.com/krux/postscribe/issues", + "licenses": [{ + "type": "MIT", + "url": "https://github.com/krux/postscribe/blob/master/LICENSE" + }], + "repository": { + "type": "git", + "url": "git@github.com:krux/postscribe.git" + }, + "dependencies": {}, + "devDependencies": { + "grunt": ">=0.4", + "phantomjs": "~1.9", + "grunt-cli": "~0.1", + "grunt-contrib-concat": "~0.3", + "grunt-contrib-jshint": "~0.7", + "grunt-contrib-qunit": "~0.3", + "grunt-contrib-uglify": "~0.2", + "grunt-contrib-watch": "~0.5", + "lodash": "~2.4", + "testem": "~0.5" + }, + "homepage": "https://krux.github.com/postscribe", + "engines": { + "node": ">=0.8" + }, + "scripts": { + "lint": "grunt jshint", + "tdd": "grunt watch", + "test": "grunt" + } +} diff --git a/ajax/libs/reactive-coffee/1.1.1/reactive-coffee.js b/ajax/libs/reactive-coffee/1.1.1/reactive-coffee.js new file mode 100644 index 000000000..ec5c5a471 --- /dev/null +++ b/ajax/libs/reactive-coffee/1.1.1/reactive-coffee.js @@ -0,0 +1,1750 @@ +(function() { + var rxFactory, + __slice = [].slice, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + rxFactory = function(_, _str, $) { + var DepArray, DepCell, DepMap, DepMgr, Ev, FakeObsCell, FakeSrcCell, IndexedArray, IndexedDepArray, IndexedMappedDepArray, MappedDepArray, ObsArray, ObsCell, ObsMap, ObsMapEntryCell, RawHtml, Recorder, SrcArray, SrcCell, SrcMap, SrcMapEntryCell, asyncBind, bind, depMgr, ev, events, firstWhere, flatten, lagBind, mkAtts, mkMap, mktag, mkuid, nextUid, nthWhere, permToSplices, popKey, postLagBind, prop, propSet, props, recorder, rx, rxt, setDynProp, setProp, specialAttrs, sum, tag, tags, _fn, _i, _len, _ref, _ref1, _ref2, _ref3, _ref4, + _this = this; + + rx = {}; + nextUid = 0; + mkuid = function() { + return nextUid += 1; + }; + popKey = function(x, k) { + var v; + + if (!(k in x)) { + throw new Error('object has no key ' + k); + } + v = x[k]; + delete x[k]; + return v; + }; + nthWhere = function(xs, n, f) { + var i, x, _i, _len; + + for (i = _i = 0, _len = xs.length; _i < _len; i = ++_i) { + x = xs[i]; + if (f(x) && (n -= 1) < 0) { + return [x, i]; + } + } + return [null, -1]; + }; + firstWhere = function(xs, f) { + return nthWhere(xs, 0, f); + }; + mkMap = function(xs) { + var k, map, v, _i, _len, _ref; + + if (xs == null) { + xs = []; + } + map = Object.create != null ? Object.create(null) : {}; + if (_.isArray(xs)) { + for (_i = 0, _len = xs.length; _i < _len; _i++) { + _ref = xs[_i], k = _ref[0], v = _ref[1]; + map[k] = v; + } + } else { + for (k in xs) { + v = xs[k]; + map[k] = v; + } + } + return map; + }; + sum = function(xs) { + var n, x, _i, _len; + + n = 0; + for (_i = 0, _len = xs.length; _i < _len; _i++) { + x = xs[_i]; + n += x; + } + return n; + }; + DepMgr = rx.DepMgr = (function() { + function DepMgr() { + this.uid2src = {}; + this.buffering = 0; + this.buffer = []; + } + + DepMgr.prototype.sub = function(uid, src) { + return this.uid2src[uid] = src; + }; + + DepMgr.prototype.unsub = function(uid) { + return popKey(this.uid2src, uid); + }; + + DepMgr.prototype.transaction = function(f) { + var b, res, _i, _len, _ref; + + this.buffering += 1; + try { + res = f(); + } finally { + this.buffering -= 1; + if (this.buffering === 0) { + _ref = this.buffer; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + b = _ref[_i]; + b(); + } + this.buffer = []; + } + } + return res; + }; + + return DepMgr; + + })(); + rx._depMgr = depMgr = new DepMgr(); + Ev = rx.Ev = (function() { + function Ev(inits) { + this.inits = inits; + this.subs = mkMap(); + } + + Ev.prototype.sub = function(listener) { + var init, uid, _i, _len, _ref; + + uid = mkuid(); + if (this.inits != null) { + _ref = this.inits(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + init = _ref[_i]; + listener(init); + } + } + this.subs[uid] = listener; + depMgr.sub(uid, this); + return uid; + }; + + Ev.prototype.pub = function(data) { + var listener, uid, _ref, _results, + _this = this; + + if (depMgr.buffering) { + return depMgr.buffer.push(function() { + return _this.pub(data); + }); + } else { + _ref = this.subs; + _results = []; + for (uid in _ref) { + listener = _ref[uid]; + _results.push(listener(data)); + } + return _results; + } + }; + + Ev.prototype.unsub = function(uid) { + popKey(this.subs, uid); + return depMgr.unsub(uid, this); + }; + + Ev.prototype.scoped = function(listener, context) { + var uid; + + uid = this.sub(listener); + try { + return context(); + } finally { + this.unsub(uid); + } + }; + + return Ev; + + })(); + rx.skipFirst = function(f) { + var first; + + first = true; + return function() { + var args; + + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (first) { + return first = false; + } else { + return f.apply(null, args); + } + }; + }; + Recorder = rx.Recorder = (function() { + function Recorder() { + this.stack = []; + this.isMutating = false; + this.isIgnoring = false; + this.onMutationWarning = new Ev(); + } + + Recorder.prototype.record = function(dep, f) { + var wasIgnoring, wasMutating; + + if (this.stack.length > 0 && !this.isMutating) { + _(this.stack).last().addNestedBind(dep); + } + this.stack.push(dep); + wasMutating = this.isMutating; + this.isMutating = false; + wasIgnoring = this.isIgnoring; + this.isIgnoring = false; + try { + return f(); + } finally { + this.isIgnoring = wasIgnoring; + this.isMutating = wasMutating; + this.stack.pop(); + } + }; + + Recorder.prototype.sub = function(sub) { + var handle, topCell; + + if (this.stack.length > 0 && !this.isIgnoring) { + topCell = _(this.stack).last(); + return handle = sub(topCell); + } + }; + + Recorder.prototype.addCleanup = function(cleanup) { + if (this.stack.length > 0) { + return _(this.stack).last().addCleanup(cleanup); + } + }; + + Recorder.prototype.mutating = function(f) { + var wasMutating; + + if (this.stack.length > 0) { + console.warn('Mutation to observable detected during a bind context'); + this.onMutationWarning.pub(null); + } + wasMutating = this.isMutating; + this.isMutating = true; + try { + return f(); + } finally { + this.isMutating = wasMutating; + } + }; + + Recorder.prototype.ignoring = function(f) { + var wasIgnoring; + + wasIgnoring = this.isIgnoring; + this.isIgnoring = true; + try { + return f(); + } finally { + this.isIgnoring = wasIgnoring; + } + }; + + return Recorder; + + })(); + rx._recorder = recorder = new Recorder(); + rx.asyncBind = asyncBind = function(init, f) { + var dep; + + dep = new DepCell(f, init); + dep.refresh(); + return dep; + }; + rx.bind = bind = function(f) { + return asyncBind(null, function() { + return this.done(this.record(f)); + }); + }; + rx.lagBind = lagBind = function(lag, init, f) { + var timeout; + + timeout = null; + return asyncBind(init, function() { + var _this = this; + + if (timeout != null) { + clearTimeout(timeout); + } + return timeout = setTimeout(function() { + return _this.done(_this.record(f)); + }, lag); + }); + }; + rx.postLagBind = postLagBind = function(init, f) { + var timeout; + + timeout = null; + return asyncBind(init, function() { + var ms, val, _ref, + _this = this; + + _ref = this.record(f), val = _ref.val, ms = _ref.ms; + if (timeout != null) { + clearTimeout(timeout); + } + return timeout = setTimeout((function() { + return _this.done(val); + }), ms); + }); + }; + rx.snap = function(f) { + return recorder.ignoring(f); + }; + rx.onDispose = function(cleanup) { + return recorder.addCleanup(cleanup); + }; + rx.autoSub = function(ev, listener) { + var subid; + + subid = ev.sub(listener); + rx.onDispose(function() { + return ev.unsub(subid); + }); + return subid; + }; + ObsCell = rx.ObsCell = (function() { + function ObsCell(x) { + var _ref, + _this = this; + + this.x = x; + this.x = (_ref = this.x) != null ? _ref : null; + this.onSet = new Ev(function() { + return [[null, _this.x]]; + }); + } + + ObsCell.prototype.get = function() { + var _this = this; + + recorder.sub(function(target) { + return rx.autoSub(_this.onSet, function() { + return target.refresh(); + }); + }); + return this.x; + }; + + return ObsCell; + + })(); + SrcCell = rx.SrcCell = (function(_super) { + __extends(SrcCell, _super); + + function SrcCell() { + _ref = SrcCell.__super__.constructor.apply(this, arguments); + return _ref; + } + + SrcCell.prototype.set = function(x) { + var _this = this; + + return recorder.mutating(function() { + var old; + + if (_this.x !== x) { + old = _this.x; + _this.x = x; + _this.onSet.pub([old, x]); + return old; + } + }); + }; + + return SrcCell; + + })(ObsCell); + DepCell = rx.DepCell = (function(_super) { + __extends(DepCell, _super); + + function DepCell(body, init) { + this.body = body; + DepCell.__super__.constructor.call(this, init != null ? init : null); + this.refreshing = false; + this.nestedBinds = []; + this.cleanups = []; + } + + DepCell.prototype.refresh = function() { + var env, isSynchronous, old, realDone, syncResult, + _this = this; + + if (!this.refreshing) { + old = this.x; + realDone = function(x) { + _this.x = x; + return _this.onSet.pub([old, _this.x]); + }; + ({ + recorded: false + }); + syncResult = null; + isSynchronous = false; + env = { + record: function(f) { + var recorded, res; + + if (!_this.refreshing) { + _this.disconnect(); + if (recorded) { + throw new Error('this refresh has already recorded its dependencies'); + } + _this.refreshing = true; + recorded = true; + try { + res = recorder.record(_this, function() { + return f.call(env); + }); + } finally { + _this.refreshing = false; + } + if (isSynchronous) { + realDone(syncResult); + } + return res; + } + }, + done: function(x) { + if (old !== x) { + if (_this.refreshing) { + isSynchronous = true; + return syncResult = x; + } else { + return realDone(x); + } + } + } + }; + return this.body.call(env); + } + }; + + DepCell.prototype.disconnect = function() { + var cleanup, nestedBind, _i, _j, _len, _len1, _ref1, _ref2; + + _ref1 = this.cleanups; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + cleanup = _ref1[_i]; + cleanup(); + } + _ref2 = this.nestedBinds; + for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { + nestedBind = _ref2[_j]; + nestedBind.disconnect(); + } + this.nestedBinds = []; + return this.cleanups = []; + }; + + DepCell.prototype.addNestedBind = function(nestedBind) { + return this.nestedBinds.push(nestedBind); + }; + + DepCell.prototype.addCleanup = function(cleanup) { + return this.cleanups.push(cleanup); + }; + + return DepCell; + + })(ObsCell); + ObsArray = rx.ObsArray = (function() { + function ObsArray(xs, diff) { + var _this = this; + + this.xs = xs != null ? xs : []; + this.diff = diff != null ? diff : rx.basicDiff(); + this.onChange = new Ev(function() { + return [[0, [], _this.xs]]; + }); + this.indexed_ = null; + } + + ObsArray.prototype.all = function() { + var _this = this; + + recorder.sub(function(target) { + return rx.autoSub(_this.onChange, function() { + return target.refresh(); + }); + }); + return _.clone(this.xs); + }; + + ObsArray.prototype.raw = function() { + var _this = this; + + recorder.sub(function(target) { + return rx.autoSub(_this.onChange, function() { + return target.refresh(); + }); + }); + return this.xs; + }; + + ObsArray.prototype.at = function(i) { + var _this = this; + + recorder.sub(function(target) { + return rx.autoSub(_this.onChange, function(_arg) { + var added, index, removed; + + index = _arg[0], removed = _arg[1], added = _arg[2]; + if (index === i) { + return target.refresh(); + } + }); + }); + return this.xs[i]; + }; + + ObsArray.prototype.length = function() { + var _this = this; + + recorder.sub(function(target) { + return rx.autoSub(_this.onChange, function(_arg) { + var added, index, removed; + + index = _arg[0], removed = _arg[1], added = _arg[2]; + if (removed.length !== added.length) { + return target.refresh(); + } + }); + }); + return this.xs.length; + }; + + ObsArray.prototype.map = function(f) { + var ys; + + ys = new MappedDepArray(); + rx.autoSub(this.onChange, function(_arg) { + var added, index, removed; + + index = _arg[0], removed = _arg[1], added = _arg[2]; + return ys.realSplice(index, removed.length, added.map(f)); + }); + return ys; + }; + + ObsArray.prototype.indexed = function() { + var _this = this; + + if (this.indexed_ == null) { + this.indexed_ = new IndexedDepArray(); + rx.autoSub(this.onChange, function(_arg) { + var added, index, removed; + + index = _arg[0], removed = _arg[1], added = _arg[2]; + return _this.indexed_.realSplice(index, removed.length, added); + }); + } + return this.indexed_; + }; + + ObsArray.prototype.concat = function(that) { + return rx.concat(this, that); + }; + + ObsArray.prototype.realSplice = function(index, count, additions) { + var removed; + + removed = this.xs.splice.apply(this.xs, [index, count].concat(additions)); + return this.onChange.pub([index, removed, additions]); + }; + + ObsArray.prototype._update = function(val, diff) { + var additions, count, fullSplice, index, old, splice, splices, x, _i, _len, _ref1, _results; + + if (diff == null) { + diff = this.diff; + } + old = this.xs; + fullSplice = [0, old.length, val]; + x = null; + splices = diff != null ? (_ref1 = permToSplices(old.length, val, diff(old, val))) != null ? _ref1 : [fullSplice] : [fullSplice]; + _results = []; + for (_i = 0, _len = splices.length; _i < _len; _i++) { + splice = splices[_i]; + index = splice[0], count = splice[1], additions = splice[2]; + _results.push(this.realSplice(index, count, additions)); + } + return _results; + }; + + return ObsArray; + + })(); + SrcArray = rx.SrcArray = (function(_super) { + __extends(SrcArray, _super); + + function SrcArray() { + _ref1 = SrcArray.__super__.constructor.apply(this, arguments); + return _ref1; + } + + SrcArray.prototype.spliceArray = function(index, count, additions) { + var _this = this; + + return recorder.mutating(function() { + return _this.realSplice(index, count, additions); + }); + }; + + SrcArray.prototype.splice = function() { + var additions, count, index; + + index = arguments[0], count = arguments[1], additions = 3 <= arguments.length ? __slice.call(arguments, 2) : []; + return this.spliceArray(index, count, additions); + }; + + SrcArray.prototype.insert = function(x, index) { + return this.splice(index, 0, x); + }; + + SrcArray.prototype.remove = function(x) { + var i; + + i = _(this.raw()).indexOf(x); + if (i >= 0) { + return this.removeAt(i); + } + }; + + SrcArray.prototype.removeAt = function(index) { + return this.splice(index, 1); + }; + + SrcArray.prototype.push = function(x) { + return this.splice(this.length(), 0, x); + }; + + SrcArray.prototype.put = function(i, x) { + return this.splice(i, 1, x); + }; + + SrcArray.prototype.replace = function(xs) { + return this.spliceArray(0, this.length(), xs); + }; + + SrcArray.prototype.update = function(xs) { + var _this = this; + + return recorder.mutating(function() { + return _this._update(xs); + }); + }; + + return SrcArray; + + })(ObsArray); + MappedDepArray = rx.MappedDepArray = (function(_super) { + __extends(MappedDepArray, _super); + + function MappedDepArray() { + _ref2 = MappedDepArray.__super__.constructor.apply(this, arguments); + return _ref2; + } + + return MappedDepArray; + + })(ObsArray); + IndexedDepArray = rx.IndexedDepArray = (function(_super) { + __extends(IndexedDepArray, _super); + + function IndexedDepArray(xs, diff) { + var i, x, + _this = this; + + if (xs == null) { + xs = []; + } + IndexedDepArray.__super__.constructor.call(this, xs, diff); + this.is = (function() { + var _i, _len, _ref3, _results; + + _ref3 = this.xs; + _results = []; + for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) { + x = _ref3[i]; + _results.push(rx.cell(i)); + } + return _results; + }).call(this); + this.onChange = new Ev(function() { + return [[0, [], _.zip(_this.xs, _this.is)]]; + }); + } + + IndexedDepArray.prototype.map = function(f) { + var ys; + + ys = new IndexedMappedDepArray(); + rx.autoSub(this.onChange, function(_arg) { + var a, added, i, index, removed; + + index = _arg[0], removed = _arg[1], added = _arg[2]; + return ys.realSplice(index, removed.length, (function() { + var _i, _len, _ref3, _results; + + _results = []; + for (_i = 0, _len = added.length; _i < _len; _i++) { + _ref3 = added[_i], a = _ref3[0], i = _ref3[1]; + _results.push(f(a, i)); + } + return _results; + })()); + }); + return ys; + }; + + IndexedDepArray.prototype.realSplice = function(index, count, additions) { + var i, newIs, offset, removed, _i, _len, _ref3, _ref4, _ref5; + + removed = (_ref3 = this.xs).splice.apply(_ref3, [index, count].concat(__slice.call(additions))); + _ref4 = this.is.slice(index + count); + for (offset = _i = 0, _len = _ref4.length; _i < _len; offset = ++_i) { + i = _ref4[offset]; + i.set(index + additions.length + offset); + } + newIs = (function() { + var _j, _ref5, _results; + + _results = []; + for (i = _j = 0, _ref5 = additions.length; 0 <= _ref5 ? _j < _ref5 : _j > _ref5; i = 0 <= _ref5 ? ++_j : --_j) { + _results.push(rx.cell(index + i)); + } + return _results; + })(); + (_ref5 = this.is).splice.apply(_ref5, [index, count].concat(__slice.call(newIs))); + return this.onChange.pub([index, removed, _.zip(additions, newIs)]); + }; + + return IndexedDepArray; + + })(ObsArray); + IndexedMappedDepArray = rx.IndexedMappedDepArray = (function(_super) { + __extends(IndexedMappedDepArray, _super); + + function IndexedMappedDepArray() { + _ref3 = IndexedMappedDepArray.__super__.constructor.apply(this, arguments); + return _ref3; + } + + return IndexedMappedDepArray; + + })(IndexedDepArray); + DepArray = rx.DepArray = (function(_super) { + __extends(DepArray, _super); + + function DepArray(f, diff) { + var _this = this; + + this.f = f; + DepArray.__super__.constructor.call(this, [], diff); + rx.autoSub((bind(function() { + return _this.f(); + })).onSet, function(_arg) { + var old, val; + + old = _arg[0], val = _arg[1]; + return _this._update(val); + }); + } + + return DepArray; + + })(ObsArray); + IndexedArray = rx.IndexedArray = (function(_super) { + __extends(IndexedArray, _super); + + function IndexedArray(xs) { + this.xs = xs; + } + + IndexedArray.prototype.map = function(f) { + var ys; + + ys = new MappedDepArray(); + rx.autoSub(this.xs.onChange, function(_arg) { + var added, index, removed; + + index = _arg[0], removed = _arg[1], added = _arg[2]; + return ys.realSplice(index, removed.length, added.map(f)); + }); + return ys; + }; + + return IndexedArray; + + })(DepArray); + rx.concat = function() { + var repLens, xs, xss, ys; + + xss = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + ys = new MappedDepArray(); + repLens = (function() { + var _i, _len, _results; + + _results = []; + for (_i = 0, _len = xss.length; _i < _len; _i++) { + xs = xss[_i]; + _results.push(0); + } + return _results; + })(); + xss.map(function(xs, i) { + return rx.autoSub(xs.onChange, function(_arg) { + var added, index, removed, xsOffset; + + index = _arg[0], removed = _arg[1], added = _arg[2]; + xsOffset = sum(repLens.slice(0, i)); + repLens[i] += added.length - removed.length; + return ys.realSplice(xsOffset + index, removed.length, added); + }); + }); + return ys; + }; + FakeSrcCell = rx.FakeSrcCell = (function(_super) { + __extends(FakeSrcCell, _super); + + function FakeSrcCell(_getter, _setter) { + this._getter = _getter; + this._setter = _setter; + } + + FakeSrcCell.prototype.get = function() { + return this._getter(); + }; + + FakeSrcCell.prototype.set = function(x) { + return this._setter(x); + }; + + return FakeSrcCell; + + })(SrcCell); + FakeObsCell = rx.FakeObsCell = (function(_super) { + __extends(FakeObsCell, _super); + + function FakeObsCell(_getter) { + this._getter = _getter; + } + + FakeObsCell.prototype.get = function() { + return this._getter(); + }; + + return FakeObsCell; + + })(ObsCell); + SrcMapEntryCell = rx.MapEntryCell = (function(_super) { + __extends(MapEntryCell, _super); + + function MapEntryCell(_map, _key) { + this._map = _map; + this._key = _key; + } + + MapEntryCell.prototype.get = function() { + return this._map.get(this._key); + }; + + MapEntryCell.prototype.set = function(x) { + return this._map.put(this._key, x); + }; + + return MapEntryCell; + + })(FakeSrcCell); + ObsMapEntryCell = rx.ObsMapEntryCell = (function(_super) { + __extends(ObsMapEntryCell, _super); + + function ObsMapEntryCell(_map, _key) { + this._map = _map; + this._key = _key; + } + + ObsMapEntryCell.prototype.get = function() { + return this._map.get(this._key); + }; + + return ObsMapEntryCell; + + })(FakeObsCell); + ObsMap = rx.ObsMap = (function() { + function ObsMap(x) { + var _this = this; + + this.x = x != null ? x : {}; + this.onAdd = new Ev(function() { + var k, v, _results; + + _results = []; + for (k in x) { + v = x[k]; + _results.push([k, v]); + } + return _results; + }); + this.onRemove = new Ev(); + this.onChange = new Ev(); + } + + ObsMap.prototype.get = function(key) { + var _this = this; + + recorder.sub(function(target) { + return rx.autoSub(_this.onAdd, function(_arg) { + var subkey, val; + + subkey = _arg[0], val = _arg[1]; + if (key === subkey) { + return target.refresh(); + } + }); + }); + recorder.sub(function(target) { + return rx.autoSub(_this.onChange, function(_arg) { + var old, subkey, val; + + subkey = _arg[0], old = _arg[1], val = _arg[2]; + if (key === subkey) { + return target.refresh(); + } + }); + }); + recorder.sub(function(target) { + return rx.autoSub(_this.onRemove, function(_arg) { + var old, subkey; + + subkey = _arg[0], old = _arg[1]; + if (key === subkey) { + return target.refresh(); + } + }); + }); + return this.x[key]; + }; + + ObsMap.prototype.all = function() { + var _this = this; + + recorder.sub(function(target) { + return rx.autoSub(_this.onAdd, function() { + return target.refresh(); + }); + }); + recorder.sub(function(target) { + return rx.autoSub(_this.onChange, function() { + return target.refresh(); + }); + }); + recorder.sub(function(target) { + return rx.autoSub(_this.onRemove, function() { + return target.refresh(); + }); + }); + return _.clone(this.x); + }; + + ObsMap.prototype.realPut = function(key, val) { + var old; + + if (key in this.x) { + old = this.x[key]; + this.x[key] = val; + this.onChange.pub([key, old, val]); + return old; + } else { + this.x[key] = val; + this.onAdd.pub([key, val]); + return void 0; + } + }; + + ObsMap.prototype.realRemove = function(key) { + var val; + + val = popKey(this.x, key); + this.onRemove.pub([key, val]); + return val; + }; + + ObsMap.prototype.cell = function(key) { + return new ObsMapEntryCell(this, key); + }; + + return ObsMap; + + })(); + SrcMap = rx.SrcMap = (function(_super) { + __extends(SrcMap, _super); + + function SrcMap() { + _ref4 = SrcMap.__super__.constructor.apply(this, arguments); + return _ref4; + } + + SrcMap.prototype.put = function(key, val) { + var _this = this; + + return recorder.mutating(function() { + return _this.realPut(key, val); + }); + }; + + SrcMap.prototype.remove = function(key) { + var _this = this; + + return recorder.mutating(function() { + return _this.realRemove(key); + }); + }; + + SrcMap.prototype.cell = function(key) { + return new SrcMapEntryCell(this, key); + }; + + return SrcMap; + + })(ObsMap); + DepMap = rx.DepMap = (function(_super) { + __extends(DepMap, _super); + + function DepMap(f) { + this.f = f; + DepMap.__super__.constructor.call(this); + rx.autoSub(new DepCell(this.f).onSet, function(_arg) { + var k, old, v, val, _results; + + old = _arg[0], val = _arg[1]; + for (k in old) { + v = old[k]; + if (!(k in val)) { + this.realRemove(k); + } + } + _results = []; + for (k in val) { + v = val[k]; + if (this.x[k] !== v) { + _results.push(this.realPut(k, v)); + } else { + _results.push(void 0); + } + } + return _results; + }); + } + + return DepMap; + + })(ObsMap); + rx.liftSpec = function(obj) { + var name, type, val; + + return _.object((function() { + var _i, _len, _ref5, _results; + + _ref5 = Object.getOwnPropertyNames(obj); + _results = []; + for (_i = 0, _len = _ref5.length; _i < _len; _i++) { + name = _ref5[_i]; + val = obj[name]; + if ((val != null) && (val instanceof rx.ObsMap || val instanceof rx.ObsCell || val instanceof rx.ObsArray)) { + continue; + } + type = _.isFunction(val) ? null : _.isArray(val) ? 'array' : 'cell'; + _results.push([ + name, { + type: type, + val: val + } + ]); + } + return _results; + })()); + }; + rx.lift = function(x, fieldspec) { + var name, spec; + + if (fieldspec == null) { + fieldspec = rx.liftSpec(x); + } + for (name in fieldspec) { + spec = fieldspec[name]; + x[name] = (function() { + switch (spec.type) { + case 'cell': + return rx.cell(x[name]); + case 'array': + return rx.array(x[name]); + case 'map': + return rx.map(x[name]); + default: + return x[name]; + } + })(); + } + return x; + }; + rx.unlift = function(x) { + var k, v; + + return _.object((function() { + var _results; + + _results = []; + for (k in x) { + v = x[k]; + _results.push([k, v instanceof rx.ObsCell ? v.get() : v instanceof rx.ObsArray ? v.all() : v]); + } + return _results; + })()); + }; + rx.reactify = function(obj, fieldspec) { + var arr, methName, name, spec; + + if (_.isArray(obj)) { + arr = rx.array(_.clone(obj)); + Object.defineProperties(obj, _.object((function() { + var _i, _len, _ref5, _results; + + _ref5 = _.functions(arr); + _results = []; + for (_i = 0, _len = _ref5.length; _i < _len; _i++) { + methName = _ref5[_i]; + if (methName !== 'length') { + _results.push((function(methName) { + var meth, newMeth, spec; + + meth = obj[methName]; + newMeth = function() { + var args, res, _ref6; + + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (meth != null) { + res = meth.call.apply(meth, [obj].concat(__slice.call(args))); + } + (_ref6 = arr[methName]).call.apply(_ref6, [arr].concat(__slice.call(args))); + return res; + }; + spec = { + configurable: true, + enumerable: false, + value: newMeth, + writable: true + }; + return [methName, spec]; + })(methName)); + } + } + return _results; + })())); + return obj; + } else { + return Object.defineProperties(obj, _.object((function() { + var _results; + + _results = []; + for (name in fieldspec) { + spec = fieldspec[name]; + _results.push((function(name, spec) { + var desc, obs, view, _ref5, _ref6; + + desc = null; + switch (spec.type) { + case 'cell': + obs = rx.cell((_ref5 = spec.val) != null ? _ref5 : null); + desc = { + configurable: true, + enumerable: true, + get: function() { + return obs.get(); + }, + set: function(x) { + return obs.set(x); + } + }; + break; + case 'array': + view = rx.reactify((_ref6 = spec.val) != null ? _ref6 : []); + desc = { + configurable: true, + enumerable: true, + get: function() { + view.raw(); + return view; + }, + set: function(x) { + view.splice.apply(view, [0, view.length].concat(__slice.call(x))); + return view; + } + }; + break; + default: + throw new Error("Unknown observable type: " + type); + } + return [name, desc]; + })(name, spec)); + } + return _results; + })())); + } + }; + rx.autoReactify = function(obj) { + var name, type, val; + + return rx.reactify(obj, _.object((function() { + var _i, _len, _ref5, _results; + + _ref5 = Object.getOwnPropertyNames(obj); + _results = []; + for (_i = 0, _len = _ref5.length; _i < _len; _i++) { + name = _ref5[_i]; + val = obj[name]; + if (val instanceof ObsMap || val instanceof ObsCell || val instanceof ObsArray) { + continue; + } + type = _.isFunction(val) ? null : _.isArray(val) ? 'array' : 'cell'; + _results.push([ + name, { + type: type, + val: val + } + ]); + } + return _results; + })())); + }; + _.extend(rx, { + cell: function(x) { + return new SrcCell(x); + }, + array: function(xs, diff) { + return new SrcArray(xs, diff); + }, + map: function(x) { + return new SrcMap(x); + } + }); + rx.flatten = function(xs) { + return new DepArray(function() { + var x; + + return _((function() { + var _i, _len, _results; + + _results = []; + for (_i = 0, _len = xs.length; _i < _len; _i++) { + x = xs[_i]; + if (x instanceof ObsArray) { + _results.push(x.raw()); + } else if (x instanceof ObsCell) { + _results.push(x.get()); + } else { + _results.push(x); + } + } + return _results; + })()).chain().flatten(true).filter(function(x) { + return x != null; + }).value(); + }); + }; + flatten = function(xss) { + var xs; + + xs = _.flatten(xss); + return rx.cellToArray(bind(function() { + return _.flatten(xss); + })); + }; + rx.cellToArray = function(cell, diff) { + return new DepArray((function() { + return cell.get(); + }), diff); + }; + rx.basicDiff = function(key) { + if (key == null) { + key = rx.smartUidify; + } + return function(oldXs, newXs) { + var i, oldKeys, x, _i, _len, _ref5, _results; + + oldKeys = mkMap((function() { + var _i, _len, _results; + + _results = []; + for (i = _i = 0, _len = oldXs.length; _i < _len; i = ++_i) { + x = oldXs[i]; + _results.push([key(x), i]); + } + return _results; + })()); + _results = []; + for (_i = 0, _len = newXs.length; _i < _len; _i++) { + x = newXs[_i]; + _results.push((_ref5 = oldKeys[key(x)]) != null ? _ref5 : -1); + } + return _results; + }; + }; + rx.uidify = function(x) { + var _ref5; + + return (_ref5 = x.__rxUid) != null ? _ref5 : (Object.defineProperty(x, '__rxUid', { + enumerable: false, + value: mkuid() + })).__rxUid; + }; + rx.smartUidify = function(x) { + if (_.isObject(x)) { + return rx.uidify(x); + } else { + return JSON.stringify(x); + } + }; + permToSplices = function(oldLength, newXs, perm) { + var cur, i, last, refs, splice, splices; + + refs = (function() { + var _i, _len, _results; + + _results = []; + for (_i = 0, _len = perm.length; _i < _len; _i++) { + i = perm[_i]; + if (i >= 0) { + _results.push(i); + } + } + return _results; + })(); + if (_.some((function() { + var _i, _ref5, _results; + + _results = []; + for (i = _i = 0, _ref5 = refs.length - 1; 0 <= _ref5 ? _i < _ref5 : _i > _ref5; i = 0 <= _ref5 ? ++_i : --_i) { + _results.push(refs[i + 1] - refs[i] <= 0); + } + return _results; + })())) { + return null; + } + splices = []; + last = -1; + i = 0; + while (i < perm.length) { + while (i < perm.length && perm[i] === last + 1) { + last += 1; + i += 1; + } + splice = { + index: i, + count: 0, + additions: [] + }; + while (i < perm.length && perm[i] === -1) { + splice.additions.push(newXs[i]); + i += 1; + } + cur = i === perm.length ? oldLength : perm[i]; + splice.count = cur - (last + 1); + if (splice.count > 0 || splice.additions.length > 0) { + splices.push([splice.index, splice.count, splice.additions]); + } + last = cur; + i += 1; + } + return splices; + }; + rx.transaction = function(f) { + return depMgr.transaction(f); + }; + if ($ != null) { + $.fn.rx = function(prop) { + var checked, focused, map, val; + + map = this.data('rx-map'); + if (map == null) { + this.data('rx-map', map = mkMap()); + } + if (prop in map) { + return map[prop]; + } + return map[prop] = (function() { + var _this = this; + + switch (prop) { + case 'focused': + focused = rx.cell(this.is(':focus')); + this.focus(function() { + return focused.set(true); + }); + this.blur(function() { + return focused.set(false); + }); + return focused; + case 'val': + val = rx.cell(this.val()); + this.change(function() { + return val.set(_this.val()); + }); + this.on('input', function() { + return val.set(_this.val()); + }); + return val; + case 'checked': + checked = rx.cell(this.is(':checked')); + this.change(function() { + return checked.set(_this.is(':checked')); + }); + return checked; + default: + throw new Error('Unknown reactive property type'); + } + }).call(this); + }; + rxt = {}; + RawHtml = rxt.RawHtml = (function() { + function RawHtml(html) { + this.html = html; + } + + return RawHtml; + + })(); + events = ["blur", "change", "click", "dblclick", "error", "focus", "focusin", "focusout", "hover", "keydown", "keypress", "keyup", "load", "mousedown", "mouseenter", "mouseleave", "mousemove", "mouseout", "mouseover", "mouseup", "ready", "resize", "scroll", "select", "submit", "toggle", "unload"]; + specialAttrs = rxt.specialAttrs = { + init: function(elt, fn) { + return fn.call(elt); + } + }; + _fn = function(ev) { + return specialAttrs[ev] = function(elt, fn) { + return elt[ev](function(e) { + return fn.call(elt, e); + }); + }; + }; + for (_i = 0, _len = events.length; _i < _len; _i++) { + ev = events[_i]; + _fn(ev); + } + props = ['async', 'autofocus', 'checked', 'location', 'multiple', 'readOnly', 'selected', 'selectedIndex', 'tagName', 'nodeName', 'nodeType', 'ownerDocument', 'defaultChecked', 'defaultSelected']; + propSet = _.object((function() { + var _j, _len1, _results; + + _results = []; + for (_j = 0, _len1 = props.length; _j < _len1; _j++) { + prop = props[_j]; + _results.push([prop, null]); + } + return _results; + })()); + setProp = function(elt, prop, val) { + if (prop === 'value') { + return elt.val(val); + } else if (prop in propSet) { + return elt.prop(prop, val); + } else { + return elt.attr(prop, val); + } + }; + setDynProp = function(elt, prop, val, xform) { + if (xform == null) { + xform = _.identity; + } + if (val instanceof ObsCell) { + return rx.autoSub(val.onSet, function(_arg) { + var n, o; + + o = _arg[0], n = _arg[1]; + return setProp(elt, prop, xform(n)); + }); + } else { + return setProp(elt, prop, xform(val)); + } + }; + rxt.mkAtts = mkAtts = function(attstr) { + return (function(atts) { + var classes, cls, id; + + id = attstr.match(/[#](\w+)/); + if (id) { + atts.id = id[1]; + } + classes = attstr.match(/\.\w+/g); + if (classes) { + atts["class"] = ((function() { + var _j, _len1, _results; + + _results = []; + for (_j = 0, _len1 = classes.length; _j < _len1; _j++) { + cls = classes[_j]; + _results.push(cls.replace(/^\./, '')); + } + return _results; + })()).join(' '); + } + return atts; + })({}); + }; + rxt.mktag = mktag = function(tag) { + return function(arg1, arg2) { + var attrs, contents, elt, key, name, toNodes, updateContents, value, _ref5, _ref6; + + _ref5 = (arg1 == null) && (arg2 == null) ? [{}, null] : arg1 instanceof Object && (arg2 != null) ? [arg1, arg2] : _.isString(arg1) && (arg2 != null) ? [mkAtts(arg1), arg2] : (arg2 == null) && _.isString(arg1) || arg1 instanceof Element || arg1 instanceof RawHtml || arg1 instanceof $ || _.isArray(arg1) || arg1 instanceof ObsCell || arg1 instanceof ObsArray ? [{}, arg1] : [arg1, null], attrs = _ref5[0], contents = _ref5[1]; + elt = $("<" + tag + "/>"); + _ref6 = _.omit(attrs, _.keys(specialAttrs)); + for (name in _ref6) { + value = _ref6[name]; + setDynProp(elt, name, value); + } + if (contents != null) { + toNodes = function(contents) { + var child, parsed, _j, _len1, _results; + + _results = []; + for (_j = 0, _len1 = contents.length; _j < _len1; _j++) { + child = contents[_j]; + if (_.isString(child)) { + _results.push(document.createTextNode(child)); + } else if (child instanceof Element) { + _results.push(child); + } else if (child instanceof RawHtml) { + parsed = $(child.html); + if (parsed.length !== 1) { + throw new Error('RawHtml must wrap a single element'); + } + _results.push(parsed[0]); + } else if (child instanceof $) { + if (child.length !== 1) { + throw new Error('jQuery object must wrap a single element'); + } + _results.push(child[0]); + } else { + throw new Error("Unknown element type in array: " + child.constructor.name + " (must be string, Element, RawHtml, or jQuery objects)"); + } + } + return _results; + }; + updateContents = function(contents) { + var covers, hasWidth, left, node, nodes, top; + + elt.html(''); + if (_.isArray(contents)) { + nodes = toNodes(contents); + elt.append(nodes); + if (false) { + hasWidth = function(node) { + var e; + + try { + return ($(node).width() != null) !== 0; + } catch (_error) { + e = _error; + return false; + } + }; + covers = (function() { + var _j, _len1, _ref7, _ref8, _results; + + _ref7 = nodes != null ? nodes : []; + _results = []; + for (_j = 0, _len1 = _ref7.length; _j < _len1; _j++) { + node = _ref7[_j]; + if (!(hasWidth(node))) { + continue; + } + _ref8 = $(node).offset(), left = _ref8.left, top = _ref8.top; + _results.push($('
    ').appendTo($('body').first()).addClass('updated-element').offset({ + top: top, + left: left + }).width($(node).width()).height($(node).height())); + } + return _results; + })(); + return setTimeout((function() { + var cover, _j, _len1, _results; + + _results = []; + for (_j = 0, _len1 = covers.length; _j < _len1; _j++) { + cover = covers[_j]; + _results.push($(cover).remove()); + } + return _results; + }), 2000); + } + } else if (_.isString(contents) || contents instanceof Element || contents instanceof RawHtml || contents instanceof $) { + return updateContents([contents]); + } else { + throw new Error("Unknown type for element contents: " + contents.constructor.name + " (accepted types: string, Element, RawHtml, jQuery object of single element, or array of the aforementioned)"); + } + }; + if (contents instanceof ObsArray) { + rx.autoSub(contents.onChange, function(_arg) { + var added, index, removed, toAdd; + + index = _arg[0], removed = _arg[1], added = _arg[2]; + elt.contents().slice(index, index + removed.length).remove(); + toAdd = toNodes(added); + if (index === elt.contents().length) { + return elt.append(toAdd); + } else { + return elt.contents().eq(index).before(toAdd); + } + }); + } else if (contents instanceof ObsCell) { + rx.autoSub(contents.onSet, function(_arg) { + var old, val; + + old = _arg[0], val = _arg[1]; + return updateContents(val); + }); + } else { + updateContents(contents); + } + } + for (key in attrs) { + if (key in specialAttrs) { + specialAttrs[key](elt, attrs[key], attrs, contents); + } + } + return elt; + }; + }; + tags = ['html', 'head', 'title', 'base', 'link', 'meta', 'style', 'script', 'noscript', 'body', 'body', 'section', 'nav', 'article', 'aside', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h1', 'h6', 'header', 'footer', 'address', 'main', 'main', 'p', 'hr', 'pre', 'blockquote', 'ol', 'ul', 'li', 'dl', 'dt', 'dd', 'dd', 'figure', 'figcaption', 'div', 'a', 'em', 'strong', 'small', 's', 'cite', 'q', 'dfn', 'abbr', 'data', 'time', 'code', 'var', 'samp', 'kbd', 'sub', 'sup', 'i', 'b', 'u', 'mark', 'ruby', 'rt', 'rp', 'bdi', 'bdo', 'span', 'br', 'wbr', 'ins', 'del', 'img', 'iframe', 'embed', 'object', 'param', 'object', 'video', 'audio', 'source', 'video', 'audio', 'track', 'video', 'audio', 'canvas', 'map', 'area', 'area', 'map', 'svg', 'math', 'table', 'caption', 'colgroup', 'col', 'tbody', 'thead', 'tfoot', 'tr', 'td', 'th', 'form', 'fieldset', 'legend', 'fieldset', 'label', 'input', 'button', 'select', 'datalist', 'optgroup', 'option', 'select', 'datalist', 'textarea', 'keygen', 'output', 'progress', 'meter', 'details', 'summary', 'details', 'menuitem', 'menu']; + rxt.tags = _.object((function() { + var _j, _len1, _results; + + _results = []; + for (_j = 0, _len1 = tags.length; _j < _len1; _j++) { + tag = tags[_j]; + _results.push([tag, rxt.mktag(tag)]); + } + return _results; + })()); + rxt.rawHtml = function(html) { + return new RawHtml(html); + }; + rxt.importTags = function(x) { + return _(x != null ? x : _this).extend(rxt.tags); + }; + rxt.cast = function(opts, types) { + var key, newval, value; + + return _.object((function() { + var _results; + + _results = []; + for (key in opts) { + value = opts[key]; + newval = (function() { + switch (types[key]) { + case 'array': + if (value instanceof rx.ObsArray) { + return value; + } else if (_.isArray(value)) { + return new rx.DepArray(function() { + return value; + }); + } else if (value instanceof rx.ObsCell) { + return new rx.DepArray(function() { + return value.get(); + }); + } else { + throw new Error('Cannot cast to array: ' + value.constructor.name); + } + break; + case 'cell': + if (value instanceof rx.ObsCell) { + return value; + } else { + return bind(function() { + return value; + }); + } + break; + default: + return value; + } + })(); + _results.push([key, newval]); + } + return _results; + })()); + }; + rxt.cssify = function(map) { + var k, v; + + return ((function() { + var _results; + + _results = []; + for (k in map) { + v = map[k]; + if (v != null) { + _results.push("" + (_.str.dasherize(k)) + ": " + (_.isNumber(v) ? v + 'px' : v) + ";"); + } + } + return _results; + })()).join(' '); + }; + specialAttrs.style = function(elt, value) { + return setDynProp(elt, 'style', value, function(val) { + if (_.isString(val)) { + return val; + } else { + return rxt.cssify(val); + } + }); + }; + rxt.smushClasses = function(xs) { + return _(xs).chain().flatten().compact().value().join(' ').replace(/\s+/, ' ').trim(); + }; + specialAttrs["class"] = function(elt, value) { + return setDynProp(elt, 'class', value, function(val) { + if (_.isString(val)) { + return val; + } else { + return rxt.smushClasses(val); + } + }); + }; + } + rx.rxt = rxt; + return rx; + }; + + (function(root, factory, deps) { + var rx, _, _str; + + if ((typeof define !== "undefined" && define !== null ? define.amd : void 0) != null) { + return define(deps, factory); + } else if ((typeof module !== "undefined" && module !== null ? module.exports : void 0) != null) { + _ = require('underscore'); + _str = require('underscore.string'); + rx = factory(_, _str); + return module.exports = rx; + } else if ((root._ != null) && (root.$ != null)) { + return root.rx = factory(root._, void 0, root.$); + } else { + throw "Dependencies are not met for reactive: _ and $ not found"; + } + })(this, rxFactory, ['underscore', 'underscore.string', 'jquery']); + +}).call(this); diff --git a/ajax/libs/reactive-coffee/1.1.1/reactive-coffee.min.js b/ajax/libs/reactive-coffee/1.1.1/reactive-coffee.min.js new file mode 100644 index 000000000..b90c71af6 --- /dev/null +++ b/ajax/libs/reactive-coffee/1.1.1/reactive-coffee.min.js @@ -0,0 +1 @@ +(function(){var a,b=[].slice,c={}.hasOwnProperty,d=function(a,b){function d(){this.constructor=a}for(var e in b)c.call(b,e)&&(a[e]=b[e]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a};a=function(a,c,e){var f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,_,ab,bb,cb,db,eb,fb,gb,hb,ib,jb=this;if(V={},M=0,L=function(){return M+=1},P=function(a,b){var c;if(!(b in a))throw new Error("object has no key "+b);return c=a[b],delete a[b],c},N=function(a,b,c){var d,e,f,g;for(d=f=0,g=a.length;g>f;d=++f)if(e=a[d],c(e)&&(b-=1)<0)return[e,d];return[null,-1]},F=function(a,b){return N(a,0,b)},J=function(b){var c,d,e,f,g,h;if(null==b&&(b=[]),d=null!=Object.create?Object.create(null):{},a.isArray(b))for(f=0,g=b.length;g>f;f++)h=b[f],c=h[0],e=h[1],d[c]=e;else for(c in b)e=b[c],d[c]=e;return d},$=function(a){var b,c,d,e;for(b=0,d=0,e=a.length;e>d;d++)c=a[d],b+=c;return b},i=V.DepMgr=function(){function a(){this.uid2src={},this.buffering=0,this.buffer=[]}return a.prototype.sub=function(a,b){return this.uid2src[a]=b},a.prototype.unsub=function(a){return P(this.uid2src,a)},a.prototype.transaction=function(a){var b,c,d,e,f;this.buffering+=1;try{c=a()}finally{if(this.buffering-=1,0===this.buffering){for(f=this.buffer,d=0,e=f.length;e>d;d++)(b=f[d])();this.buffer=[]}}return c},a}(),V._depMgr=C=new i,j=V.Ev=function(){function a(a){this.inits=a,this.subs=J()}return a.prototype.sub=function(a){var b,c,d,e,f;if(c=L(),null!=this.inits)for(f=this.inits(),d=0,e=f.length;e>d;d++)b=f[d],a(b);return this.subs[c]=a,C.sub(c,this),c},a.prototype.pub=function(a){var b,c,d,e,f=this;if(C.buffering)return C.buffer.push(function(){return f.pub(a)});d=this.subs,e=[];for(c in d)b=d[c],e.push(b(a));return e},a.prototype.unsub=function(a){return P(this.subs,a),C.unsub(a,this)},a.prototype.scoped=function(a,b){var c;c=this.sub(a);try{return b()}finally{this.unsub(c)}},a}(),V.skipFirst=function(a){var c;return c=!0,function(){var d;return d=1<=arguments.length?b.call(arguments,0):[],c?c=!1:a.apply(null,d)}},v=V.Recorder=function(){function b(){this.stack=[],this.isMutating=!1,this.isIgnoring=!1,this.onMutationWarning=new j}return b.prototype.record=function(b,c){var d,e;this.stack.length>0&&!this.isMutating&&a(this.stack).last().addNestedBind(b),this.stack.push(b),e=this.isMutating,this.isMutating=!1,d=this.isIgnoring,this.isIgnoring=!1;try{return c()}finally{this.isIgnoring=d,this.isMutating=e,this.stack.pop()}},b.prototype.sub=function(b){var c,d;return this.stack.length>0&&!this.isIgnoring?(d=a(this.stack).last(),c=b(d)):void 0},b.prototype.addCleanup=function(b){return this.stack.length>0?a(this.stack).last().addCleanup(b):void 0},b.prototype.mutating=function(a){var b;this.stack.length>0&&(console.warn("Mutation to observable detected during a bind context"),this.onMutationWarning.pub(null)),b=this.isMutating,this.isMutating=!0;try{return a()}finally{this.isMutating=b}},b.prototype.ignoring=function(a){var b;b=this.isIgnoring,this.isIgnoring=!0;try{return a()}finally{this.isIgnoring=b}},b}(),V._recorder=U=new v,V.asyncBind=A=function(a,b){var c;return c=new g(b,a),c.refresh(),c},V.bind=B=function(a){return A(null,function(){return this.done(this.record(a))})},V.lagBind=H=function(a,b,c){var d;return d=null,A(b,function(){var b=this;return null!=d&&clearTimeout(d),d=setTimeout(function(){return b.done(b.record(c))},a)})},V.postLagBind=Q=function(a,b){var c;return c=null,A(a,function(){var a,d,e,f=this;return e=this.record(b),d=e.val,a=e.ms,null!=c&&clearTimeout(c),c=setTimeout(function(){return f.done(d)},a)})},V.snap=function(a){return U.ignoring(a)},V.onDispose=function(a){return U.addCleanup(a)},V.autoSub=function(a,b){var c;return c=a.sub(b),V.onDispose(function(){return a.unsub(c)}),c},r=V.ObsCell=function(){function a(a){var b,c=this;this.x=a,this.x=null!=(b=this.x)?b:null,this.onSet=new j(function(){return[[null,c.x]]})}return a.prototype.get=function(){var a=this;return U.sub(function(b){return V.autoSub(a.onSet,function(){return b.refresh()})}),this.x},a}(),x=V.SrcCell=function(a){function b(){return eb=b.__super__.constructor.apply(this,arguments)}return d(b,a),b.prototype.set=function(a){var b=this;return U.mutating(function(){var c;return b.x!==a?(c=b.x,b.x=a,b.onSet.pub([c,a]),c):void 0})},b}(r),g=V.DepCell=function(a){function b(a,c){this.body=a,b.__super__.constructor.call(this,null!=c?c:null),this.refreshing=!1,this.nestedBinds=[],this.cleanups=[]}return d(b,a),b.prototype.refresh=function(){var a,b,c,d,e,f=this;return this.refreshing?void 0:(c=this.x,d=function(a){return f.x=a,f.onSet.pub([c,f.x])},e=null,b=!1,a={record:function(c){var g,h;if(!f.refreshing){if(f.disconnect(),g)throw new Error("this refresh has already recorded its dependencies");f.refreshing=!0,g=!0;try{h=U.record(f,function(){return c.call(a)})}finally{f.refreshing=!1}return b&&d(e),h}},done:function(a){return c!==a?f.refreshing?(b=!0,e=a):d(a):void 0}},this.body.call(a))},b.prototype.disconnect=function(){var a,b,c,d,e,f,g,h;for(g=this.cleanups,c=0,e=g.length;e>c;c++)(a=g[c])();for(h=this.nestedBinds,d=0,f=h.length;f>d;d++)b=h[d],b.disconnect();return this.nestedBinds=[],this.cleanups=[]},b.prototype.addNestedBind=function(a){return this.nestedBinds.push(a)},b.prototype.addCleanup=function(a){return this.cleanups.push(a)},b}(r),q=V.ObsArray=function(){function b(a,b){var c=this;this.xs=null!=a?a:[],this.diff=null!=b?b:V.basicDiff(),this.onChange=new j(function(){return[[0,[],c.xs]]}),this.indexed_=null}return b.prototype.all=function(){var b=this;return U.sub(function(a){return V.autoSub(b.onChange,function(){return a.refresh()})}),a.clone(this.xs)},b.prototype.raw=function(){var a=this;return U.sub(function(b){return V.autoSub(a.onChange,function(){return b.refresh()})}),this.xs},b.prototype.at=function(a){var b=this;return U.sub(function(c){return V.autoSub(b.onChange,function(b){var d,e,f;return e=b[0],f=b[1],d=b[2],e===a?c.refresh():void 0})}),this.xs[a]},b.prototype.length=function(){var a=this;return U.sub(function(b){return V.autoSub(a.onChange,function(a){var c,d,e;return d=a[0],e=a[1],c=a[2],e.length!==c.length?b.refresh():void 0})}),this.xs.length},b.prototype.map=function(a){var b;return b=new p,V.autoSub(this.onChange,function(c){var d,e,f;return e=c[0],f=c[1],d=c[2],b.realSplice(e,f.length,d.map(a))}),b},b.prototype.indexed=function(){var a=this;return null==this.indexed_&&(this.indexed_=new n,V.autoSub(this.onChange,function(b){var c,d,e;return d=b[0],e=b[1],c=b[2],a.indexed_.realSplice(d,e.length,c)})),this.indexed_},b.prototype.concat=function(a){return V.concat(this,a)},b.prototype.realSplice=function(a,b,c){var d;return d=this.xs.splice.apply(this.xs,[a,b].concat(c)),this.onChange.pub([a,d,c])},b.prototype._update=function(a,b){var c,d,e,f,g,h,i,j,k,l,m,n;for(null==b&&(b=this.diff),g=this.xs,e=[0,g.length,a],j=null,i=null!=b?null!=(m=O(g.length,a,b(g,a)))?m:[e]:[e],n=[],k=0,l=i.length;l>k;k++)h=i[k],f=h[0],d=h[1],c=h[2],n.push(this.realSplice(f,d,c));return n},b}(),w=V.SrcArray=function(c){function e(){return fb=e.__super__.constructor.apply(this,arguments)}return d(e,c),e.prototype.spliceArray=function(a,b,c){var d=this;return U.mutating(function(){return d.realSplice(a,b,c)})},e.prototype.splice=function(){var a,c,d;return d=arguments[0],c=arguments[1],a=3<=arguments.length?b.call(arguments,2):[],this.spliceArray(d,c,a)},e.prototype.insert=function(a,b){return this.splice(b,0,a)},e.prototype.remove=function(b){var c;return c=a(this.raw()).indexOf(b),c>=0?this.removeAt(c):void 0},e.prototype.removeAt=function(a){return this.splice(a,1)},e.prototype.push=function(a){return this.splice(this.length(),0,a)},e.prototype.put=function(a,b){return this.splice(a,1,b)},e.prototype.replace=function(a){return this.spliceArray(0,this.length(),a)},e.prototype.update=function(a){var b=this;return U.mutating(function(){return b._update(a)})},e}(q),p=V.MappedDepArray=function(a){function b(){return gb=b.__super__.constructor.apply(this,arguments)}return d(b,a),b}(q),n=V.IndexedDepArray=function(c){function e(b,c){var d,f,g=this;null==b&&(b=[]),e.__super__.constructor.call(this,b,c),this.is=function(){var a,b,c,e;for(c=this.xs,e=[],d=a=0,b=c.length;b>a;d=++a)f=c[d],e.push(V.cell(d));return e}.call(this),this.onChange=new j(function(){return[[0,[],a.zip(g.xs,g.is)]]})}return d(e,c),e.prototype.map=function(a){var b;return b=new o,V.autoSub(this.onChange,function(c){var d,e,f,g,h;return g=c[0],h=c[1],e=c[2],b.realSplice(g,h.length,function(){var b,c,g,h;for(h=[],b=0,c=e.length;c>b;b++)g=e[b],d=g[0],f=g[1],h.push(a(d,f));return h}())}),b},e.prototype.realSplice=function(c,d,e){var f,g,h,i,j,k,l,m,n;for(i=(l=this.xs).splice.apply(l,[c,d].concat(b.call(e))),m=this.is.slice(c+d),h=j=0,k=m.length;k>j;h=++j)f=m[h],f.set(c+e.length+h);return g=function(){var a,b,d;for(d=[],f=a=0,b=e.length;b>=0?b>a:a>b;f=b>=0?++a:--a)d.push(V.cell(c+f));return d}(),(n=this.is).splice.apply(n,[c,d].concat(b.call(g))),this.onChange.pub([c,i,a.zip(e,g)])},e}(q),o=V.IndexedMappedDepArray=function(a){function b(){return hb=b.__super__.constructor.apply(this,arguments)}return d(b,a),b}(n),f=V.DepArray=function(a){function b(a,c){var d=this;this.f=a,b.__super__.constructor.call(this,[],c),V.autoSub(B(function(){return d.f()}).onSet,function(a){var b,c;return b=a[0],c=a[1],d._update(c)})}return d(b,a),b}(q),m=V.IndexedArray=function(a){function b(a){this.xs=a}return d(b,a),b.prototype.map=function(a){var b;return b=new p,V.autoSub(this.xs.onChange,function(c){var d,e,f;return e=c[0],f=c[1],d=c[2],b.realSplice(e,f.length,d.map(a))}),b},b}(f),V.concat=function(){var a,c,d,e;return d=1<=arguments.length?b.call(arguments,0):[],e=new p,a=function(){var a,b,e;for(e=[],a=0,b=d.length;b>a;a++)c=d[a],e.push(0);return e}(),d.map(function(b,c){return V.autoSub(b.onChange,function(b){var d,f,g,h;return f=b[0],g=b[1],d=b[2],h=$(a.slice(0,c)),a[c]+=d.length-g.length,e.realSplice(h+f,g.length,d)})}),e},l=V.FakeSrcCell=function(a){function b(a,b){this._getter=a,this._setter=b}return d(b,a),b.prototype.get=function(){return this._getter()},b.prototype.set=function(a){return this._setter(a)},b}(x),k=V.FakeObsCell=function(a){function b(a){this._getter=a}return d(b,a),b.prototype.get=function(){return this._getter()},b}(r),z=V.MapEntryCell=function(a){function b(a,b){this._map=a,this._key=b}return d(b,a),b.prototype.get=function(){return this._map.get(this._key)},b.prototype.set=function(a){return this._map.put(this._key,a)},b}(l),t=V.ObsMapEntryCell=function(a){function b(a,b){this._map=a,this._key=b}return d(b,a),b.prototype.get=function(){return this._map.get(this._key)},b}(k),s=V.ObsMap=function(){function b(a){this.x=null!=a?a:{},this.onAdd=new j(function(){var b,c,d;d=[];for(b in a)c=a[b],d.push([b,c]);return d}),this.onRemove=new j,this.onChange=new j}return b.prototype.get=function(a){var b=this;return U.sub(function(c){return V.autoSub(b.onAdd,function(b){var d,e;return d=b[0],e=b[1],a===d?c.refresh():void 0})}),U.sub(function(c){return V.autoSub(b.onChange,function(b){var d,e,f;return e=b[0],d=b[1],f=b[2],a===e?c.refresh():void 0})}),U.sub(function(c){return V.autoSub(b.onRemove,function(b){var d,e;return e=b[0],d=b[1],a===e?c.refresh():void 0})}),this.x[a]},b.prototype.all=function(){var b=this;return U.sub(function(a){return V.autoSub(b.onAdd,function(){return a.refresh()})}),U.sub(function(a){return V.autoSub(b.onChange,function(){return a.refresh()})}),U.sub(function(a){return V.autoSub(b.onRemove,function(){return a.refresh()})}),a.clone(this.x)},b.prototype.realPut=function(a,b){var c;return a in this.x?(c=this.x[a],this.x[a]=b,this.onChange.pub([a,c,b]),c):(this.x[a]=b,void this.onAdd.pub([a,b]))},b.prototype.realRemove=function(a){var b;return b=P(this.x,a),this.onRemove.pub([a,b]),b},b.prototype.cell=function(a){return new t(this,a)},b}(),y=V.SrcMap=function(a){function b(){return ib=b.__super__.constructor.apply(this,arguments)}return d(b,a),b.prototype.put=function(a,b){var c=this;return U.mutating(function(){return c.realPut(a,b)})},b.prototype.remove=function(a){var b=this;return U.mutating(function(){return b.realRemove(a)})},b.prototype.cell=function(a){return new z(this,a)},b}(s),h=V.DepMap=function(a){function b(a){this.f=a,b.__super__.constructor.call(this),V.autoSub(new g(this.f).onSet,function(a){var b,c,d,e,f;c=a[0],e=a[1];for(b in c)d=c[b],b in e||this.realRemove(b);f=[];for(b in e)d=e[b],f.push(this.x[b]!==d?this.realPut(b,d):void 0);return f})}return d(b,a),b}(s),V.liftSpec=function(b){var c,d,e;return a.object(function(){var f,g,h,i;for(h=Object.getOwnPropertyNames(b),i=[],f=0,g=h.length;g>f;f++)c=h[f],e=b[c],null!=e&&(e instanceof V.ObsMap||e instanceof V.ObsCell||e instanceof V.ObsArray)||(d=a.isFunction(e)?null:a.isArray(e)?"array":"cell",i.push([c,{type:d,val:e}]));return i}())},V.lift=function(a,b){var c,d;null==b&&(b=V.liftSpec(a));for(c in b)d=b[c],a[c]=function(){switch(d.type){case"cell":return V.cell(a[c]);case"array":return V.array(a[c]);case"map":return V.map(a[c]);default:return a[c]}}();return a},V.unlift=function(b){var c,d;return a.object(function(){var a;a=[];for(c in b)d=b[c],a.push([c,d instanceof V.ObsCell?d.get():d instanceof V.ObsArray?d.all():d]);return a}())},V.reactify=function(c,d){var e,f,g,h;return a.isArray(c)?(e=V.array(a.clone(c)),Object.defineProperties(c,a.object(function(){var d,g,h,i;for(h=a.functions(e),i=[],d=0,g=h.length;g>d;d++)f=h[d],"length"!==f&&i.push(function(a){var d,f,g;return d=c[a],f=function(){var f,g,h;return f=1<=arguments.length?b.call(arguments,0):[],null!=d&&(g=d.call.apply(d,[c].concat(b.call(f)))),(h=e[a]).call.apply(h,[e].concat(b.call(f))),g},g={configurable:!0,enumerable:!1,value:f,writable:!0},[a,g]}(f));return i}())),c):Object.defineProperties(c,a.object(function(){var a;a=[];for(g in d)h=d[g],a.push(function(a,c){var d,e,f,g,h;switch(d=null,c.type){case"cell":e=V.cell(null!=(g=c.val)?g:null),d={configurable:!0,enumerable:!0,get:function(){return e.get()},set:function(a){return e.set(a)}};break;case"array":f=V.reactify(null!=(h=c.val)?h:[]),d={configurable:!0,enumerable:!0,get:function(){return f.raw(),f},set:function(a){return f.splice.apply(f,[0,f.length].concat(b.call(a))),f}};break;default:throw new Error("Unknown observable type: "+type)}return[a,d]}(g,h));return a}()))},V.autoReactify=function(b){var c,d,e;return V.reactify(b,a.object(function(){var f,g,h,i;for(h=Object.getOwnPropertyNames(b),i=[],f=0,g=h.length;g>f;f++)c=h[f],e=b[c],e instanceof s||e instanceof r||e instanceof q||(d=a.isFunction(e)?null:a.isArray(e)?"array":"cell",i.push([c,{type:d,val:e}]));return i}()))},a.extend(V,{cell:function(a){return new x(a)},array:function(a,b){return new w(a,b)},map:function(a){return new y(a)}}),V.flatten=function(b){return new f(function(){var c;return a(function(){var a,d,e;for(e=[],a=0,d=b.length;d>a;a++)c=b[a],e.push(c instanceof q?c.raw():c instanceof r?c.get():c);return e}()).chain().flatten(!0).filter(function(a){return null!=a}).value()})},G=function(b){var c;return c=a.flatten(b),V.cellToArray(B(function(){return a.flatten(b)}))},V.cellToArray=function(a,b){return new f(function(){return a.get()},b)},V.basicDiff=function(a){return null==a&&(a=V.smartUidify),function(b,c){var d,e,f,g,h,i,j;for(e=J(function(){var c,e,g;for(g=[],d=c=0,e=b.length;e>c;d=++c)f=b[d],g.push([a(f),d]);return g}()),j=[],g=0,h=c.length;h>g;g++)f=c[g],j.push(null!=(i=e[a(f)])?i:-1);return j}},V.uidify=function(a){var b;return null!=(b=a.__rxUid)?b:Object.defineProperty(a,"__rxUid",{enumerable:!1,value:L()}).__rxUid},V.smartUidify=function(b){return a.isObject(b)?V.uidify(b):JSON.stringify(b)},O=function(b,c,d){var e,f,g,h,i,j;if(h=function(){var a,b,c;for(c=[],a=0,b=d.length;b>a;a++)f=d[a],f>=0&&c.push(f);return c}(),a.some(function(){var a,b,c;for(c=[],f=a=0,b=h.length-1;b>=0?b>a:a>b;f=b>=0?++a:--a)c.push(h[f+1]-h[f]<=0);return c}()))return null;for(j=[],g=-1,f=0;f0||i.additions.length>0)&&j.push([i.index,i.count,i.additions]),g=e,f+=1}return j},V.transaction=function(a){return C.transaction(a)},null!=e){e.fn.rx=function(a){var b,c,d,e;return d=this.data("rx-map"),null==d&&this.data("rx-map",d=J()),a in d?d[a]:d[a]=function(){var d=this;switch(a){case"focused":return c=V.cell(this.is(":focus")),this.focus(function(){return c.set(!0)}),this.blur(function(){return c.set(!1)}),c;case"val":return e=V.cell(this.val()),this.change(function(){return e.set(d.val())}),this.on("input",function(){return e.set(d.val())}),e;case"checked":return b=V.cell(this.is(":checked")),this.change(function(){return b.set(d.is(":checked"))}),b;default:throw new Error("Unknown reactive property type")}}.call(this)},W={},u=W.RawHtml=function(){function a(a){this.html=a}return a}(),E=["blur","change","click","dblclick","error","focus","focusin","focusout","hover","keydown","keypress","keyup","load","mousedown","mouseenter","mouseleave","mousemove","mouseout","mouseover","mouseup","ready","resize","scroll","select","submit","toggle","unload"],Z=W.specialAttrs={init:function(a,b){return b.call(a)}},bb=function(a){return Z[a]=function(b,c){return b[a](function(a){return c.call(b,a)})}};for(cb=0,db=E.length;db>cb;cb++)D=E[cb],bb(D);T=["async","autofocus","checked","location","multiple","readOnly","selected","selectedIndex","tagName","nodeName","nodeType","ownerDocument","defaultChecked","defaultSelected"],S=a.object(function(){var a,b,c;for(c=[],a=0,b=T.length;b>a;a++)R=T[a],c.push([R,null]);return c}()),Y=function(a,b,c){return"value"===b?a.val(c):b in S?a.prop(b,c):a.attr(b,c)},X=function(b,c,d,e){return null==e&&(e=a.identity),d instanceof r?V.autoSub(d.onSet,function(a){var d,f;return f=a[0],d=a[1],Y(b,c,e(d))}):Y(b,c,e(d))},W.mkAtts=I=function(a){return function(b){var c,d,e;return e=a.match(/[#](\w+)/),e&&(b.id=e[1]),c=a.match(/\.\w+/g),c&&(b["class"]=function(){var a,b,e;for(e=[],a=0,b=c.length;b>a;a++)d=c[a],e.push(d.replace(/^\./,""));return e}().join(" ")),b}({})},W.mktag=K=function(b){return function(c,d){var f,g,h,i,j,k,l,m,n,o;n=null==c&&null==d?[{},null]:c instanceof Object&&null!=d?[c,d]:a.isString(c)&&null!=d?[I(c),d]:null==d&&a.isString(c)||c instanceof Element||c instanceof u||c instanceof e||a.isArray(c)||c instanceof r||c instanceof q?[{},c]:[c,null],f=n[0],g=n[1],h=e("<"+b+"/>"),o=a.omit(f,a.keys(Z));for(j in o)m=o[j],X(h,j,m);null!=g&&(k=function(b){var c,d,f,g,h;for(h=[],f=0,g=b.length;g>f;f++)if(c=b[f],a.isString(c))h.push(document.createTextNode(c));else if(c instanceof Element)h.push(c);else if(c instanceof u){if(d=e(c.html),1!==d.length)throw new Error("RawHtml must wrap a single element");h.push(d[0])}else{if(!(c instanceof e))throw new Error("Unknown element type in array: "+c.constructor.name+" (must be string, Element, RawHtml, or jQuery objects)");if(1!==c.length)throw new Error("jQuery object must wrap a single element");h.push(c[0])}return h},l=function(b){var c;if(h.html(""),!a.isArray(b)){if(a.isString(b)||b instanceof Element||b instanceof u||b instanceof e)return l([b]);throw new Error("Unknown type for element contents: "+b.constructor.name+" (accepted types: string, Element, RawHtml, jQuery object of single element, or array of the aforementioned)")}c=k(b),h.append(c)},g instanceof q?V.autoSub(g.onChange,function(a){var b,c,d,e;return c=a[0],d=a[1],b=a[2],h.contents().slice(c,c+d.length).remove(),e=k(b),c===h.contents().length?h.append(e):h.contents().eq(c).before(e)}):g instanceof r?V.autoSub(g.onSet,function(a){var b,c;return b=a[0],c=a[1],l(c)}):l(g));for(i in f)i in Z&&Z[i](h,f[i],f,g);return h}},ab=["html","head","title","base","link","meta","style","script","noscript","body","body","section","nav","article","aside","h1","h2","h3","h4","h5","h6","h1","h6","header","footer","address","main","main","p","hr","pre","blockquote","ol","ul","li","dl","dt","dd","dd","figure","figcaption","div","a","em","strong","small","s","cite","q","dfn","abbr","data","time","code","var","samp","kbd","sub","sup","i","b","u","mark","ruby","rt","rp","bdi","bdo","span","br","wbr","ins","del","img","iframe","embed","object","param","object","video","audio","source","video","audio","track","video","audio","canvas","map","area","area","map","svg","math","table","caption","colgroup","col","tbody","thead","tfoot","tr","td","th","form","fieldset","legend","fieldset","label","input","button","select","datalist","optgroup","option","select","datalist","textarea","keygen","output","progress","meter","details","summary","details","menuitem","menu"],W.tags=a.object(function(){var a,b,c;for(c=[],a=0,b=ab.length;b>a;a++)_=ab[a],c.push([_,W.mktag(_)]);return c}()),W.rawHtml=function(a){return new u(a)},W.importTags=function(b){return a(null!=b?b:jb).extend(W.tags)},W.cast=function(b,c){var d,e,f;return a.object(function(){var g;g=[];for(d in b)f=b[d],e=function(){switch(c[d]){case"array":if(f instanceof V.ObsArray)return f;if(a.isArray(f))return new V.DepArray(function(){return f});if(f instanceof V.ObsCell)return new V.DepArray(function(){return f.get()});throw new Error("Cannot cast to array: "+f.constructor.name);case"cell":return f instanceof V.ObsCell?f:B(function(){return f});default:return f}}(),g.push([d,e]);return g}())},W.cssify=function(b){var c,d;return function(){var e;e=[];for(c in b)d=b[c],null!=d&&e.push(""+a.str.dasherize(c)+": "+(a.isNumber(d)?d+"px":d)+";");return e}().join(" ")},Z.style=function(b,c){return X(b,"style",c,function(b){return a.isString(b)?b:W.cssify(b)})},W.smushClasses=function(b){return a(b).chain().flatten().compact().value().join(" ").replace(/\s+/," ").trim()},Z["class"]=function(b,c){return X(b,"class",c,function(b){return a.isString(b)?b:W.smushClasses(b)})}}return V.rxt=W,V},function(a,b,c){var d,e,f;if(null!=("undefined"!=typeof define&&null!==define?define.amd:void 0))return define(c,b);if(null!=("undefined"!=typeof module&&null!==module?module.exports:void 0))return e=require("underscore"),f=require("underscore.string"),d=b(e,f),module.exports=d;if(null!=a._&&null!=a.$)return a.rx=b(a._,void 0,a.$);throw"Dependencies are not met for reactive: _ and $ not found"}(this,a,["underscore","underscore.string","jquery"])}).call(this); \ No newline at end of file diff --git a/ajax/libs/reactive-coffee/package.json b/ajax/libs/reactive-coffee/package.json index c16645f25..df1a558bb 100644 --- a/ajax/libs/reactive-coffee/package.json +++ b/ajax/libs/reactive-coffee/package.json @@ -1,7 +1,7 @@ { "name": "reactive-coffee", "filename": "reactive-coffee.min.js", - "version": "1.1.0", + "version": "1.1.1", "description": "A lightweight CoffeeScript library/DSL for reactive programming and for declaratively building scalable web UIs.", "homepage": "http://yang.github.io/reactive-coffee/", "keywords": [ diff --git a/ajax/libs/sprintf/0.0.7/sprintf.js b/ajax/libs/sprintf/0.0.7/sprintf.js new file mode 100644 index 000000000..03075221a --- /dev/null +++ b/ajax/libs/sprintf/0.0.7/sprintf.js @@ -0,0 +1,134 @@ +/*! sprintf.js | Copyright (c) 2007-2013 Alexandru Marasteanu | 3 clause BSD license */ + +(function(ctx) { + var sprintf = function() { + if (!sprintf.cache.hasOwnProperty(arguments[0])) { + sprintf.cache[arguments[0]] = sprintf.parse(arguments[0]); + } + return sprintf.format.call(null, sprintf.cache[arguments[0]], arguments); + }; + + sprintf.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = arg >>> 0; break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + sprintf.cache = {}; + + sprintf.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + var vsprintf = function(fmt, argv, _argv) { + _argv = argv.slice(0); + _argv.splice(0, 0, fmt); + return sprintf.apply(null, _argv); + }; + + /** + * helpers + */ + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + /** + * export to either browser or node.js + */ + ctx.sprintf = sprintf; + ctx.vsprintf = vsprintf; +})(typeof exports != "undefined" ? exports : window); diff --git a/ajax/libs/sprintf/0.0.7/sprintf.min.js b/ajax/libs/sprintf/0.0.7/sprintf.min.js new file mode 100644 index 000000000..23d5fefbd --- /dev/null +++ b/ajax/libs/sprintf/0.0.7/sprintf.min.js @@ -0,0 +1 @@ +/*! sprintf.js | Copyright (c) 2007-2013 Alexandru Marasteanu | 3 clause BSD license */(function(e){function r(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function i(e,t){for(var n=[];t>0;n[--t]=e);return n.join("")}var t=function(){return t.cache.hasOwnProperty(arguments[0])||(t.cache[arguments[0]]=t.parse(arguments[0])),t.format.call(null,t.cache[arguments[0]],arguments)};t.format=function(e,n){var s=1,o=e.length,u="",a,f=[],l,c,h,p,d,v;for(l=0;l>>=0;break;case"x":a=a.toString(16);break;case"X":a=a.toString(16).toUpperCase()}a=/[def]/.test(h[8])&&h[3]&&a>=0?"+"+a:a,d=h[4]?h[4]=="0"?"0":h[4].charAt(1):" ",v=h[6]-String(a).length,p=h[6]?i(d,v):"",f.push(h[5]?a+p:p+a)}}return f.join("")},t.cache={},t.parse=function(e){var t=e,n=[],r=[],i=0;while(t){if((n=/^[^\x25]+/.exec(t))!==null)r.push(n[0]);else if((n=/^\x25{2}/.exec(t))!==null)r.push("%");else{if((n=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(t))===null)throw"[sprintf] huh?";if(n[2]){i|=1;var s=[],o=n[2],u=[];if((u=/^([a-z_][a-z_\d]*)/i.exec(o))===null)throw"[sprintf] huh?";s.push(u[1]);while((o=o.substring(u[0].length))!=="")if((u=/^\.([a-z_][a-z_\d]*)/i.exec(o))!==null)s.push(u[1]);else{if((u=/^\[(\d+)\]/.exec(o))===null)throw"[sprintf] huh?";s.push(u[1])}n[2]=s}else i|=2;if(i===3)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";r.push(n)}t=t.substring(n[0].length)}return r};var n=function(e,n,r){return r=n.slice(0),r.splice(0,0,e),t.apply(null,r)};e.sprintf=t,e.vsprintf=n})(typeof exports!="undefined"?exports:window); \ No newline at end of file diff --git a/ajax/libs/sprintf/package.json b/ajax/libs/sprintf/package.json new file mode 100644 index 000000000..9583ac778 --- /dev/null +++ b/ajax/libs/sprintf/package.json @@ -0,0 +1,25 @@ +{ + "name": "sprintf", + "npmName": "sprintf-js", + "npmFileMap": [{ + "basePath": "/src/", + "files": [ + "sprintf.js", + "sprintf.min.js" + ] + }], + "filename": "sprintf.min.js", + "version": "0.0.7", + "description": "JavaScript sprintf implementation", + "homepage:": "https://www.npmjs.org/package/sprintf-js", + "repository": { + "type": "git", + "url": "https://github.com/alexei/sprintf.js.git" + }, + "author": { + "name": "Alexandru Marasteanu", + "email": "hello@alexei.ro", + "url": "http://alexei.ro/" + }, + "license": "BSD" +}