-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.min.js
More file actions
2 lines (2 loc) · 32.2 KB
/
scripts.min.js
File metadata and controls
2 lines (2 loc) · 32.2 KB
1
2
!function(a){"function"==typeof define&&define.amd?define(["underscore","jquery"],a):"object"==typeof exports?a(require("underscore"),require("jquery")):a(this._,this.jQuery||this.Zepto||this.ender||this.$)}(function(a,b){"use strict";var c,d="undefined"==typeof window?exports:window,e=d.Backbone;c="undefined"!=typeof exports?exports:d.Backbone={};var f=a=c.utils=a||{};c.$=b;var g=[];g.push;var h=g.slice;g.splice,c.noConflict=function(){return d.Backbone=e,this},c.emulateHTTP=!1,c.emulateJSON=!1,c.extend=function(b,c){var d,e=this;d=b&&hasOwnProperty.call(b,"constructor")?b.constructor:function(){return e.apply(this,arguments)},a.extend(d,e,c);var f=function(){this.constructor=d};return f.prototype=e.prototype,d.prototype=new f,b&&a.extend(d.prototype,b),d.__super__=e.prototype,d};var i=function(){throw new Error('A "url" property or function must be specified')},j=function(a,b){var c=b.error;b.error=function(d){c&&c(a,d,b),a.trigger("error",a,d,b)}};f.result=function(a,b){var c=a?a[b]:void 0;return"function"==typeof c?a[b]():c},f.defaults=function(a){return[].slice.call(arguments,1).forEach(function(b){for(var c in b)void 0===a[c]&&(a[c]=b[c])}),a},f.extend=function(a){return[].slice.call(arguments,1).forEach(function(b){for(var c in b)a[c]=b[c]}),a};var k={"&":"&","<":"<",">":">",'"':""","'":"'"};f.escape=function(a){return null==a?"":String(a).replace(/[&<>"']/g,function(a){return k[a]})},f.sortedIndex=function(a,b,c,d){c=null==c?Function.prototype:"function"==typeof c?c:function(a){return a[c]};for(var e=c.call(d,b),f=0,g=a.length;g>f;){var h=f+g>>>1;c.call(d,a[h])<e?f=h+1:g=h}return f},f.sortBy=function(a,b,c){var d="function"==typeof b?b:function(a){return a[b]};return a.map(function(a,b,e){return{value:a,index:b,criteria:d.call(c,a,b,e)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;if(c!==d){if(c>d||void 0===c)return 1;if(d>c||void 0===d)return-1}return a.index-b.index}).map(function(a){return a.value})};var l=0;f.uniqueId=function(a){var b=++l+"";return a?a+b:b};var m=function(a,b,c,d){if(a===b)return 0!==a||1/a==1/b;if(null==a||null==b)return a===b;var e=Object.prototype.toString.call(a);if(e!=Object.prototype.toString.call(b))return!1;switch(e){case"[object String]":return a==String(b);case"[object Number]":return a!==+a?b!==+b:0===a?1/a===1/b:a===+b;case"[object Date]":case"[object Boolean]":return+a==+b;case"[object RegExp]":return a.source==b.source&&a.global==b.global&&a.multiline==b.multiline&&a.ignoreCase==b.ignoreCase}if("object"!=typeof a||"object"!=typeof b)return!1;for(var f=c.length;f--;)if(c[f]==a)return d[f]==b;var g=a.constructor,h=b.constructor;if(g!==h&&!("function"==typeof g&&g instanceof g&&"function"==typeof h&&h instanceof h))return!1;c.push(a),d.push(b);var i=0,j=!0;if("[object Array]"==e){if(i=a.length,j=i==b.length)for(;i--&&(j=m(a[i],b[i],c,d)););}else{for(var k in a)if(hasOwnProperty.call(a,k)&&(i++,!(j=hasOwnProperty.call(b,k)&&m(a[k],b[k],c,d))))break;if(j){for(k in b)if(hasOwnProperty.call(b,k)&&!i--)break;j=!i}}return c.pop(),d.pop(),j};f.isEqual=function(a,b){return m(a,b,[],[])},f.matchesSelector=function(){var a,b="MatchesSelector",c=document.createElement("div");if(["matches","webkit"+b,"moz"+b,"ms"+b].some(function(b){var d=b in c;return a=b,d}),!a)throw new Error("Element#matches is not supported");return function(b,c){return b[a](c)}}();var n=c.Events={on:function(a,b,c){if(!p(this,"on",a,[b,c])||!b)return this;this._events||(this._events={});var d=this._events[a]||(this._events[a]=[]);return d.push({callback:b,context:c,ctx:c||this}),this},once:function(a,b,c){if(!p(this,"once",a,[b,c])||!b)return this;var d,e=this,f=function(){d||(d=!0,e.off(a,f),b.apply(this,arguments))};return f._callback=b,this.on(a,f,c)},off:function(a,b,c){var d,e,f,g,h,i,j,k;if(!this._events||!p(this,"off",a,[b,c]))return this;if(!a&&!b&&!c)return this._events={},this;for(g=a?[a]:Object.keys(this._events),h=0,i=g.length;i>h;h++)if(a=g[h],f=this._events[a]){if(this._events[a]=d=[],b||c)for(j=0,k=f.length;k>j;j++)e=f[j],(b&&b!==e.callback&&b!==e.callback._callback||c&&c!==e.context)&&d.push(e);d.length||delete this._events[a]}return this},trigger:function(a){if(!this._events)return this;var b=h.call(arguments,1);if(!p(this,"trigger",a,b))return this;var c=this._events[a],d=this._events.all;return c&&q(c,b),d&&q(d,arguments),this},stopListening:function(a,b,c){var d=this._listeningTo;if(!d)return this;var e=!b&&!c;c||"object"!=typeof b||(c=this),a&&((d={})[a._listenId]=a);for(var f in d)a=d[f],a.off(b,c,this),(e||!Object.keys(a._events).length)&&delete this._listeningTo[f];return this}},o=/\s+/,p=function(a,b,c,d){if(!c)return!0;if("object"==typeof c){for(var e in c)a[b].apply(a,[e,c[e]].concat(d));return!1}if(o.test(c)){for(var f=c.split(o),g=0,h=f.length;h>g;g++)a[b].apply(a,[f[g]].concat(d));return!1}return!0},q=function(a,b){var c,d=-1,e=a.length,f=b[0],g=b[1],h=b[2];switch(b.length){case 0:for(;++d<e;)(c=a[d]).callback.call(c.ctx);return;case 1:for(;++d<e;)(c=a[d]).callback.call(c.ctx,f);return;case 2:for(;++d<e;)(c=a[d]).callback.call(c.ctx,f,g);return;case 3:for(;++d<e;)(c=a[d]).callback.call(c.ctx,f,g,h);return;default:for(;++d<e;)(c=a[d]).callback.apply(c.ctx,b)}},r={listenTo:"on",listenToOnce:"once"};Object.keys(r).forEach(function(b){var c=r[b];n[b]=function(b,d,e){var f=this._listeningTo||(this._listeningTo={}),g=b._listenId||(b._listenId=a.uniqueId("l"));return f[g]=b,e||"object"!=typeof d||(e=this),b[c](d,e,this),this}}),n.bind=n.on,n.unbind=n.off;var s=c.Model=function(b,c){var d=b||{};c||(c={}),this.cid=a.uniqueId("c"),this.attributes=Object.create(null),c.collection&&(this.collection=c.collection),c.parse&&(d=this.parse(d,c)||{}),d=a.defaults({},d,a.result(this,"defaults")),this.set(d,c),this.changed=Object.create(null),this.initialize.apply(this,arguments)};if(a.extend(s.prototype,n,{changed:null,validationError:null,idAttribute:"id",initialize:function(){},toJSON:function(){return a.extend(Object.create(null),this.attributes)},sync:function(){return c.sync.apply(this,arguments)},get:function(a){return this.attributes[a]},escape:function(b){return a.escape(this.get(b))},has:function(a){return null!=this.get(a)},set:function(b,c,d){var e,f,g,h,i,j,k,l;if(null==b)return this;if("object"==typeof b?(f=b,d=c):(f={})[b]=c,d||(d={}),!this._validate(f,d))return!1;g=d.unset,i=d.silent,h=[],j=this._changing,this._changing=!0,j||(this._previousAttributes=a.extend(Object.create(null),this.attributes),this.changed={}),l=this.attributes,k=this._previousAttributes,this.idAttribute in f&&(this.id=f[this.idAttribute]);for(e in f)c=f[e],a.isEqual(l[e],c)||h.push(e),a.isEqual(k[e],c)?delete this.changed[e]:this.changed[e]=c,g?delete l[e]:l[e]=c;if(!i){h.length&&(this._pending=!0);for(var m=0,n=h.length;n>m;m++)this.trigger("change:"+h[m],this,l[h[m]],d)}if(j)return this;if(!i)for(;this._pending;)this._pending=!1,this.trigger("change",this,d);return this._pending=!1,this._changing=!1,this},unset:function(b,c){return this.set(b,void 0,a.extend({},c,{unset:!0}))},clear:function(b){var c={};for(var d in this.attributes)c[d]=void 0;return this.set(c,a.extend({},b,{unset:!0}))},hasChanged:function(a){return null==a?!!Object.keys(this.changed).length:hasOwnProperty.call(this.changed,a)},changedAttributes:function(b){if(!b)return this.hasChanged()?a.extend(Object.create(null),this.changed):!1;var c,d=!1,e=this._changing?this._previousAttributes:this.attributes;for(var f in b)a.isEqual(e[f],c=b[f])||((d||(d={}))[f]=c);return d},previous:function(a){return null!=a&&this._previousAttributes?this._previousAttributes[a]:null},previousAttributes:function(){return a.extend(Object.create(null),this._previousAttributes)},fetch:function(b){b=b?a.extend({},b):{},void 0===b.parse&&(b.parse=!0);var c=this,d=b.success;return b.success=function(a){return c.set(c.parse(a,b),b)?(d&&d(c,a,b),c.trigger("sync",c,a,b),void 0):!1},j(this,b),this.sync("read",this,b)},save:function(b,c,d){var e,f,g,h=this.attributes;if(null==b||"object"==typeof b?(e=b,d=c):(e={})[b]=c,d=a.extend({validate:!0},d),e&&!d.wait){if(!this.set(e,d))return!1}else if(!this._validate(e,d))return!1;e&&d.wait&&(this.attributes=a.extend(Object.create(null),h,e)),void 0===d.parse&&(d.parse=!0);var i=this,k=d.success;return d.success=function(b){i.attributes=h;var c=i.parse(b,d);return d.wait&&(c=a.extend(e||{},c)),c&&"object"==typeof c&&!i.set(c,d)?!1:(k&&k(i,b,d),i.trigger("sync",i,b,d),void 0)},j(this,d),f=this.isNew()?"create":d.patch?"patch":"update","patch"===f&&(d.attrs=e),g=this.sync(f,this,d),e&&d.wait&&(this.attributes=h),g},destroy:function(b){b=b?a.extend({},b):{};var c=this,d=b.success,e=function(){c.trigger("destroy",c,c.collection,b)};if(b.success=function(a){(b.wait||c.isNew())&&e(),d&&d(c,a,b),c.isNew()||c.trigger("sync",c,a,b)},this.isNew())return b.success(),!1;j(this,b);var f=this.sync("delete",this,b);return b.wait||e(),f},url:function(){var b=a.result(this,"urlRoot")||a.result(this.collection,"url")||i();return this.isNew()?b:b+("/"===b.charAt(b.length-1)?"":"/")+encodeURIComponent(this.id)},parse:function(a){return a},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return null==this.id},isValid:function(b){return this._validate({},a.extend(b||{},{validate:!0}))},_validate:function(b,c){if(!c.validate||!this.validate)return!0;b=a.extend(Object.create(null),this.attributes,b);var d=this.validationError=this.validate(b,c)||null;return d?(this.trigger("invalid",this,d,a.extend(c,{validationError:d})),!1):!0}}),a.keys){var t=["keys","values","pairs","invert","pick","omit"];t.forEach(function(b){s.prototype[b]=function(){var c=h.call(arguments);return c.unshift(this.attributes),a[b].apply(a,c)}})}var u=c.Collection=function(b,c){c||(c={}),c.model&&(this.model=c.model),void 0!==c.comparator&&(this.comparator=c.comparator),this._reset(),this.initialize.apply(this,arguments),b&&this.reset(b,a.extend({silent:!0},c))},v={add:!0,remove:!0,merge:!0},w={add:!0,remove:!1};if(a.extend(u.prototype,n,{model:"undefined"==typeof s?null:s,initialize:function(){},toJSON:function(a){return this.map(function(b){return b.toJSON(a)})},sync:function(){return c.sync.apply(this,arguments)},add:function(b,c){return this.set(b,a.extend({merge:!1},c,w))},remove:function(a,b){var c=!Array.isArray(a);a=c?[a]:a.slice(),b||(b={});var d,e,f,g;for(d=0,e=a.length;e>d;d++)g=a[d]=this.get(a[d]),g&&(delete this._byId[g.id],delete this._byId[g.cid],f=this.indexOf(g),this.models.splice(f,1),this.length--,b.silent||(b.index=f,g.trigger("remove",g,this,b)),this._removeReference(g));return c?a[0]:a},set:function(b,c){c=a.defaults({},c,v),c.parse&&(b=this.parse(b,c));var d=!Array.isArray(b);b=d?b?[b]:[]:b.slice();var e,f,g,h,i,j,k,l=c.at,m=this.model,n=this.comparator&&null==l&&c.sort!==!1,o="string"==typeof this.comparator?this.comparator:null,p=[],q=[],r={},t=c.add,u=c.merge,w=c.remove,x=!n&&t&&w?[]:!1;for(e=0,f=b.length;f>e;e++){if(i=b[e],g=i instanceof s?h=i:i[m.prototype.idAttribute],j=this.get(g))w&&(r[j.cid]=!0),u&&(i=i===h?h.attributes:i,c.parse&&(i=j.parse(i,c)),j.set(i,c),n&&!k&&j.hasChanged(o)&&(k=!0)),b[e]=j;else if(t){if(h=b[e]=this._prepareModel(i,c),!h)continue;p.push(h),h.on("all",this._onModelEvent,this),this._byId[h.cid]=h,null!=h.id&&(this._byId[h.id]=h)}x&&x.push(j||h)}if(w){for(e=0,f=this.length;f>e;++e)r[(h=this.models[e]).cid]||q.push(h);q.length&&this.remove(q,c)}if(p.length||x&&x.length)if(n&&(k=!0),this.length+=p.length,null!=l)for(e=0,f=p.length;f>e;e++)this.models.splice(l+e,0,p[e]);else{x&&(this.models.length=0);var y=x||p;for(e=0,f=y.length;f>e;e++)this.models.push(y[e])}if(k&&this.sort({silent:!0}),!c.silent){for(e=0,f=p.length;f>e;e++)(h=p[e]).trigger("add",h,this,c);(k||x&&x.length)&&this.trigger("sort",this,c)}return d?b[0]:b},reset:function(b,c){c||(c={});for(var d=0,e=this.models.length;e>d;d++)this._removeReference(this.models[d]);return c.previousModels=this.models,this._reset(),b=this.add(b,a.extend({silent:!0},c)),c.silent||this.trigger("reset",this,c),b},push:function(b,c){return this.add(b,a.extend({at:this.length},c))},pop:function(a){var b=this.at(this.length-1);return this.remove(b,a),b},unshift:function(b,c){return this.add(b,a.extend({at:0},c))},shift:function(a){var b=this.at(0);return this.remove(b,a),b},slice:function(){return h.apply(this.models,arguments)},get:function(a){return null==a?void 0:this._byId[a.id]||this._byId[a.cid]||this._byId[a]},at:function(a){return this.models[a]},where:function(a,b){return a&&Object.keys(a).length?this[b?"find":"filter"](function(b){for(var c in a)if(a[c]!==b.get(c))return!1;return!0}):b?void 0:[]},findWhere:function(a){return this.where(a,!0)},sort:function(a){if(!this.comparator)throw new Error("Cannot sort a set without a comparator");return a||(a={}),"string"==typeof this.comparator||1===this.comparator.length?this.models=this.sortBy(this.comparator,this):this.models.sort(this.comparator.bind(this)),a.silent||this.trigger("sort",this,a),this},pluck:function(a){return this.models.map(function(b){return b.get(a)})},fetch:function(b){b=b?a.extend({},b):{},void 0===b.parse&&(b.parse=!0);var c=b.success,d=this;return b.success=function(a){var e=b.reset?"reset":"set";d[e](a,b),c&&c(d,a,b),d.trigger("sync",d,a,b)},j(this,b),this.sync("read",this,b)},create:function(b,c){if(c=c?a.extend({},c):{},!(b=this._prepareModel(b,c)))return!1;c.wait||this.add(b,c);var d=this,e=c.success;return c.success=function(a,b,c){c.wait&&d.add(a,c),e&&e(a,b,c)},b.save(null,c),b},parse:function(a){return a},clone:function(){return new this.constructor(this.models)},_reset:function(){this.length=0,this.models=[],this._byId={}},_prepareModel:function(b,c){if(b instanceof u.prototype.model)return b.collection||(b.collection=this),b;c=c?a.extend({},c):{},c.collection=this;var d=new this.model(b,c);return d.validationError?(this.trigger("invalid",this,d.validationError,c),!1):d},_removeReference:function(a){this===a.collection&&delete a.collection,a.off("all",this._onModelEvent,this)},_onModelEvent:function(a,b,c,d){("add"!==a&&"remove"!==a||c===this)&&("destroy"===a&&this.remove(b,d),b&&a==="change:"+b.idAttribute&&(delete this._byId[b.previous(b.idAttribute)],null!=b.id&&(this._byId[b.id]=b)),this.trigger.apply(this,arguments))}}),a.each){var x=["forEach","each","map","collect","reduce","foldl","inject","reduceRight","foldr","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","toArray","size","first","head","take","initial","rest","tail","drop","last","without","difference","indexOf","shuffle","lastIndexOf","isEmpty","chain"];x.forEach(function(b){u.prototype[b]=function(){var c=h.call(arguments);return c.unshift(this.models),a[b].apply(a,c)}});var y=["groupBy","countBy","sortBy"];y.forEach(function(b){u.prototype[b]=function(c,d){var e="function"==typeof c?c:function(a){return a.get(c)};return a[b](this.models,e,d)}})}else["forEach","map","filter","some","every","reduce","reduceRight","indexOf","lastIndexOf"].forEach(function(a){var b=Array.prototype[a];u.prototype[a]=function(a,c){return b.call(this.models,a,c)}}),["sortBy"].forEach(function(b){u.prototype[b]=function(c,d){var e="function"==typeof c?c:function(a){return a.get(c)};return a[b](this.models,e,d)}});var z=/^(\S+)\s*(.*)$/,A=["model","collection","el","id","attributes","className","tagName","events"],B=c.View=function(b){this.cid=a.uniqueId("view"),b&&Object.keys(b).forEach(function(a){-1!==A.indexOf(a)&&(this[a]=b[a])},this),this._handlers=[],this._ensureElement(),this.initialize.apply(this,arguments),this.delegateEvents()};a.extend(B.prototype,n,{tagName:"div",$:function(a){return c.$?this.$el.find(a):this.findAll(a)},find:function(a){return this.el.querySelector(a)},findAll:function(a){return h.call(this.el.querySelectorAll(a))},initialize:function(){},render:function(){return this},remove:function(){return c.$?this.$el.remove():this.el.parentNode&&this.el.parentNode.removeChild(this.el),this.stopListening(),this},setElement:function(a,b){if(c.$)this.$el&&this.undelegateEvents(),this.$el=a instanceof c.$?a:c.$(a),this.el=this.$el[0];else{this.el&&this.undelegateEvents();var d="string"==typeof a?document.querySelector(a):a;this.el=d}return b!==!1&&this.delegateEvents(),this},delegate:function(a,b,c){if("function"==typeof b&&(c=b,b=null),"function"!=typeof c)throw new TypeError("View#delegate expects callback function");var d=this.el,e=c.bind(this),g=b?function(a){for(var c=a.target;c&&c!==d;c=c.parentNode)if(f.matchesSelector(c,b))return a.delegateTarget=c,e(a)}:e;return d.addEventListener(a,g,!1),this._handlers.push({eventName:a,selector:b,callback:c,handler:g}),g},undelegate:function(a,b,c){"function"==typeof b&&(c=b,b=null);var d=this.el,e=this._handlers,f=function(a){d.removeEventListener(a.eventName,a.handler,!1)};a||b||c?e.filter(function(d){return d.eventName===a&&(c?d.callback===c:!0)&&(b?d.selector===b:!0)}).forEach(function(a){f(a),e.splice(e.indexOf(a),1)}):(e.forEach(f),this._handlers=[])},delegateEvents:function(b,d){if(!b&&!(b=a.result(this,"events")))return this;d||this.undelegateEvents();for(var e in b){var f=b[e];"function"!=typeof f&&(f=this[b[e]]);var g=e.match(z),h=g[1],i=g[2];c.$?(h+=".delegateEvents"+this.cid,f=f.bind(this),this.$el.on(h,i?i:null,f)):this.delegate(h,i,f)}return this},undelegateEvents:function(){return c.$?this.$el.off(".delegateEvents"+this.cid):this.undelegate(),this},_ensureElement:function(){if(this.el)this.setElement(a.result(this,"el"),!1);else{var b=a.extend({},a.result(this,"attributes"));this.id&&(b.id=a.result(this,"id")),this.className&&(b.className=a.result(this,"className")),b["class"]&&(b.className=b["class"]);var c=a.extend(document.createElement(a.result(this,"tagName")),b);this.setElement(c,!1)}}}),c.sync=function(b,d,e){var f=C[b];a.defaults(e||(e={}),{emulateHTTP:c.emulateHTTP,emulateJSON:c.emulateJSON});var g={type:f,dataType:"json"};if(e.url||(g.url=a.result(d,"url")||i()),null!=e.data||!d||"create"!==b&&"update"!==b&&"patch"!==b||(g.contentType="application/json",g.data=JSON.stringify(e.attrs||d.toJSON(e))),e.emulateJSON&&(g.contentType="application/x-www-form-urlencoded",g.data=g.data?{model:g.data}:{}),e.emulateHTTP&&("PUT"===f||"DELETE"===f||"PATCH"===f)){g.type="POST",e.emulateJSON&&(g.data._method=f);var h=e.beforeSend;e.beforeSend=function(a){return a.setRequestHeader("X-HTTP-Method-Override",f),h?h.apply(this,arguments):void 0}}"GET"===g.type||e.emulateJSON||(g.processData=!1);var j=e.xhr=c.ajax(a.extend(g,e));return d.trigger("request",d,j,e),j};var C={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};c.ajax=function(){return c.$.ajax.apply(c.$,arguments)};var D=c.Router=function(a){a||(a={}),a.routes&&(this.routes=a.routes),this._bindRoutes(),this.initialize.apply(this,arguments)},E=/\((.*?)\)/g,F=/(\(\?)?:\w+/g,G=/\*\w+/g,H=/[\-{}\[\]+?.,\\\^$|#\s]/g,I=function(a){return a?"object"==typeof a&&"[object RegExp]"===toString.call(a):!1};a.extend(D.prototype,n,{initialize:function(){},route:function(a,b,d){I(a)||(a=this._routeToRegExp(a)),"function"==typeof b&&(d=b,b=""),d||(d=this[b]);var e=this;return c.history.route(a,function(f){var g=e._extractParameters(a,f);d&&d.apply(e,g),e.trigger.apply(e,["route:"+b].concat(g)),e.trigger("route",b,g),c.history.trigger("route",e,b,g)}),this},navigate:function(a,b){return c.history.navigate(a,b),this},_bindRoutes:function(){if(this.routes){this.routes=a.result(this,"routes");for(var b,c=Object.keys(this.routes);null!=(b=c.pop());)this.route(b,this.routes[b])}},_routeToRegExp:function(a){return a=a.replace(H,"\\$&").replace(E,"(?:$1)?").replace(F,function(a,b){return b?a:"([^/]+)"}).replace(G,"(.*?)"),new RegExp("^"+a+"$")},_extractParameters:function(a,b){var c=a.exec(b).slice(1);return c.map(function(a){return a?decodeURIComponent(a):null})}});var J=c.History=function(){this.handlers=[],this.checkUrl=this.checkUrl.bind(this),"undefined"!=typeof window&&(this.location=window.location,this.history=window.history)},K=/^[#\/]|\s+$/g,L=/^\/+|\/+$/g,M=/\/$/,N=/[#].*$/;return J.started=!1,a.extend(J.prototype,n,{getHash:function(a){var b=(a||this).location.href.match(/#(.*)$/);return b?b[1]:""},getFragment:function(a){if(null==a)if(this._wantsPushState||!this._wantsHashChange){a=this.location.pathname+this.location.search;var b=this.root.replace(M,"");a.indexOf(b)||(a=a.slice(b.length))}else a=this.getHash();return a.replace(K,"")},start:function(b){if(J.started)throw new Error("Backbone.history has already been started");J.started=!0,this.options=a.extend({root:"/"},this.options,b),this.root=this.options.root,this._wantsHashChange=this.options.hashChange!==!1,this._wantsPushState=!!this.options.pushState;var c=this.getFragment();this.root=("/"+this.root+"/").replace(L,"/"),this._wantsPushState?window.addEventListener("popstate",this.checkUrl,!1):this._wantsHashChange&&window.addEventListener("hashchange",this.checkUrl,!1),this.fragment=c;var d=this.location,e=d.pathname.replace(/[^\/]$/,"$&/")===this.root;return this._wantsHashChange&&this._wantsPushState&&e&&d.hash&&(this.fragment=this.getHash().replace(K,""),this.history.replaceState({},document.title,this.root+this.fragment)),this.options.silent?void 0:this.loadUrl()},stop:function(){window.removeEventListener("popstate",this.checkUrl),window.removeEventListener("hashchange",this.checkUrl),J.started=!1},route:function(a,b){this.handlers.unshift({route:a,callback:b})},checkUrl:function(){var a=this.getFragment();return a===this.fragment?!1:(this.loadUrl(),void 0)},loadUrl:function(a){return a=this.fragment=this.getFragment(a),this.handlers.some(function(b){return b.route.test(a)?(b.callback(a),!0):void 0})},navigate:function(a,b){if(!J.started)return!1;b&&b!==!0||(b={trigger:!!b});var c=this.root+(a=this.getFragment(a||""));if(a=a.replace(N,""),this.fragment!==a){if(this.fragment=a,""===a&&"/"!==c&&(c=c.slice(0,-1)),this._wantsPushState)this.history[b.replace?"replaceState":"pushState"]({},document.title,c);else{if(!this._wantsHashChange)return this.location.assign(c);this._updateHash(this.location,a,b.replace)}return b.trigger?this.loadUrl(a):void 0}},_updateHash:function(a,b,c){if(c){var d=a.href.replace(/(javascript:|#).*$/,"");a.replace(d+"#"+b)}else a.hash="#"+b}}),s.extend=u.extend=D.extend=B.extend=J.extend=c.extend,a.extend(c,n),c.history=new J,c}),function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s={}.hasOwnProperty,t=function(a,b){function c(){this.constructor=a}for(var d in b)s.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};h=function(a){function b(){return k=b.__super__.constructor.apply(this,arguments)}return t(b,a),b.prototype.defaults={offset:0,duration:5e3,resizable:!1,visible:!1},b.prototype.initialize=function(a){var b,c=this;return null!=a?(b=new FileReader,b.onload=function(b){return c.set("name",a.name),c.set("size",a.size),c.set("type",a.type),c.set("data",b.target.result),"audio/mp3"===a.type?c.set("mp3",new Audio(b.target.result)):void 0},b.readAsDataURL(a)):void 0},b.prototype.offset=function(a){return null!=a?this.set("offset",1e3*a):this.get("offset")/1e3},b.prototype.duration=function(a){return null!=a?this.set("duration",1e3*a):this.get("duration")/1e3},b}(Backbone.Model),i=function(a){function b(){return l=b.__super__.constructor.apply(this,arguments)}return t(b,a),b.prototype.model=h,b}(Backbone.Collection),f=function(a){function b(){return m=b.__super__.constructor.apply(this,arguments)}return t(b,a),b.prototype.defaults={volume:.5,position:0,len:10,fullscreen:!1,played:!1},b.prototype.initialize=function(){var a,b=this;return a=new i,a.on("change",function(){var c;return c=0,a.forEach(function(a){var b;return b=a.offset()+a.duration(),b>c?c=b:void 0}),b.get("len")<c?b.set("len",c):void 0}),this.set("tracks",a),window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame),this.next()},b.prototype.add=function(a){var b;return b=this.get("tracks"),b.add(a),a},b.prototype.remove=function(a){var b;return b=this.get("tracks"),b.remove(a),a},b.prototype.next=function(){var a,b,c=this;return this.get("played")===!0?(0!==this.lastFrame&&(b=+new Date-this.lastFrame,a=this.get("position"),a+=b/1e3,a>this.get("len")&&(a=0),this.set("position",a+b/1e3)),this.lastFrame=+new Date):this.lastFrame=0,window.requestAnimationFrame(function(){return c.next()})},b.prototype.play=function(){return this.set("played",!0)},b.prototype.pause=function(){return this.set("played",!1)},b.prototype.volume=function(a){return null!=a?this.set("volume",a):this.get("volume")},b.prototype.position=function(a){return null!=a?this.set("position",a):this.get("position")},b.prototype.tracks=function(){return this.get("tracks").models},b}(Backbone.Model),e=new f,a=function(a){function f(){return n=f.__super__.constructor.apply(this,arguments)}return t(f,a),f.prototype.render=function(){var a,f,h,i;for(a=new b({model:e}),a.render(),f=new c({model:e}),f.render(),h=new d({model:e}),h.render(),i=new g({model:e}),i.render();this.el.firstChild;)this.el.removeChild(this.el.firstChild);return this.el.appendChild(a.el),this.el.appendChild(f.el),this.el.appendChild(h.el),this.el.appendChild(i.el)},f}(Backbone.View),b=function(a){function b(){return o=b.__super__.constructor.apply(this,arguments)}return t(b,a),b.prototype.tagName="div",b.prototype.className="pure-menu pure-menu-open pure-menu-horizontal",b.prototype.events={"change .upload-media":"upload","click .playpause":"playpause","click .fullscreen":"fullscreen","click .save":"save","click .load":"load","click .volumeup":"volumeup","click .volumedown":"volumedown"},b.prototype.initialize=function(){return this.items=[{className:"playpause",caption:"Воспроизведение/Пауза"},{className:"fullscreen disabled",caption:"Полноэкранный режим"},{className:"volumeup",caption:"Громче"},{className:"volumedown",caption:"Тише"},{className:"save",caption:"Сохранить"},{className:"load",caption:"Загрузить"}]},b.prototype.upload=function(a){var b,c,d,f,g,i,j,k,l,m;for(b=a.target,i=b.files,c=i.length,m=[],k=0,l=i.length;l>k;k++)f=i[k],g=f.name,d=g.split(".").pop(),"json"!==d?(j=new h(f),m.push(e.add(j))):m.push(this.loadJSON(f));return m},b.prototype.playpause=function(a){var b;return a.preventDefault(),b=this.model.get("played"),this.model.set("played",!b)},b.prototype.fullscreen=function(a){var b;return a.preventDefault(),b=this.model.get("fullscreen"),this.model.set("fullscreen",!b),!1},b.prototype.save=function(){var a,b,c,d;return b=JSON.stringify(this.model.get("tracks").toJSON()),a=new Blob([b],{type:"application/json"}),d=URL.createObjectURL(a),c=document.querySelector(".save"),c.download="project.json",c.href=d},b.prototype.load=function(a){return a.preventDefault(),alert("Загрузите json-файл проекта в первом пункте меню (как медиафрагмент)")},b.prototype.loadJSON=function(a){var b,c=this;return b=new FileReader,b.onload=function(a){var b;return b=JSON.parse(a.target.result),c.model.get("tracks").reset(b)},b.readAsText(a)},b.prototype.volumeup=function(a){var b;return a.preventDefault(),b=this.model.get("volume"),b=Math.min(b+.1,1),this.model.set("volume",b)},b.prototype.volumedown=function(a){var b;return a.preventDefault(),b=this.model.get("volume"),b=Math.max(b-.1,0),this.model.set("volume",b)},b.prototype.template=function(a){return'<li><a href="#" class="'+a.className+'">'+a.caption+"</a></li>"},b.prototype.render=function(){var a,b,c;return a=document.createElement("B"),a.className="pure-menu-heading",a.innerHTML="Загрузка файлов:",b=document.createElement("ul"),b.innerHTML=this.items.map(this.template).join(""),c=document.createElement("INPUT"),c.setAttribute("type","file"),c.setAttribute("multiple","multiple"),c.setAttribute("accept","image/*|audio/*"),c.className="upload-media",this.el.appendChild(a),this.el.appendChild(c),this.el.appendChild(b),this},b}(Backbone.View),c=function(a){function b(){return p=b.__super__.constructor.apply(this,arguments)}return t(b,a),b.prototype.tagName="div",b.prototype.className="video",b.prototype.initialize=function(){var a;return this.status=document.createElement("div"),this.status.className="status",this.el.appendChild(this.status),this.imageContainer=document.createElement("div"),this.imageContainer.className="imageContainer",this.el.appendChild(this.imageContainer),a=Backbone.Collection.extend({model:h}),this.active=new a,this.active.on("add",this.addMedia,this),this.active.on("remove",this.removeMedia,this),this.model.on("change:played change:position change:volume",this.render,this),this.model.on("change:volume",this.changeVolume,this)},b.prototype.addMedia=function(a){var b,c;return("image/jpeg"===(c=a.get("type"))||"image/png"===c)&&(b=a.get("data"),this.imageContainer.style.backgroundImage="url("+b+")"),"audio/mp3"===a.get("type")?(a.get("mp3").volume=this.model.get("volume"),a.get("mp3").currentTime=this.model.get("position")-a.get("offset"),a.get("mp3").play()):void 0},b.prototype.removeMedia=function(a){var b,c;return"image/jpeg"===(c=a.get("type"))||"image/png"===c?(b="",this.active.forEach(function(a){var c;return"image/jpeg"===(c=a.get("type"))||"image/png"===c?b=a.get("data"):void 0}),this.imageContainer.style.backgroundImage=b?"url("+b+")":"none"):a.get("mp3").pause()},b.prototype.changeVolume=function(){var a,b;return b=this.model.get("volume"),a=this.model.get("tracks"),a.forEach(function(a){return"audio/mp3"===a.get("type")?a.get("mp3").volume=b:void 0})},b.prototype.render=function(){var a,b,c,d,e,f=this;return e=Math.floor(100*this.model.get("volume")),b=this.model.get("position"),a=this.model.get("played"),c=a?"Играется":"На паузе",this.status.innerHTML=""+c+" Громкость: "+e,d=this.model.get("tracks"),d.forEach(function(a){if(b>=a.offset()&&b<a.offset()+a.duration()){if(a.get("visible")===!1)return a.set("visible",!0),f.active.add(a)}else if(a.get("visible")===!0)return a.set("visible",!1),f.active.remove(a)}),this},b}(Backbone.View),d=function(a){function b(){return q=b.__super__.constructor.apply(this,arguments)}return t(b,a),b.prototype.tagName="div",b.prototype.className="progress",b.prototype.events={"click .indicator":"goto"},b.prototype.initialize=function(){return this.indicator=document.createElement("b"),this.indicator.className="indicator",this.el.appendChild(this.indicator),this.model.on("change:position",this.render,this)},b.prototype.goto=function(a){return this.model.set("position",a.clientX/100)},b.prototype.render=function(){return this.indicator.style.width=100*this.model.get("position")+"px"},b}(Backbone.View),g=function(a){function b(){return r=b.__super__.constructor.apply(this,arguments)}return t(b,a),b.prototype.tagName="ul",b.prototype.className="timeline",b.prototype.events={"mousedown .element span":"dragstart",mouseup:"dragend",mousemove:"drag"},b.prototype.initialize=function(){return this.collection=this.model.get("tracks"),this.collection.on("add remove reset",this.render,this)},b.prototype.dragstart=function(a){return this.dragEl=a.delegateTarget,"b"===a.target.tagName.toLowerCase()?this.dragEl.classList.add("draggable"):this.dragEl.classList.add("resizable"),this.dragX=a.clientX,this.dragW=parseInt(this.dragEl.firstChild.style.width,10)},b.prototype.drag=function(a){var b,c;return null!=this.dragEl&&(this.dragEl.classList.contains("draggable")&&(b=0|this.dragEl.dataset.offset,b+=a.clientX-this.dragX,this.dragEl.style.left=""+b+"px"),this.dragEl.classList.contains("resizable"))?(b=a.clientX-this.dragX,c=this.dragW+b,this.dragEl.firstChild.style.width=""+c+"px"):void 0},b.prototype.dragend=function(a){var b,c,d;return null!=this.dragEl?(this.dragEl.classList.contains("draggable")&&(this.dragEl.classList.remove("draggable"),c=0|this.dragEl.dataset.offset,c+=a.clientX-this.dragX,this.dragEl.style.left=""+c+"px",this.dragEl.dataset.offset=c,b=this.dragEl.dataset.cid,this.collection.get(b).set("offset",10*c)),this.dragEl.classList.contains("resizable")&&(this.dragEl.classList.remove("resizable"),c=a.clientX-this.dragX,d=this.dragW+c,b=this.dragEl.dataset.cid,this.collection.get(b).set("duration",10*d)),this.dragEl=null):void 0
},b.prototype.template=function(a){var b,c;return c=a.get("duration")/10,b=a.get("offset")/10,'<li class="element"><span data-cid="'+a.cid+'" style="left: '+b+'px" data-offset="'+b+'"><b style="width:'+c+'px">'+a.get("name")+" ("+a.get("type")+")</b><span></li>"},b.prototype.render=function(){return this.el.innerHTML=this.collection.map(this.template,this).join(""),this},b}(Backbone.View),j=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||function(a){return window.setTimeout(a,1e3/60)},window.onload=function(){var b;return b=new a({el:document.body}),b.render()}}.call(this);