+<!-- include MSA js + css -->
+<!-- <script src="https://s3-eu-west-1.amazonaws.com/biojs/msa/latest/msa.js"></script> -->
+<!-- <link type=text/css rel=stylesheet href=https://s3-eu-west-1.amazonaws.com/biojs/msa/latest/msa.css /> -->
+
+ <img src="http://www.jalview.org/help/html/Jalview_Logo.png" alt="Jalview Logo" title="This html page was generated from Jalview, to import the data back to Jalview, please drag the generated html file and drop it unto the Jalview workbench.
+
+ Alternatively, you could copy the url from the address bar and use Jalview's url importer (main menu-> File-> Input Alignment-> from URL) to import back the alignment jalview." >
+
+</br>
+</br>
+
+<input type="button" name="divToggleButton" id="divToggleButton" onclick="javascipt:toggleMenuVisibility();" value="Show Menu"></input>
+<button onclick="javascipt:openJalviewUsingCurrentUrl();">Launch in Jalview</button>
+
+</br>
+</br>
+
+<div id="yourDiv">press "Run with JS"</div>
+<input type='hidden' id='seqData' name='seqData' value='#sequenceData#'/>
+
+</body>
+</html>
+
+
+
+<script>
+
+function toggleMenuVisibility(){
+ var menu = document.getElementsByClassName("biojs_msa_menubar");
+ var divToggleButton = document.getElementById("divToggleButton");
+ if(menu[0].style.display == 'block'){
+ menu[0].style.display = 'none';
+ divToggleButton.value="Show Menu";
+ }else{
+ menu[0].style.display = 'block';
+ divToggleButton.value="Hide Menu";
+ }
+}
+
+
+function openJalviewUsingCurrentUrl(){
+ var jalviewData = JSON.parse(document.getElementById("seqData").value)
+ var jalviewVersion = jalviewData['jalviewVersion'];
+ var url = jalviewData['webStartUrl'];
+ var myForm = document.createElement("form");
+ myForm.action = url;
+
+ var heap = document.createElement("input") ;
+ heap.setAttribute("name", "jvm-max-heap") ;
+ heap.setAttribute("value", "2G");
+ myForm.appendChild(heap) ;
+
+ var target = document.createElement("input") ;
+ target.setAttribute("name", "open") ;
+ target.setAttribute("value", document.URL);
+ myForm.appendChild(target) ;
+
+ var jvVersion = document.createElement("input") ;
+ jvVersion.setAttribute("name", "version") ;
+ jvVersion.setAttribute("value", jalviewVersion);
+ myForm.appendChild(jvVersion) ;
+
+
+ document.body.appendChild(myForm) ;
+ myForm.submit() ;
+ document.body.removeChild(myForm) ;
+}
+
+
+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);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
+var css = ".biojs_msa_stage {\n cursor: default;\n line-height: normal; }\n\n.biojs_msa_labels {\n color: black;\n display: inline-block;\n white-space: nowrap;\n cursor: pointer;\n vertical-align: top; }\n\n.biojs_msa_seqblock {\n cursor: move; }\n\n.biojs_msa_layer {\n display: block;\n white-space: nowrap; }\n\n.biojs_msa_labelblock::-webkit-scrollbar, .biojs_msa_header::-webkit-scrollbar {\n -webkit-appearance: none;\n width: 7px;\n height: 7px; }\n\n.biojs_msa_labelblock::-webkit-scrollbar-thumb, .biojs_msa_header::-webkit-scrollbar-thumb {\n border-radius: 4px;\n background-color: rgba(0, 0, 0, 0.5);\n box-shadow: 0 0 1px rgba(255, 255, 255, 0.5); }\n\n.biojs_msa_marker {\n color: grey;\n white-space: nowrap;\n cursor: pointer; }\n\n.biojs_msa_marker span {\n text-align: center; }\n\n.biojs_msa_menubar .biojs_msa_menubar_alink {\n background: #3498db;\n background-image: -webkit-linear-gradient(top, #3498db, #2980b9);\n background-image: -moz-linear-gradient(top, #3498db, #2980b9);\n background-image: -ms-linear-gradient(top, #3498db, #2980b9);\n background-image: -o-linear-gradient(top, #3498db, #2980b9);\n background-image: linear-gradient(to bottom, #3498db, #2980b9);\n -webkit-border-radius: 28;\n -moz-border-radius: 28;\n border-radius: 28px;\n font-family: Arial;\n color: #ffffff;\n padding: 3px 10px 3px 10px;\n margin-left: 10px;\n text-decoration: none; }\n\n.biojs_msa_menubar .biojs_msa_menubar_alink:hover {\n cursor: pointer; }\n\n/* jquery dropdown CSS */\n.dropdown {\n position: absolute;\n z-index: 9999999;\n display: none; }\n\n.dropdown .dropdown-menu,\n.dropdown .dropdown-panel {\n min-width: 160px;\n max-width: 360px;\n list-style: none;\n background: #FFF;\n border: solid 1px #DDD;\n border: solid 1px rgba(0, 0, 0, 0.2);\n border-radius: 6px;\n box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);\n overflow: visible;\n padding: 4px 0;\n margin: 0; }\n\n.dropdown .dropdown-panel {\n padding: 10px; }\n\n.dropdown.dropdown-scroll .dropdown-menu,\n.dropdown.dropdown-scroll .dropdown-panel {\n max-height: 358px;\n overflow: auto; }\n\n.dropdown .dropdown-menu LI {\n list-style: none;\n padding: 0 0;\n margin: 0;\n line-height: 18px; }\n\n.dropdown .dropdown-menu LI,\n.dropdown .dropdown-menu LABEL {\n display: block;\n color: #555;\n text-decoration: none;\n line-height: 18px;\n padding: 3px 15px;\n white-space: nowrap; }\n\n.dropdown .dropdown-menu LI:hover,\n.dropdown .dropdown-menu LABEL:hover {\n background-color: #08C;\n color: #FFF;\n cursor: pointer; }\n\n.dropdown .dropdown-menu .dropdown-divider {\n font-size: 1px;\n border-top: solid 1px #E5E5E5;\n padding: 0;\n margin: 5px 0; }\n"; (require("/home/travis/build/greenify/biojs-vis-msa/node_modules/cssify"))(css); module.exports = css;
+},{"/home/travis/build/greenify/biojs-vis-msa/node_modules/cssify":48}],2:[function(require,module,exports){
+module.exports = require("./src/index");
+
+},{"./src/index":72}],3:[function(require,module,exports){
+var _ = require('underscore');
+var viewType = require("backbone-viewj");
+var pluginator;
+
+module.exports = pluginator = viewType.extend({
+ renderSubviews: function() {
+ var oldEl = this.el;
+ var el = document.createElement("div");
+ this.setElement(el);
+ var frag = document.createDocumentFragment();
+ if (oldEl.parentNode != null) {
+ oldEl.parentNode.replaceChild(this.el, oldEl);
+ }
+ var views = this._views();
+ var viewsSorted = _.sortBy(views, function(el) {
+ return el.ordering;
+ });
+ var view, node;
+ for (var i = 0; i < viewsSorted.length; i++) {
+ view = viewsSorted[i];
+ view.render();
+ node = view.el;
+ if (node != null) {
+ frag.appendChild(node);
+ }
+ }
+ el.appendChild(frag);
+ return el;
+ },
+ addView: function(key, view) {
+ var views = this._views();
+ if (view == null) {
+ throw "Invalid plugin. ";
+ }
+ if (view.ordering == null) {
+ view.ordering = key;
+ }
+ return views[key] = view;
+ },
+ removeViews: function() {
+ var el, key;
+ var views = this._views();
+ for (key in views) {
+ el = views[key];
+ el.undelegateEvents();
+ el.unbind();
+ if (el.removeViews != null) {
+ el.removeViews();
+ }
+ el.remove();
+ }
+ return this.views = {};
+ },
+ removeView: function(key) {
+ var views = this._views();
+ views[key].remove();
+ return delete views[key];
+ },
+ getView: function(key) {
+ var views = this._views();
+ return views[key];
+ },
+ remove: function() {
+ this.removeViews();
+ return viewType.prototype.remove.apply(this);
+ },
+ _views: function() {
+ if (this.views == null) {
+ this.views = {};
+ }
+ return this.views;
+ }
+});
+
+},{"backbone-viewj":10,"underscore":59}],4:[function(require,module,exports){
+// Backbone.js 1.1.2
+
+// (c) 2010-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
+// Backbone may be freely distributed under the MIT license.
+// For all details and documentation:
+// http://backbonejs.org
+
+var Events = require("backbone-events-standalone");
+var extend = require("backbone-extend-standalone");
+var _ = require("underscore");
+var Model = require("./model");
+
+// Create local references to array methods we'll want to use later.
+var array = [];
+var slice = array.slice;
+
+// Backbone.Collection
+// -------------------
+
+// If models tend to represent a single row of data, a Backbone Collection is
+// more analogous to a table full of data ... or a small slice or page of that
+// table, or a collection of rows that belong together for a particular reason
+// -- all of the messages in this particular folder, all of the documents
+// belonging to this particular author, and so on. Collections maintain
+// indexes of their models, both in order, and for lookup by `id`.
+
+// Create a new **Collection**, perhaps to contain a specific type of `model`.
+// If a `comparator` is specified, the Collection will maintain
+// its models in sort order, as they're added and removed.
+var Collection = function(models, options) {
+ options || (options = {});
+ if (options.model) this.model = options.model;
+ if (options.comparator !== void 0) this.comparator = options.comparator;
+ this._reset();
+ this.initialize.apply(this, arguments);
+ if (models) this.reset(models, _.extend({silent: true}, options));
+};
+
+// Default options for `Collection#set`.
+var setOptions = {add: true, remove: true, merge: true};
+var addOptions = {add: true, remove: false};
+
+// Define the Collection's inheritable methods.
+_.extend(Collection.prototype, Events, {
+
+ // The default model for a collection is just a **Backbone.Model**.
+ // This should be overridden in most cases.
+ model: Model,
+
+ // Initialize is an empty function by default. Override it with your own
+ // initialization logic.
+ initialize: function(){},
+
+ // The JSON representation of a Collection is an array of the
+ // models' attributes.
+ toJSON: function(options) {
+ return this.map(function(model){ return model.toJSON(options); });
+ },
+
+ // Proxy `Backbone.sync` by default.
+ sync: function() {
+ return Backbone.sync.apply(this, arguments);
+ },
+
+ // Add a model, or list of models to the set.
+ add: function(models, options) {
+ return this.set(models, _.extend({merge: false}, options, addOptions));
+ },
+
+ // Remove a model, or a list of models from the set.
+ remove: function(models, options) {
+ var singular = !_.isArray(models);
+ models = singular ? [models] : _.clone(models);
+ options || (options = {});
+ for (var i = 0, length = models.length; i < length; i++) {
+ var model = models[i] = this.get(models[i]);
+ if (!model) continue;
+ var id = this.modelId(model.attributes);
+ if (id != null) delete this._byId[id];
+ delete this._byId[model.cid];
+ var index = this.indexOf(model);
+ this.models.splice(index, 1);
+ this.length--;
+ if (!options.silent) {
+ options.index = index;
+ model.trigger('remove', model, this, options);
+ }
+ this._removeReference(model, options);
+ }
+ return singular ? models[0] : models;
+ },
+
+ // Update a collection by `set`-ing a new list of models, adding new ones,
+ // removing models that are no longer present, and merging models that
+ // already exist in the collection, as necessary. Similar to **Model#set**,
+ // the core operation for updating the data contained by the collection.
+ set: function(models, options) {
+ options = _.defaults({}, options, setOptions);
+ if (options.parse) models = this.parse(models, options);
+ var singular = !_.isArray(models);
+ models = singular ? (models ? [models] : []) : models.slice();
+ var id, model, attrs, existing, sort;
+ var at = options.at;
+ var sortable = this.comparator && (at == null) && options.sort !== false;
+ var sortAttr = _.isString(this.comparator) ? this.comparator : null;
+ var toAdd = [], toRemove = [], modelMap = {};
+ var add = options.add, merge = options.merge, remove = options.remove;
+ var order = !sortable && add && remove ? [] : false;
+
+ // Turn bare objects into model references, and prevent invalid models
+ // from being added.
+ for (var i = 0, length = models.length; i < length; i++) {
+ attrs = models[i];
+
+ // If a duplicate is found, prevent it from being added and
+ // optionally merge it into the existing model.
+ if (existing = this.get(attrs)) {
+ if (remove) modelMap[existing.cid] = true;
+ if (merge && attrs !== existing) {
+ attrs = this._isModel(attrs) ? attrs.attributes : attrs;
+ if (options.parse) attrs = existing.parse(attrs, options);
+ existing.set(attrs, options);
+ if (sortable && !sort && existing.hasChanged(sortAttr)) sort = true;
+ }
+ models[i] = existing;
+
+ // If this is a new, valid model, push it to the `toAdd` list.
+ } else if (add) {
+ model = models[i] = this._prepareModel(attrs, options);
+ if (!model) continue;
+ toAdd.push(model);
+ this._addReference(model, options);
+ }
+
+ // Do not add multiple models with the same `id`.
+ model = existing || model;
+ if (!model) continue;
+ id = this.modelId(model.attributes);
+ if (order && (model.isNew() || !modelMap[id])) order.push(model);
+ modelMap[id] = true;
+ }
+
+ // Remove nonexistent models if appropriate.
+ if (remove) {
+ for (var i = 0, length = this.length; i < length; i++) {
+ if (!modelMap[(model = this.models[i]).cid]) toRemove.push(model);
+ }
+ if (toRemove.length) this.remove(toRemove, options);
+ }
+
+ // See if sorting is needed, update `length` and splice in new models.
+ if (toAdd.length || (order && order.length)) {
+ if (sortable) sort = true;
+ this.length += toAdd.length;
+ if (at != null) {
+ for (var i = 0, length = toAdd.length; i < length; i++) {
+ this.models.splice(at + i, 0, toAdd[i]);
+ }
+ } else {
+ if (order) this.models.length = 0;
+ var orderedModels = order || toAdd;
+ for (var i = 0, length = orderedModels.length; i < length; i++) {
+ this.models.push(orderedModels[i]);
+ }
+ }
+ }
+
+ // Silently sort the collection if appropriate.
+ if (sort) this.sort({silent: true});
+
+ // Unless silenced, it's time to fire all appropriate add/sort events.
+ if (!options.silent) {
+ var addOpts = at != null ? _.clone(options) : options;
+ for (var i = 0, length = toAdd.length; i < length; i++) {
+ if (at != null) addOpts.index = at + i;
+ (model = toAdd[i]).trigger('add', model, this, addOpts);
+ }
+ if (sort || (order && order.length)) this.trigger('sort', this, options);
+ }
+
+ // Return the added (or merged) model (or models).
+ return singular ? models[0] : models;
+ },
+
+ // When you have more items than you want to add or remove individually,
+ // you can reset the entire set with a new list of models, without firing
+ // any granular `add` or `remove` events. Fires `reset` when finished.
+ // Useful for bulk operations and optimizations.
+ reset: function(models, options) {
+ options || (options = {});
+ for (var i = 0, length = this.models.length; i < length; i++) {
+ this._removeReference(this.models[i], options);
+ }
+ options.previousModels = this.models;
+ this._reset();
+ models = this.add(models, _.extend({silent: true}, options));
+ if (!options.silent) this.trigger('reset', this, options);
+ return models;
+ },
+
+ // Add a model to the end of the collection.
+ push: function(model, options) {
+ return this.add(model, _.extend({at: this.length}, options));
+ },
+
+ // Remove a model from the end of the collection.
+ pop: function(options) {
+ var model = this.at(this.length - 1);
+ this.remove(model, options);
+ return model;
+ },
+
+ // Add a model to the beginning of the collection.
+ unshift: function(model, options) {
+ return this.add(model, _.extend({at: 0}, options));
+ },
+
+ // Remove a model from the beginning of the collection.
+ shift: function(options) {
+ var model = this.at(0);
+ this.remove(model, options);
+ return model;
+ },
+
+ // Slice out a sub-array of models from the collection.
+ slice: function() {
+ return slice.apply(this.models, arguments);
+ },
+
+ // Get a model from the set by id.
+ get: function(obj) {
+ if (obj == null) return void 0;
+ var id = this.modelId(this._isModel(obj) ? obj.attributes : obj);
+ return this._byId[obj] || this._byId[id] || this._byId[obj.cid];
+ },
+
+ // Get the model at the given index.
+ at: function(index) {
+ if (index < 0) index += this.length;
+ return this.models[index];
+ },
+
+ // Return models with matching attributes. Useful for simple cases of
+ // `filter`.
+ where: function(attrs, first) {
+ if (_.isEmpty(attrs)) return first ? void 0 : [];
+ return this[first ? 'find' : 'filter'](function(model) {
+ for (var key in attrs) {
+ if (attrs[key] !== model.get(key)) return false;
+ }
+ return true;
+ });
+ },
+
+ // Return the first model with matching attributes. Useful for simple cases
+ // of `find`.
+ findWhere: function(attrs) {
+ return this.where(attrs, true);
+ },
+
+ // Force the collection to re-sort itself. You don't need to call this under
+ // normal circumstances, as the set will maintain sort order as each item
+ // is added.
+ sort: function(options) {
+ if (!this.comparator) throw new Error('Cannot sort a set without a comparator');
+ options || (options = {});
+
+ // Run sort based on type of `comparator`.
+ if (_.isString(this.comparator) || this.comparator.length === 1) {
+ this.models = this.sortBy(this.comparator, this);
+ } else {
+ this.models.sort(_.bind(this.comparator, this));
+ }
+
+ if (!options.silent) this.trigger('sort', this, options);
+ return this;
+ },
+
+ // Pluck an attribute from each model in the collection.
+ pluck: function(attr) {
+ return _.invoke(this.models, 'get', attr);
+ },
+
+ // Fetch the default set of models for this collection, resetting the
+ // collection when they arrive. If `reset: true` is passed, the response
+ // data will be passed through the `reset` method instead of `set`.
+ fetch: function(options) {
+ options = options ? _.clone(options) : {};
+ if (options.parse === void 0) options.parse = true;
+ var success = options.success;
+ var collection = this;
+ options.success = function(resp) {
+ var method = options.reset ? 'reset' : 'set';
+ collection[method](resp, options);
+ if (success) success(collection, resp, options);
+ collection.trigger('sync', collection, resp, options);
+ };
+ wrapError(this, options);
+ return this.sync('read', this, options);
+ },
+
+ // Create a new instance of a model in this collection. Add the model to the
+ // collection immediately, unless `wait: true` is passed, in which case we
+ // wait for the server to agree.
+ create: function(model, options) {
+ options = options ? _.clone(options) : {};
+ if (!(model = this._prepareModel(model, options))) return false;
+ if (!options.wait) this.add(model, options);
+ var collection = this;
+ var success = options.success;
+ options.success = function(model, resp) {
+ if (options.wait) collection.add(model, options);
+ if (success) success(model, resp, options);
+ };
+ model.save(null, options);
+ return model;
+ },
+
+ // **parse** converts a response into a list of models to be added to the
+ // collection. The default implementation is just to pass it through.
+ parse: function(resp, options) {
+ return resp;
+ },
+
+ // Create a new collection with an identical list of models as this one.
+ clone: function() {
+ return new this.constructor(this.models, {
+ model: this.model,
+ comparator: this.comparator
+ });
+ },
+
+ // Define how to uniquely identify models in the collection.
+ modelId: function (attrs) {
+ return attrs[this.model.prototype.idAttribute || 'id'];
+ },
+
+ // Private method to reset all internal state. Called when the collection
+ // is first initialized or reset.
+ _reset: function() {
+ this.length = 0;
+ this.models = [];
+ this._byId = {};
+ },
+
+ // Prepare a hash of attributes (or other model) to be added to this
+ // collection.
+ _prepareModel: function(attrs, options) {
+ if (this._isModel(attrs)) {
+ if (!attrs.collection) attrs.collection = this;
+ return attrs;
+ }
+ options = options ? _.clone(options) : {};
+ options.collection = this;
+ var model = new this.model(attrs, options);
+ if (!model.validationError) return model;
+ this.trigger('invalid', this, model.validationError, options);
+ return false;
+ },
+
+ // Method for checking whether an object should be considered a model for
+ // the purposes of adding to the collection.
+ _isModel: function (model) {
+ return model instanceof Model;
+ },
+
+ // Internal method to create a model's ties to a collection.
+ _addReference: function(model, options) {
+ this._byId[model.cid] = model;
+ var id = this.modelId(model.attributes);
+ if (id != null) this._byId[id] = model;
+ model.on('all', this._onModelEvent, this);
+ },
+
+ // Internal method to sever a model's ties to a collection.
+ _removeReference: function(model, options) {
+ if (this === model.collection) delete model.collection;
+ model.off('all', this._onModelEvent, this);
+ },
+
+ // Internal method called every time a model in the set fires an event.
+ // Sets need to update their indexes when models change ids. All other
+ // events simply proxy through. "add" and "remove" events that originate
+ // in other collections are ignored.
+ _onModelEvent: function(event, model, collection, options) {
+ if ((event === 'add' || event === 'remove') && collection !== this) return;
+ if (event === 'destroy') this.remove(model, options);
+ if (event === 'change') {
+ var prevId = this.modelId(model.previousAttributes());
+ var id = this.modelId(model.attributes);
+ if (prevId !== id) {
+ if (prevId != null) delete this._byId[prevId];
+ if (id != null) this._byId[id] = model;
+ }
+ }
+ this.trigger.apply(this, arguments);
+ }
+
+});
+
+// Underscore methods that we want to implement on the Collection.
+// 90% of the core usefulness of Backbone Collections is actually implemented
+// right here:
+var methods = ['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', 'sample', 'partition'];
+
+// Mix in each Underscore method as a proxy to `Collection#models`.
+_.each(methods, function(method) {
+ if (!_[method]) return;
+ Collection.prototype[method] = function() {
+ var args = slice.call(arguments);
+ args.unshift(this.models);
+ return _[method].apply(_, args);
+ };
+});
+
+// Underscore methods that take a property name as an argument.
+var attributeMethods = ['groupBy', 'countBy', 'sortBy', 'indexBy'];
+
+// Use attributes instead of properties.
+_.each(attributeMethods, function(method) {
+ if (!_[method]) return;
+ Collection.prototype[method] = function(value, context) {
+ var iterator = _.isFunction(value) ? value : function(model) {
+ return model.get(value);
+ };
+ return _[method](this.models, iterator, context);
+ };
+});
+
+// setup inheritance
+Collection.extend = extend;
+module.exports = Collection;
+
+},{"./model":6,"backbone-events-standalone":8,"backbone-extend-standalone":9,"underscore":59}],5:[function(require,module,exports){
+module.exports.Model = require("./model");
+module.exports.Collection = require("./collection");
+module.exports.Events = require("backbone-events-standalone");
+module.exports.extend = require("backbone-extend-standalone");
+
+},{"./collection":4,"./model":6,"backbone-events-standalone":8,"backbone-extend-standalone":9}],6:[function(require,module,exports){
+// Backbone.js 1.1.2
+
+// (c) 2010-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
+// Backbone may be freely distributed under the MIT license.
+// For all details and documentation:
+// http://backbonejs.org
+
+var Events = require("backbone-events-standalone");
+var extend = require("backbone-extend-standalone");
+var _ = require("underscore");
+
+// Backbone.Model
+// --------------
+
+// Backbone **Models** are the basic data object in the framework --
+// frequently representing a row in a table in a database on your server.
+// A discrete chunk of data and a bunch of useful, related methods for
+// performing computations and transformations on that data.
+
+// Create a new model with the specified attributes. A client id (`cid`)
+// is automatically generated and assigned for you.
+var Model = function(attributes, options) {
+ var attrs = attributes || {};
+ options || (options = {});
+ this.cid = _.uniqueId('c');
+ this.attributes = {};
+ if (options.collection) this.collection = options.collection;
+ if (options.parse) attrs = this.parse(attrs, options) || {};
+ attrs = _.defaults({}, attrs, _.result(this, 'defaults'));
+ this.set(attrs, options);
+ this.changed = {};
+ this.initialize.apply(this, arguments);
+};
+
+// Attach all inheritable methods to the Model prototype.
+_.extend(Model.prototype, Events, {
+
+ // A hash of attributes whose current and previous value differ.
+ changed: null,
+
+ // The value returned during the last failed validation.
+ validationError: null,
+
+ // The default name for the JSON `id` attribute is `"id"`. MongoDB and
+ // CouchDB users may want to set this to `"_id"`.
+ idAttribute: 'id',
+
+ // Initialize is an empty function by default. Override it with your own
+ // initialization logic.
+ initialize: function(){},
+
+ // Return a copy of the model's `attributes` object.
+ toJSON: function(options) {
+ return _.clone(this.attributes);
+ },
+
+ // Proxy `Backbone.sync` by default -- but override this if you need
+ // custom syncing semantics for *this* particular model.
+ sync: function() {
+ return Backbone.sync.apply(this, arguments);
+ },
+
+ // Get the value of an attribute.
+ get: function(attr) {
+ return this.attributes[attr];
+ },
+
+ // Get the HTML-escaped value of an attribute.
+ escape: function(attr) {
+ return _.escape(this.get(attr));
+ },
+
+ // Returns `true` if the attribute contains a value that is not null
+ // or undefined.
+ has: function(attr) {
+ return this.get(attr) != null;
+ },
+
+ // Set a hash of model attributes on the object, firing `"change"`. This is
+ // the core primitive operation of a model, updating the data and notifying
+ // anyone who needs to know about the change in state. The heart of the beast.
+ set: function(key, val, options) {
+ var attr, attrs, unset, changes, silent, changing, prev, current;
+ if (key == null) return this;
+
+ // Handle both `"key", value` and `{key: value}` -style arguments.
+ if (typeof key === 'object') {
+ attrs = key;
+ options = val;
+ } else {
+ (attrs = {})[key] = val;
+ }
+
+ options || (options = {});
+
+ // Run validation.
+ if (!this._validate(attrs, options)) return false;
+
+ // Extract attributes and options.
+ unset = options.unset;
+ silent = options.silent;
+ changes = [];
+ changing = this._changing;
+ this._changing = true;
+
+ if (!changing) {
+ this._previousAttributes = _.clone(this.attributes);
+ this.changed = {};
+ }
+ current = this.attributes, prev = this._previousAttributes;
+
+ // Check for changes of `id`.
+ if (this.idAttribute in attrs) this.id = attrs[this.idAttribute];
+
+ // For each `set` attribute, update or delete the current value.
+ for (attr in attrs) {
+ val = attrs[attr];
+ if (!_.isEqual(current[attr], val)) changes.push(attr);
+ if (!_.isEqual(prev[attr], val)) {
+ this.changed[attr] = val;
+ } else {
+ delete this.changed[attr];
+ }
+ unset ? delete current[attr] : current[attr] = val;
+ }
+
+ // Trigger all relevant attribute changes.
+ if (!silent) {
+ if (changes.length) this._pending = options;
+ for (var i = 0, length = changes.length; i < length; i++) {
+ this.trigger('change:' + changes[i], this, current[changes[i]], options);
+ }
+ }
+
+ // You might be wondering why there's a `while` loop here. Changes can
+ // be recursively nested within `"change"` events.
+ if (changing) return this;
+ if (!silent) {
+ while (this._pending) {
+ options = this._pending;
+ this._pending = false;
+ this.trigger('change', this, options);
+ }
+ }
+ this._pending = false;
+ this._changing = false;
+ return this;
+ },
+
+ // Remove an attribute from the model, firing `"change"`. `unset` is a noop
+ // if the attribute doesn't exist.
+ unset: function(attr, options) {
+ return this.set(attr, void 0, _.extend({}, options, {unset: true}));
+ },
+
+ // Clear all attributes on the model, firing `"change"`.
+ clear: function(options) {
+ var attrs = {};
+ for (var key in this.attributes) attrs[key] = void 0;
+ return this.set(attrs, _.extend({}, options, {unset: true}));
+ },
+
+ // Determine if the model has changed since the last `"change"` event.
+ // If you specify an attribute name, determine if that attribute has changed.
+ hasChanged: function(attr) {
+ if (attr == null) return !_.isEmpty(this.changed);
+ return _.has(this.changed, attr);
+ },
+
+ // Return an object containing all the attributes that have changed, or
+ // false if there are no changed attributes. Useful for determining what
+ // parts of a view need to be updated and/or what attributes need to be
+ // persisted to the server. Unset attributes will be set to undefined.
+ // You can also pass an attributes object to diff against the model,
+ // determining if there *would be* a change.
+ changedAttributes: function(diff) {
+ if (!diff) return this.hasChanged() ? _.clone(this.changed) : false;
+ var val, changed = false;
+ var old = this._changing ? this._previousAttributes : this.attributes;
+ for (var attr in diff) {
+ if (_.isEqual(old[attr], (val = diff[attr]))) continue;
+ (changed || (changed = {}))[attr] = val;
+ }
+ return changed;
+ },
+
+ // Get the previous value of an attribute, recorded at the time the last
+ // `"change"` event was fired.
+ previous: function(attr) {
+ if (attr == null || !this._previousAttributes) return null;
+ return this._previousAttributes[attr];
+ },
+
+ // Get all of the attributes of the model at the time of the previous
+ // `"change"` event.
+ previousAttributes: function() {
+ return _.clone(this._previousAttributes);
+ },
+
+ // Fetch the model from the server. If the server's representation of the
+ // model differs from its current attributes, they will be overridden,
+ // triggering a `"change"` event.
+ fetch: function(options) {
+ options = options ? _.clone(options) : {};
+ if (options.parse === void 0) options.parse = true;
+ var model = this;
+ var success = options.success;
+ options.success = function(resp) {
+ if (!model.set(model.parse(resp, options), options)) return false;
+ if (success) success(model, resp, options);
+ model.trigger('sync', model, resp, options);
+ };
+ wrapError(this, options);
+ return this.sync('read', this, options);
+ },
+
+ // Set a hash of model attributes, and sync the model to the server.
+ // If the server returns an attributes hash that differs, the model's
+ // state will be `set` again.
+ save: function(key, val, options) {
+ var attrs, method, xhr, attributes = this.attributes;
+
+ // Handle both `"key", value` and `{key: value}` -style arguments.
+ if (key == null || typeof key === 'object') {
+ attrs = key;
+ options = val;
+ } else {
+ (attrs = {})[key] = val;
+ }
+
+ options = _.extend({validate: true}, options);
+
+ // If we're not waiting and attributes exist, save acts as
+ // `set(attr).save(null, opts)` with validation. Otherwise, check if
+ // the model will be valid when the attributes, if any, are set.
+ if (attrs && !options.wait) {
+ if (!this.set(attrs, options)) return false;
+ } else {
+ if (!this._validate(attrs, options)) return false;
+ }
+
+ // Set temporary attributes if `{wait: true}`.
+ if (attrs && options.wait) {
+ this.attributes = _.extend({}, attributes, attrs);
+ }
+
+ // After a successful server-side save, the client is (optionally)
+ // updated with the server-side state.
+ if (options.parse === void 0) options.parse = true;
+ var model = this;
+ var success = options.success;
+ options.success = function(resp) {
+ // Ensure attributes are restored during synchronous saves.
+ model.attributes = attributes;
+ var serverAttrs = model.parse(resp, options);
+ if (options.wait) serverAttrs = _.extend(attrs || {}, serverAttrs);
+ if (_.isObject(serverAttrs) && !model.set(serverAttrs, options)) {
+ return false;
+ }
+ if (success) success(model, resp, options);
+ model.trigger('sync', model, resp, options);
+ };
+ wrapError(this, options);
+
+ method = this.isNew() ? 'create' : (options.patch ? 'patch' : 'update');
+ if (method === 'patch' && !options.attrs) options.attrs = attrs;
+ xhr = this.sync(method, this, options);
+
+ // Restore attributes.
+ if (attrs && options.wait) this.attributes = attributes;
+
+ return xhr;
+ },
+
+ // Destroy this model on the server if it was already persisted.
+ // Optimistically removes the model from its collection, if it has one.
+ // If `wait: true` is passed, waits for the server to respond before removal.
+ destroy: function(options) {
+ options = options ? _.clone(options) : {};
+ var model = this;
+ var success = options.success;
+
+ var destroy = function() {
+ model.stopListening();
+ model.trigger('destroy', model, model.collection, options);
+ };
+
+ options.success = function(resp) {
+ if (options.wait || model.isNew()) destroy();
+ if (success) success(model, resp, options);
+ if (!model.isNew()) model.trigger('sync', model, resp, options);
+ };
+
+ if (this.isNew()) {
+ options.success();
+ return false;
+ }
+ wrapError(this, options);
+
+ var xhr = this.sync('delete', this, options);
+ if (!options.wait) destroy();
+ return xhr;
+ },
+
+ // Default URL for the model's representation on the server -- if you're
+ // using Backbone's restful methods, override this to change the endpoint
+ // that will be called.
+ url: function() {
+ var base =
+ _.result(this, 'urlRoot') ||
+ _.result(this.collection, 'url') ||
+ urlError();
+ if (this.isNew()) return base;
+ return base.replace(/([^\/])$/, '$1/') + encodeURIComponent(this.id);
+ },
+
+ // **parse** converts a response into the hash of attributes to be `set` on
+ // the model. The default implementation is just to pass the response along.
+ parse: function(resp, options) {
+ return resp;
+ },
+
+ // Create a new model with identical attributes to this one.
+ clone: function() {
+ return new this.constructor(this.attributes);
+ },
+
+ // A model is new if it has never been saved to the server, and lacks an id.
+ isNew: function() {
+ return !this.has(this.idAttribute);
+ },
+
+ // Check if the model is currently in a valid state.
+ isValid: function(options) {
+ return this._validate({}, _.extend(options || {}, { validate: true }));
+ },
+
+ // Run validation against the next complete set of model attributes,
+ // returning `true` if all is well. Otherwise, fire an `"invalid"` event.
+ _validate: function(attrs, options) {
+ if (!options.validate || !this.validate) return true;
+ attrs = _.extend({}, this.attributes, attrs);
+ var error = this.validationError = this.validate(attrs, options) || null;
+ if (!error) return true;
+ this.trigger('invalid', this, error, _.extend(options, {validationError: error}));
+ return false;
+ }
+
+});
+
+// Underscore methods that we want to implement on the Model.
+var modelMethods = ['keys', 'values', 'pairs', 'invert', 'pick', 'omit', 'chain', 'isEmpty'];
+
+// Mix in each Underscore method as a proxy to `Model#attributes`.
+_.each(modelMethods, function(method) {
+ if (!_[method]) return;
+ Model.prototype[method] = function() {
+ var args = slice.call(arguments);
+ args.unshift(this.attributes);
+ return _[method].apply(_, args);
+ };
+});
+
+// setup inheritance
+Model.extend = extend;
+module.exports = Model;
+
+},{"backbone-events-standalone":8,"backbone-extend-standalone":9,"underscore":59}],7:[function(require,module,exports){
+/**
+ * Standalone extraction of Backbone.Events, no external dependency required.
+ * Degrades nicely when Backone/underscore are already available in the current
+ * global context.
+ *
+ * Note that docs suggest to use underscore's `_.extend()` method to add Events
+ * support to some given object. A `mixin()` method has been added to the Events
+ * prototype to avoid using underscore for that sole purpose:
+ *
+ * var myEventEmitter = BackboneEvents.mixin({});
+ *
+ * Or for a function constructor:
+ *
+ * function MyConstructor(){}
+ * MyConstructor.prototype.foo = function(){}
+ * BackboneEvents.mixin(MyConstructor.prototype);
+ *
+ * (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
+ * (c) 2013 Nicolas Perriault
+ */
+/* global exports:true, define, module */
+(function() {
+ var root = this,
+ breaker = {},
+ nativeForEach = Array.prototype.forEach,
+ hasOwnProperty = Object.prototype.hasOwnProperty,
+ slice = Array.prototype.slice,
+ idCounter = 0;
+
+ // Returns a partial implementation matching the minimal API subset required
+ // by Backbone.Events
+ function miniscore() {
+ return {
+ keys: Object.keys || function (obj) {
+ if (typeof obj !== "object" && typeof obj !== "function" || obj === null) {
+ throw new TypeError("keys() called on a non-object");
+ }
+ var key, keys = [];
+ for (key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ keys[keys.length] = key;
+ }
+ }
+ return keys;
+ },
+
+ uniqueId: function(prefix) {
+ var id = ++idCounter + '';
+ return prefix ? prefix + id : id;
+ },
+
+ has: function(obj, key) {
+ return hasOwnProperty.call(obj, key);
+ },
+
+ each: function(obj, iterator, context) {
+ if (obj == null) return;
+ if (nativeForEach && obj.forEach === nativeForEach) {
+ obj.forEach(iterator, context);
+ } else if (obj.length === +obj.length) {
+ for (var i = 0, l = obj.length; i < l; i++) {
+ if (iterator.call(context, obj[i], i, obj) === breaker) return;
+ }
+ } else {
+ for (var key in obj) {
+ if (this.has(obj, key)) {
+ if (iterator.call(context, obj[key], key, obj) === breaker) return;
+ }
+ }
+ }
+ },
+
+ once: function(func) {
+ var ran = false, memo;
+ return function() {
+ if (ran) return memo;
+ ran = true;
+ memo = func.apply(this, arguments);
+ func = null;
+ return memo;
+ };
+ }
+ };
+ }
+
+ var _ = miniscore(), Events;
+
+ // Backbone.Events
+ // ---------------
+
+ // A module that can be mixed in to *any object* in order to provide it with
+ // custom events. You may bind with `on` or remove with `off` callback
+ // functions to an event; `trigger`-ing an event fires all callbacks in
+ // succession.
+ //
+ // var object = {};
+ // _.extend(object, Backbone.Events);
+ // object.on('expand', function(){ alert('expanded'); });
+ // object.trigger('expand');
+ //
+ Events = {
+
+ // Bind an event to a `callback` function. Passing `"all"` will bind
+ // the callback to all events fired.
+ on: function(name, callback, context) {
+ if (!eventsApi(this, 'on', name, [callback, context]) || !callback) return this;
+ this._events || (this._events = {});
+ var events = this._events[name] || (this._events[name] = []);
+ events.push({callback: callback, context: context, ctx: context || this});
+ return this;
+ },
+
+ // Bind an event to only be triggered a single time. After the first time
+ // the callback is invoked, it will be removed.
+ once: function(name, callback, context) {
+ if (!eventsApi(this, 'once', name, [callback, context]) || !callback) return this;
+ var self = this;
+ var once = _.once(function() {
+ self.off(name, once);
+ callback.apply(this, arguments);
+ });
+ once._callback = callback;
+ return this.on(name, once, context);
+ },
+
+ // Remove one or many callbacks. If `context` is null, removes all
+ // callbacks with that function. If `callback` is null, removes all
+ // callbacks for the event. If `name` is null, removes all bound
+ // callbacks for all events.
+ off: function(name, callback, context) {
+ var retain, ev, events, names, i, l, j, k;
+ if (!this._events || !eventsApi(this, 'off', name, [callback, context])) return this;
+ if (!name && !callback && !context) {
+ this._events = {};
+ return this;
+ }
+
+ names = name ? [name] : _.keys(this._events);
+ for (i = 0, l = names.length; i < l; i++) {
+ name = names[i];
+ if (events = this._events[name]) {
+ this._events[name] = retain = [];
+ if (callback || context) {
+ for (j = 0, k = events.length; j < k; j++) {
+ ev = events[j];
+ if ((callback && callback !== ev.callback && callback !== ev.callback._callback) ||
+ (context && context !== ev.context)) {
+ retain.push(ev);
+ }
+ }
+ }
+ if (!retain.length) delete this._events[name];
+ }
+ }
+
+ return this;
+ },
+
+ // Trigger one or many events, firing all bound callbacks. Callbacks are
+ // passed the same arguments as `trigger` is, apart from the event name
+ // (unless you're listening on `"all"`, which will cause your callback to
+ // receive the true name of the event as the first argument).
+ trigger: function(name) {
+ if (!this._events) return this;
+ var args = slice.call(arguments, 1);
+ if (!eventsApi(this, 'trigger', name, args)) return this;
+ var events = this._events[name];
+ var allEvents = this._events.all;
+ if (events) triggerEvents(events, args);
+ if (allEvents) triggerEvents(allEvents, arguments);
+ return this;
+ },
+
+ // Tell this object to stop listening to either specific events ... or
+ // to every object it's currently listening to.
+ stopListening: function(obj, name, callback) {
+ var listeners = this._listeners;
+ if (!listeners) return this;
+ var deleteListener = !name && !callback;
+ if (typeof name === 'object') callback = this;
+ if (obj) (listeners = {})[obj._listenerId] = obj;
+ for (var id in listeners) {
+ listeners[id].off(name, callback, this);
+ if (deleteListener) delete this._listeners[id];
+ }
+ return this;
+ }
+
+ };
+
+ // Regular expression used to split event strings.
+ var eventSplitter = /\s+/;
+
+ // Implement fancy features of the Events API such as multiple event
+ // names `"change blur"` and jQuery-style event maps `{change: action}`
+ // in terms of the existing API.
+ var eventsApi = function(obj, action, name, rest) {
+ if (!name) return true;
+
+ // Handle event maps.
+ if (typeof name === 'object') {
+ for (var key in name) {
+ obj[action].apply(obj, [key, name[key]].concat(rest));
+ }
+ return false;
+ }
+
+ // Handle space separated event names.
+ if (eventSplitter.test(name)) {
+ var names = name.split(eventSplitter);
+ for (var i = 0, l = names.length; i < l; i++) {
+ obj[action].apply(obj, [names[i]].concat(rest));
+ }
+ return false;
+ }
+
+ return true;
+ };
+
+ // A difficult-to-believe, but optimized internal dispatch function for
+ // triggering events. Tries to keep the usual cases speedy (most internal
+ // Backbone events have 3 arguments).
+ var triggerEvents = function(events, args) {
+ var ev, i = -1, l = events.length, a1 = args[0], a2 = args[1], a3 = args[2];
+ switch (args.length) {
+ case 0: while (++i < l) (ev = events[i]).callback.call(ev.ctx); return;
+ case 1: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1); return;
+ case 2: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2); return;
+ case 3: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2, a3); return;
+ default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args);
+ }
+ };
+
+ var listenMethods = {listenTo: 'on', listenToOnce: 'once'};
+
+ // Inversion-of-control versions of `on` and `once`. Tell *this* object to
+ // listen to an event in another object ... keeping track of what it's
+ // listening to.
+ _.each(listenMethods, function(implementation, method) {
+ Events[method] = function(obj, name, callback) {
+ var listeners = this._listeners || (this._listeners = {});
+ var id = obj._listenerId || (obj._listenerId = _.uniqueId('l'));
+ listeners[id] = obj;
+ if (typeof name === 'object') callback = this;
+ obj[implementation](name, callback, this);
+ return this;
+ };
+ });
+
+ // Aliases for backwards compatibility.
+ Events.bind = Events.on;
+ Events.unbind = Events.off;
+
+ // Mixin utility
+ Events.mixin = function(proto) {
+ var exports = ['on', 'once', 'off', 'trigger', 'stopListening', 'listenTo',
+ 'listenToOnce', 'bind', 'unbind'];
+ _.each(exports, function(name) {
+ proto[name] = this[name];
+ }, this);
+ return proto;
+ };
+
+ // Export Events as BackboneEvents depending on current context
+ if (typeof define === "function") {
+ define(function() {
+ return Events;
+ });
+ } else if (typeof exports !== 'undefined') {
+ if (typeof module !== 'undefined' && module.exports) {
+ exports = module.exports = Events;
+ }
+ exports.BackboneEvents = Events;
+ } else {
+ root.BackboneEvents = Events;
+ }
+})(this);
+
+},{}],8:[function(require,module,exports){
+module.exports = require('./backbone-events-standalone');
+
+},{"./backbone-events-standalone":7}],9:[function(require,module,exports){
+(function (definition) {
+ if (typeof exports === "object") {
+ module.exports = definition();
+ }
+ else if (typeof define === 'function' && define.amd) {
+ define(definition);
+ }
+ else {
+ window.BackboneExtend = definition();
+ }
+})(function () {
+ "use strict";
+
+ // mini-underscore
+ var _ = {
+ has: function (obj, key) {
+ return Object.prototype.hasOwnProperty.call(obj, key);
+ },
+
+ extend: function(obj) {
+ for (var i=1; i<arguments.length; ++i) {
+ var source = arguments[i];
+ if (source) {
+ for (var prop in source) {
+ obj[prop] = source[prop];
+ }
+ }
+ }
+ return obj;
+ }
+ };
+
+ /// Following code is pasted from Backbone.js ///
+
+ // Helper function to correctly set up the prototype chain, for subclasses.
+ // Similar to `goog.inherits`, but uses a hash of prototype properties and
+ // class properties to be extended.
+ var extend = function(protoProps, staticProps) {
+ var parent = this;
+ var child;
+
+ // The constructor function for the new subclass is either defined by you
+ // (the "constructor" property in your `extend` definition), or defaulted
+ // by us to simply call the parent's constructor.
+ if (protoProps && _.has(protoProps, 'constructor')) {
+ child = protoProps.constructor;
+ } else {
+ child = function(){ return parent.apply(this, arguments); };
+ }
+
+ // Add static properties to the constructor function, if supplied.
+ _.extend(child, parent, staticProps);
+
+ // Set the prototype chain to inherit from `parent`, without calling
+ // `parent`'s constructor function.
+ var Surrogate = function(){ this.constructor = child; };
+ Surrogate.prototype = parent.prototype;
+ child.prototype = new Surrogate();
+
+ // Add prototype properties (instance properties) to the subclass,
+ // if supplied.
+ if (protoProps) _.extend(child.prototype, protoProps);
+
+ // Set a convenience property in case the parent's prototype is needed
+ // later.
+ child.__super__ = parent.prototype;
+
+ return child;
+ };
+
+ // Expose the extend function
+ return extend;
+});
+
+},{}],10:[function(require,module,exports){
+// this is the extracted view model from backbone
+// note that we inject jbone as jquery replacment
+// (and underscore directly)
+//
+// Views are almost more convention than they are actual code.
+// MVC pattern
+// Backbone.View
+// -------------
+
+var _ = require("underscore");
+var Events = require("backbone-events-standalone");
+var extend = require("backbone-extend-standalone");
+var $ = require('jbone');
+
+// Backbone Views are almost more convention than they are actual code. A View
+// is simply a JavaScript object that represents a logical chunk of UI in the
+// DOM. This might be a single item, an entire list, a sidebar or panel, or
+// even the surrounding frame which wraps your whole app. Defining a chunk of
+// UI as a **View** allows you to define your DOM events declaratively, without
+// having to worry about render order ... and makes it easy for the view to
+// react to specific changes in the state of your models.
+
+// Creating a Backbone.View creates its initial element outside of the DOM,
+// if an existing element is not provided...
+var View = function(options) {
+ this.cid = _.uniqueId('view');
+ options || (options = {});
+ _.extend(this, _.pick(options, viewOptions));
+ this._ensureElement();
+ this.initialize.apply(this, arguments);
+};
+
+// Cached regex to split keys for `delegate`.
+var delegateEventSplitter = /^(\S+)\s*(.*)$/;
+
+// List of view options to be merged as properties.
+var viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName', 'events'];
+
+// Set up all inheritable **Backbone.View** properties and methods.
+_.extend(View.prototype, Events, {
+
+ // The default `tagName` of a View's element is `"div"`.
+ tagName: 'div',
+
+ // jQuery delegate for element lookup, scoped to DOM elements within the
+ // current view. This should be preferred to global lookups where possible.
+ $: function(selector) {
+ return this.$el.find(selector);
+ },
+
+ // Initialize is an empty function by default. Override it with your own
+ // initialization logic.
+ initialize: function(){},
+
+ // **render** is the core function that your view should override, in order
+ // to populate its element (`this.el`), with the appropriate HTML. The
+ // convention is for **render** to always return `this`.
+ render: function() {
+ return this;
+ },
+
+ // Remove this view by taking the element out of the DOM, and removing any
+ // applicable Backbone.Events listeners.
+ remove: function() {
+ this._removeElement();
+ this.stopListening();
+ return this;
+ },
+
+ // Remove this view's element from the document and all event listeners
+ // attached to it. Exposed for subclasses using an alternative DOM
+ // manipulation API.
+ _removeElement: function() {
+ this.$el.remove();
+ },
+
+ // Change the view's element (`this.el` property) and re-delegate the
+ // view's events on the new element.
+ setElement: function(element) {
+ this.undelegateEvents();
+ this._setElement(element);
+ this.delegateEvents();
+ return this;
+ },
+
+ // Creates the `this.el` and `this.$el` references for this view using the
+ // given `el`. `el` can be a CSS selector or an HTML string, a jQuery
+ // context or an element. Subclasses can override this to utilize an
+ // alternative DOM manipulation API and are only required to set the
+ // `this.el` property.
+ _setElement: function(el) {
+ this.$el = el instanceof $ ? el : $(el);
+ this.el = this.$el[0];
+ },
+
+ // Set callbacks, where `this.events` is a hash of
+ //
+ // *{"event selector": "callback"}*
+ //
+ // {
+ // 'mousedown .title': 'edit',
+ // 'click .button': 'save',
+ // 'click .open': function(e) { ... }
+ // }
+ //
+ // pairs. Callbacks will be bound to the view, with `this` set properly.
+ // Uses event delegation for efficiency.
+ // Omitting the selector binds the event to `this.el`.
+ delegateEvents: function(events) {
+ if (!(events || (events = _.result(this, 'events')))) return this;
+ this.undelegateEvents();
+ for (var key in events) {
+ var method = events[key];
+ if (!_.isFunction(method)) method = this[events[key]];
+ if (!method) continue;
+ var match = key.match(delegateEventSplitter);
+ this.delegate(match[1], match[2], _.bind(method, this));
+ }
+ return this;
+ },
+
+ // Add a single event listener to the view's element (or a child element
+ // using `selector`). This only works for delegate-able events: not `focus`,
+ // `blur`, and not `change`, `submit`, and `reset` in Internet Explorer.
+ delegate: function(eventName, selector, listener) {
+ this.$el.on(eventName + '.delegateEvents' + this.cid, selector, listener);
+ },
+
+ // Clears all callbacks previously bound to the view by `delegateEvents`.
+ // You usually don't need to use this, but may wish to if you have multiple
+ // Backbone views attached to the same DOM element.
+ undelegateEvents: function() {
+ if (this.$el) this.$el.off('.delegateEvents' + this.cid);
+ return this;
+ },
+
+ // A finer-grained `undelegateEvents` for removing a single delegated event.
+ // `selector` and `listener` are both optional.
+ undelegate: function(eventName, selector, listener) {
+ this.$el.off(eventName + '.delegateEvents' + this.cid, selector, listener);
+ },
+
+ // Produces a DOM element to be assigned to your view. Exposed for
+ // subclasses using an alternative DOM manipulation API.
+ _createElement: function(tagName) {
+ return document.createElement(tagName);
+ },
+
+ // Ensure that the View has a DOM element to render into.
+ // If `this.el` is a string, pass it through `$()`, take the first
+ // matching element, and re-assign it to `el`. Otherwise, create
+ // an element from the `id`, `className` and `tagName` properties.
+ _ensureElement: function() {
+ if (!this.el) {
+ var attrs = _.extend({}, _.result(this, 'attributes'));
+ if (this.id) attrs.id = _.result(this, 'id');
+ if (this.className) attrs['class'] = _.result(this, 'className');
+ this.setElement(this._createElement(_.result(this, 'tagName')));
+ this._setAttributes(attrs);
+ } else {
+ this.setElement(_.result(this, 'el'));
+ }
+ },
+
+ // Set attributes from a hash on this view's element. Exposed for
+ // subclasses using an alternative DOM manipulation API.
+ _setAttributes: function(attributes) {
+ this.$el.attr(attributes);
+ }
+
+});
+
+// setup inheritance
+View.extend = extend;
+module.exports = View;
+
+},{"backbone-events-standalone":12,"backbone-extend-standalone":13,"jbone":50,"underscore":59}],11:[function(require,module,exports){
+module.exports=require(7)
+},{"/home/travis/build/greenify/biojs-vis-msa/node_modules/backbone-thin/node_modules/backbone-events-standalone/backbone-events-standalone.js":7}],12:[function(require,module,exports){
+module.exports=require(8)
+},{"./backbone-events-standalone":11,"/home/travis/build/greenify/biojs-vis-msa/node_modules/backbone-thin/node_modules/backbone-events-standalone/index.js":8}],13:[function(require,module,exports){
+module.exports=require(9)
+},{"/home/travis/build/greenify/biojs-vis-msa/node_modules/backbone-thin/node_modules/backbone-extend-standalone/backbone-extend-standalone.js":9}],14:[function(require,module,exports){
+var events = require("backbone-events-standalone");
+
+events.onAll = function(callback,context){
+ this.on("all", callback,context);
+ return this;
+};
+
+// Mixin utility
+events.oldMixin = events.mixin;
+events.mixin = function(proto) {
+ events.oldMixin(proto);
+ // add custom onAll
+ var exports = ['onAll'];
+ for(var i=0; i < exports.length;i++){
+ var name = exports[i];
+ proto[name] = this[name];
+ }
+ return proto;
+};
+
+module.exports = events;
+
+},{"backbone-events-standalone":16}],15:[function(require,module,exports){
+module.exports=require(7)
+},{"/home/travis/build/greenify/biojs-vis-msa/node_modules/backbone-thin/node_modules/backbone-events-standalone/backbone-events-standalone.js":7}],16:[function(require,module,exports){
+module.exports=require(8)
+},{"./backbone-events-standalone":15,"/home/travis/build/greenify/biojs-vis-msa/node_modules/backbone-thin/node_modules/backbone-events-standalone/index.js":8}],17:[function(require,module,exports){
+// Generated by CoffeeScript 1.8.0
+var GenericReader, xhr;
+
+xhr = require('nets');
+
+module.exports = GenericReader = (function() {
+ function GenericReader() {}
+
+ GenericReader.read = function(url, callback) {
+ var onret;
+ onret = (function(_this) {
+ return function(err, response, text) {
+ return _this._onRetrieval(text, callback);
+ };
+ })(this);
+ return xhr(url, onret);
+ };
+
+ GenericReader._onRetrieval = function(text, callback) {
+ var rText;
+ rText = this.parse(text);
+ return callback(rText);
+ };
+
+ return GenericReader;
+
+})();
+
+},{"nets":undefined}],18:[function(require,module,exports){
+// Generated by CoffeeScript 1.8.0
+var Seq;
+
+module.exports = Seq = (function() {
+ function Seq(seq, name, id) {
+ var meta;
+ this.seq = seq;
+ this.name = name;
+ this.id = id;
+ meta = {};
+ }
+
+ return Seq;
+
+})();
+
+},{}],19:[function(require,module,exports){
+// Generated by CoffeeScript 1.8.0
+var strings;
+
+strings = {
+ contains: function(text, search) {
+ return ''.indexOf.call(text, search, 0) !== -1;
+ }
+};
+
+module.exports = strings;
+
+},{}],20:[function(require,module,exports){
+module.exports=require(17)
+},{"/home/travis/build/greenify/biojs-vis-msa/node_modules/biojs-io-clustal/lib/generic_reader.js":17,"nets":undefined}],21:[function(require,module,exports){
+// Generated by CoffeeScript 1.8.0
+var Fasta, GenericReader, Seq, Str,
+ __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; };
+
+Str = require("./strings");
+
+GenericReader = require("./generic_reader");
+
+Seq = require("biojs-model").seq;
+
+module.exports = Fasta = (function(_super) {
+ __extends(Fasta, _super);
+
+ function Fasta() {
+ return Fasta.__super__.constructor.apply(this, arguments);
+ }
+
+ Fasta.parse = function(text) {
+ var currentSeq, database, databaseID, identifiers, k, label, line, seqs, _i, _len;
+ seqs = [];
+ if (Object.prototype.toString.call(text) !== '[object Array]') {
+ text = text.split("\n");
+ }
+ for (_i = 0, _len = text.length; _i < _len; _i++) {
+ line = text[_i];
+ if (line[0] === ">" || line[0] === ";") {
+ label = line.slice(1);
+ currentSeq = new Seq("", label, seqs.length);
+ seqs.push(currentSeq);
+ if (Str.contains("|", line)) {
+ identifiers = label.split("|");
+ k = 1;
+ while (k < identifiers.length) {
+ database = identifiers[k];
+ databaseID = identifiers[k + 1];
+ currentSeq.meta[database] = databaseID;
+ k += 2;
+ }
+ currentSeq.name = identifiers[identifiers.length - 1];
+ }
+ } else {
+ currentSeq.seq += line;
+ }
+ }
+ return seqs;
+ };
+
+ return Fasta;
+
+})(GenericReader);
+
+},{"./generic_reader":20,"./strings":22,"biojs-model":25}],22:[function(require,module,exports){
+module.exports=require(19)
+},{"/home/travis/build/greenify/biojs-vis-msa/node_modules/biojs-io-clustal/lib/strings.js":19}],23:[function(require,module,exports){
+// Generated by CoffeeScript 1.8.0
+var Utils;
+
+Utils = {};
+
+Utils.splitNChars = function(txt, num) {
+ var i, result, _i, _ref;
+ result = [];
+ for (i = _i = 0, _ref = txt.length - 1; num > 0 ? _i <= _ref : _i >= _ref; i = _i += num) {
+ result.push(txt.substr(i, num));
+ }
+ return result;
+};
+
+module.exports = Utils;
+
+},{}],24:[function(require,module,exports){
+// Generated by CoffeeScript 1.8.0
+var FastaExporter, Utils;
+
+Utils = require("./utils");
+
+module.exports = FastaExporter = (function() {
+ function FastaExporter() {}
+
+ FastaExporter["export"] = function(seqs, access) {
+ var seq, text, _i, _len;
+ text = "";
+ for (_i = 0, _len = seqs.length; _i < _len; _i++) {
+ seq = seqs[_i];
+ if (access != null) {
+ seq = access(seq);
+ }
+ text += ">" + seq.name + "\n";
+ text += (Utils.splitNChars(seq.seq, 80)).join("\n");
+ text += "\n";
+ }
+ return text;
+ };
+
+ return FastaExporter;
+
+})();
+
+},{"./utils":23}],25:[function(require,module,exports){
+module.exports.seq = require("./seq");
+
+},{"./seq":26}],26:[function(require,module,exports){
+module.exports = function(seq, name, id) {
+ this.seq = seq;
+ this.name = name;
+ this.id = id;
+ this.meta = {};
+};
+
+},{}],27:[function(require,module,exports){
+module.exports=require(25)
+},{"./seq":28,"/home/travis/build/greenify/biojs-vis-msa/node_modules/biojs-io-fasta/node_modules/biojs-model/src/index.js":25}],28:[function(require,module,exports){
+module.exports=require(26)
+},{"/home/travis/build/greenify/biojs-vis-msa/node_modules/biojs-io-fasta/node_modules/biojs-model/src/seq.js":26}],29:[function(require,module,exports){
+module.exports = require('./src/index.js')
+
+},{"./src/index.js":36}],30:[function(require,module,exports){
+module.exports = {
+ A: "#00a35c",
+ R: "#00fc03",
+ N: "#00eb14",
+ D: "#00eb14",
+ C: "#0000ff",
+ Q: "#00f10e",
+ E: "#00f10e",
+ G: "#009d62",
+ H: "#00d52a",
+ I: "#0054ab",
+ L: "#007b84",
+ K: "#00ff00",
+ M: "#009768",
+ F: "#008778",
+ P: "#00e01f",
+ S: "#00d52a",
+ T: "#00db24",
+ W: "#00a857",
+ Y: "#00e619",
+ V: "#005fa0",
+ B: "#00eb14",
+ X: "#00b649",
+ Z: "#00f10e"
+};
+
+},{}],31:[function(require,module,exports){
+module.exports = {
+ A: "#BBBBBB",
+ B: "grey",
+ C: "yellow",
+ D: "red",
+ E: "red",
+ F: "magenta",
+ G: "brown",
+ H: "#00FFFF",
+ I: "#BBBBBB",
+ J: "#fff",
+ K: "#00FFFF",
+ L: "#BBBBBB",
+ M: "#BBBBBB",
+ N: "green",
+ O: "#fff",
+ P: "brown",
+ Q: "green",
+ R: "#00FFFF",
+ S: "green",
+ T: "green",
+ U: "#fff",
+ V: "#BBBBBB",
+ W: "magenta",
+ X: "grey",
+ Y: "magenta",
+ Z: "grey",
+ Gap: "grey"
+};
+
+},{}],32:[function(require,module,exports){
+module.exports = {
+ A: "orange",
+ B: "#fff",
+ C: "green",
+ D: "red",
+ E: "red",
+ F: "blue",
+ G: "orange",
+ H: "red",
+ I: "green",
+ J: "#fff",
+ K: "red",
+ L: "green",
+ M: "green",
+ N: "#fff",
+ O: "#fff",
+ P: "orange",
+ Q: "#fff",
+ R: "red",
+ S: "orange",
+ T: "orange",
+ U: "#fff",
+ V: "green",
+ W: "blue",
+ X: "#fff",
+ Y: "blue",
+ Z: "#fff",
+ Gap: "#fff"
+};
+
+},{}],33:[function(require,module,exports){
+module.exports = {
+ A: "#80a0f0",
+ R: "#f01505",
+ N: "#00ff00",
+ D: "#c048c0",
+ C: "#f08080",
+ Q: "#00ff00",
+ E: "#c048c0",
+ G: "#f09048",
+ H: "#15a4a4",
+ I: "#80a0f0",
+ L: "#80a0f0",
+ K: "#f01505",
+ M: "#80a0f0",
+ F: "#80a0f0",
+ P: "#ffff00",
+ S: "#00ff00",
+ T: "#00ff00",
+ W: "#80a0f0",
+ Y: "#15a4a4",
+ V: "#80a0f0",
+ B: "#fff",
+ X: "#fff",
+ Z: "#fff"
+};
+
+},{}],34:[function(require,module,exports){
+module.exports = {
+ A: "#e718e7",
+ R: "#6f906f",
+ N: "#1be41b",
+ D: "#778877",
+ C: "#23dc23",
+ Q: "#926d92",
+ E: "#ff00ff",
+ G: "#00ff00",
+ H: "#758a75",
+ I: "#8a758a",
+ L: "#ae51ae",
+ K: "#a05fa0",
+ M: "#ef10ef",
+ F: "#986798",
+ P: "#00ff00",
+ S: "#36c936",
+ T: "#47b847",
+ W: "#8a758a",
+ Y: "#21de21",
+ V: "#857a85",
+ B: "#49b649",
+ X: "#758a75",
+ Z: "#c936c9"
+};
+
+},{}],35:[function(require,module,exports){
+module.exports = {
+ A: "#ad0052",
+ B: "#0c00f3",
+ C: "#c2003d",
+ D: "#0c00f3",
+ E: "#0c00f3",
+ F: "#cb0034",
+ G: "#6a0095",
+ H: "#1500ea",
+ I: "#ff0000",
+ J: "#fff",
+ K: "#0000ff",
+ L: "#ea0015",
+ M: "#b0004f",
+ N: "#0c00f3",
+ O: "#fff",
+ P: "#4600b9",
+ Q: "#0c00f3",
+ R: "#0000ff",
+ S: "#5e00a1",
+ T: "#61009e",
+ U: "#fff",
+ V: "#f60009",
+ W: "#5b00a4",
+ X: "#680097",
+ Y: "#4f00b0",
+ Z: "#0c00f3"
+};
+
+},{}],36:[function(require,module,exports){
+module.exports.selector = require("./selector");
+
+// basics
+module.exports.taylor = require("./taylor");
+module.exports.zappo= require("./zappo");
+module.exports.hydro= require("./hydrophobicity");
+
+module.exports.clustal = require("./clustal");
+module.exports.clustal2 = require("./clustal2");
+
+module.exports.curied = require("./buried");
+module.exports.cinema = require("./cinema");
+module.exports.nucleotide = require("./nucleotide");
+module.exports.helix = require("./helix");
+module.exports.lesk = require("./lesk");
+module.exports.mae = require("./mae");
+module.exports.purine = require("./purine");
+module.exports.strand = require("./strand");
+module.exports.turn = require("./turn");
+
+},{"./buried":30,"./cinema":31,"./clustal":32,"./clustal2":33,"./helix":34,"./hydrophobicity":35,"./lesk":37,"./mae":38,"./nucleotide":39,"./purine":40,"./selector":41,"./strand":42,"./taylor":43,"./turn":44,"./zappo":45}],37:[function(require,module,exports){
+module.exports = {
+ A: " orange",
+ B: " #fff",
+ C: " green",
+ D: " red",
+ E: " red",
+ F: " green",
+ G: " orange",
+ H: " magenta",
+ I: " green",
+ J: " #fff",
+ K: " red",
+ L: " green",
+ M: " green",
+ N: " magenta",
+ O: " #fff",
+ P: " green",
+ Q: " magenta",
+ R: " red",
+ S: " orange",
+ T: " orange",
+ U: " #fff",
+ V: " green",
+ W: " green",
+ X: " #fff",
+ Y: " green",
+ Z: " #fff",
+ Gap: " #fff"
+};
+
+},{}],38:[function(require,module,exports){
+module.exports = {
+ A: " #77dd88",
+ B: " #fff",
+ C: " #99ee66",
+ D: " #55bb33",
+ E: " #55bb33",
+ F: " #9999ff",
+ G: " #77dd88",
+ H: " #5555ff",
+ I: " #66bbff",
+ J: " #fff",
+ K: " #ffcc77",
+ L: " #66bbff",
+ M: " #66bbff",
+ N: " #55bb33",
+ O: " #fff",
+ P: " #eeaaaa",
+ Q: " #55bb33",
+ R: " #ffcc77",
+ S: " #ff4455",
+ T: " #ff4455",
+ U: " #fff",
+ V: " #66bbff",
+ W: " #9999ff",
+ X: " #fff",
+ Y: " #9999ff",
+ Z: " #fff",
+ Gap: " #fff"
+};
+
+},{}],39:[function(require,module,exports){
+module.exports = {
+ A: " #64F73F",
+ C: " #FFB340",
+ G: " #EB413C",
+ T: " #3C88EE",
+ U: " #3C88EE"
+};
+
+},{}],40:[function(require,module,exports){
+module.exports = {
+ A: " #FF83FA",
+ C: " #40E0D0",
+ G: " #FF83FA",
+ R: " #FF83FA",
+ T: " #40E0D0",
+ U: " #40E0D0",
+ Y: " #40E0D0"
+};
+
+},{}],41:[function(require,module,exports){
+var Buried = require("./buried");
+var Cinema = require("./cinema");
+var Clustal = require("./clustal");
+var Clustal2 = require("./clustal2");
+var Helix = require("./helix");
+var Hydro = require("./hydrophobicity");
+var Lesk = require("./lesk");
+var Mae = require("./mae");
+var Nucleotide = require("./nucleotide");
+var Purine = require("./purine");
+var Strand = require("./strand");
+var Taylor = require("./taylor");
+var Turn = require("./turn");
+var Zappo = require("./zappo");
+
+module.exports = Colors = {
+ mapping: {
+ buried: Buried,
+ buried_index: Buried,
+ cinema: Cinema,
+ clustal2: Clustal2,
+ clustal: Clustal,
+ helix: Helix,
+ helix_propensity: Helix,
+ hydro: Hydro,
+ lesk: Lesk,
+ mae: Mae,
+ nucleotide: Nucleotide,
+ purine: Purine,
+ purine_pyrimidine: Purine,
+ strand: Strand,
+ strand_propensity: Strand,
+ taylor: Taylor,
+ turn: Turn,
+ turn_propensity: Turn,
+ zappo: Zappo,
+ },
+ getColor: function(scheme) {
+ var color = Colors.mapping[scheme];
+ if (color === undefined) {
+ color = {};
+ }
+ return color;
+ }
+};
+
+},{"./buried":30,"./cinema":31,"./clustal":32,"./clustal2":33,"./helix":34,"./hydrophobicity":35,"./lesk":37,"./mae":38,"./nucleotide":39,"./purine":40,"./strand":42,"./taylor":43,"./turn":44,"./zappo":45}],42:[function(require,module,exports){
+module.exports = {
+ A: "#5858a7",
+ R: "#6b6b94",
+ N: "#64649b",
+ D: "#2121de",
+ C: "#9d9d62",
+ Q: "#8c8c73",
+ E: "#0000ff",
+ G: "#4949b6",
+ H: "#60609f",
+ I: "#ecec13",
+ L: "#b2b24d",
+ K: "#4747b8",
+ M: "#82827d",
+ F: "#c2c23d",
+ P: "#2323dc",
+ S: "#4949b6",
+ T: "#9d9d62",
+ W: "#c0c03f",
+ Y: "#d3d32c",
+ V: "#ffff00",
+ B: "#4343bc",
+ X: "#797986",
+ Z: "#4747b8"
+};
+
+},{}],43:[function(require,module,exports){
+module.exports = {
+ A: "#ccff00",
+ R: "#0000ff",
+ N: "#cc00ff",
+ D: "#ff0000",
+ C: "#ffff00",
+ Q: "#ff00cc",
+ E: "#ff0066",
+ G: "#ff9900",
+ H: "#0066ff",
+ I: "#66ff00",
+ L: "#33ff00",
+ K: "#6600ff",
+ M: "#00ff00",
+ F: "#00ff66",
+ P: "#ffcc00",
+ S: "#ff3300",
+ T: "#ff6600",
+ W: "#00ccff",
+ Y: "#00ffcc",
+ V: "#99ff00",
+ B: "#fff",
+ X: "#fff",
+ Z: "#fff"
+};
+
+},{}],44:[function(require,module,exports){
+module.exports = {
+ A: "#2cd3d3",
+ R: "#708f8f",
+ N: "#ff0000",
+ D: "#e81717",
+ C: "#a85757",
+ Q: "#3fc0c0",
+ E: "#778888",
+ G: "#ff0000",
+ H: "#708f8f",
+ I: "#00ffff",
+ L: "#1ce3e3",
+ K: "#7e8181",
+ M: "#1ee1e1",
+ F: "#1ee1e1",
+ P: "#f60909",
+ S: "#e11e1e",
+ T: "#738c8c",
+ W: "#738c8c",
+ Y: "#9d6262",
+ V: "#07f8f8",
+ B: "#f30c0c",
+ X: "#7c8383",
+ Z: "#5ba4a4"
+};
+
+},{}],45:[function(require,module,exports){
+module.exports = {
+ A: "#ffafaf",
+ R: "#6464ff",
+ N: "#00ff00",
+ D: "#ff0000",
+ C: "#ffff00",
+ Q: "#00ff00",
+ E: "#ff0000",
+ G: "#ff00ff",
+ H: "#6464ff",
+ I: "#ffafaf",
+ L: "#ffafaf",
+ K: "#6464ff",
+ M: "#ffafaf",
+ F: "#ffc800",
+ P: "#ff00ff",
+ S: "#00ff00",
+ T: "#00ff00",
+ W: "#ffc800",
+ Y: "#ffc800",
+ V: "#ffafaf",
+ B: "#fff",
+ X: "#fff",
+ Z: "#fff"
+};
+
+},{}],46:[function(require,module,exports){
+/*
+ * JavaScript Canvas to Blob 2.0.5
+ * https://github.com/blueimp/JavaScript-Canvas-to-Blob
+ *
+ * Copyright 2012, Sebastian Tschan
+ * https://blueimp.net
+ *
+ * Licensed under the MIT license:
+ * http://www.opensource.org/licenses/MIT
+ *
+ * Based on stackoverflow user Stoive's code snippet:
+ * http://stackoverflow.com/q/4998908
+ */
+var CanvasPrototype = window.HTMLCanvasElement &&
+window.HTMLCanvasElement.prototype,
+ hasBlobConstructor = window.Blob && (function () {
+ try {
+ return Boolean(new Blob());
+ } catch (e) {
+ return false;
+ }
+ }()),
+ hasArrayBufferViewSupport = hasBlobConstructor && window.Uint8Array &&
+ (function () {
+ try {
+ return new Blob([new Uint8Array(100)]).size === 100;
+ } catch (e) {
+ return false;
+ }
+ }()),
+ BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder ||
+ window.MozBlobBuilder || window.MSBlobBuilder,
+ dataURLtoBlob = (hasBlobConstructor || BlobBuilder) && window.atob &&
+ window.ArrayBuffer && window.Uint8Array && function (dataURI) {
+ var byteString,
+ arrayBuffer,
+ intArray,
+ i,
+ mimeString,
+ bb;
+ if (dataURI.split(',')[0].indexOf('base64') >= 0) {
+ // Convert base64 to raw binary data held in a string:
+ byteString = atob(dataURI.split(',')[1]);
+ } else {
+ // Convert base64/URLEncoded data component to raw binary data:
+ byteString = decodeURIComponent(dataURI.split(',')[1]);
+ }
+ // Write the bytes of the string to an ArrayBuffer:
+ arrayBuffer = new ArrayBuffer(byteString.length);
+ intArray = new Uint8Array(arrayBuffer);
+ for (i = 0; i < byteString.length; i += 1) {
+ intArray[i] = byteString.charCodeAt(i);
+ }
+ // Separate out the mime component:
+ mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
+ // Write the ArrayBuffer (or ArrayBufferView) to a blob:
+ if (hasBlobConstructor) {
+ return new Blob(
+ [hasArrayBufferViewSupport ? intArray : arrayBuffer],
+ {type: mimeString}
+ );
+ }
+ bb = new BlobBuilder();
+ bb.append(arrayBuffer);
+ return bb.getBlob(mimeString);
+ };
+if (window.HTMLCanvasElement && !CanvasPrototype.toBlob) {
+ if (CanvasPrototype.mozGetAsFile) {
+ CanvasPrototype.toBlob = function (callback, type, quality) {
+ if (quality && CanvasPrototype.toDataURL && dataURLtoBlob) {
+ callback(dataURLtoBlob(this.toDataURL(type, quality)));
+ } else {
+ callback(this.mozGetAsFile('blob', type));
+ }
+ };
+ } else if (CanvasPrototype.toDataURL && dataURLtoBlob) {
+ CanvasPrototype.toBlob = function (callback, type, quality) {
+ callback(dataURLtoBlob(this.toDataURL(type, quality)));
+ };
+ }
+}
+
+module.exports = dataURLtoBlob;
+
+},{}],47:[function(require,module,exports){
+/* FileSaver.js
+ * A saveAs() FileSaver implementation.
+ * 2014-05-27
+ *
+ * By Eli Grey, http://eligrey.com
+ * License: X11/MIT
+ * See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
+ */
+
+/*global self */
+/*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
+
+/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
+
+var saveAs = saveAs
+ // IE 10+ (native saveAs)
+ || (typeof navigator !== "undefined" &&
+ navigator.msSaveOrOpenBlob && navigator.msSaveOrOpenBlob.bind(navigator))
+ // Everyone else
+ || (function(view) {
+ "use strict";
+ // IE <10 is explicitly unsupported
+ if (typeof navigator !== "undefined" &&
+ /MSIE [1-9]\./.test(navigator.userAgent)) {
+ return;
+ }
+ var
+ doc = view.document
+ // only get URL when necessary in case Blob.js hasn't overridden it yet
+ , get_URL = function() {
+ return view.URL || view.webkitURL || view;
+ }
+ , save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
+ , can_use_save_link = !view.externalHost && "download" in save_link
+ , click = function(node) {
+ var event = doc.createEvent("MouseEvents");
+ event.initMouseEvent(
+ "click", true, false, view, 0, 0, 0, 0, 0
+ , false, false, false, false, 0, null
+ );
+ node.dispatchEvent(event);
+ }
+ , webkit_req_fs = view.webkitRequestFileSystem
+ , req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem
+ , throw_outside = function(ex) {
+ (view.setImmediate || view.setTimeout)(function() {
+ throw ex;
+ }, 0);
+ }
+ , force_saveable_type = "application/octet-stream"
+ , fs_min_size = 0
+ , deletion_queue = []
+ , process_deletion_queue = function() {
+ var i = deletion_queue.length;
+ while (i--) {
+ var file = deletion_queue[i];
+ if (typeof file === "string") { // file is an object URL
+ get_URL().revokeObjectURL(file);
+ } else { // file is a File
+ file.remove();
+ }
+ }
+ deletion_queue.length = 0; // clear queue
+ }
+ , dispatch = function(filesaver, event_types, event) {
+ event_types = [].concat(event_types);
+ var i = event_types.length;
+ while (i--) {
+ var listener = filesaver["on" + event_types[i]];
+ if (typeof listener === "function") {
+ try {
+ listener.call(filesaver, event || filesaver);
+ } catch (ex) {
+ throw_outside(ex);
+ }
+ }
+ }
+ }
+ , FileSaver = function(blob, name) {
+ // First try a.download, then web filesystem, then object URLs
+ var
+ filesaver = this
+ , type = blob.type
+ , blob_changed = false
+ , object_url
+ , target_view
+ , get_object_url = function() {
+ var object_url = get_URL().createObjectURL(blob);
+ deletion_queue.push(object_url);
+ return object_url;
+ }
+ , dispatch_all = function() {
+ dispatch(filesaver, "writestart progress write writeend".split(" "));
+ }
+ // on any filesys errors revert to saving with object URLs
+ , fs_error = function() {
+ // don't create more object URLs than needed
+ if (blob_changed || !object_url) {
+ object_url = get_object_url(blob);
+ }
+ if (target_view) {
+ target_view.location.href = object_url;
+ } else {
+ window.open(object_url, "_blank");
+ }
+ filesaver.readyState = filesaver.DONE;
+ dispatch_all();
+ }
+ , abortable = function(func) {
+ return function() {
+ if (filesaver.readyState !== filesaver.DONE) {
+ return func.apply(this, arguments);
+ }
+ };
+ }
+ , create_if_not_found = {create: true, exclusive: false}
+ , slice
+ ;
+ filesaver.readyState = filesaver.INIT;
+ if (!name) {
+ name = "download";
+ }
+ if (can_use_save_link) {
+ object_url = get_object_url(blob);
+ save_link.href = object_url;
+ save_link.download = name;
+ click(save_link);
+ filesaver.readyState = filesaver.DONE;
+ dispatch_all();
+ return;
+ }
+ // Object and web filesystem URLs have a problem saving in Google Chrome when
+ // viewed in a tab, so I force save with application/octet-stream
+ // http://code.google.com/p/chromium/issues/detail?id=91158
+ if (view.chrome && type && type !== force_saveable_type) {
+ slice = blob.slice || blob.webkitSlice;
+ blob = slice.call(blob, 0, blob.size, force_saveable_type);
+ blob_changed = true;
+ }
+ // Since I can't be sure that the guessed media type will trigger a download
+ // in WebKit, I append .download to the filename.
+ // https://bugs.webkit.org/show_bug.cgi?id=65440
+ if (webkit_req_fs && name !== "download") {
+ name += ".download";
+ }
+ if (type === force_saveable_type || webkit_req_fs) {
+ target_view = view;
+ }
+ if (!req_fs) {
+ fs_error();
+ return;
+ }
+ fs_min_size += blob.size;
+ req_fs(view.TEMPORARY, fs_min_size, abortable(function(fs) {
+ fs.root.getDirectory("saved", create_if_not_found, abortable(function(dir) {
+ var save = function() {
+ dir.getFile(name, create_if_not_found, abortable(function(file) {
+ file.createWriter(abortable(function(writer) {
+ writer.onwriteend = function(event) {
+ target_view.location.href = file.toURL();
+ deletion_queue.push(file);
+ filesaver.readyState = filesaver.DONE;
+ dispatch(filesaver, "writeend", event);
+ };
+ writer.onerror = function() {
+ var error = writer.error;
+ if (error.code !== error.ABORT_ERR) {
+ fs_error();
+ }
+ };
+ "writestart progress write abort".split(" ").forEach(function(event) {
+ writer["on" + event] = filesaver["on" + event];
+ });
+ writer.write(blob);
+ filesaver.abort = function() {
+ writer.abort();
+ filesaver.readyState = filesaver.DONE;
+ };
+ filesaver.readyState = filesaver.WRITING;
+ }), fs_error);
+ }), fs_error);
+ };
+ dir.getFile(name, {create: false}, abortable(function(file) {
+ // delete file if it already exists
+ file.remove();
+ save();
+ }), abortable(function(ex) {
+ if (ex.code === ex.NOT_FOUND_ERR) {
+ save();
+ } else {
+ fs_error();
+ }
+ }));
+ }), fs_error);
+ }), fs_error);
+ }
+ , FS_proto = FileSaver.prototype
+ , saveAs = function(blob, name) {
+ return new FileSaver(blob, name);
+ }
+ ;
+ FS_proto.abort = function() {
+ var filesaver = this;
+ filesaver.readyState = filesaver.DONE;
+ dispatch(filesaver, "abort");
+ };
+ FS_proto.readyState = FS_proto.INIT = 0;
+ FS_proto.WRITING = 1;
+ FS_proto.DONE = 2;
+
+ FS_proto.error =
+ FS_proto.onwritestart =
+ FS_proto.onprogress =
+ FS_proto.onwrite =
+ FS_proto.onabort =
+ FS_proto.onerror =
+ FS_proto.onwriteend =
+ null;
+
+ view.addEventListener("unload", process_deletion_queue, false);
+ saveAs.unload = function() {
+ process_deletion_queue();
+ view.removeEventListener("unload", process_deletion_queue, false);
+ };
+ return saveAs;
+}(
+ typeof self !== "undefined" && self
+ || typeof window !== "undefined" && window
+ || this.content
+));
+// `self` is undefined in Firefox for Android content script context
+// while `this` is nsIContentFrameMessageManager
+// with an attribute `content` that corresponds to the window
+
+amdDefine = window.define;
+if( typeof amdDefine === "undefined" && (typeof window.almond !== "undefined"
+ && "define" in window.almond )){
+ amdDefine = window.almond.define;
+}
+
+if (typeof module !== "undefined" && module !== null) {
+ module.exports = saveAs;
+} else if ((typeof amdDefine !== "undefined" && amdDefine !== null) && (amdDefine.amd != null)) {
+ amdDefine("saveAs",[], function() {
+ return saveAs;
+ });
+}
+
+},{}],48:[function(require,module,exports){
+module.exports = function (css, customDocument) {
+ var doc = customDocument || document;
+ if (doc.createStyleSheet) {
+ var sheet = doc.createStyleSheet()
+ sheet.cssText = css;
+ return sheet.ownerNode;
+ } else {
+ var head = doc.getElementsByTagName('head')[0],
+ style = doc.createElement('style');
+
+ style.type = 'text/css';
+
+ if (style.styleSheet) {
+ style.styleSheet.cssText = css;
+ } else {
+ style.appendChild(doc.createTextNode(css));
+ }
+
+ head.appendChild(style);
+ return style;
+ }
+};
+
+module.exports.byUrl = function(url) {
+ if (document.createStyleSheet) {
+ return document.createStyleSheet(url).ownerNode;
+ } else {
+ var head = document.getElementsByTagName('head')[0],
+ link = document.createElement('link');
+
+ link.rel = 'stylesheet';
+ link.href = url;
+
+ head.appendChild(link);
+ return link;
+ }
+};
+
+},{}],49:[function(require,module,exports){
+var Utils = {};
+
+
+/*
+Remove an element and provide a function that inserts it into its original position
+https://developers.google.com/speed/articles/javascript-dom
+@param element {Element} The element to be temporarily removed
+@return {Function} A function that inserts the element into its original position
+ */
+
+Utils.removeToInsertLater = function(element) {
+ var nextSibling, parentNode;
+ parentNode = element.parentNode;
+ nextSibling = element.nextSibling;
+ parentNode.removeChild(element);
+ return function() {
+ if (nextSibling) {
+ parentNode.insertBefore(element, nextSibling);
+ } else {
+ parentNode.appendChild(element);
+ }
+ };
+};
+
+
+/*
+fastest possible way to destroy all sub nodes (aka childs)
+http://jsperf.com/innerhtml-vs-removechild/15
+@param element {Element} The element for which all childs should be removed
+ */
+
+Utils.removeAllChilds = function(element) {
+ var count;
+ count = 0;
+ while (element.firstChild) {
+ count++;
+ element.removeChild(element.firstChild);
+ }
+};
+
+module.exports = Utils;
+
+},{}],50:[function(require,module,exports){
+/*!
+ * jBone v1.0.19 - 2014-10-12 - Library for DOM manipulation
+ *
+ * https://github.com/kupriyanenko/jbone
+ *
+ * Copyright 2014 Alexey Kupriyanenko
+ * Released under the MIT license.
+ */
+
+(function (win) {
+
+var
+// cache previous versions
+_$ = win.$,
+_jBone = win.jBone,
+
+// Quick match a standalone tag
+rquickSingleTag = /^<(\w+)\s*\/?>$/,
+
+// A simple way to check for HTML strings
+// Prioritize #id over <tag> to avoid XSS via location.hash
+rquickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
+
+// Alias for function
+slice = [].slice,
+splice = [].splice,
+keys = Object.keys,
+
+// Alias for global variables
+doc = document,
+
+isString = function(el) {
+ return typeof el === "string";
+},
+isObject = function(el) {
+ return el instanceof Object;
+},
+isFunction = function(el) {
+ var getType = {};
+ return el && getType.toString.call(el) === "[object Function]";
+},
+isArray = function(el) {
+ return Array.isArray(el);
+},
+jBone = function(element, data) {
+ return new fn.init(element, data);
+},
+fn;
+
+// set previous values and return the instance upon calling the no-conflict mode
+jBone.noConflict = function() {
+ win.$ = _$;
+ win.jBone = _jBone;
+
+ return jBone;
+};
+
+fn = jBone.fn = jBone.prototype = {
+ init: function(element, data) {
+ var elements, tag, wraper, fragment;
+
+ if (!element) {
+ return this;
+ }
+ if (isString(element)) {
+ // Create single DOM element
+ if (tag = rquickSingleTag.exec(element)) {
+ this[0] = doc.createElement(tag[1]);
+ this.length = 1;
+
+ if (isObject(data)) {
+ this.attr(data);
+ }
+
+ return this;
+ }
+ // Create DOM collection
+ if ((tag = rquickExpr.exec(element)) && tag[1]) {
+ fragment = doc.createDocumentFragment();
+ wraper = doc.createElement("div");
+ wraper.innerHTML = element;
+ while (wraper.lastChild) {
+ fragment.appendChild(wraper.firstChild);
+ }
+ elements = slice.call(fragment.childNodes);
+
+ return jBone.merge(this, elements);
+ }
+ // Find DOM elements with querySelectorAll
+ if (jBone.isElement(data)) {
+ return jBone(data).find(element);
+ }
+
+ try {
+ elements = doc.querySelectorAll(element);
+
+ return jBone.merge(this, elements);
+ } catch (e) {
+ return this;
+ }
+ }
+ // Wrap DOMElement
+ if (element.nodeType) {
+ this[0] = element;
+ this.length = 1;
+
+ return this;
+ }
+ // Run function
+ if (isFunction(element)) {
+ return element();
+ }
+ // Return jBone element as is
+ if (element instanceof jBone) {
+ return element;
+ }
+
+ // Return element wrapped by jBone
+ return jBone.makeArray(element, this);
+ },
+
+ pop: [].pop,
+ push: [].push,
+ reverse: [].reverse,
+ shift: [].shift,
+ sort: [].sort,
+ splice: [].splice,
+ slice: [].slice,
+ indexOf: [].indexOf,
+ forEach: [].forEach,
+ unshift: [].unshift,
+ concat: [].concat,
+ join: [].join,
+ every: [].every,
+ some: [].some,
+ filter: [].filter,
+ map: [].map,
+ reduce: [].reduce,
+ reduceRight: [].reduceRight,
+ length: 0
+};
+
+fn.constructor = jBone;
+
+fn.init.prototype = fn;
+
+jBone.setId = function(el) {
+ var jid = el.jid;
+
+ if (el === win) {
+ jid = "window";
+ } else if (el.jid === undefined) {
+ el.jid = jid = ++jBone._cache.jid;
+ }
+
+ if (!jBone._cache.events[jid]) {
+ jBone._cache.events[jid] = {};
+ }
+};
+
+jBone.getData = function(el) {
+ el = el instanceof jBone ? el[0] : el;
+
+ var jid = el === win ? "window" : el.jid;
+
+ return {
+ jid: jid,
+ events: jBone._cache.events[jid]
+ };
+};
+
+jBone.isElement = function(el) {
+ return el && el instanceof jBone || el instanceof HTMLElement || isString(el);
+};
+
+jBone._cache = {
+ events: {},
+ jid: 0
+};
+
+function isArraylike(obj) {
+ var length = obj.length,
+ type = typeof obj;
+
+ if (isFunction(type) || obj === win) {
+ return false;
+ }
+
+ if (obj.nodeType === 1 && length) {
+ return true;
+ }
+
+ return isArray(type) || length === 0 ||
+ typeof length === "number" && length > 0 && (length - 1) in obj;
+}
+
+jBone.merge = function(first, second) {
+ var l = second.length,
+ i = first.length,
+ j = 0;
+
+ while (j < l) {
+ first[i++] = second[j++];
+ }
+
+ first.length = i;
+
+ return first;
+};
+
+jBone.contains = function(container, contained) {
+ var result;
+
+ container.reverse().some(function(el) {
+ if (el.contains(contained)) {
+ return result = el;
+ }
+ });
+
+ return result;
+};
+
+jBone.extend = function(target) {
+ var k, kl, i, tg;
+
+ splice.call(arguments, 1).forEach(function(object) {
+ if (!object) {
+ return;
+ }
+
+ k = keys(object);
+ kl = k.length;
+ i = 0;
+ tg = target; //caching target for perf improvement
+
+ for (; i < kl; i++) {
+ tg[k[i]] = object[k[i]];
+ }
+ });
+
+ return target;
+};
+
+jBone.makeArray = function(arr, results) {
+ var ret = results || [];
+
+ if (arr !== null) {
+ if (isArraylike(arr)) {
+ jBone.merge(ret, isString(arr) ? [arr] : arr);
+ } else {
+ ret.push(arr);
+ }
+ }
+
+ return ret;
+};
+
+function BoneEvent(e, data) {
+ var key, setter;
+
+ this.originalEvent = e;
+
+ setter = function(key, e) {
+ if (key === "preventDefault") {
+ this[key] = function() {
+ this.defaultPrevented = true;
+ return e[key]();
+ };
+ } else if (isFunction(e[key])) {
+ this[key] = function() {
+ return e[key]();
+ };
+ } else {
+ this[key] = e[key];
+ }
+ };
+
+ for (key in e) {
+ if (e[key] || typeof e[key] === "function") {
+ setter.call(this, key, e);
+ }
+ }
+
+ jBone.extend(this, data);
+}
+
+jBone.Event = function(event, data) {
+ var namespace, eventType;
+
+ if (event.type && !data) {
+ data = event;
+ event = event.type;
+ }
+
+ namespace = event.split(".").splice(1).join(".");
+ eventType = event.split(".")[0];
+
+ event = doc.createEvent("Event");
+ event.initEvent(eventType, true, true);
+
+ return jBone.extend(event, {
+ namespace: namespace,
+ isDefaultPrevented: function() {
+ return event.defaultPrevented;
+ }
+ }, data);
+};
+
+fn.on = function(event) {
+ var args = arguments,
+ length = this.length,
+ i = 0,
+ callback, target, namespace, fn, events, eventType, expectedTarget, addListener;
+
+ if (args.length === 2) {
+ callback = args[1];
+ } else {
+ target = args[1];
+ callback = args[2];
+ }
+
+ addListener = function(el) {
+ jBone.setId(el);
+ events = jBone.getData(el).events;
+ event.split(" ").forEach(function(event) {
+ eventType = event.split(".")[0];
+ namespace = event.split(".").splice(1).join(".");
+ events[eventType] = events[eventType] || [];
+
+ fn = function(e) {
+ if (e.namespace && e.namespace !== namespace) {
+ return;
+ }
+
+ expectedTarget = null;
+ if (!target) {
+ callback.call(el, e);
+ } else if (~jBone(el).find(target).indexOf(e.target) || (expectedTarget = jBone.contains(jBone(el).find(target), e.target))) {
+ expectedTarget = expectedTarget || e.target;
+ e = new BoneEvent(e, {
+ currentTarget: expectedTarget
+ });
+
+ callback.call(expectedTarget, e);
+ }
+ };
+
+ events[eventType].push({
+ namespace: namespace,
+ fn: fn,
+ originfn: callback
+ });
+
+ el.addEventListener && el.addEventListener(eventType, fn, false);
+ });
+ };
+
+ for (; i < length; i++) {
+ addListener(this[i]);
+ }
+
+ return this;
+};
+
+fn.one = function(event) {
+ var args = arguments,
+ i = 0,
+ length = this.length,
+ callback, target, addListener;
+
+ if (args.length === 2) {
+ callback = args[1];
+ } else {
+ target = args[1], callback = args[2];
+ }
+
+ addListener = function(el) {
+ event.split(" ").forEach(function(event) {
+ var fn = function(e) {
+ jBone(el).off(event, fn);
+ callback.call(el, e);
+ };
+
+ if (!target) {
+ jBone(el).on(event, fn);
+ } else {
+ jBone(el).on(event, target, fn);
+ }
+ });
+ };
+
+ for (; i < length; i++) {
+ addListener(this[i]);
+ }
+
+ return this;
+};
+
+fn.trigger = function(event) {
+ var events = [],
+ i = 0,
+ length = this.length,
+ dispatchEvents;
+
+ if (!event) {
+ return this;
+ }
+
+ if (isString(event)) {
+ events = event.split(" ").map(function(event) {
+ return jBone.Event(event);
+ });
+ } else {
+ event = event instanceof Event ? event : jBone.Event(event);
+ events = [event];
+ }
+
+ dispatchEvents = function(el) {
+ events.forEach(function(event) {
+ if (!event.type) {
+ return;
+ }
+
+ el.dispatchEvent && el.dispatchEvent(event);
+ });
+ };
+
+ for (; i < length; i++) {
+ dispatchEvents(this[i]);
+ }
+
+ return this;
+};
+
+fn.off = function(event, fn) {
+ var i = 0,
+ length = this.length,
+ removeListener = function(events, eventType, index, el, e) {
+ var callback;
+
+ // get callback
+ if ((fn && e.originfn === fn) || !fn) {
+ callback = e.fn;
+ }
+
+ if (events[eventType][index].fn === callback) {
+ el.removeEventListener(eventType, callback);
+
+ // remove handler from cache
+ jBone._cache.events[jBone.getData(el).jid][eventType].splice(index, 1);
+ }
+ },
+ events, namespace, removeListeners, eventType;
+
+ removeListeners = function(el) {
+ var l, eventsByType, e;
+
+ events = jBone.getData(el).events;
+
+ if (!events) {
+ return;
+ }
+
+ // remove all events
+ if (!event && events) {
+ return keys(events).forEach(function(eventType) {
+ eventsByType = events[eventType];
+ l = eventsByType.length;
+
+ while(l--) {
+ removeListener(events, eventType, l, el, eventsByType[l]);
+ }
+ });
+ }
+
+ event.split(" ").forEach(function(event) {
+ eventType = event.split(".")[0];
+ namespace = event.split(".").splice(1).join(".");
+
+ // remove named events
+ if (events[eventType]) {
+ eventsByType = events[eventType];
+ l = eventsByType.length;
+
+ while(l--) {
+ e = eventsByType[l];
+ if (!namespace || (namespace && e.namespace === namespace)) {
+ removeListener(events, eventType, l, el, e);
+ }
+ }
+ }
+ // remove all namespaced events
+ else if (namespace) {
+ keys(events).forEach(function(eventType) {
+ eventsByType = events[eventType];
+ l = eventsByType.length;
+
+ while(l--) {
+ e = eventsByType[l];
+ if (e.namespace.split(".")[0] === namespace.split(".")[0]) {
+ removeListener(events, eventType, l, el, e);
+ }
+ }
+ });
+ }
+ });
+ };
+
+ for (; i < length; i++) {
+ removeListeners(this[i]);
+ }
+
+ return this;
+};
+
+fn.find = function(selector) {
+ var results = [],
+ i = 0,
+ length = this.length,
+ finder = function(el) {
+ if (isFunction(el.querySelectorAll)) {
+ [].forEach.call(el.querySelectorAll(selector), function(found) {
+ results.push(found);
+ });
+ }
+ };
+
+ for (; i < length; i++) {
+ finder(this[i]);
+ }
+
+ return jBone(results);
+};
+
+fn.get = function(index) {
+ return this[index];
+};
+
+fn.eq = function(index) {
+ return jBone(this[index]);
+};
+
+fn.parent = function() {
+ var results = [],
+ parent,
+ i = 0,
+ length = this.length;
+
+ for (; i < length; i++) {
+ if (!~results.indexOf(parent = this[i].parentElement) && parent) {
+ results.push(parent);
+ }
+ }
+
+ return jBone(results);
+};
+
+fn.toArray = function() {
+ return slice.call(this);
+};
+
+fn.is = function() {
+ var args = arguments;
+
+ return this.some(function(el) {
+ return el.tagName.toLowerCase() === args[0];
+ });
+};
+
+fn.has = function() {
+ var args = arguments;
+
+ return this.some(function(el) {
+ return el.querySelectorAll(args[0]).length;
+ });
+};
+
+fn.attr = function(key, value) {
+ var args = arguments,
+ i = 0,
+ length = this.length,
+ setter;
+
+ if (isString(key) && args.length === 1) {
+ return this[0] && this[0].getAttribute(key);
+ }
+
+ if (args.length === 2) {
+ setter = function(el) {
+ el.setAttribute(key, value);
+ };
+ } else if (isObject(key)) {
+ setter = function(el) {
+ keys(key).forEach(function(name) {
+ el.setAttribute(name, key[name]);
+ });
+ };
+ }
+
+ for (; i < length; i++) {
+ setter(this[i]);
+ }
+
+ return this;
+};
+
+fn.removeAttr = function(key) {
+ var i = 0,
+ length = this.length;
+
+ for (; i < length; i++) {
+ this[i].removeAttribute(key);
+ }
+
+ return this;
+};
+
+fn.val = function(value) {
+ var i = 0,
+ length = this.length;
+
+ if (arguments.length === 0) {
+ return this[0] && this[0].value;
+ }
+
+ for (; i < length; i++) {
+ this[i].value = value;
+ }
+
+ return this;
+};
+
+fn.css = function(key, value) {
+ var args = arguments,
+ i = 0,
+ length = this.length,
+ setter;
+
+ // Get attribute
+ if (isString(key) && args.length === 1) {
+ return this[0] && win.getComputedStyle(this[0])[key];
+ }
+
+ // Set attributes
+ if (args.length === 2) {
+ setter = function(el) {
+ el.style[key] = value;
+ };
+ } else if (isObject(key)) {
+ setter = function(el) {
+ keys(key).forEach(function(name) {
+ el.style[name] = key[name];
+ });
+ };
+ }
+
+ for (; i < length; i++) {
+ setter(this[i]);
+ }
+
+ return this;
+};
+
+fn.data = function(key, value) {
+ var args = arguments, data = {},
+ i = 0,
+ length = this.length,
+ setter,
+ setValue = function(el, key, value) {
+ if (isObject(value)) {
+ el.jdata = el.jdata || {};
+ el.jdata[key] = value;
+ } else {
+ el.dataset[key] = value;
+ }
+ },
+ getValue = function(value) {
+ if (value === "true") {
+ return true;
+ } else if (value === "false") {
+ return false;
+ } else {
+ return value;
+ }
+ };
+
+ // Get all data
+ if (args.length === 0) {
+ this[0].jdata && (data = this[0].jdata);
+
+ keys(this[0].dataset).forEach(function(key) {
+ data[key] = getValue(this[0].dataset[key]);
+ }, this);
+
+ return data;
+ }
+ // Get data by name
+ if (args.length === 1 && isString(key)) {
+ return this[0] && getValue(this[0].dataset[key] || this[0].jdata && this[0].jdata[key]);
+ }
+
+ // Set data
+ if (args.length === 1 && isObject(key)) {
+ setter = function(el) {
+ keys(key).forEach(function(name) {
+ setValue(el, name, key[name]);
+ });
+ };
+ } else if (args.length === 2) {
+ setter = function(el) {
+ setValue(el, key, value);
+ };
+ }
+
+ for (; i < length; i++) {
+ setter(this[i]);
+ }
+
+ return this;
+};
+
+fn.removeData = function(key) {
+ var i = 0,
+ length = this.length,
+ jdata, dataset;
+
+ for (; i < length; i++) {
+ jdata = this[i].jdata;
+ dataset = this[i].dataset;
+
+ if (key) {
+ jdata && jdata[key] && delete jdata[key];
+ delete dataset[key];
+ } else {
+ for (key in jdata) {
+ delete jdata[key];
+ }
+
+ for (key in dataset) {
+ delete dataset[key];
+ }
+ }
+ }
+
+ return this;
+};
+
+fn.html = function(value) {
+ var args = arguments,
+ el;
+
+ // add HTML into elements
+ if (args.length === 1 && value !== undefined) {
+ return this.empty().append(value);
+ }
+ // get HTML from element
+ else if (args.length === 0 && (el = this[0])) {
+ return el.innerHTML;
+ }
+
+ return this;
+};
+
+fn.append = function(appended) {
+ var i = 0,
+ length = this.length,
+ setter;
+
+ // create jBone object and then append
+ if (isString(appended) && rquickExpr.exec(appended)) {
+ appended = jBone(appended);
+ }
+ // create text node for inserting
+ else if (!isObject(appended)) {
+ appended = document.createTextNode(appended);
+ }
+
+ appended = appended instanceof jBone ? appended : jBone(appended);
+
+ setter = function(el, i) {
+ appended.forEach(function(node) {
+ if (i) {
+ el.appendChild(node.cloneNode());
+ } else {
+ el.appendChild(node);
+ }
+ });
+ };
+
+ for (; i < length; i++) {
+ setter(this[i], i);
+ }
+
+ return this;
+};
+
+fn.appendTo = function(to) {
+ jBone(to).append(this);
+
+ return this;
+};
+
+fn.empty = function() {
+ var i = 0,
+ length = this.length,
+ el;
+
+ for (; i < length; i++) {
+ el = this[i];
+
+ while (el.lastChild) {
+ el.removeChild(el.lastChild);
+ }
+ }
+
+ return this;
+};
+
+fn.remove = function() {
+ var i = 0,
+ length = this.length,
+ el;
+
+ // remove all listners
+ this.off();
+
+ for (; i < length; i++) {
+ el = this[i];
+
+ // remove data and nodes
+ delete el.jdata;
+ el.parentNode && el.parentNode.removeChild(el);
+ }
+
+ return this;
+};
+
+if (typeof module === "object" && module && typeof module.exports === "object") {
+ // Expose jBone as module.exports in loaders that implement the Node
+ // module pattern (including browserify). Do not create the global, since
+ // the user will be storing it themselves locally, and globals are frowned
+ // upon in the Node module world.
+ module.exports = jBone;
+}
+// Register as a AMD module
+else if (typeof define === "function" && define.amd) {
+ define(function() {
+ return jBone;
+ });
+
+ win.jBone = win.$ = jBone;
+} else if (typeof win === "object" && typeof win.document === "object") {
+ win.jBone = win.$ = jBone;
+}
+
+}(window));
+
+},{}],51:[function(require,module,exports){
+var Mouse;
+
+module.exports = Mouse = {
+ rel: function(e) {
+ var mouseX, mouseY, rect, target;
+ mouseX = e.offsetX;
+ mouseY = e.offsetY;
+ if (mouseX == null) {
+ rect = target.getBoundingClientRect();
+ target = e.target || e.srcElement;
+ if (mouseX == null) {
+ mouseX = e.clientX - rect.left;
+ mouseY = e.clientY - rect.top;
+ }
+ if (mouseX == null) {
+ mouseX = e.pageX - target.offsetLeft;
+ mouseY = e.pageY - target.offsetTop;
+ }
+ if (mouseX == null) {
+ console.log(e, "no mouse event defined. your browser sucks");
+ return;
+ }
+ }
+ return [mouseX, mouseY];
+ },
+ abs: function(e) {
+ var mouseX, mouseY;
+ mouseX = e.pageX;
+ mouseY = e.pageY;
+ if (mouseX == null) {
+ mouseX = e.layerX;
+ mouseY = e.layerY;
+ }
+ if (mouseX == null) {
+ mouseX = e.clientX;
+ mouseY = e.clientY;
+ }
+ if (mouseX == null) {
+ mouseX = e.x;
+ mouseY = e.y;
+ }
+ return [mouseX, mouseY];
+ },
+ wheelDelta: function(e) {
+ var delta, dir;
+ delta = [e.deltaX, e.deltaY];
+ if (delta[0] == null) {
+ dir = Math.floor(e.detail / 3);
+ delta = [0, e.mozMovementX * dir];
+ }
+ return delta;
+ }
+};
+
+},{}],52:[function(require,module,exports){
+var window = require("global/window")
+var once = require("once")
+var parseHeaders = require('parse-headers')
+
+var messages = {
+ "0": "Internal XMLHttpRequest Error",
+ "4": "4xx Client Error",
+ "5": "5xx Server Error"
+}
+
+var XHR = window.XMLHttpRequest || noop
+var XDR = "withCredentials" in (new XHR()) ? XHR : window.XDomainRequest
+
+module.exports = createXHR
+
+function createXHR(options, callback) {
+ if (typeof options === "string") {
+ options = { uri: options }
+ }
+
+ options = options || {}
+ callback = once(callback)
+
+ var xhr = options.xhr || null
+
+ if (!xhr) {
+ if (options.cors || options.useXDR) {
+ xhr = new XDR()
+ }else{
+ xhr = new XHR()
+ }
+ }
+
+ var uri = xhr.url = options.uri || options.url
+ var method = xhr.method = options.method || "GET"
+ var body = options.body || options.data
+ var headers = xhr.headers = options.headers || {}
+ var sync = !!options.sync
+ var isJson = false
+ var key
+ var load = options.response ? loadResponse : loadXhr
+
+ if ("json" in options) {
+ isJson = true
+ headers["Accept"] = "application/json"
+ if (method !== "GET" && method !== "HEAD") {
+ headers["Content-Type"] = "application/json"
+ body = JSON.stringify(options.json)
+ }
+ }
+
+ xhr.onreadystatechange = readystatechange
+ xhr.onload = load
+ xhr.onerror = error
+ // IE9 must have onprogress be set to a unique function.
+ xhr.onprogress = function () {
+ // IE must die
+ }
+ // hate IE
+ xhr.ontimeout = noop
+ xhr.open(method, uri, !sync)
+ //backward compatibility
+ if (options.withCredentials || (options.cors && options.withCredentials !== false)) {
+ xhr.withCredentials = true
+ }
+
+ // Cannot set timeout with sync request
+ if (!sync) {
+ xhr.timeout = "timeout" in options ? options.timeout : 5000
+ }
+
+ if (xhr.setRequestHeader) {
+ for(key in headers){
+ if(headers.hasOwnProperty(key)){
+ xhr.setRequestHeader(key, headers[key])
+ }
+ }
+ } else if (options.headers) {
+ throw new Error("Headers cannot be set on an XDomainRequest object")
+ }
+
+ if ("responseType" in options) {
+ xhr.responseType = options.responseType
+ }
+
+ if ("beforeSend" in options &&
+ typeof options.beforeSend === "function"
+ ) {
+ options.beforeSend(xhr)
+ }
+
+ xhr.send(body)
+
+ return xhr
+
+ function readystatechange() {
+ if (xhr.readyState === 4) {
+ load()
+ }
+ }
+
+ function getBody() {
+ // Chrome with requestType=blob throws errors arround when even testing access to responseText
+ var body = null
+
+ if (xhr.response) {
+ body = xhr.response
+ } else if (xhr.responseType === 'text' || !xhr.responseType) {
+ body = xhr.responseText || xhr.responseXML
+ }
+
+ if (isJson) {
+ try {
+ body = JSON.parse(body)
+ } catch (e) {}
+ }
+
+ return body
+ }
+
+ function getStatusCode() {
+ return xhr.status === 1223 ? 204 : xhr.status
+ }
+
+ // if we're getting a none-ok statusCode, build & return an error
+ function errorFromStatusCode(status) {
+ var error = null
+ if (status === 0 || (status >= 400 && status < 600)) {
+ var message = (typeof body === "string" ? body : false) ||
+ messages[String(status).charAt(0)]
+ error = new Error(message)
+ error.statusCode = status
+ }
+
+ return error
+ }
+
+ // will load the data & process the response in a special response object
+ function loadResponse() {
+ var status = getStatusCode()
+ var error = errorFromStatusCode(status)
+ var response = {
+ body: getBody(),
+ statusCode: status,
+ statusText: xhr.statusText,
+ raw: xhr
+ }
+ if(xhr.getAllResponseHeaders){ //remember xhr can in fact be XDR for CORS in IE
+ response.headers = parseHeaders(xhr.getAllResponseHeaders())
+ } else {
+ response.headers = {}
+ }
+
+ callback(error, response, response.body)
+ }
+
+ // will load the data and add some response properties to the source xhr
+ // and then respond with that
+ function loadXhr() {
+ var status = getStatusCode()
+ var error = errorFromStatusCode(status)
+
+ xhr.status = xhr.statusCode = status
+ xhr.body = getBody()
+ xhr.headers = parseHeaders(xhr.getAllResponseHeaders())
+
+ callback(error, xhr, xhr.body)
+ }
+
+ function error(evt) {
+ callback(evt, xhr)
+ }
+}
+
+
+function noop() {}
+
+},{"global/window":53,"once":54,"parse-headers":58}],53:[function(require,module,exports){
+(function (global){
+if (typeof window !== "undefined") {
+ module.exports = window;
+} else if (typeof global !== "undefined") {
+ module.exports = global;
+} else if (typeof self !== "undefined"){
+ module.exports = self;
+} else {
+ module.exports = {};
+}
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{}],54:[function(require,module,exports){
+module.exports = once
+
+once.proto = once(function () {
+ Object.defineProperty(Function.prototype, 'once', {
+ value: function () {
+ return once(this)
+ },
+ configurable: true
+ })
+})
+
+function once (fn) {
+ var called = false
+ return function () {
+ if (called) return
+ called = true
+ return fn.apply(this, arguments)
+ }
+}
+
+},{}],55:[function(require,module,exports){
+var isFunction = require('is-function')
+
+module.exports = forEach
+
+var toString = Object.prototype.toString
+var hasOwnProperty = Object.prototype.hasOwnProperty
+
+function forEach(list, iterator, context) {
+ if (!isFunction(iterator)) {
+ throw new TypeError('iterator must be a function')
+ }
+
+ if (arguments.length < 3) {
+ context = this
+ }
+
+ if (toString.call(list) === '[object Array]')
+ forEachArray(list, iterator, context)
+ else if (typeof list === 'string')
+ forEachString(list, iterator, context)
+ else
+ forEachObject(list, iterator, context)
+}
+
+function forEachArray(array, iterator, context) {
+ for (var i = 0, len = array.length; i < len; i++) {
+ if (hasOwnProperty.call(array, i)) {
+ iterator.call(context, array[i], i, array)
+ }
+ }
+}
+
+function forEachString(string, iterator, context) {
+ for (var i = 0, len = string.length; i < len; i++) {
+ // no such thing as a sparse string.
+ iterator.call(context, string.charAt(i), i, string)
+ }
+}
+
+function forEachObject(object, iterator, context) {
+ for (var k in object) {
+ if (hasOwnProperty.call(object, k)) {
+ iterator.call(context, object[k], k, object)
+ }
+ }
+}
+
+},{"is-function":56}],56:[function(require,module,exports){
+module.exports = isFunction
+
+var toString = Object.prototype.toString
+
+function isFunction (fn) {
+ var string = toString.call(fn)
+ return string === '[object Function]' ||
+ (typeof fn === 'function' && string !== '[object RegExp]') ||
+ (typeof window !== 'undefined' &&
+ // IE8 and below
+ (fn === window.setTimeout ||
+ fn === window.alert ||
+ fn === window.confirm ||
+ fn === window.prompt))
+};
+
+},{}],57:[function(require,module,exports){
+
+exports = module.exports = trim;
+
+function trim(str){
+ return str.replace(/^\s*|\s*$/g, '');
+}
+
+exports.left = function(str){
+ return str.replace(/^\s*/, '');
+};
+
+exports.right = function(str){
+ return str.replace(/\s*$/, '');
+};
+
+},{}],58:[function(require,module,exports){
+var trim = require('trim')
+ , forEach = require('for-each')
+ , isArray = function(arg) {
+ return Object.prototype.toString.call(arg) === '[object Array]';
+ }
+
+module.exports = function (headers) {
+ if (!headers)
+ return {}
+
+ var result = {}
+
+ forEach(
+ trim(headers).split('\n')
+ , function (row) {
+ var index = row.indexOf(':')
+ , key = trim(row.slice(0, index)).toLowerCase()
+ , value = trim(row.slice(index + 1))
+
+ if (typeof(result[key]) === 'undefined') {
+ result[key] = value
+ } else if (isArray(result[key])) {
+ result[key].push(value)
+ } else {
+ result[key] = [ result[key], value ]
+ }
+ }
+ )
+
+ return result
+}
+},{"for-each":55,"trim":57}],59:[function(require,module,exports){
+// Underscore.js 1.7.0
+// http://underscorejs.org
+// (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
+// Underscore may be freely distributed under the MIT license.
+
+(function() {
+
+ // Baseline setup
+ // --------------
+
+ // Establish the root object, `window` in the browser, or `exports` on the server.
+ var root = this;
+
+ // Save the previous value of the `_` variable.
+ var previousUnderscore = root._;
+
+ // Save bytes in the minified (but not gzipped) version:
+ var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
+
+ // Create quick reference variables for speed access to core prototypes.
+ var
+ push = ArrayProto.push,
+ slice = ArrayProto.slice,
+ concat = ArrayProto.concat,
+ toString = ObjProto.toString,
+ hasOwnProperty = ObjProto.hasOwnProperty;
+
+ // All **ECMAScript 5** native function implementations that we hope to use
+ // are declared here.
+ var
+ nativeIsArray = Array.isArray,
+ nativeKeys = Object.keys,
+ nativeBind = FuncProto.bind;
+
+ // Create a safe reference to the Underscore object for use below.
+ var _ = function(obj) {
+ if (obj instanceof _) return obj;
+ if (!(this instanceof _)) return new _(obj);
+ this._wrapped = obj;
+ };
+
+ // Export the Underscore object for **Node.js**, with
+ // backwards-compatibility for the old `require()` API. If we're in
+ // the browser, add `_` as a global object.
+ if (typeof exports !== 'undefined') {
+ if (typeof module !== 'undefined' && module.exports) {
+ exports = module.exports = _;
+ }
+ exports._ = _;
+ } else {
+ root._ = _;
+ }
+
+ // Current version.
+ _.VERSION = '1.7.0';
+
+ // Internal function that returns an efficient (for current engines) version
+ // of the passed-in callback, to be repeatedly applied in other Underscore
+ // functions.
+ var createCallback = function(func, context, argCount) {
+ if (context === void 0) return func;
+ switch (argCount == null ? 3 : argCount) {
+ case 1: return function(value) {
+ return func.call(context, value);
+ };
+ case 2: return function(value, other) {
+ return func.call(context, value, other);
+ };
+ case 3: return function(value, index, collection) {
+ return func.call(context, value, index, collection);
+ };
+ case 4: return function(accumulator, value, index, collection) {
+ return func.call(context, accumulator, value, index, collection);
+ };
+ }
+ return function() {
+ return func.apply(context, arguments);
+ };
+ };
+
+ // A mostly-internal function to generate callbacks that can be applied
+ // to each element in a collection, returning the desired result — either
+ // identity, an arbitrary callback, a property matcher, or a property accessor.
+ _.iteratee = function(value, context, argCount) {
+ if (value == null) return _.identity;
+ if (_.isFunction(value)) return createCallback(value, context, argCount);
+ if (_.isObject(value)) return _.matches(value);
+ return _.property(value);
+ };
+
+ // Collection Functions
+ // --------------------
+
+ // The cornerstone, an `each` implementation, aka `forEach`.
+ // Handles raw objects in addition to array-likes. Treats all
+ // sparse array-likes as if they were dense.
+ _.each = _.forEach = function(obj, iteratee, context) {
+ if (obj == null) return obj;
+ iteratee = createCallback(iteratee, context);
+ var i, length = obj.length;
+ if (length === +length) {
+ for (i = 0; i < length; i++) {
+ iteratee(obj[i], i, obj);
+ }
+ } else {
+ var keys = _.keys(obj);
+ for (i = 0, length = keys.length; i < length; i++) {
+ iteratee(obj[keys[i]], keys[i], obj);
+ }
+ }
+ return obj;
+ };
+
+ // Return the results of applying the iteratee to each element.
+ _.map = _.collect = function(obj, iteratee, context) {
+ if (obj == null) return [];
+ iteratee = _.iteratee(iteratee, context);
+ var keys = obj.length !== +obj.length && _.keys(obj),
+ length = (keys || obj).length,
+ results = Array(length),
+ currentKey;
+ for (var index = 0; index < length; index++) {
+ currentKey = keys ? keys[index] : index;
+ results[index] = iteratee(obj[currentKey], currentKey, obj);
+ }
+ return results;
+ };
+
+ var reduceError = 'Reduce of empty array with no initial value';
+
+ // **Reduce** builds up a single result from a list of values, aka `inject`,
+ // or `foldl`.
+ _.reduce = _.foldl = _.inject = function(obj, iteratee, memo, context) {
+ if (obj == null) obj = [];
+ iteratee = createCallback(iteratee, context, 4);
+ var keys = obj.length !== +obj.length && _.keys(obj),
+ length = (keys || obj).length,
+ index = 0, currentKey;
+ if (arguments.length < 3) {
+ if (!length) throw new TypeError(reduceError);
+ memo = obj[keys ? keys[index++] : index++];
+ }
+ for (; index < length; index++) {
+ currentKey = keys ? keys[index] : index;
+ memo = iteratee(memo, obj[currentKey], currentKey, obj);
+ }
+ return memo;
+ };
+
+ // The right-associative version of reduce, also known as `foldr`.
+ _.reduceRight = _.foldr = function(obj, iteratee, memo, context) {
+ if (obj == null) obj = [];
+ iteratee = createCallback(iteratee, context, 4);
+ var keys = obj.length !== + obj.length && _.keys(obj),
+ index = (keys || obj).length,
+ currentKey;
+ if (arguments.length < 3) {
+ if (!index) throw new TypeError(reduceError);
+ memo = obj[keys ? keys[--index] : --index];
+ }
+ while (index--) {
+ currentKey = keys ? keys[index] : index;
+ memo = iteratee(memo, obj[currentKey], currentKey, obj);
+ }
+ return memo;
+ };
+
+ // Return the first value which passes a truth test. Aliased as `detect`.
+ _.find = _.detect = function(obj, predicate, context) {
+ var result;
+ predicate = _.iteratee(predicate, context);
+ _.some(obj, function(value, index, list) {
+ if (predicate(value, index, list)) {
+ result = value;
+ return true;
+ }
+ });
+ return result;
+ };
+
+ // Return all the elements that pass a truth test.
+ // Aliased as `select`.
+ _.filter = _.select = function(obj, predicate, context) {
+ var results = [];
+ if (obj == null) return results;
+ predicate = _.iteratee(predicate, context);
+ _.each(obj, function(value, index, list) {
+ if (predicate(value, index, list)) results.push(value);
+ });
+ return results;
+ };
+
+ // Return all the elements for which a truth test fails.
+ _.reject = function(obj, predicate, context) {
+ return _.filter(obj, _.negate(_.iteratee(predicate)), context);
+ };
+
+ // Determine whether all of the elements match a truth test.
+ // Aliased as `all`.
+ _.every = _.all = function(obj, predicate, context) {
+ if (obj == null) return true;
+ predicate = _.iteratee(predicate, context);
+ var keys = obj.length !== +obj.length && _.keys(obj),
+ length = (keys || obj).length,
+ index, currentKey;
+ for (index = 0; index < length; index++) {
+ currentKey = keys ? keys[index] : index;
+ if (!predicate(obj[currentKey], currentKey, obj)) return false;
+ }
+ return true;
+ };
+
+ // Determine if at least one element in the object matches a truth test.
+ // Aliased as `any`.
+ _.some = _.any = function(obj, predicate, context) {
+ if (obj == null) return false;
+ predicate = _.iteratee(predicate, context);
+ var keys = obj.length !== +obj.length && _.keys(obj),
+ length = (keys || obj).length,
+ index, currentKey;
+ for (index = 0; index < length; index++) {
+ currentKey = keys ? keys[index] : index;
+ if (predicate(obj[currentKey], currentKey, obj)) return true;
+ }
+ return false;
+ };
+
+ // Determine if the array or object contains a given value (using `===`).
+ // Aliased as `include`.
+ _.contains = _.include = function(obj, target) {
+ if (obj == null) return false;
+ if (obj.length !== +obj.length) obj = _.values(obj);
+ return _.indexOf(obj, target) >= 0;
+ };
+
+ // Invoke a method (with arguments) on every item in a collection.
+ _.invoke = function(obj, method) {
+ var args = slice.call(arguments, 2);
+ var isFunc = _.isFunction(method);
+ return _.map(obj, function(value) {
+ return (isFunc ? method : value[method]).apply(value, args);
+ });
+ };
+
+ // Convenience version of a common use case of `map`: fetching a property.
+ _.pluck = function(obj, key) {
+ return _.map(obj, _.property(key));
+ };
+
+ // Convenience version of a common use case of `filter`: selecting only objects
+ // containing specific `key:value` pairs.
+ _.where = function(obj, attrs) {
+ return _.filter(obj, _.matches(attrs));
+ };
+
+ // Convenience version of a common use case of `find`: getting the first object
+ // containing specific `key:value` pairs.
+ _.findWhere = function(obj, attrs) {
+ return _.find(obj, _.matches(attrs));
+ };
+
+ // Return the maximum element (or element-based computation).
+ _.max = function(obj, iteratee, context) {
+ var result = -Infinity, lastComputed = -Infinity,
+ value, computed;
+ if (iteratee == null && obj != null) {
+ obj = obj.length === +obj.length ? obj : _.values(obj);
+ for (var i = 0, length = obj.length; i < length; i++) {
+ value = obj[i];
+ if (value > result) {
+ result = value;
+ }
+ }
+ } else {
+ iteratee = _.iteratee(iteratee, context);
+ _.each(obj, function(value, index, list) {
+ computed = iteratee(value, index, list);
+ if (computed > lastComputed || computed === -Infinity && result === -Infinity) {
+ result = value;
+ lastComputed = computed;
+ }
+ });
+ }
+ return result;
+ };
+
+ // Return the minimum element (or element-based computation).
+ _.min = function(obj, iteratee, context) {
+ var result = Infinity, lastComputed = Infinity,
+ value, computed;
+ if (iteratee == null && obj != null) {
+ obj = obj.length === +obj.length ? obj : _.values(obj);
+ for (var i = 0, length = obj.length; i < length; i++) {
+ value = obj[i];
+ if (value < result) {
+ result = value;
+ }
+ }
+ } else {
+ iteratee = _.iteratee(iteratee, context);
+ _.each(obj, function(value, index, list) {
+ computed = iteratee(value, index, list);
+ if (computed < lastComputed || computed === Infinity && result === Infinity) {
+ result = value;
+ lastComputed = computed;
+ }
+ });
+ }
+ return result;
+ };
+
+ // Shuffle a collection, using the modern version of the
+ // [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
+ _.shuffle = function(obj) {
+ var set = obj && obj.length === +obj.length ? obj : _.values(obj);
+ var length = set.length;
+ var shuffled = Array(length);
+ for (var index = 0, rand; index < length; index++) {
+ rand = _.random(0, index);
+ if (rand !== index) shuffled[index] = shuffled[rand];
+ shuffled[rand] = set[index];
+ }
+ return shuffled;
+ };
+
+ // Sample **n** random values from a collection.
+ // If **n** is not specified, returns a single random element.
+ // The internal `guard` argument allows it to work with `map`.
+ _.sample = function(obj, n, guard) {
+ if (n == null || guard) {
+ if (obj.length !== +obj.length) obj = _.values(obj);
+ return obj[_.random(obj.length - 1)];
+ }
+ return _.shuffle(obj).slice(0, Math.max(0, n));
+ };
+
+ // Sort the object's values by a criterion produced by an iteratee.
+ _.sortBy = function(obj, iteratee, context) {
+ iteratee = _.iteratee(iteratee, context);
+ return _.pluck(_.map(obj, function(value, index, list) {
+ return {
+ value: value,
+ index: index,
+ criteria: iteratee(value, index, list)
+ };
+ }).sort(function(left, right) {
+ var a = left.criteria;
+ var b = right.criteria;
+ if (a !== b) {
+ if (a > b || a === void 0) return 1;
+ if (a < b || b === void 0) return -1;
+ }
+ return left.index - right.index;
+ }), 'value');
+ };
+
+ // An internal function used for aggregate "group by" operations.
+ var group = function(behavior) {
+ return function(obj, iteratee, context) {
+ var result = {};
+ iteratee = _.iteratee(iteratee, context);
+ _.each(obj, function(value, index) {
+ var key = iteratee(value, index, obj);
+ behavior(result, value, key);
+ });
+ return result;
+ };
+ };
+
+ // Groups the object's values by a criterion. Pass either a string attribute
+ // to group by, or a function that returns the criterion.
+ _.groupBy = group(function(result, value, key) {
+ if (_.has(result, key)) result[key].push(value); else result[key] = [value];
+ });
+
+ // Indexes the object's values by a criterion, similar to `groupBy`, but for
+ // when you know that your index values will be unique.
+ _.indexBy = group(function(result, value, key) {
+ result[key] = value;
+ });
+
+ // Counts instances of an object that group by a certain criterion. Pass
+ // either a string attribute to count by, or a function that returns the
+ // criterion.
+ _.countBy = group(function(result, value, key) {
+ if (_.has(result, key)) result[key]++; else result[key] = 1;
+ });
+
+ // Use a comparator function to figure out the smallest index at which
+ // an object should be inserted so as to maintain order. Uses binary search.
+ _.sortedIndex = function(array, obj, iteratee, context) {
+ iteratee = _.iteratee(iteratee, context, 1);
+ var value = iteratee(obj);
+ var low = 0, high = array.length;
+ while (low < high) {
+ var mid = low + high >>> 1;
+ if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
+ }
+ return low;
+ };
+
+ // Safely create a real, live array from anything iterable.
+ _.toArray = function(obj) {
+ if (!obj) return [];
+ if (_.isArray(obj)) return slice.call(obj);
+ if (obj.length === +obj.length) return _.map(obj, _.identity);
+ return _.values(obj);
+ };
+
+ // Return the number of elements in an object.
+ _.size = function(obj) {
+ if (obj == null) return 0;
+ return obj.length === +obj.length ? obj.length : _.keys(obj).length;
+ };
+
+ // Split a collection into two arrays: one whose elements all satisfy the given
+ // predicate, and one whose elements all do not satisfy the predicate.
+ _.partition = function(obj, predicate, context) {
+ predicate = _.iteratee(predicate, context);
+ var pass = [], fail = [];
+ _.each(obj, function(value, key, obj) {
+ (predicate(value, key, obj) ? pass : fail).push(value);
+ });
+ return [pass, fail];
+ };
+
+ // Array Functions
+ // ---------------
+
+ // Get the first element of an array. Passing **n** will return the first N
+ // values in the array. Aliased as `head` and `take`. The **guard** check
+ // allows it to work with `_.map`.
+ _.first = _.head = _.take = function(array, n, guard) {
+ if (array == null) return void 0;
+ if (n == null || guard) return array[0];
+ if (n < 0) return [];
+ return slice.call(array, 0, n);
+ };
+
+ // Returns everything but the last entry of the array. Especially useful on
+ // the arguments object. Passing **n** will return all the values in
+ // the array, excluding the last N. The **guard** check allows it to work with
+ // `_.map`.
+ _.initial = function(array, n, guard) {
+ return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
+ };
+
+ // Get the last element of an array. Passing **n** will return the last N
+ // values in the array. The **guard** check allows it to work with `_.map`.
+ _.last = function(array, n, guard) {
+ if (array == null) return void 0;
+ if (n == null || guard) return array[array.length - 1];
+ return slice.call(array, Math.max(array.length - n, 0));
+ };
+
+ // Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
+ // Especially useful on the arguments object. Passing an **n** will return
+ // the rest N values in the array. The **guard**
+ // check allows it to work with `_.map`.
+ _.rest = _.tail = _.drop = function(array, n, guard) {
+ return slice.call(array, n == null || guard ? 1 : n);
+ };
+
+ // Trim out all falsy values from an array.
+ _.compact = function(array) {
+ return _.filter(array, _.identity);
+ };
+
+ // Internal implementation of a recursive `flatten` function.
+ var flatten = function(input, shallow, strict, output) {
+ if (shallow && _.every(input, _.isArray)) {
+ return concat.apply(output, input);
+ }
+ for (var i = 0, length = input.length; i < length; i++) {
+ var value = input[i];
+ if (!_.isArray(value) && !_.isArguments(value)) {
+ if (!strict) output.push(value);
+ } else if (shallow) {
+ push.apply(output, value);
+ } else {
+ flatten(value, shallow, strict, output);
+ }
+ }
+ return output;
+ };
+
+ // Flatten out an array, either recursively (by default), or just one level.
+ _.flatten = function(array, shallow) {
+ return flatten(array, shallow, false, []);
+ };
+
+ // Return a version of the array that does not contain the specified value(s).
+ _.without = function(array) {
+ return _.difference(array, slice.call(arguments, 1));
+ };
+
+ // Produce a duplicate-free version of the array. If the array has already
+ // been sorted, you have the option of using a faster algorithm.
+ // Aliased as `unique`.
+ _.uniq = _.unique = function(array, isSorted, iteratee, context) {
+ if (array == null) return [];
+ if (!_.isBoolean(isSorted)) {
+ context = iteratee;
+ iteratee = isSorted;
+ isSorted = false;
+ }
+ if (iteratee != null) iteratee = _.iteratee(iteratee, context);
+ var result = [];
+ var seen = [];
+ for (var i = 0, length = array.length; i < length; i++) {
+ var value = array[i];
+ if (isSorted) {
+ if (!i || seen !== value) result.push(value);
+ seen = value;
+ } else if (iteratee) {
+ var computed = iteratee(value, i, array);
+ if (_.indexOf(seen, computed) < 0) {
+ seen.push(computed);
+ result.push(value);
+ }
+ } else if (_.indexOf(result, value) < 0) {
+ result.push(value);
+ }
+ }
+ return result;
+ };
+
+ // Produce an array that contains the union: each distinct element from all of
+ // the passed-in arrays.
+ _.union = function() {
+ return _.uniq(flatten(arguments, true, true, []));
+ };
+
+ // Produce an array that contains every item shared between all the
+ // passed-in arrays.
+ _.intersection = function(array) {
+ if (array == null) return [];
+ var result = [];
+ var argsLength = arguments.length;
+ for (var i = 0, length = array.length; i < length; i++) {
+ var item = array[i];
+ if (_.contains(result, item)) continue;
+ for (var j = 1; j < argsLength; j++) {
+ if (!_.contains(arguments[j], item)) break;
+ }
+ if (j === argsLength) result.push(item);
+ }
+ return result;
+ };
+
+ // Take the difference between one array and a number of other arrays.
+ // Only the elements present in just the first array will remain.
+ _.difference = function(array) {
+ var rest = flatten(slice.call(arguments, 1), true, true, []);
+ return _.filter(array, function(value){
+ return !_.contains(rest, value);
+ });
+ };
+
+ // Zip together multiple lists into a single array -- elements that share
+ // an index go together.
+ _.zip = function(array) {
+ if (array == null) return [];
+ var length = _.max(arguments, 'length').length;
+ var results = Array(length);
+ for (var i = 0; i < length; i++) {
+ results[i] = _.pluck(arguments, i);
+ }
+ return results;
+ };
+
+ // Converts lists into objects. Pass either a single array of `[key, value]`
+ // pairs, or two parallel arrays of the same length -- one of keys, and one of
+ // the corresponding values.
+ _.object = function(list, values) {
+ if (list == null) return {};
+ var result = {};
+ for (var i = 0, length = list.length; i < length; i++) {
+ if (values) {
+ result[list[i]] = values[i];
+ } else {
+ result[list[i][0]] = list[i][1];
+ }
+ }
+ return result;
+ };
+
+ // Return the position of the first occurrence of an item in an array,
+ // or -1 if the item is not included in the array.
+ // If the array is large and already in sort order, pass `true`
+ // for **isSorted** to use binary search.
+ _.indexOf = function(array, item, isSorted) {
+ if (array == null) return -1;
+ var i = 0, length = array.length;
+ if (isSorted) {
+ if (typeof isSorted == 'number') {
+ i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted;
+ } else {
+ i = _.sortedIndex(array, item);
+ return array[i] === item ? i : -1;
+ }
+ }
+ for (; i < length; i++) if (array[i] === item) return i;
+ return -1;
+ };
+
+ _.lastIndexOf = function(array, item, from) {
+ if (array == null) return -1;
+ var idx = array.length;
+ if (typeof from == 'number') {
+ idx = from < 0 ? idx + from + 1 : Math.min(idx, from + 1);
+ }
+ while (--idx >= 0) if (array[idx] === item) return idx;
+ return -1;
+ };
+
+ // Generate an integer Array containing an arithmetic progression. A port of
+ // the native Python `range()` function. See
+ // [the Python documentation](http://docs.python.org/library/functions.html#range).
+ _.range = function(start, stop, step) {
+ if (arguments.length <= 1) {
+ stop = start || 0;
+ start = 0;
+ }
+ step = step || 1;
+
+ var length = Math.max(Math.ceil((stop - start) / step), 0);
+ var range = Array(length);
+
+ for (var idx = 0; idx < length; idx++, start += step) {
+ range[idx] = start;
+ }
+
+ return range;
+ };
+
+ // Function (ahem) Functions
+ // ------------------
+
+ // Reusable constructor function for prototype setting.
+ var Ctor = function(){};
+
+ // Create a function bound to a given object (assigning `this`, and arguments,
+ // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
+ // available.
+ _.bind = function(func, context) {
+ var args, bound;
+ if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
+ if (!_.isFunction(func)) throw new TypeError('Bind must be called on a function');
+ args = slice.call(arguments, 2);
+ bound = function() {
+ if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments)));
+ Ctor.prototype = func.prototype;
+ var self = new Ctor;
+ Ctor.prototype = null;
+ var result = func.apply(self, args.concat(slice.call(arguments)));
+ if (_.isObject(result)) return result;
+ return self;
+ };
+ return bound;
+ };
+
+ // Partially apply a function by creating a version that has had some of its
+ // arguments pre-filled, without changing its dynamic `this` context. _ acts
+ // as a placeholder, allowing any combination of arguments to be pre-filled.
+ _.partial = function(func) {
+ var boundArgs = slice.call(arguments, 1);
+ return function() {
+ var position = 0;
+ var args = boundArgs.slice();
+ for (var i = 0, length = args.length; i < length; i++) {
+ if (args[i] === _) args[i] = arguments[position++];
+ }
+ while (position < arguments.length) args.push(arguments[position++]);
+ return func.apply(this, args);
+ };
+ };
+
+ // Bind a number of an object's methods to that object. Remaining arguments
+ // are the method names to be bound. Useful for ensuring that all callbacks
+ // defined on an object belong to it.
+ _.bindAll = function(obj) {
+ var i, length = arguments.length, key;
+ if (length <= 1) throw new Error('bindAll must be passed function names');
+ for (i = 1; i < length; i++) {
+ key = arguments[i];
+ obj[key] = _.bind(obj[key], obj);
+ }
+ return obj;
+ };
+
+ // Memoize an expensive function by storing its results.
+ _.memoize = function(func, hasher) {
+ var memoize = function(key) {
+ var cache = memoize.cache;
+ var address = hasher ? hasher.apply(this, arguments) : key;
+ if (!_.has(cache, address)) cache[address] = func.apply(this, arguments);
+ return cache[address];
+ };
+ memoize.cache = {};
+ return memoize;
+ };
+
+ // Delays a function for the given number of milliseconds, and then calls
+ // it with the arguments supplied.
+ _.delay = function(func, wait) {
+ var args = slice.call(arguments, 2);
+ return setTimeout(function(){
+ return func.apply(null, args);
+ }, wait);
+ };
+
+ // Defers a function, scheduling it to run after the current call stack has
+ // cleared.
+ _.defer = function(func) {
+ return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
+ };
+
+ // Returns a function, that, when invoked, will only be triggered at most once
+ // during a given window of time. Normally, the throttled function will run
+ // as much as it can, without ever going more than once per `wait` duration;
+ // but if you'd like to disable the execution on the leading edge, pass
+ // `{leading: false}`. To disable execution on the trailing edge, ditto.
+ _.throttle = function(func, wait, options) {
+ var context, args, result;
+ var timeout = null;
+ var previous = 0;
+ if (!options) options = {};
+ var later = function() {
+ previous = options.leading === false ? 0 : _.now();
+ timeout = null;
+ result = func.apply(context, args);
+ if (!timeout) context = args = null;
+ };
+ return function() {
+ var now = _.now();
+ if (!previous && options.leading === false) previous = now;
+ var remaining = wait - (now - previous);
+ context = this;
+ args = arguments;
+ if (remaining <= 0 || remaining > wait) {
+ clearTimeout(timeout);
+ timeout = null;
+ previous = now;
+ result = func.apply(context, args);
+ if (!timeout) context = args = null;
+ } else if (!timeout && options.trailing !== false) {
+ timeout = setTimeout(later, remaining);
+ }
+ return result;
+ };
+ };
+
+ // Returns a function, that, as long as it continues to be invoked, will not
+ // be triggered. The function will be called after it stops being called for
+ // N milliseconds. If `immediate` is passed, trigger the function on the
+ // leading edge, instead of the trailing.
+ _.debounce = function(func, wait, immediate) {
+ var timeout, args, context, timestamp, result;
+
+ var later = function() {
+ var last = _.now() - timestamp;
+
+ if (last < wait && last > 0) {
+ timeout = setTimeout(later, wait - last);
+ } else {
+ timeout = null;
+ if (!immediate) {
+ result = func.apply(context, args);
+ if (!timeout) context = args = null;
+ }
+ }
+ };
+
+ return function() {
+ context = this;
+ args = arguments;
+ timestamp = _.now();
+ var callNow = immediate && !timeout;
+ if (!timeout) timeout = setTimeout(later, wait);
+ if (callNow) {
+ result = func.apply(context, args);
+ context = args = null;
+ }
+
+ return result;
+ };
+ };
+
+ // Returns the first function passed as an argument to the second,
+ // allowing you to adjust arguments, run code before and after, and
+ // conditionally execute the original function.
+ _.wrap = function(func, wrapper) {
+ return _.partial(wrapper, func);
+ };
+
+ // Returns a negated version of the passed-in predicate.
+ _.negate = function(predicate) {
+ return function() {
+ return !predicate.apply(this, arguments);
+ };
+ };
+
+ // Returns a function that is the composition of a list of functions, each
+ // consuming the return value of the function that follows.
+ _.compose = function() {
+ var args = arguments;
+ var start = args.length - 1;
+ return function() {
+ var i = start;
+ var result = args[start].apply(this, arguments);
+ while (i--) result = args[i].call(this, result);
+ return result;
+ };
+ };
+
+ // Returns a function that will only be executed after being called N times.
+ _.after = function(times, func) {
+ return function() {
+ if (--times < 1) {
+ return func.apply(this, arguments);
+ }
+ };
+ };
+
+ // Returns a function that will only be executed before being called N times.
+ _.before = function(times, func) {
+ var memo;
+ return function() {
+ if (--times > 0) {
+ memo = func.apply(this, arguments);
+ } else {
+ func = null;
+ }
+ return memo;
+ };
+ };
+
+ // Returns a function that will be executed at most one time, no matter how
+ // often you call it. Useful for lazy initialization.
+ _.once = _.partial(_.before, 2);
+
+ // Object Functions
+ // ----------------
+
+ // Retrieve the names of an object's properties.
+ // Delegates to **ECMAScript 5**'s native `Object.keys`
+ _.keys = function(obj) {
+ if (!_.isObject(obj)) return [];
+ if (nativeKeys) return nativeKeys(obj);
+ var keys = [];
+ for (var key in obj) if (_.has(obj, key)) keys.push(key);
+ return keys;
+ };
+
+ // Retrieve the values of an object's properties.
+ _.values = function(obj) {
+ var keys = _.keys(obj);
+ var length = keys.length;
+ var values = Array(length);
+ for (var i = 0; i < length; i++) {
+ values[i] = obj[keys[i]];
+ }
+ return values;
+ };
+
+ // Convert an object into a list of `[key, value]` pairs.
+ _.pairs = function(obj) {
+ var keys = _.keys(obj);
+ var length = keys.length;
+ var pairs = Array(length);
+ for (var i = 0; i < length; i++) {
+ pairs[i] = [keys[i], obj[keys[i]]];
+ }
+ return pairs;
+ };
+
+ // Invert the keys and values of an object. The values must be serializable.
+ _.invert = function(obj) {
+ var result = {};
+ var keys = _.keys(obj);
+ for (var i = 0, length = keys.length; i < length; i++) {
+ result[obj[keys[i]]] = keys[i];
+ }
+ return result;
+ };
+
+ // Return a sorted list of the function names available on the object.
+ // Aliased as `methods`
+ _.functions = _.methods = function(obj) {
+ var names = [];
+ for (var key in obj) {
+ if (_.isFunction(obj[key])) names.push(key);
+ }
+ return names.sort();
+ };
+
+ // Extend a given object with all the properties in passed-in object(s).
+ _.extend = function(obj) {
+ if (!_.isObject(obj)) return obj;
+ var source, prop;
+ for (var i = 1, length = arguments.length; i < length; i++) {
+ source = arguments[i];
+ for (prop in source) {
+ if (hasOwnProperty.call(source, prop)) {
+ obj[prop] = source[prop];
+ }
+ }
+ }
+ return obj;
+ };
+
+ // Return a copy of the object only containing the whitelisted properties.
+ _.pick = function(obj, iteratee, context) {
+ var result = {}, key;
+ if (obj == null) return result;
+ if (_.isFunction(iteratee)) {
+ iteratee = createCallback(iteratee, context);
+ for (key in obj) {
+ var value = obj[key];
+ if (iteratee(value, key, obj)) result[key] = value;
+ }
+ } else {
+ var keys = concat.apply([], slice.call(arguments, 1));
+ obj = new Object(obj);
+ for (var i = 0, length = keys.length; i < length; i++) {
+ key = keys[i];
+ if (key in obj) result[key] = obj[key];
+ }
+ }
+ return result;
+ };
+
+ // Return a copy of the object without the blacklisted properties.
+ _.omit = function(obj, iteratee, context) {
+ if (_.isFunction(iteratee)) {
+ iteratee = _.negate(iteratee);
+ } else {
+ var keys = _.map(concat.apply([], slice.call(arguments, 1)), String);
+ iteratee = function(value, key) {
+ return !_.contains(keys, key);
+ };
+ }
+ return _.pick(obj, iteratee, context);
+ };
+
+ // Fill in a given object with default properties.
+ _.defaults = function(obj) {
+ if (!_.isObject(obj)) return obj;
+ for (var i = 1, length = arguments.length; i < length; i++) {
+ var source = arguments[i];
+ for (var prop in source) {
+ if (obj[prop] === void 0) obj[prop] = source[prop];
+ }
+ }
+ return obj;
+ };
+
+ // Create a (shallow-cloned) duplicate of an object.
+ _.clone = function(obj) {
+ if (!_.isObject(obj)) return obj;
+ return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
+ };
+
+ // Invokes interceptor with the obj, and then returns obj.
+ // The primary purpose of this method is to "tap into" a method chain, in
+ // order to perform operations on intermediate results within the chain.
+ _.tap = function(obj, interceptor) {
+ interceptor(obj);
+ return obj;
+ };
+
+ // Internal recursive comparison function for `isEqual`.
+ var eq = function(a, b, aStack, bStack) {
+ // Identical objects are equal. `0 === -0`, but they aren't identical.
+ // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
+ if (a === b) return a !== 0 || 1 / a === 1 / b;
+ // A strict comparison is necessary because `null == undefined`.
+ if (a == null || b == null) return a === b;
+ // Unwrap any wrapped objects.
+ if (a instanceof _) a = a._wrapped;
+ if (b instanceof _) b = b._wrapped;
+ // Compare `[[Class]]` names.
+ var className = toString.call(a);
+ if (className !== toString.call(b)) return false;
+ switch (className) {
+ // Strings, numbers, regular expressions, dates, and booleans are compared by value.
+ case '[object RegExp]':
+ // RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
+ case '[object String]':
+ // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
+ // equivalent to `new String("5")`.
+ return '' + a === '' + b;
+ case '[object Number]':
+ // `NaN`s are equivalent, but non-reflexive.
+ // Object(NaN) is equivalent to NaN
+ if (+a !== +a) return +b !== +b;
+ // An `egal` comparison is performed for other numeric values.
+ return +a === 0 ? 1 / +a === 1 / b : +a === +b;
+ case '[object Date]':
+ case '[object Boolean]':
+ // Coerce dates and booleans to numeric primitive values. Dates are compared by their
+ // millisecond representations. Note that invalid dates with millisecond representations
+ // of `NaN` are not equivalent.
+ return +a === +b;
+ }
+ if (typeof a != 'object' || typeof b != 'object') return false;
+ // Assume equality for cyclic structures. The algorithm for detecting cyclic
+ // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
+ var length = aStack.length;
+ while (length--) {
+ // Linear search. Performance is inversely proportional to the number of
+ // unique nested structures.
+ if (aStack[length] === a) return bStack[length] === b;
+ }
+ // Objects with different constructors are not equivalent, but `Object`s
+ // from different frames are.
+ var aCtor = a.constructor, bCtor = b.constructor;
+ if (
+ aCtor !== bCtor &&
+ // Handle Object.create(x) cases
+ 'constructor' in a && 'constructor' in b &&
+ !(_.isFunction(aCtor) && aCtor instanceof aCtor &&
+ _.isFunction(bCtor) && bCtor instanceof bCtor)
+ ) {
+ return false;
+ }
+ // Add the first object to the stack of traversed objects.
+ aStack.push(a);
+ bStack.push(b);
+ var size, result;
+ // Recursively compare objects and arrays.
+ if (className === '[object Array]') {
+ // Compare array lengths to determine if a deep comparison is necessary.
+ size = a.length;
+ result = size === b.length;
+ if (result) {
+ // Deep compare the contents, ignoring non-numeric properties.
+ while (size--) {
+ if (!(result = eq(a[size], b[size], aStack, bStack))) break;
+ }
+ }
+ } else {
+ // Deep compare objects.
+ var keys = _.keys(a), key;
+ size = keys.length;
+ // Ensure that both objects contain the same number of properties before comparing deep equality.
+ result = _.keys(b).length === size;
+ if (result) {
+ while (size--) {
+ // Deep compare each member
+ key = keys[size];
+ if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break;
+ }
+ }
+ }
+ // Remove the first object from the stack of traversed objects.
+ aStack.pop();
+ bStack.pop();
+ return result;
+ };
+
+ // Perform a deep comparison to check if two objects are equal.
+ _.isEqual = function(a, b) {
+ return eq(a, b, [], []);
+ };
+
+ // Is a given array, string, or object empty?
+ // An "empty" object has no enumerable own-properties.
+ _.isEmpty = function(obj) {
+ if (obj == null) return true;
+ if (_.isArray(obj) || _.isString(obj) || _.isArguments(obj)) return obj.length === 0;
+ for (var key in obj) if (_.has(obj, key)) return false;
+ return true;
+ };
+
+ // Is a given value a DOM element?
+ _.isElement = function(obj) {
+ return !!(obj && obj.nodeType === 1);
+ };
+
+ // Is a given value an array?
+ // Delegates to ECMA5's native Array.isArray
+ _.isArray = nativeIsArray || function(obj) {
+ return toString.call(obj) === '[object Array]';
+ };
+
+ // Is a given variable an object?
+ _.isObject = function(obj) {
+ var type = typeof obj;
+ return type === 'function' || type === 'object' && !!obj;
+ };
+
+ // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
+ _.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
+ _['is' + name] = function(obj) {
+ return toString.call(obj) === '[object ' + name + ']';
+ };
+ });
+
+ // Define a fallback version of the method in browsers (ahem, IE), where
+ // there isn't any inspectable "Arguments" type.
+ if (!_.isArguments(arguments)) {
+ _.isArguments = function(obj) {
+ return _.has(obj, 'callee');
+ };
+ }
+
+ // Optimize `isFunction` if appropriate. Work around an IE 11 bug.
+ if (typeof /./ !== 'function') {
+ _.isFunction = function(obj) {
+ return typeof obj == 'function' || false;
+ };
+ }
+
+ // Is a given object a finite number?
+ _.isFinite = function(obj) {
+ return isFinite(obj) && !isNaN(parseFloat(obj));
+ };
+
+ // Is the given value `NaN`? (NaN is the only number which does not equal itself).
+ _.isNaN = function(obj) {
+ return _.isNumber(obj) && obj !== +obj;
+ };
+
+ // Is a given value a boolean?
+ _.isBoolean = function(obj) {
+ return obj === true || obj === false || toString.call(obj) === '[object Boolean]';
+ };
+
+ // Is a given value equal to null?
+ _.isNull = function(obj) {
+ return obj === null;
+ };
+
+ // Is a given variable undefined?
+ _.isUndefined = function(obj) {
+ return obj === void 0;
+ };
+
+ // Shortcut function for checking if an object has a given property directly
+ // on itself (in other words, not on a prototype).
+ _.has = function(obj, key) {
+ return obj != null && hasOwnProperty.call(obj, key);
+ };
+
+ // Utility Functions
+ // -----------------
+
+ // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
+ // previous owner. Returns a reference to the Underscore object.
+ _.noConflict = function() {
+ root._ = previousUnderscore;
+ return this;
+ };
+
+ // Keep the identity function around for default iteratees.
+ _.identity = function(value) {
+ return value;
+ };
+
+ _.constant = function(value) {
+ return function() {
+ return value;
+ };
+ };
+
+ _.noop = function(){};
+
+ _.property = function(key) {
+ return function(obj) {
+ return obj[key];
+ };
+ };
+
+ // Returns a predicate for checking whether an object has a given set of `key:value` pairs.
+ _.matches = function(attrs) {
+ var pairs = _.pairs(attrs), length = pairs.length;
+ return function(obj) {
+ if (obj == null) return !length;
+ obj = new Object(obj);
+ for (var i = 0; i < length; i++) {
+ var pair = pairs[i], key = pair[0];
+ if (pair[1] !== obj[key] || !(key in obj)) return false;
+ }
+ return true;
+ };
+ };
+
+ // Run a function **n** times.
+ _.times = function(n, iteratee, context) {
+ var accum = Array(Math.max(0, n));
+ iteratee = createCallback(iteratee, context, 1);
+ for (var i = 0; i < n; i++) accum[i] = iteratee(i);
+ return accum;
+ };
+
+ // Return a random integer between min and max (inclusive).
+ _.random = function(min, max) {
+ if (max == null) {
+ max = min;
+ min = 0;
+ }
+ return min + Math.floor(Math.random() * (max - min + 1));
+ };
+
+ // A (possibly faster) way to get the current timestamp as an integer.
+ _.now = Date.now || function() {
+ return new Date().getTime();
+ };
+
+ // List of HTML entities for escaping.
+ var escapeMap = {
+ '&': '&',
+ '<': '<',
+ '>': '>',
+ '"': '"',
+ "'": ''',
+ '`': '`'
+ };
+ var unescapeMap = _.invert(escapeMap);
+
+ // Functions for escaping and unescaping strings to/from HTML interpolation.
+ var createEscaper = function(map) {
+ var escaper = function(match) {
+ return map[match];
+ };
+ // Regexes for identifying a key that needs to be escaped
+ var source = '(?:' + _.keys(map).join('|') + ')';
+ var testRegexp = RegExp(source);
+ var replaceRegexp = RegExp(source, 'g');
+ return function(string) {
+ string = string == null ? '' : '' + string;
+ return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
+ };
+ };
+ _.escape = createEscaper(escapeMap);
+ _.unescape = createEscaper(unescapeMap);
+
+ // If the value of the named `property` is a function then invoke it with the
+ // `object` as context; otherwise, return it.
+ _.result = function(object, property) {
+ if (object == null) return void 0;
+ var value = object[property];
+ return _.isFunction(value) ? object[property]() : value;
+ };
+
+ // Generate a unique integer id (unique within the entire client session).
+ // Useful for temporary DOM ids.
+ var idCounter = 0;
+ _.uniqueId = function(prefix) {
+ var id = ++idCounter + '';
+ return prefix ? prefix + id : id;
+ };
+
+ // By default, Underscore uses ERB-style template delimiters, change the
+ // following template settings to use alternative delimiters.
+ _.templateSettings = {
+ evaluate : /<%([\s\S]+?)%>/g,
+ interpolate : /<%=([\s\S]+?)%>/g,
+ escape : /<%-([\s\S]+?)%>/g
+ };
+
+ // When customizing `templateSettings`, if you don't want to define an
+ // interpolation, evaluation or escaping regex, we need one that is
+ // guaranteed not to match.
+ var noMatch = /(.)^/;
+
+ // Certain characters need to be escaped so that they can be put into a
+ // string literal.
+ var escapes = {
+ "'": "'",
+ '\\': '\\',
+ '\r': 'r',
+ '\n': 'n',
+ '\u2028': 'u2028',
+ '\u2029': 'u2029'
+ };
+
+ var escaper = /\\|'|\r|\n|\u2028|\u2029/g;
+
+ var escapeChar = function(match) {
+ return '\\' + escapes[match];
+ };
+
+ // JavaScript micro-templating, similar to John Resig's implementation.
+ // Underscore templating handles arbitrary delimiters, preserves whitespace,
+ // and correctly escapes quotes within interpolated code.
+ // NB: `oldSettings` only exists for backwards compatibility.
+ _.template = function(text, settings, oldSettings) {
+ if (!settings && oldSettings) settings = oldSettings;
+ settings = _.defaults({}, settings, _.templateSettings);
+
+ // Combine delimiters into one regular expression via alternation.
+ var matcher = RegExp([
+ (settings.escape || noMatch).source,
+ (settings.interpolate || noMatch).source,
+ (settings.evaluate || noMatch).source
+ ].join('|') + '|$', 'g');
+
+ // Compile the template source, escaping string literals appropriately.
+ var index = 0;
+ var source = "__p+='";
+ text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
+ source += text.slice(index, offset).replace(escaper, escapeChar);
+ index = offset + match.length;
+
+ if (escape) {
+ source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
+ } else if (interpolate) {
+ source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
+ } else if (evaluate) {
+ source += "';\n" + evaluate + "\n__p+='";
+ }
+
+ // Adobe VMs need the match returned to produce the correct offest.
+ return match;
+ });
+ source += "';\n";
+
+ // If a variable is not specified, place data values in local scope.
+ if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
+
+ source = "var __t,__p='',__j=Array.prototype.join," +
+ "print=function(){__p+=__j.call(arguments,'');};\n" +
+ source + 'return __p;\n';
+
+ try {
+ var render = new Function(settings.variable || 'obj', '_', source);
+ } catch (e) {
+ e.source = source;
+ throw e;
+ }
+
+ var template = function(data) {
+ return render.call(this, data, _);
+ };
+
+ // Provide the compiled source as a convenience for precompilation.
+ var argument = settings.variable || 'obj';
+ template.source = 'function(' + argument + '){\n' + source + '}';
+
+ return template;
+ };
+
+ // Add a "chain" function. Start chaining a wrapped Underscore object.
+ _.chain = function(obj) {
+ var instance = _(obj);
+ instance._chain = true;
+ return instance;
+ };
+
+ // OOP
+ // ---------------
+ // If Underscore is called as a function, it returns a wrapped object that
+ // can be used OO-style. This wrapper holds altered versions of all the
+ // underscore functions. Wrapped objects may be chained.
+
+ // Helper function to continue chaining intermediate results.
+ var result = function(obj) {
+ return this._chain ? _(obj).chain() : obj;
+ };
+
+ // Add your own custom functions to the Underscore object.
+ _.mixin = function(obj) {
+ _.each(_.functions(obj), function(name) {
+ var func = _[name] = obj[name];
+ _.prototype[name] = function() {
+ var args = [this._wrapped];
+ push.apply(args, arguments);
+ return result.call(this, func.apply(_, args));
+ };
+ });
+ };
+
+ // Add all of the Underscore functions to the wrapper object.
+ _.mixin(_);
+
+ // Add all mutator Array functions to the wrapper.
+ _.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
+ var method = ArrayProto[name];
+ _.prototype[name] = function() {
+ var obj = this._wrapped;
+ method.apply(obj, arguments);
+ if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0];
+ return result.call(this, obj);
+ };
+ });
+
+ // Add all accessor Array functions to the wrapper.
+ _.each(['concat', 'join', 'slice'], function(name) {
+ var method = ArrayProto[name];
+ _.prototype[name] = function() {
+ return result.call(this, method.apply(this._wrapped, arguments));
+ };
+ });
+
+ // Extracts the result from a wrapped and chained object.
+ _.prototype.value = function() {
+ return this._wrapped;
+ };
+
+ // AMD registration happens at the end for compatibility with AMD loaders
+ // that may not enforce next-turn semantics on modules. Even though general
+ // practice for AMD registration is to be anonymous, underscore registers
+ // as a named module because, like jQuery, it is a base library that is
+ // popular enough to be bundled in a third party lib, but not be part of
+ // an AMD load request. Those cases could generate an error when an
+ // anonymous define() is called outside of a loader request.
+ if (typeof define === 'function' && define.amd) {
+ define('underscore', [], function() {
+ return _;
+ });
+ }
+}.call(this));
+
+},{}],60:[function(require,module,exports){
+var _;
+
+_ = require("underscore");
+
+module.exports = function(seqs) {
+ var occs;
+ seqs = seqs.map(function(el) {
+ return el.get("seq");
+ });
+ occs = new Array(seqs.length);
+ _.each(seqs, function(el, i) {
+ return _.each(el, function(char, pos) {
+ if (occs[pos] == null) {
+ occs[pos] = {};
+ }
+ if (occs[pos][char] == null) {
+ occs[pos][char] = 0;
+ }
+ return occs[pos][char]++;
+ });
+ });
+ return _.reduce(occs, function(memo, occ) {
+ var keys;
+ keys = _.keys(occ);
+ return memo += _.max(keys, function(key) {
+ return occ[key];
+ });
+ }, "");
+};
+
+
+
+},{"underscore":59}],61:[function(require,module,exports){
+var identitiyCalc;
+
+module.exports = identitiyCalc = function(seqs, consensus) {
+ if (consensus === void 0) {
+ console.warn("bug on consenus calc");
+ return;
+ }
+ return seqs.each(function(seqObj) {
+ var i, matches, seq, total, _i, _ref;
+ seq = seqObj.get("seq");
+ matches = 0;
+ total = 0;
+ for (i = _i = 0, _ref = seq.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
+ if (seq[i] !== "-" && consensus[i] !== "-") {
+ total++;
+ if (seq[i] === consensus[i]) {
+ matches++;
+ }
+ }
+ }
+ return seqObj.set("identity", matches / total);
+ });
+};
+
+
+
+},{}],62:[function(require,module,exports){
+module.exports.consensus = require("./ConsensusCalc");
+
+
+
+},{"./ConsensusCalc":60}],63:[function(require,module,exports){
+var Colorator, Model;
+
+Model = require("backbone-thin").Model;
+
+module.exports = Colorator = Model.extend({
+ defaults: {
+ scheme: "taylor",
+ colorBackground: true,
+ showLowerCase: true,
+ opacity: 0.6
+ }
+});
+
+
+
+},{"backbone-thin":5}],64:[function(require,module,exports){
+var Columns, Model, consenus, _;
+
+Model = require("backbone-thin").Model;
+
+consenus = require("../algo/ConsensusCalc");
+
+_ = require("underscore");
+
+module.exports = Columns = Model.extend({
+ defaults: {
+ scaling: "lin"
+ },
+ initialize: function() {
+ if (this.get("hidden") == null) {
+ return this.set("hidden", []);
+ }
+ },
+ calcHiddenColumns: function(n) {
+ var hidden, i, newX, _i, _len;
+ hidden = this.get("hidden");
+ newX = n;
+ for (_i = 0, _len = hidden.length; _i < _len; _i++) {
+ i = hidden[_i];
+ if (i <= newX) {
+ newX++;
+ }
+ }
+ return newX - n;
+ },
+ _calcConservationPre: function(seqs) {
+ var cons, matches, nMax, total;
+ console.log(seqs.length);
+ if (seqs.length > 1000) {
+ return;
+ }
+ cons = consenus(seqs);
+ seqs = seqs.map(function(el) {
+ return el.get("seq");
+ });
+ nMax = (_.max(seqs, function(el) {
+ return el.length;
+ })).length;
+ total = new Array(nMax);
+ matches = new Array(nMax);
+ _.each(seqs, function(el, i) {
+ return _.each(el, function(char, pos) {
+ total[pos] = total[pos] + 1 || 1;
+ if (cons[pos] === char) {
+ return matches[pos] = matches[pos] + 1 || 1;
+ }
+ });
+ });
+ return [matches, total, nMax];
+ },
+ calcConservation: function(seqs) {
+ if (this.attributes.scaling === "exp") {
+ return this.calcConservationExp(seqs);
+ } else if (this.attributes.scaling === "log") {
+ return this.calcConservationLog(seqs);
+ } else if (this.attributes.scaling === "lin") {
+ return this.calcConservationLin(seqs);
+ }
+ },
+ calcConservationLin: function(seqs) {
+ var i, matches, nMax, total, _i, _ref, _ref1;
+ _ref = this._calcConservationPre(seqs), matches = _ref[0], total = _ref[1], nMax = _ref[2];
+ for (i = _i = 0, _ref1 = nMax - 1; 0 <= _ref1 ? _i <= _ref1 : _i >= _ref1; i = 0 <= _ref1 ? ++_i : --_i) {
+ matches[i] = matches[i] / total[i];
+ }
+ this.set("conserv", matches);
+ return matches;
+ },
+ calcConservationLog: function(seqs) {
+ var i, matches, nMax, total, _i, _ref, _ref1;
+ _ref = this._calcConservationPre(seqs), matches = _ref[0], total = _ref[1], nMax = _ref[2];
+ for (i = _i = 0, _ref1 = nMax - 1; 0 <= _ref1 ? _i <= _ref1 : _i >= _ref1; i = 0 <= _ref1 ? ++_i : --_i) {
+ matches[i] = Math.log(matches[i] + 1) / Math.log(total[i] + 1);
+ }
+ this.set("conserv", matches);
+ return matches;
+ },
+ calcConservationExp: function(seqs) {
+ var i, matches, nMax, total, _i, _ref, _ref1;
+ _ref = this._calcConservationPre(seqs), matches = _ref[0], total = _ref[1], nMax = _ref[2];
+ for (i = _i = 0, _ref1 = nMax - 1; 0 <= _ref1 ? _i <= _ref1 : _i >= _ref1; i = 0 <= _ref1 ? ++_i : --_i) {
+ matches[i] = Math.exp(matches[i] + 1) / Math.exp(total[i] + 1);
+ }
+ this.set("conserv", matches);
+ return matches;
+ }
+});
+
+
+
+},{"../algo/ConsensusCalc":60,"backbone-thin":5,"underscore":59}],65:[function(require,module,exports){
+var Config, Model;
+
+Model = require("backbone-thin").Model;
+
+module.exports = Config = Model.extend({
+ defaults: {
+ registerMouseHover: false,
+ registerMouseClicks: true,
+ importProxy: "https://cors-anywhere.herokuapp.com/",
+ eventBus: true
+ }
+});
+
+
+
+},{"backbone-thin":5}],66:[function(require,module,exports){
+var Consenus, Model, consenusCalc;
+
+Model = require("backbone-thin").Model;
+
+consenusCalc = require("../algo/ConsensusCalc");
+
+module.exports = Consenus = Model.extend({
+ defaults: {
+ consenus: ""
+ },
+ getConsensus: function(seqs) {
+ var cons;
+ if (seqs.length > 1000) {
+ return;
+ }
+ cons = consenusCalc(seqs);
+ this.set("consenus", cons);
+ return cons;
+ }
+});
+
+
+
+},{"../algo/ConsensusCalc":60,"backbone-thin":5}],67:[function(require,module,exports){
+var ColumnSelection, Model, PosSelection, RowSelection, Selection, _;
+
+_ = require("underscore");
+
+Model = require("backbone-thin").Model;
+
+Selection = Model.extend({
+ defaults: {
+ type: "super"
+ }
+});
+
+RowSelection = Selection.extend({
+ defaults: _.extend({}, Selection.prototype.defaults, {
+ type: "row",
+ seqId: ""
+ }),
+ inRow: function(seqId) {
+ return seqId === this.get("seqId");
+ },
+ inColumn: function(rowPos) {
+ return true;
+ },
+ getLength: function() {
+ return 1;
+ }
+});
+
+ColumnSelection = Selection.extend({
+ defaults: _.extend({}, Selection.prototype.defaults, {
+ type: "column",
+ xStart: -1,
+ xEnd: -1
+ }),
+ inRow: function() {
+ return true;
+ },
+ inColumn: function(rowPos) {
+ return xStart <= rowPos && rowPos <= xEnd;
+ },
+ getLength: function() {
+ return xEnd - xStart;
+ }
+});
+
+PosSelection = RowSelection.extend(_.extend({}, _.pick(ColumnSelection, "inColumn"), _.pick(ColumnSelection, "getLength"), {
+ defaults: _.extend({}, ColumnSelection.prototype.defaults, RowSelection.prototype.defaults, {
+ type: "pos"
+ })
+}));
+
+module.exports.sel = Selection;
+
+module.exports.possel = PosSelection;
+
+module.exports.rowsel = RowSelection;
+
+module.exports.columnsel = ColumnSelection;
+
+
+
+},{"backbone-thin":5,"underscore":59}],68:[function(require,module,exports){
+var Collection, SelectionManager, sel, _;
+
+sel = require("./Selection");
+
+_ = require("underscore");
+
+Collection = require("backbone-thin").Collection;
+
+module.exports = SelectionManager = Collection.extend({
+ model: sel.sel,
+ initialize: function(data, opts) {
+ this.g = opts.g;
+ this.listenTo(this.g, "residue:click", function(e) {
+ return this._handleE(e.evt, new sel.possel({
+ xStart: e.rowPos,
+ xEnd: e.rowPos,
+ seqId: e.seqId
+ }));
+ });
+ this.listenTo(this.g, "row:click", function(e) {
+ return this._handleE(e.evt, new sel.rowsel({
+ xStart: e.rowPos,
+ xEnd: e.rowPos,
+ seqId: e.seqId
+ }));
+ });
+ return this.listenTo(this.g, "column:click", function(e) {
+ return this._handleE(e.evt, new sel.columnsel({
+ xStart: e.rowPos,
+ xEnd: e.rowPos + e.stepSize - 1
+ }));
+ });
+ },
+ getSelForRow: function(seqId) {
+ return this.filter(function(el) {
+ return el.inRow(seqId);
+ });
+ },
+ getSelForColumns: function(rowPos) {
+ return this.filter(function(el) {
+ return el.inColumn(rowPos);
+ });
+ },
+ getBlocksForRow: function(seqId, maxLen) {
+ var blocks, seli, selis, _i, _j, _k, _len, _ref, _ref1, _results, _results1;
+ selis = this.filter(function(el) {
+ return el.inRow(seqId);
+ });
+ blocks = [];
+ for (_i = 0, _len = selis.length; _i < _len; _i++) {
+ seli = selis[_i];
+ if (seli.attributes.type === "row") {
+ blocks = (function() {
+ _results = [];
+ for (var _j = 0; 0 <= maxLen ? _j <= maxLen : _j >= maxLen; 0 <= maxLen ? _j++ : _j--){ _results.push(_j); }
+ return _results;
+ }).apply(this);
+ break;
+ } else {
+ blocks = blocks.concat((function() {
+ _results1 = [];
+ for (var _k = _ref = seli.attributes.xStart, _ref1 = seli.attributes.xEnd; _ref <= _ref1 ? _k <= _ref1 : _k >= _ref1; _ref <= _ref1 ? _k++ : _k--){ _results1.push(_k); }
+ return _results1;
+ }).apply(this));
+ }
+ }
+ return blocks;
+ },
+ getAllColumnBlocks: function(conf) {
+ var blocks, filtered, maxLen, seli, withPos, _i, _j, _len, _ref, _ref1, _results;
+ maxLen = conf.maxLen;
+ withPos = conf.withPos;
+ blocks = [];
+ if (conf.withPos) {
+ filtered = this.filter(function(el) {
+ return el.get('xStart') != null;
+ });
+ } else {
+ filtered = this.filter(function(el) {
+ return el.get('type') === "column";
+ });
+ }
+ for (_i = 0, _len = filtered.length; _i < _len; _i++) {
+ seli = filtered[_i];
+ blocks = blocks.concat((function() {
+ _results = [];
+ for (var _j = _ref = seli.attributes.xStart, _ref1 = seli.attributes.xEnd; _ref <= _ref1 ? _j <= _ref1 : _j >= _ref1; _ref <= _ref1 ? _j++ : _j--){ _results.push(_j); }
+ return _results;
+ }).apply(this));
+ }
+ blocks = _.uniq(blocks);
+ return blocks;
+ },
+ invertRow: function(rows) {
+ var el, inverted, s, selRows, _i, _len;
+ selRows = this.where({
+ type: "row"
+ });
+ selRows = _.map(selRows, function(el) {
+ return el.attributes.seqId;
+ });
+ inverted = _.filter(rows, function(el) {
+ if (selRows.indexOf(el) >= 0) {
+ return false;
+ }
+ return true;
+ });
+ s = [];
+ for (_i = 0, _len = inverted.length; _i < _len; _i++) {
+ el = inverted[_i];
+ s.push(new sel.rowsel({
+ seqId: el
+ }));
+ }
+ console.log(s);
+ return this.reset(s);
+ },
+ invertCol: function(columns) {
+ var el, inverted, s, selColumns, xEnd, xStart, _i, _len;
+ selColumns = this.where({
+ type: "column"
+ });
+ selColumns = _.reduce(selColumns, function(memo, el) {
+ var _i, _ref, _ref1, _results;
+ return memo.concat((function() {
+ _results = [];
+ for (var _i = _ref = el.attributes.xStart, _ref1 = el.attributes.xEnd; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; _ref <= _ref1 ? _i++ : _i--){ _results.push(_i); }
+ return _results;
+ }).apply(this));
+ }, []);
+ inverted = _.filter(columns, function(el) {
+ if (selColumns.indexOf(el) >= 0) {
+ return false;
+ }
+ return true;
+ });
+ if (inverted.length === 0) {
+ return;
+ }
+ s = [];
+ console.log(inverted);
+ xStart = xEnd = inverted[0];
+ for (_i = 0, _len = inverted.length; _i < _len; _i++) {
+ el = inverted[_i];
+ if (xEnd + 1 === el) {
+ xEnd = el;
+ } else {
+ s.push(new sel.columnsel({
+ xStart: xStart,
+ xEnd: xEnd
+ }));
+ xStart = xEnd = el;
+ }
+ }
+ if (xStart !== xEnd) {
+ s.push(new sel.columnsel({
+ xStart: xStart,
+ xEnd: inverted[inverted.length - 1]
+ }));
+ }
+ return this.reset(s);
+ },
+ _handleE: function(e, selection) {
+ if (e.ctrlKey || e.metaKey) {
+ return this.add(selection);
+ } else {
+ return this.reset([selection]);
+ }
+ },
+ _reduceColumns: function() {
+ return this.each(function(el, index, arr) {
+ var cols, left, lefts, right, rights, xEnd, xStart, _i, _j, _len, _len1;
+ cols = _.filter(arr, function(el) {
+ return el.get('type') === 'column';
+ });
+ xStart = el.get('xStart');
+ xEnd = el.get('xEnd');
+ lefts = _.filter(cols, function(el) {
+ return el.get('xEnd') === (xStart - 1);
+ });
+ for (_i = 0, _len = lefts.length; _i < _len; _i++) {
+ left = lefts[_i];
+ left.set('xEnd', xStart);
+ }
+ rights = _.filter(cols, function(el) {
+ return el.get('xStart') === (xEnd + 1);
+ });
+ for (_j = 0, _len1 = rights.length; _j < _len1; _j++) {
+ right = rights[_j];
+ right.set('xStart', xEnd);
+ }
+ if (lefts.length > 0 || rights.length > 0) {
+ console.log("removed el");
+ return el.collection.remove(el);
+ }
+ });
+ }
+});
+
+
+
+},{"./Selection":67,"backbone-thin":5,"underscore":59}],69:[function(require,module,exports){
+var Model, Visibility;
+
+Model = require("backbone-thin").Model;
+
+module.exports = Visibility = Model.extend({
+ defaults: {
+ overviewBox: 30,
+ headerBox: -1,
+ alignmentBody: 0
+ }
+});
+
+
+
+},{"backbone-thin":5}],70:[function(require,module,exports){
+var Model, Visibility;
+
+Model = require("backbone-thin").Model;
+
+module.exports = Visibility = Model.extend({
+ defaults: {
+ sequences: true,
+ markers: true,
+ metacell: false,
+ conserv: true,
+ overviewbox: false,
+ labels: true,
+ labelName: true,
+ labelId: true,
+ labelPartition: false,
+ labelCheckbox: false
+ }
+});
+
+
+
+},{"backbone-thin":5}],71:[function(require,module,exports){
+var Model, Zoomer;
+
+Model = require("backbone-thin").Model;
+
+module.exports = Zoomer = Model.extend({
+ constructor: function(attributes, options) {
+ Model.apply(this, arguments);
+ this.g = options.g;
+ return this;
+ },
+ defaults: {
+ alignmentWidth: "auto",
+ alignmentHeight: 195,
+ columnWidth: 15,
+ rowHeight: 15,
+ labelWidth: 100,
+ metaWidth: 100,
+ textVisible: true,
+ labelIdLength: 30,
+ labelFontsize: "13px",
+ labelLineHeight: "13px",
+ markerFontsize: "10px",
+ stepSize: 1,
+ markerStepSize: 2,
+ residueFont: "13px mono",
+ canvasEventScale: 1,
+ boxRectHeight: 5,
+ boxRectWidth: 5,
+ menuFontsize: "20px",
+ menuItemFontsize: "18px",
+ menuItemLineHeight: "18px",
+ menuMarginLeft: "5px",
+ menuPadding: "3px 5px 3px 5px",
+ _alignmentScrollLeft: 0,
+ _alignmentScrollTop: 0
+ },
+ getAlignmentWidth: function(n) {
+ if (this.get("alignmentWidth") === "auto") {
+ return this.get("columnWidth") * n;
+ } else {
+ return this.get("alignmentWidth");
+ }
+ },
+ setLeftOffset: function(n) {
+ var val;
+ val = (n - 1) * this.get('columnWidth');
+ val = Math.max(0, val);
+ return this.set("_alignmentScrollLeft", val);
+ },
+ setTopOffset: function(n) {
+ var val;
+ val = (n - 1) * this.get('rowHeight');
+ val = Math.max(0, val);
+ return this.set("_alignmentScrollTop", val);
+ },
+ getLabelWidth: function() {
+ var paddingLeft;
+ paddingLeft = 0;
+ if (this.g.vis.get("labels")) {
+ paddingLeft += this.get("labelWidth");
+ }
+ if (this.g.vis.get("metacell")) {
+ paddingLeft += this.get("metaWidth");
+ }
+ return paddingLeft;
+ },
+ _adjustWidth: function(el, model) {
+ var calcWidth, maxWidth, parentWidth, val;
+ if ((el.parentNode != null) && el.parentNode.offsetWidth !== 0) {
+ parentWidth = el.parentNode.offsetWidth;
+ } else {
+ parentWidth = document.body.clientWidth - 35;
+ }
+ maxWidth = parentWidth - this.getLabelWidth();
+ calcWidth = this.getAlignmentWidth(model.getMaxLength() - this.g.columns.get('hidden').length);
+ val = Math.min(maxWidth, calcWidth);
+ val = Math.floor(val / this.get("columnWidth")) * this.get("columnWidth");
+ return this.set("alignmentWidth", val);
+ },
+ _checkScrolling: function(scrollObj, opts) {
+ var xScroll, yScroll;
+ xScroll = scrollObj[0];
+ yScroll = scrollObj[1];
+ this.set("_alignmentScrollLeft", xScroll, opts);
+ return this.set("_alignmentScrollTop", yScroll, opts);
+ }
+});
+
+
+
+},{"backbone-thin":5}],72:[function(require,module,exports){
+module.exports.msa = require("./msa");
+
+module.exports.model = require("./model");
+
+module.exports.algo = require("./algo");
+
+module.exports.menu = require("./menu");
+
+module.exports.utils = require("./utils");
+
+module.exports.selection = require("./g/selection/Selection");
+
+module.exports.view = require("backbone-viewj");
+
+module.exports.boneView = require("backbone-childs");
+
+module.exports._ = require('underscore');
+
+module.exports.$ = require('jbone');
+
+module.exports.version = "0.1.0";
+
+
+
+},{"./algo":62,"./g/selection/Selection":67,"./menu":74,"./model":89,"./msa":90,"./utils":92,"backbone-childs":3,"backbone-viewj":10,"jbone":50,"underscore":59}],73:[function(require,module,exports){
+var ColorMenu, ExportMenu, ExtraMenu, FilterMenu, HelpMenu, ImportMenu, MenuView, OrderingMenu, SelectionMenu, VisMenu, boneView;
+
+boneView = require("backbone-childs");
+
+ImportMenu = require("./views/ImportMenu");
+
+FilterMenu = require("./views/FilterMenu");
+
+SelectionMenu = require("./views/SelectionMenu");
+
+VisMenu = require("./views/VisMenu");
+
+ColorMenu = require("./views/ColorMenu");
+
+OrderingMenu = require("./views/OrderingMenu");
+
+ExtraMenu = require("./views/ExtraMenu");
+
+ExportMenu = require("./views/ExportMenu");
+
+HelpMenu = require("./views/HelpMenu");
+
+module.exports = MenuView = boneView.extend({
+ initialize: function(data) {
+ this.msa = data.msa;
+ this.addView("10_import", new ImportMenu({
+ model: this.msa.seqs,
+ g: this.msa.g
+ }));
+ this.addView("20_filter", new FilterMenu({
+ model: this.msa.seqs,
+ g: this.msa.g
+ }));
+ this.addView("30_selection", new SelectionMenu({
+ model: this.msa.seqs,
+ g: this.msa.g
+ }));
+ this.addView("40_vis", new VisMenu({
+ model: this.msa.seqs,
+ g: this.msa.g
+ }));
+ this.addView("50_color", new ColorMenu({
+ model: this.msa.seqs,
+ g: this.msa.g
+ }));
+ this.addView("60_ordering", new OrderingMenu({
+ model: this.msa.seqs,
+ g: this.msa.g
+ }));
+ this.addView("70_extra", new ExtraMenu({
+ model: this.msa.seqs,
+ g: this.msa.g
+ }));
+ this.addView("80_export", new ExportMenu({
+ model: this.msa.seqs,
+ g: this.msa.g,
+ msa: this.msa
+ }));
+ return this.addView("90_help", new HelpMenu({
+ g: this.msa.g
+ }));
+ },
+ render: function() {
+ this.renderSubviews();
+ this.el.setAttribute("class", "biojs_msa_menubar");
+ return this.el.appendChild(document.createElement("p"));
+ }
+});
+
+
+
+},{"./views/ColorMenu":76,"./views/ExportMenu":77,"./views/ExtraMenu":78,"./views/FilterMenu":79,"./views/HelpMenu":80,"./views/ImportMenu":81,"./views/OrderingMenu":82,"./views/SelectionMenu":83,"./views/VisMenu":84,"backbone-childs":3}],74:[function(require,module,exports){
+module.exports.defaultmenu = require("./defaultmenu");
+
+module.exports.menubuilder = require("./menubuilder");
+
+
+
+},{"./defaultmenu":73,"./menubuilder":75}],75:[function(require,module,exports){
+var BMath, MenuBuilder, jbone, view;
+
+BMath = require("../utils/bmath");
+
+jbone = require("jbone");
+
+view = require("backbone-viewj");
+
+module.exports = MenuBuilder = view.extend({
+ setName: function(name) {
+ this.name = name;
+ return this._nodes = [];
+ },
+ addNode: function(label, callback, data) {
+ var style;
+ if (data != null) {
+ style = data.style;
+ }
+ if (this._nodes == null) {
+ this._nodes = [];
+ }
+ return this._nodes.push({
+ label: label,
+ callback: callback,
+ style: style
+ });
+ },
+ buildDOM: function() {
+ return this._buildM({
+ nodes: this._nodes,
+ name: this.name
+ });
+ },
+ _buildM: function(data) {
+ var displayedButton, frag, key, li, menu, menuUl, name, node, nodes, style, _i, _len, _ref;
+ nodes = data.nodes;
+ name = data.name;
+ menu = document.createElement("div");
+ menu.className = "dropdown dropdown-tip";
+ menu.id = "adrop-" + BMath.uniqueId();
+ menu.style.display = "none";
+ menuUl = document.createElement("ul");
+ menuUl.className = "dropdown-menu";
+ for (_i = 0, _len = nodes.length; _i < _len; _i++) {
+ node = nodes[_i];
+ li = document.createElement("li");
+ li.textContent = node.label;
+ _ref = node.style;
+ for (key in _ref) {
+ style = _ref[key];
+ li.style[key] = style;
+ }
+ li.addEventListener("click", node.callback);
+ if (this.g != null) {
+ li.style.lineHeight = this.g.zoomer.get("menuItemLineHeight");
+ }
+ menuUl.appendChild(li);
+ }
+ menu.appendChild(menuUl);
+ frag = document.createDocumentFragment();
+ displayedButton = document.createElement("a");
+ displayedButton.textContent = name;
+ displayedButton.className = "biojs_msa_menubar_alink";
+ if (this.g != null) {
+ menuUl.style.fontSize = this.g.zoomer.get("menuItemFontsize");
+ displayedButton.style.fontSize = this.g.zoomer.get("menuFontsize");
+ displayedButton.style.marginLeft = this.g.zoomer.get("menuMarginLeft");
+ displayedButton.style.padding = this.g.zoomer.get("menuPadding");
+ }
+ jbone(displayedButton).on("click", (function(_this) {
+ return function(e) {
+ _this._showMenu(e, menu, displayedButton);
+ return window.setTimeout(function() {
+ return jbone(document.body).one("click", function(e) {
+ console.log("next click");
+ return menu.style.display = "none";
+ });
+ }, 5);
+ };
+ })(this));
+ frag.appendChild(menu);
+ frag.appendChild(displayedButton);
+ return frag;
+ },
+ _showMenu: function(e, menu, target) {
+ var rect;
+ menu.style.display = "block";
+ menu.style.position = "absolute";
+ rect = target.getBoundingClientRect();
+ menu.style.left = rect.left + "px";
+ return menu.style.top = (rect.top + target.offsetHeight) + "px";
+ }
+});
+
+
+
+},{"../utils/bmath":91,"backbone-viewj":10,"jbone":50}],76:[function(require,module,exports){
+var ColorMenu, MenuBuilder, dom, _;
+
+MenuBuilder = require("../menubuilder");
+
+_ = require("underscore");
+
+dom = require("dom-helper");
+
+module.exports = ColorMenu = MenuBuilder.extend({
+ initialize: function(data) {
+ this.g = data.g;
+ this.el.style.display = "inline-block";
+ return this.listenTo(this.g.colorscheme, "change", function() {
+ return this.render();
+ });
+ },
+ render: function() {
+ var colorschemes, menuColor, scheme, text, _i, _len;
+ menuColor = this.setName("Color scheme");
+ colorschemes = this.getColorschemes();
+ for (_i = 0, _len = colorschemes.length; _i < _len; _i++) {
+ scheme = colorschemes[_i];
+ this.addScheme(menuColor, scheme);
+ }
+ text = "Background";
+ if (this.g.colorscheme.get("colorBackground")) {
+ text = "Hide " + text;
+ } else {
+ text = "Show " + text;
+ }
+ this.addNode(text, (function(_this) {
+ return function() {
+ return _this.g.colorscheme.set("colorBackground", !_this.g.colorscheme.get("colorBackground"));
+ };
+ })(this));
+ this.grey(menuColor);
+ dom.removeAllChilds(this.el);
+ this.el.appendChild(this.buildDOM());
+ return this;
+ },
+ addScheme: function(menuColor, scheme) {
+ var current, style;
+ style = {};
+ current = this.g.colorscheme.get("scheme");
+ if (current === scheme.id) {
+ style.backgroundColor = "#77ED80";
+ }
+ return this.addNode(scheme.name, (function(_this) {
+ return function() {
+ return _this.g.colorscheme.set("scheme", scheme.id);
+ };
+ })(this), {
+ style: style
+ });
+ },
+ getColorschemes: function() {
+ var schemes;
+ schemes = [];
+ schemes.push({
+ name: "Zappo",
+ id: "zappo"
+ });
+ schemes.push({
+ name: "Taylor",
+ id: "taylor"
+ });
+ schemes.push({
+ name: "Hydrophobicity",
+ id: "hydro"
+ });
+ schemes.push({
+ name: "Lesk",
+ id: "lesk"
+ });
+ schemes.push({
+ name: "Cinema",
+ id: "cinema"
+ });
+ schemes.push({
+ name: "MAE",
+ id: "mae"
+ });
+ schemes.push({
+ name: "Clustal",
+ id: "clustal"
+ });
+ schemes.push({
+ name: "Clustal2",
+ id: "clustal2"
+ });
+ schemes.push({
+ name: "Turn",
+ id: "turn"
+ });
+ schemes.push({
+ name: "Strand",
+ id: "strand"
+ });
+ schemes.push({
+ name: "Buried",
+ id: "buried"
+ });
+ schemes.push({
+ name: "Helix",
+ id: "helix"
+ });
+ schemes.push({
+ name: "Nucleotide",
+ id: "nucleotide"
+ });
+ schemes.push({
+ name: "Purine",
+ id: "purine"
+ });
+ schemes.push({
+ name: "PID",
+ id: "pid"
+ });
+ schemes.push({
+ name: "No color",
+ id: "foo"
+ });
+ return schemes;
+ },
+ grey: function(menuColor) {
+ this.addNode("Grey", (function(_this) {
+ return function() {
+ _this.g.colorscheme.set("showLowerCase", false);
+ return _this.model.each(function(seq) {
+ var grey, residues;
+ residues = seq.get("seq");
+ grey = [];
+ _.each(residues, function(el, index) {
+ if (el === el.toLowerCase()) {
+ return grey.push(index);
+ }
+ });
+ return seq.set("grey", grey);
+ });
+ };
+ })(this));
+ this.addNode("Grey by threshold", (function(_this) {
+ return function() {
+ var conserv, grey, i, maxLen, threshold, _i, _ref;
+ threshold = prompt("Enter threshold (in percent)", 20);
+ threshold = threshold / 100;
+ maxLen = _this.model.getMaxLength();
+ conserv = _this.g.columns.get("conserv");
+ grey = [];
+ for (i = _i = 0, _ref = maxLen - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
+ console.log(conserv[i]);
+ if (conserv[i] < threshold) {
+ grey.push(i);
+ }
+ }
+ return _this.model.each(function(seq) {
+ return seq.set("grey", grey);
+ });
+ };
+ })(this));
+ this.addNode("Grey selection", (function(_this) {
+ return function() {
+ var maxLen;
+ maxLen = _this.model.getMaxLength();
+ return _this.model.each(function(seq) {
+ var blocks;
+ blocks = _this.g.selcol.getBlocksForRow(seq.get("id"), maxLen);
+ return seq.set("grey", blocks);
+ });
+ };
+ })(this));
+ return this.addNode("Reset grey", (function(_this) {
+ return function() {
+ _this.g.colorscheme.set("showLowerCase", true);
+ return _this.model.each(function(seq) {
+ return seq.set("grey", []);
+ });
+ };
+ })(this));
+ }
+});
+
+
+
+},{"../menubuilder":75,"dom-helper":49,"underscore":59}],77:[function(require,module,exports){
+var ExportMenu, FastaExporter, MenuBuilder, blobURL, saveAs, _;
+
+MenuBuilder = require("../menubuilder");
+
+saveAs = require("browser-saveas");
+
+FastaExporter = require("biojs-io-fasta").writer;
+
+_ = require("underscore");
+
+blobURL = require("blueimp_canvastoblob");
+
+module.exports = ExportMenu = MenuBuilder.extend({
+ initialize: function(data) {
+ this.g = data.g;
+ this.msa = data.msa;
+ return this.el.style.display = "inline-block";
+ },
+ render: function() {
+ this.setName("Export");
+ this.addNode("Export sequences", (function(_this) {
+ return function() {
+ var blob, text;
+ text = FastaExporter["export"](_this.model.toJSON());
+ blob = new Blob([text], {
+ type: 'text/plain'
+ });
+ return saveAs(blob, "all.fasta");
+ };
+ })(this));
+ this.addNode("Export selection", (function(_this) {
+ return function() {
+ var blob, i, selection, text, _i, _ref;
+ selection = _this.g.selcol.pluck("seqId");
+ if (selection != null) {
+ selection = _this.model.filter(function(el) {
+ return _.contains(selection, el.get("id"));
+ });
+ for (i = _i = 0, _ref = selection.length - 1; _i <= _ref; i = _i += 1) {
+ selection[i] = selection[i].toJSON();
+ }
+ } else {
+ selection = _this.model.toJSON();
+ console.log("no selection found");
+ }
+ text = FastaExporter["export"](selection);
+ blob = new Blob([text], {
+ type: 'text/plain'
+ });
+ return saveAs(blob, "selection.fasta");
+ };
+ })(this));
+ this.addNode("Export image", (function(_this) {
+ return function() {
+ var canvas, url;
+ canvas = _this.msa.getView('stage').getView('body').getView('seqblock').el;
+ if (canvas != null) {
+ url = canvas.toDataURL('image/png');
+ return saveAs(blobURL(url), "biojs-msa.png", "image/png");
+ }
+ };
+ })(this));
+ this.el.appendChild(this.buildDOM());
+ return this;
+ }
+});
+
+
+
+},{"../menubuilder":75,"biojs-io-fasta":undefined,"blueimp_canvastoblob":46,"browser-saveas":47,"underscore":59}],78:[function(require,module,exports){
+var ExtraMenu, MenuBuilder, Seq, consenus;
+
+MenuBuilder = require("../menubuilder");
+
+consenus = require("../../algo/ConsensusCalc");
+
+Seq = require("../../model/Sequence");
+
+module.exports = ExtraMenu = MenuBuilder.extend({
+ initialize: function(data) {
+ this.g = data.g;
+ return this.el.style.display = "inline-block";
+ },
+ render: function() {
+ this.setName("Extras");
+ this.addNode("Add consensus seq", (function(_this) {
+ return function() {
+ var con, seq;
+ con = consenus(_this.model);
+ console.log(con);
+ seq = new Seq({
+ seq: con,
+ id: "0c",
+ name: "consenus"
+ });
+ _this.model.add(seq);
+ _this.model.comparator = function(seq) {
+ return seq.get("id");
+ };
+ return _this.model.sort();
+ };
+ })(this));
+ this.addNode("Increase font size", (function(_this) {
+ return function() {
+ _this.g.zoomer.set("columnWidth", _this.g.zoomer.get("columnWidth") + 2);
+ _this.g.zoomer.set("labelWidth", _this.g.zoomer.get("columnWidth") + 5);
+ _this.g.zoomer.set("rowHeight", _this.g.zoomer.get("rowHeight") + 2);
+ return _this.g.zoomer.set("labelFontSize", _this.g.zoomer.get("labelFontSize") + 2);
+ };
+ })(this));
+ this.addNode("Decrease font size", (function(_this) {
+ return function() {
+ _this.g.zoomer.set("columnWidth", _this.g.zoomer.get("columnWidth") - 2);
+ _this.g.zoomer.set("rowHeight", _this.g.zoomer.get("rowHeight") - 2);
+ _this.g.zoomer.set("labelFontSize", _this.g.zoomer.get("labelFontSize") - 2);
+ if (_this.g.zoomer.get("columnWidth") < 8) {
+ return _this.g.zoomer.set("textVisible", false);
+ }
+ };
+ })(this));
+ this.addNode("Bar chart exp scaling", (function(_this) {
+ return function() {
+ return _this.g.columns.set("scaling", "exp");
+ };
+ })(this));
+ this.addNode("Bar chart linear scaling", (function(_this) {
+ return function() {
+ return _this.g.columns.set("scaling", "lin");
+ };
+ })(this));
+ this.addNode("Bar chart log scaling", (function(_this) {
+ return function() {
+ return _this.g.columns.set("scaling", "log");
+ };
+ })(this));
+ this.addNode("Minimized width", (function(_this) {
+ return function() {
+ return _this.g.zoomer.set("alignmentWidth", 600);
+ };
+ })(this));
+ this.addNode("Minimized height", (function(_this) {
+ return function() {
+ return _this.g.zoomer.set("alignmentHeight", 120);
+ };
+ })(this));
+ this.addNode("Jump to a column", (function(_this) {
+ return function() {
+ var offset;
+ offset = prompt("Column", "20");
+ if (offset < 0 || offset > _this.model.getMaxLength() || isNaN(offset)) {
+ alert("invalid column");
+ return;
+ }
+ return _this.g.zoomer.setLeftOffset(offset);
+ };
+ })(this));
+ this.el.appendChild(this.buildDOM());
+ return this;
+ }
+});
+
+
+
+},{"../../algo/ConsensusCalc":60,"../../model/Sequence":88,"../menubuilder":75}],79:[function(require,module,exports){
+var FilterMenu, MenuBuilder, _;
+
+MenuBuilder = require("../menubuilder");
+
+_ = require("underscore");
+
+module.exports = FilterMenu = MenuBuilder.extend({
+ initialize: function(data) {
+ this.g = data.g;
+ return this.el.style.display = "inline-block";
+ },
+ render: function() {
+ this.setName("Filter");
+ this.addNode("Hide columns by threshold", (function(_this) {
+ return function(e) {
+ var conserv, hidden, i, maxLen, threshold, _i, _ref;
+ threshold = prompt("Enter threshold (in percent)", 20);
+ threshold = threshold / 100;
+ maxLen = _this.model.getMaxLength();
+ hidden = [];
+ conserv = _this.g.columns.get("conserv");
+ for (i = _i = 0, _ref = maxLen - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
+ if (conserv[i] < threshold) {
+ hidden.push(i);
+ }
+ }
+ return _this.g.columns.set("hidden", hidden);
+ };
+ })(this));
+ this.addNode("Hide columns by selection", (function(_this) {
+ return function() {
+ var hidden, hiddenOld;
+ hiddenOld = _this.g.columns.get("hidden");
+ hidden = hiddenOld.concat(_this.g.selcol.getAllColumnBlocks({
+ maxLen: _this.model.getMaxLength(),
+ withPos: true
+ }));
+ _this.g.selcol.reset([]);
+ return _this.g.columns.set("hidden", hidden);
+ };
+ })(this));
+ this.addNode("Hide columns by gaps", (function(_this) {
+ return function() {
+ var gapContent, gaps, hidden, i, maxLen, threshold, total, _i, _ref;
+ threshold = prompt("Enter threshold (in percent)", 20);
+ threshold = threshold / 100;
+ maxLen = _this.model.getMaxLength();
+ hidden = [];
+ for (i = _i = 0, _ref = maxLen - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
+ gaps = 0;
+ total = 0;
+ _this.model.each(function(el) {
+ if (el.get('seq')[i] === "-") {
+ gaps++;
+ }
+ return total++;
+ });
+ gapContent = gaps / total;
+ if (gapContent > threshold) {
+ hidden.push(i);
+ }
+ }
+ return _this.g.columns.set("hidden", hidden);
+ };
+ })(this));
+ this.addNode("Hide seqs by identity", (function(_this) {
+ return function() {
+ var threshold;
+ threshold = prompt("Enter threshold (in percent)", 20);
+ threshold = threshold / 100;
+ return _this.model.each(function(el) {
+ if (el.get('identity') < threshold) {
+ return el.set('hidden', true);
+ }
+ });
+ };
+ })(this));
+ this.addNode("Hide seqs by selection", (function(_this) {
+ return function() {
+ var hidden, ids;
+ hidden = _this.g.selcol.where({
+ type: "row"
+ });
+ ids = _.map(hidden, function(el) {
+ return el.get('seqId');
+ });
+ _this.g.selcol.reset([]);
+ return _this.model.each(function(el) {
+ if (ids.indexOf(el.get('id')) >= 0) {
+ return el.set('hidden', true);
+ }
+ });
+ };
+ })(this));
+ this.addNode("Hide seqs by gaps", (function(_this) {
+ return function() {
+ var threshold;
+ threshold = prompt("Enter threshold (in percent)", 40);
+ return _this.model.each(function(el, i) {
+ var gaps, seq;
+ seq = el.get('seq');
+ gaps = _.reduce(seq, (function(memo, c) {
+ if (c === '-') {
+ memo++;
+ }
+ return memo;
+ }), 0);
+ console.log(gaps);
+ if (gaps > threshold) {
+ return el.set('hidden', true);
+ }
+ });
+ };
+ })(this));
+ this.addNode("Reset", (function(_this) {
+ return function() {
+ _this.g.columns.set("hidden", []);
+ return _this.model.each(function(el) {
+ if (el.get('hidden')) {
+ return el.set('hidden', false);
+ }
+ });
+ };
+ })(this));
+ this.el.appendChild(this.buildDOM());
+ return this;
+ }
+});
+
+
+
+},{"../menubuilder":75,"underscore":59}],80:[function(require,module,exports){
+var HelpMenu, MenuBuilder;
+
+MenuBuilder = require("../menubuilder");
+
+module.exports = HelpMenu = MenuBuilder.extend({
+ initialize: function(data) {
+ return this.g = data.g;
+ },
+ render: function() {
+ this.setName("Help");
+ this.addNode("About the project", (function(_this) {
+ return function() {
+ return window.open("https://github.com/greenify/biojs-vis-msa");
+ };
+ })(this));
+ this.addNode("Report issues", (function(_this) {
+ return function() {
+ return window.open("https://github.com/greenify/biojs-vis-msa/issues");
+ };
+ })(this));
+ this.addNode("User manual", (function(_this) {
+ return function() {
+ return window.open("https://github.com/greenify/biojs-vis-msa/wiki");
+ };
+ })(this));
+ this.el.style.display = "inline-block";
+ this.el.appendChild(this.buildDOM());
+ return this;
+ }
+});
+
+
+
+},{"../menubuilder":75}],81:[function(require,module,exports){
+var Clustal, FastaReader, ImportMenu, MenuBuilder, corsURL;
+
+Clustal = require("biojs-io-clustal");
+
+FastaReader = require("biojs-io-fasta").parse;
+
+MenuBuilder = require("../menubuilder");
+
+corsURL = require("../../utils/proxy").corsURL;
+
+module.exports = ImportMenu = MenuBuilder.extend({
+ initialize: function(data) {
+ this.g = data.g;
+ return this.el.style.display = "inline-block";
+ },
+ render: function() {
+ this.setName("Import");
+ this.addNode("FASTA", (function(_this) {
+ return function(e) {
+ var url;
+ url = prompt("URL", "/test/dummy/samples/p53.clustalo.fasta");
+ url = corsURL(url, _this.g);
+ return FastaReader.read(url, function(seqs) {
+ var zoomer;
+ zoomer = _this.g.zoomer.toJSON();
+ zoomer.labelWidth = 200;
+ zoomer.boxRectHeight = 2;
+ zoomer.boxRectWidth = 2;
+ _this.model.reset([]);
+ _this.g.zoomer.set(zoomer);
+ _this.model.reset(seqs);
+ return _this.g.columns.calcConservation(_this.model);
+ });
+ };
+ })(this));
+ this.addNode("CLUSTAL", (function(_this) {
+ return function() {
+ var url;
+ url = prompt("URL", "/test/dummy/samples/p53.clustalo.clustal");
+ url = corsURL(url, _this.g);
+ return Clustal.read(url, function(seqs) {
+ var zoomer;
+ zoomer = _this.g.zoomer.toJSON();
+ zoomer.labelWidth = 200;
+ zoomer.boxRectHeight = 2;
+ zoomer.boxRectWidth = 2;
+ _this.model.reset([]);
+ _this.g.zoomer.set(zoomer);
+ _this.model.reset(seqs);
+ return _this.g.columns.calcConservation(_this.model);
+ });
+ };
+ })(this));
+ this.addNode("add your own Parser", (function(_this) {
+ return function() {
+ return window.open("https://github.com/biojs/biojs2");
+ };
+ })(this));
+ this.el.appendChild(this.buildDOM());
+ return this;
+ }
+});
+
+
+
+},{"../../utils/proxy":93,"../menubuilder":75,"biojs-io-clustal":undefined,"biojs-io-fasta":undefined}],82:[function(require,module,exports){
+var MenuBuilder, OrderingMenu, dom, _;