Skip to content

Instantly share code, notes, and snippets.

@rodriguezartav
Created December 22, 2013 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodriguezartav/8089344 to your computer and use it in GitHub Desktop.
Save rodriguezartav/8089344 to your computer and use it in GitHub Desktop.
requirebin sketch
require('rspine');
require=function e(t,r,n){function i(o,u){if(!r[o]){if(!t[o]){var h="function"==typeof require&&require;if(!u&&h)return h(o,!0);if(s)return s(o,!0);throw Error("Cannot find module '"+o+"'")}var c=r[o]={exports:{}};t[o][0].call(c.exports,function(e){var r=t[o][1][e];return i(r?r:e)},c,c.exports,e,t,r,n)}return r[o].exports}for(var s="function"==typeof require&&require,o=0;n.length>o;o++)i(n[o]);return i}({AnybCS:[function(t,e){e.exports=t("./lib/rspine")},{"./lib/rspine":3}],rspine:[function(t,e){e.exports=t("AnybCS")},{}],3:[function(t,e){(function(){var t,r,n,i,s,o,u,h,c,l,a,p,f=[].slice,d=[].indexOf||function(t){for(var e=0,r=this.length;r>e;e++)if(e in this&&this[e]===t)return e;return-1},g={}.hasOwnProperty,y=function(t,e){function r(){this.constructor=t}for(var n in e)g.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},v=function(t,e){return function(){return t.apply(e,arguments)}};n={bind:function(t,e){var r,n,i,s,o;for(n=t.split(" "),r=this.hasOwnProperty("_callbacks")&&this._callbacks||(this._callbacks={}),s=0,o=n.length;o>s;s++)i=n[s],r[i]||(r[i]=[]),r[i].push(e);return this},one:function(t,e){var r;return this.bind(t,r=function(){return this.unbind(t,r),e.apply(this,arguments)})},trigger:function(){var t,e,r,n,i,s,o;if(t=arguments.length>=1?f.call(arguments,0):[],r=t.shift(),n=this.hasOwnProperty("_callbacks")&&(null!=(o=this._callbacks)?o[r]:void 0)){for(i=0,s=n.length;s>i&&(e=n[i],e.apply(this,t)!==!1);i++);return!0}},listenTo:function(t,e,r){return t.bind(e,r),this.listeningTo||(this.listeningTo=[]),this.listeningTo.push({obj:t,ev:e,callback:r}),this},listenToOnce:function(t,e,r){var n,i;return i=this.listeningToOnce||(this.listeningToOnce=[]),t.bind(e,n=function(){var s,o,u,h,c;for(o=-1,s=h=0,c=i.length;c>h;s=++h)u=i[s],u.obj===t&&u.ev===e&&u.callback===r&&(o=s);return t.unbind(e,n),-1!==o&&i.splice(o,1),r.apply(this,arguments)}),i.push({obj:t,ev:e,callback:r,handler:n}),this},stopListening:function(e,r){var n,i,s,o,u,h,c,l,a,p,f,d,g,y,v;if(0===arguments.length){for(g=[this.listeningTo,this.listeningToOnce],c=0,p=g.length;p>c;c++)if(u=g[c])for(l=0,f=u.length;f>l;l++)h=u[l],h.obj.unbind(h.ev,h.handler||h.callback);return this.listeningTo=void 0,this.listeningToOnce=void 0}if(e){for(y=[this.listeningTo,this.listeningToOnce],v=[],a=0,d=y.length;d>a;a++)u=y[a],u&&(r=r?r.split(" "):[void 0],v.push(function(){var e,c,l;for(l=[],e=0,c=r.length;c>e;e++)n=r[e],l.push(function(){var e,r,c;for(c=[],o=e=r=u.length-1;0>=r?0>=e:e>=0;o=0>=r?++e:--e)h=u[o],n&&n!==h.ev?n?(i=h.ev.split(" "),~(s=i.indexOf(n))?(i.splice(s,1),h.ev=t.trim(i.join(" ")),c.push(h.obj.unbind(n,h.handler||h.callback))):c.push(void 0)):c.push(void 0):(h.obj.unbind(h.ev,h.handler||h.callback),-1!==o?c.push(u.splice(o,1)):c.push(void 0));return c}());return l}()));return v}},unbind:function(t,e){var r,n,i,s,o,u,h,c,l,a;if(0===arguments.length)return this._callbacks={},this;if(!t)return this;for(n=t.split(" "),u=0,c=n.length;c>u;u++)if(o=n[u],s=null!=(a=this._callbacks)?a[o]:void 0)if(e){for(i=h=0,l=s.length;l>h;i=++h)if(r=s[i],r===e){s=s.slice(),s.splice(i,1),this._callbacks[o]=s;break}}else delete this._callbacks[o];return this}},n.on=n.bind,n.off=n.unbind,i={trace:!0,logPrefix:"(App)",log:function(){var t;return t=arguments.length>=1?f.call(arguments,0):[],this.trace?(this.logPrefix&&t.unshift(this.logPrefix),"undefined"!=typeof console&&null!==console&&"function"==typeof console.log&&console.log.apply(console,t),this):void 0}},p=["included","extended"],o=function(){function t(){"function"==typeof this.init&&this.init.apply(this,arguments)}return t.include=function(t){var e,r,n;if(!t)throw Error("include(obj) requires obj");for(e in t)r=t[e],0>d.call(p,e)&&(this.prototype[e]=r);return null!=(n=t.included)&&n.apply(this),this},t.extend=function(t){var e,r,n;if(!t)throw Error("extend(obj) requires obj");for(e in t)r=t[e],0>d.call(p,e)&&(this[e]=r);return null!=(n=t.extended)&&n.apply(this),this},t.proxy=function(t){var e=this;return function(){return t.apply(e,arguments)}},t.prototype.proxy=function(t){var e=this;return function(){return t.apply(e,arguments)}},t}(),s=function(e){function r(t){r.__super__.constructor.apply(this,arguments),t&&this.load(t),this.cid=(null!=t?t.cid:void 0)||this.constructor.uid("c-")}return y(r,e),r.extend(n),r.records=[],r.irecords={},r.attributes=[],r.configure=function(){var t,e;return e=arguments[0],t=arguments.length>=2?f.call(arguments,1):[],this.className=e,this.deleteAll(),t.length&&(this.attributes=t),this.attributes&&(this.attributes=a(this.attributes)),this.attributes||(this.attributes=[]),this.unbind(),this},r.toString=function(){return""+this.className+"("+this.attributes.join(", ")+")"},r.find=function(t){var e;if(e=this.exists(t),!e)throw Error('"'+this.className+'" model could not find a record for the ID "'+t+'"');return e},r.exists=function(t){var e;return null!=(e=this.irecords[t])?e.clone():void 0},r.addRecord=function(t){return t.id&&this.irecords[t.id]&&this.irecords[t.id].remove(),t.id||(t.id=t.cid),this.records.push(t),this.irecords[t.id]=t,this.irecords[t.cid]=t},r.refresh=function(t,e){var r,n,i,s,o;for(null==e&&(e={}),e.clear&&this.deleteAll(),n=this.fromJSON(t),c(n)||(n=[n]),s=0,o=n.length;o>s;s++)r=n[s],this.addRecord(r);return this.sort(),i=this.cloneArray(n),this.trigger("refresh",i,e),i},r.select=function(t){var e,r,n,i,s;for(i=this.records,s=[],r=0,n=i.length;n>r;r++)e=i[r],t(e)&&s.push(e.clone());return s},r.findByAttribute=function(t,e){var r,n,i,s;for(s=this.records,n=0,i=s.length;i>n;n++)if(r=s[n],r[t]===e)return r.clone();return null},r.findAllByAttribute=function(t,e){return this.select(function(r){return r[t]===e})},r.each=function(t){var e,r,n,i,s;for(i=this.records,s=[],r=0,n=i.length;n>r;r++)e=i[r],s.push(t(e.clone()));return s},r.all=function(){return this.cloneArray(this.records)},r.first=function(){var t;return null!=(t=this.records[0])?t.clone():void 0},r.last=function(){var t;return null!=(t=this.records[this.records.length-1])?t.clone():void 0},r.count=function(){return this.records.length},r.deleteAll=function(){return this.records=[],this.irecords={}},r.destroyAll=function(t){var e,r,n,i,s;for(i=this.records,s=[],r=0,n=i.length;n>r;r++)e=i[r],s.push(e.destroy(t));return s},r.update=function(t,e,r){return this.find(t).updateAttributes(e,r)},r.create=function(t,e){var r;return r=new this(t),r.save(e)},r.destroy=function(t,e){return this.find(t).destroy(e)},r.change=function(t){return"function"==typeof t?this.bind("change",t):this.trigger.apply(this,["change"].concat(f.call(arguments)))},r.fetch=function(t){return"function"==typeof t?this.bind("fetch",t):this.trigger.apply(this,["fetch"].concat(f.call(arguments)))},r.toJSON=function(){return this.records},r.fromJSON=function(t){var e,r,n,i;if(t){if("string"==typeof t&&(t=JSON.parse(t)),c(t)){for(i=[],r=0,n=t.length;n>r;r++)e=t[r],i.push(new this(e));return i}return new this(t)}},r.fromForm=function(){var t;return(t=new this).fromForm.apply(t,arguments)},r.sort=function(){return this.comparator&&this.records.sort(this.comparator),this},r.cloneArray=function(t){var e,r,n,i;for(i=[],r=0,n=t.length;n>r;r++)e=t[r],i.push(e.clone());return i},r.idCounter=0,r.uid=function(t){var e;return null==t&&(t=""),e=t+this.idCounter++,this.exists(e)&&(e=this.uid(t)),e},r.prototype.isNew=function(){return!this.exists()},r.prototype.isValid=function(){return!this.validate()},r.prototype.validate=function(){},r.prototype.load=function(t){var e,r;t.id&&(this.id=t.id);for(e in t)r=t[e],t.hasOwnProperty(e)&&"function"==typeof this[e]?this[e](r):this[e]=r;return this},r.prototype.attributes=function(){var t,e,r,n,i;for(e={},i=this.constructor.attributes,r=0,n=i.length;n>r;r++)t=i[r],t in this&&(e[t]="function"==typeof this[t]?this[t]():this[t]);return this.id&&(e.id=this.id),e},r.prototype.eql=function(t){return!!(t&&t.constructor===this.constructor&&t.cid===this.cid||t.id&&t.id===this.id)},r.prototype.save=function(t){var e,r;return null==t&&(t={}),t.validate!==!1&&(e=this.validate())?(this.trigger("error",e),!1):(this.trigger("beforeSave",t),r=this.isNew()?this.create(t):this.update(t),this.stripCloneAttrs(),this.trigger("save",t),r)},r.prototype.stripCloneAttrs=function(){var t,e;if(!this.hasOwnProperty("cid")){for(t in this)g.call(this,t)&&(e=this[t],this.constructor.attributes.indexOf(t)>-1&&delete this[t]);return this}},r.prototype.updateAttribute=function(t,e,r){var n;return n={},n[t]=e,this.updateAttributes(n,r)},r.prototype.updateAttributes=function(t,e){return this.load(t),this.save(e)},r.prototype.changeID=function(t){var e;if(t!==this.id)return e=this.constructor.irecords,e[t]=e[this.id],delete e[this.id],this.id=t,this.save()},r.prototype.remove=function(){var t,e,r,n,i;for(r=this.constructor.records.slice(0),t=n=0,i=r.length;i>n;t=++n)if(e=r[t],this.eql(e)){r.splice(t,1);break}return this.constructor.records=r,delete this.constructor.irecords[this.id],delete this.constructor.irecords[this.cid]},r.prototype.destroy=function(t){return null==t&&(t={}),this.trigger("beforeDestroy",t),this.remove(),this.destroyed=!0,this.trigger("destroy",t),this.trigger("change","destroy",t),this.listeningTo&&this.stopListening(),this.unbind(),this},r.prototype.dup=function(t){var e;return null==t&&(t=!0),e=this.attributes(),t?delete e.id:e.cid=this.cid,new this.constructor(e)},r.prototype.clone=function(){return h(this)},r.prototype.reload=function(){var t;return this.isNew()?this:(t=this.constructor.find(this.id),this.load(t.attributes()),t)},r.prototype.refresh=function(t){var e;return e=this.constructor.irecords[this.id],e.load(t),this.trigger("refresh"),this},r.prototype.toJSON=function(){return this.attributes()},r.prototype.toString=function(){return"<"+this.constructor.className+" ("+JSON.stringify(this)+")>"},r.prototype.fromForm=function(e){var r,n,i,s,o,u,h,c,l,a,p,f,d,g;for(s={},f=t(e).find("[type=checkbox]:not([value])"),o=0,c=f.length;c>o;o++)r=f[o],s[r.name]=t(r).prop("checked");for(d=t(e).find('[type=checkbox][name$="[]"]'),u=0,l=d.length;l>u;u++)r=d[u],i=r.name.replace(/\[\]$/,""),s[i]||(s[i]=[]),t(r).prop("checked")&&s[i].push(r.value);for(g=t(e).serializeArray(),h=0,a=g.length;a>h;h++)n=g[h],s[p=n.name]||(s[p]=n.value);return this.load(s)},r.prototype.exists=function(){return this.constructor.exists(this.id)},r.prototype.update=function(t){var e,r;return this.trigger("beforeUpdate",t),r=this.constructor.irecords,r[this.id].load(this.attributes()),this.constructor.sort(),e=r[this.id].clone(),e.trigger("update",t),e.trigger("change","update",t),e},r.prototype.create=function(t){var e,r;return this.trigger("beforeCreate",t),this.id||(this.id=this.cid),r=this.dup(!1),this.constructor.addRecord(r),this.constructor.sort(),e=r.clone(),e.trigger("create",t),e.trigger("change","create",t),e},r.prototype.bind=function(t,e){var r,n,i,s,o,u,h=this;for(this.constructor.bind(t,r=function(t){return t&&h.eql(t)?e.apply(h,arguments):void 0}),u=t.split(" "),i=function(t){var n;return h.constructor.bind("unbind",n=function(i,s,o){if(i&&h.eql(i)){if(s&&s!==t)return;if(o&&o!==e)return;return h.constructor.unbind(t,r),h.constructor.unbind("unbind",n)}})},s=0,o=u.length;o>s;s++)n=u[s],i(n);return this},r.prototype.one=function(t,e){var r,n=this;return this.bind(t,r=function(){return n.unbind(t,r),e.apply(n,arguments)})},r.prototype.trigger=function(){var t,e;return t=arguments.length>=1?f.call(arguments,0):[],t.splice(1,0,this),(e=this.constructor).trigger.apply(e,t)},r.prototype.listenTo=function(){return n.listenTo.apply(this,arguments)},r.prototype.listenToOnce=function(){return n.listenToOnce.apply(this,arguments)},r.prototype.stopListening=function(){return n.stopListening.apply(this,arguments)},r.prototype.unbind=function(t,e){var r,n,i,s,o;if(0===arguments.length)return this.trigger("unbind");if(t){for(s=t.split(" "),o=[],n=0,i=s.length;i>n;n++)r=s[n],o.push(this.trigger("unbind",r,e));return o}},r}(o),s.prototype.on=s.prototype.bind,s.prototype.off=s.prototype.unbind,r=function(e){function r(e){this.release=v(this.release,this);var n,i,s,o,u;this.options=e,u=this.options;for(i in u)o=u[i],this[i]=o;for(this.el||(this.el=document.createElement(this.tag)),this.el=t(this.el),this.$el=this.el,this.className&&this.el.addClass(this.className),this.attributes&&this.el.attr(this.attributes),this.events||(this.events=this.constructor.events),this.elements||(this.elements=this.constructor.elements),n=this;s=n.constructor.__super__;)s.events&&(this.events=t.extend({},s.events,this.events)),s.elements&&(this.elements=t.extend({},s.elements,this.elements)),n=s;this.events&&this.delegateEvents(this.events),this.elements&&this.refreshElements(),r.__super__.constructor.apply(this,arguments)}return y(r,e),r.include(n),r.include(i),r.prototype.eventSplitter=/^(\S+)\s*(.*)$/,r.prototype.tag="div",r.prototype.release=function(){return this.trigger("release",this),this.el.remove(),this.unbind(),this.stopListening()},r.prototype.$=function(e){return t(e,this.el)},r.prototype.delegateEvents=function(t){var e,r,n,i,s,o,u=this;o=[];for(r in t){if(i=t[r],"function"==typeof i)i=function(t){return function(){return t.apply(u,arguments),!0}}(i);else{if(!this[i])throw Error(""+i+" doesn't exist");i=function(t){return function(){return u[t].apply(u,arguments),!0}}(i)}n=r.match(this.eventSplitter),e=n[1],s=n[2],""===s?o.push(this.el.bind(e,i)):o.push(this.el.on(e,s,i))}return o},r.prototype.refreshElements=function(){var t,e,r,n;r=this.elements,n=[];for(t in r)e=r[t],n.push(this[e]=this.$(t));return n},r.prototype.delay=function(t,e){return setTimeout(this.proxy(t),e||0)},r.prototype.html=function(t){return this.el.html(t.el||t),this.refreshElements(),this.el},r.prototype.append=function(){var t,e,r;return e=arguments.length>=1?f.call(arguments,0):[],e=function(){var r,n,i;for(i=[],r=0,n=e.length;n>r;r++)t=e[r],i.push(t.el||t);return i}(),(r=this.el).append.apply(r,e),this.refreshElements(),this.el},r.prototype.appendTo=function(t){return this.el.appendTo(t.el||t),this.refreshElements(),this.el},r.prototype.prepend=function(){var t,e,r;return e=arguments.length>=1?f.call(arguments,0):[],e=function(){var r,n,i;for(i=[],r=0,n=e.length;n>r;r++)t=e[r],i.push(t.el||t);return i}(),(r=this.el).prepend.apply(r,e),this.refreshElements(),this.el},r.prototype.replace=function(e){var r,n,i;return e=e.el||e,"string"==typeof e&&(e=t.trim(e)),i=[this.el,t((null!=(n=t.parseHTML(e))?n[0]:void 0)||e)],r=i[0],this.el=i[1],r.replaceWith(this.el),this.delegateEvents(this.events),this.refreshElements(),this.el},r}(o),t=("undefined"!=typeof window&&null!==window?window.jQuery:void 0)||("undefined"!=typeof window&&null!==window?window.Zepto:void 0)||function(t){return t},h=Object.create||function(t){var e;return e=function(){},e.prototype=t,new e},c=function(t){return"[object Array]"===Object.prototype.toString.call(t)},l=function(t){var e;if(!t)return!0;for(e in t)return!1;return!0},a=function(t){return Array.prototype.slice.call(t,0)},u=this.RSpine={},e!==void 0&&null!==e&&(e.exports=u),u.version="0.0.1",u.isArray=c,u.isBlank=l,u.$=t,u.Events=n,u.Log=i,u.Module=o,u.Controller=r,u.Model=s,o.extend.call(u,n),o.create=o.sub=r.create=r.sub=s.sub=function(t,e){var r,n;return r=function(t){function e(){return n=e.__super__.constructor.apply(this,arguments)}return y(e,t),e}(this),t&&r.include(t),e&&r.extend(e),"function"==typeof r.unbind&&r.unbind(),r},s.setup=function(t,e){var r,n;return null==e&&(e=[]),r=function(t){function e(){return n=e.__super__.constructor.apply(this,arguments)}return y(e,t),e}(this),r.configure.apply(r,[t].concat(f.call(e))),r},u.Class=o}).call(this)},{}]},{},[]),require("rspine");
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; }
body, html { height: 100%; width: 100%; }</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment