2 var Evented, MIRROR_ATTACH, addClass, allDrops, clickEvent, createContext, extend, hasClass, removeClass, sortAttach, touchDevice, _ref,
3 __hasProp = {}.hasOwnProperty,
4 __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; },
5 __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
7 _ref = Tether.Utils, extend = _ref.extend, addClass = _ref.addClass, removeClass = _ref.removeClass, hasClass = _ref.hasClass, Evented = _ref.Evented;
9 touchDevice = 'ontouchstart' in document.documentElement;
11 clickEvent = touchDevice ? 'touchstart' : 'click';
13 sortAttach = function(str) {
14 var first, second, _ref1, _ref2;
15 _ref1 = str.split(' '), first = _ref1[0], second = _ref1[1];
16 if (first === 'left' || first === 'right') {
17 _ref2 = [second, first], first = _ref2[0], second = _ref2[1];
19 return [first, second].join(' ');
33 createContext = function(options) {
34 var DropInstance, defaultOptions, drop, _name;
35 if (options == null) {
39 return (function(func, args, ctor) {
40 ctor.prototype = func.prototype;
41 var child = new ctor, result = func.apply(child, args);
42 return Object(result) === result ? result : child;
43 })(DropInstance, arguments, function(){});
46 createContext: createContext,
53 attach: 'bottom left',
55 constrainToScrollParent: true,
56 constrainToWindow: true,
61 extend(drop, defaultOptions, options);
62 extend(drop.defaults, defaultOptions.defaults, options.defaults);
63 if (allDrops[_name = drop.classPrefix] == null) {
66 drop.updateBodyClasses = function() {
67 var anyOpen, _drop, _i, _len, _ref1;
69 _ref1 = allDrops[drop.classPrefix];
70 for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
72 if (!(_drop.isOpened())) {
79 return addClass(document.body, "" + drop.classPrefix + "-open");
81 return removeClass(document.body, "" + drop.classPrefix + "-open");
84 DropInstance = (function(_super) {
85 __extends(DropInstance, _super);
87 function DropInstance(options) {
88 this.options = options;
89 this.options = extend({}, drop.defaults, this.options);
90 this.target = this.options.target;
91 if (this.target == null) {
92 throw new Error('Drop Error: You must provide a target.');
94 drop.drops.push(this);
95 allDrops[drop.classPrefix].push(this);
101 DropInstance.prototype.setupElements = function() {
102 this.drop = document.createElement('div');
103 addClass(this.drop, drop.classPrefix);
104 if (this.options.classes) {
105 addClass(this.drop, this.options.classes);
107 this.dropContent = document.createElement('div');
108 addClass(this.dropContent, "" + drop.classPrefix + "-content");
109 if (typeof this.options.content === 'object') {
110 this.dropContent.appendChild(this.options.content);
112 this.dropContent.innerHTML = this.options.content;
114 return this.drop.appendChild(this.dropContent);
117 DropInstance.prototype.setupTether = function() {
118 var constraints, dropAttach;
119 dropAttach = this.options.position.split(' ');
120 dropAttach[0] = MIRROR_ATTACH[dropAttach[0]];
121 dropAttach = dropAttach.join(' ');
123 if (this.options.constrainToScrollParent) {
127 attachment: 'together none'
130 if (this.options.constrainToWindow !== false) {
134 attachment: 'together'
143 attachment: sortAttach(dropAttach),
144 targetAttachment: sortAttach(this.options.position),
145 classPrefix: drop.classPrefix,
149 constraints: constraints
151 if (this.options.tether !== false) {
152 return this.tether = new Tether(extend({}, options, this.options.tether));
156 DropInstance.prototype.setupEvents = function() {
159 if (!this.options.openOn) {
162 events = this.options.openOn.split(' ');
163 if (__indexOf.call(events, 'click') >= 0) {
164 this.target.addEventListener(clickEvent, function() {
165 return _this.toggle();
167 document.addEventListener(clickEvent, function(event) {
168 if (!_this.isOpened()) {
171 if (event.target === _this.drop || _this.drop.contains(event.target)) {
174 if (event.target === _this.target || _this.target.contains(event.target)) {
177 return _this.close();
180 if (__indexOf.call(events, 'hover') >= 0) {
181 this.target.addEventListener('mouseover', function() {
184 return this.target.addEventListener('mouseout', function() {
185 return _this.close();
190 DropInstance.prototype.isOpened = function() {
191 return hasClass(this.drop, "" + drop.classPrefix + "-open");
194 DropInstance.prototype.toggle = function() {
195 if (this.isOpened()) {
202 DropInstance.prototype.open = function() {
204 if (!this.drop.parentNode) {
205 document.body.appendChild(this.drop);
207 addClass(this.target, "" + drop.classPrefix + "-open");
208 addClass(this.drop, "" + drop.classPrefix + "-open");
209 if ((_ref1 = this.tether) != null) {
212 this.trigger('open');
213 return drop.updateBodyClasses();
216 DropInstance.prototype.close = function() {
218 removeClass(this.target, "" + drop.classPrefix + "-open");
219 removeClass(this.drop, "" + drop.classPrefix + "-open");
220 this.trigger('close');
221 if ((_ref1 = this.tether) != null) {
224 return drop.updateBodyClasses();
233 window.Drop = createContext();
235 document.addEventListener('DOMContentLoaded', function() {
236 return Drop.updateBodyClasses();