biojs-vis-seqlogo
Version:
A sequence logo visualizer
1,720 lines (1,461 loc) • 495 kB
JavaScript
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){
// 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":3,"backbone-extend-standalone":4,"jbone":5,"underscore":6}],2:[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);
},{}],3:[function(require,module,exports){
module.exports = require('./backbone-events-standalone');
},{"./backbone-events-standalone":2}],4:[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;
});
},{}],5:[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));
},{}],6:[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 no