Mouse.prototype.bind = function(){
  var obj = this.obj
    , self = this;

  // up
  function up(e){
    obj.onmouseup && obj.onmouseup(e);
    event.unbind(document, 'mousemove', move);
    event.unbind(document, 'mouseup', up);
    self.emit('up', e);
  }

  // move
  function move(e){
    obj.onmousemove && obj.onmousemove(e);
    self.emit('move', e);
  }

  // down
  self.down = function(e){
    obj.onmousedown && obj.onmousedown(e);
    event.bind(document, 'mouseup', up);
    event.bind(document, 'mousemove', move);
    self.emit('down', e);
  };

  // bind all.
  event.bind(this.el, 'mousedown', self.down);

  return this;
};
Example #2
0
function analytics(propertyId) {
  if (!ga(propertyId)) {
    // nothing to do
    return;
  }

  function trackEvent(ds) {
    var gaq = window._gaq = window._gaq || [];
    var args = ['_trackEvent'];

    ['Category', 'Action', 'Label', 'Value', 'Noninteraction'].forEach(function(prop) {
      args.push(ds.get('ga' + prop));
    });
    // only Category and Action are not optional in GA
    if (!args[2]) {
      args[2] = 'click'; // set action to click by default
    }
    gaq.push(args);
  }

  events.bind(document.body, 'click', function(e) {
    var ds = dataset(e.target || e.srcElement);
    if (ds.get('gaCategory')) {
      trackEvent(ds);
    }
  }, true);
}
Example #3
0
exports.bind = function(el, selector, type, fn, capture){
  return event.bind(el, type, function(e){
    var target = e.target || e.srcElement;
    e.delegateTarget = closest(target, selector, true, el);
    if (e.delegateTarget) fn.call(el, e);
  }, capture);
};
Example #4
0
function transition(el, css, dur, fn){
  fn = fn || noop;

  var cls = classes(el);
  var timer;

  // add class
  cls.add(css);

  if ('function' == typeof dur) {
    // callback function
    fn = dur;
  } else if (null != dur) {
    // set a timer fallback
    timer = setTimeout(cleanup, ms(dur));
  }

  // remove class upon transition
  event.bind(el, prop, cleanup);

  // cleanup function
  function cleanup(){
    cls.remove(css);
    fn(el, css);
    clearTimeout(timer);
    event.unbind(el, prop, cleanup)
  }
}
Example #5
0
    each(form, function (el) {
      var handler = function (e) {

        // Allow for properties to be a function. And pass it the form element
        // that was submitted.
        var props = isFunction ? properties(el) : properties;

        self.track(event, props);

        preventDefault(e);

        // Submit the form after a timeout, giving the event time to fire.
        setTimeout(function () {
          el.submit();
        }, self.timeout);
      };

      // Support the form being submitted via jQuery instead of for real. This
      // doesn't happen automatically because `el.submit()` doesn't actually
      // fire submit handlers, which is what jQuery uses internally. >_<
      var dom = window.jQuery || window.Zepto;
      if (dom) {
        dom(el).submit(handler);
      } else {
        bind(el, 'submit', handler);
      }
    });
Example #6
0
Recurly.prototype.relay = function relay (done) {
  var self = this;

  if (false === this.configured) {
    throw errors('not-configured');
  }

  events.bind(window, 'message', function listener (event) {
    var data = json.parse(event.data);
    var name = data.recurly_event;
    var body = data.recurly_message;
    var err = body.error ? errors('api-error', body.error) : null;
    events.unbind(window, 'message', listener);
    if (name) self.emit(name, err, body);
    if (frame) document.body.removeChild(frame);
  });

  if ('documentMode' in document) {
    var frame = document.createElement('iframe');
    frame.width = frame.height = 0;
    frame.src = this.url('/relay');
    frame.name = 'recurly-relay';
    frame.style.display = 'none';
    frame.onload = bind(this, done);
    document.body.appendChild(frame);
  } else {
    done();
  }
};
Example #7
0
Snap.prototype.easeTo = function(n) {
  var _this = this;
  this.easing = true;
  this.el.style[transition] = 'all '
    + this.opts.transitionSpeed + 's ' + this.opts.easing;

  var cb = function() {
    var status;
    ev.unbind(_this.el, transitionend, cb);

    _this.el.style[transition] = '';
    _this.translation = n;
    _this.easing = false;

    if (n === window.innerWidth) {
      status = 'left-expand';
    } else if (n >= _this.opts.maxPosition) {
      status = 'left-open';
    } else if (n === -window.innerWidth) {
      status = 'right-expand';
    } else if (n <= _this.opts.minPosition) {
      status = 'right-open';
    } else {
      status = 'closed';
    }

    _this.setParentClass('snap-'+ status);
    _this.emit('toggle', status);
  };

  ev.bind(this.el, transitionend, cb);
  this.emit('animate', this.state);
  this.translate(n);
};
Example #8
0
    each(links, function (el) {
      bind(el, 'click', function (e) {

        // Allow for properties to be a function. And pass it the
        // link element that was clicked.
        var props = isFunction ? properties(el) : properties;

        self.track(event, props);

        // To justify us preventing the default behavior we must:
        //
        // * Have an `href` to use.
        // * Not have a `target="_blank"` attribute.
        // * Not have any special keys pressed, because they might be trying to
        //   open in a new tab, or window, or download.
        //
        // This might not cover all cases, but we'd rather throw out an event
        // than miss a case that breaks the user experience.
        if (el.href && el.target !== '_blank' && !isMeta(e)) {

          preventDefault(e);

          // Navigate to the url after just enough of a timeout.
          setTimeout(function () {
            window.location.href = el.href;
          }, self.timeout);
        }
      });
    });
Example #9
0
Router.prototype.listenPopState = function () {
  var self = this;
  event.bind(window, 'popstate', function (e) {
    self.go();
  });
  return this;
};
Example #10
0
reactive.bind('data-model', function(el, attr, model) {
  var type = el.getAttribute('type');
  var name = el.nodeName.toLowerCase();

  // When the field changes
  events.bind(el, 'change', function(){
    model.set(attr, value(el));
  });

  // When the attribute changes
  this.change(function(){
    var val = model.get(attr);
    if(val == null) {
      val = "";
    }
    if(name !== "input" && name !== "select") {
      el.innerHTML = val;
    }
    else if(type === "radio") {
      value(el, el.value === String(val));
    }
    else {
      value(el, val);
    }
  });
  
  // Fill the model with the data immediately
  // if there is no value on the model already
  if(model.get(attr) == null) {
    model.set(attr, value(el));
  }
  
});
Example #11
0
function about() {
  var section, trigger;

  function check() {
    return typeof cookie('resorts-open') === 'undefined';
  }

  function close() {
    classes(section).add('hidden');
  }

  function open() {
    classes(section).remove('hidden');
  }

  section = document.querySelector('.hidden .about');
  if (!section) {
    // no hidden 'about' section - nothing to do
    return;
  }
  if (!check()) {
    // we already have a cookie
    return;
  }

  trigger = section.querySelector('a.close');
  section = section.parentNode;

  events.bind(trigger, 'click', function(e) {
    close();
    e.preventDefault();
  });
  open();
}
Example #12
0
Events.prototype.bind = function(event, method){
  var e = parse(event);
  var el = this.el;
  var obj = this.obj;
  var name = e.name;
  var method = method || 'on' + name;
  var args = [].slice.call(arguments, 2);

  // callback
  function cb(){
    var a = [].slice.call(arguments).concat(args);
    obj[method].apply(obj, a);
  }

  // bind
  if (e.selector) {
    cb = delegate.bind(el, e.selector, name, cb);
  } else {
    events.bind(el, name, cb);
  }

  // subscription for unbinding
  this.sub(name, method, cb);

  return cb;
};
Example #13
0
function Datepicker(el) {
  if (!(this instanceof Datepicker)) return new Datepicker(el);
  this.el = el;
  this.cal = new Calendar;
  this.cal.el.addClass('datepicker-calendar');
  event.bind(el, 'click', this.onclick.bind(this));
}
Example #14
0
function postHeight() {
  if (window === window.parent) {
    // we are not embedded - nothing to do
    return;
  }
  notify();
  events.bind(window, 'resize', debounce(notify, 300), true);
}
Example #15
0
 bind('on-' + name, function(el, method){
   var fns = this.view.fns
   event.bind(el, name, function(e){
     var fn = fns[method];
     if (!fn) throw new Error('method .' + method + '() missing');
     fns[method](e);
   });
 });
Example #16
0
 return new Promise(function (resolve, reject) {
   let btn = el.querySelector('.cd-buttons')
   event.bind(query('.yes', el), 'click', e => {
     if (removed) return
     e.preventDefault()
     let v = el.querySelector('input').value
     if (!v.trim()) return
     dismiss()
     resolve(v.trim())
   })
   event.bind(query('.no', el), 'click', e => {
     if (removed) return
     e.preventDefault()
     dismiss()
     reject(new Error('canceled'))
   })
 })
Example #17
0
module.exports = function (user) {
  var html = minstache(template, user);
  var el = domify(html);
  document.body.appendChild(el);
  var a = document.getElementById('changepass');
  event.bind(a, 'click', changepass);
  return el;
}
Example #18
0
function Validate(el) {
  if (!(this instanceof Validate)) return new Validate(el);
  this.schema = new Schema();
  this.form = Form(el)
  this.el = el;

  // noops
  this._submit = noop;
  this._blur = noop;

  // event binding
  event.bind(this.el, 'submit', this.onsubmit.bind(this));
  var inputs = this.inputs = el.querySelectorAll('input,textarea');
  for (var i = 0, input; input = inputs[i++];) {
    event.bind(input, 'blur', this.onblur.bind(this));
  }
}
Example #19
0
module.exports = function(el, fn){
  event.bind(el, 'mouseup', callback);
  event.bind(el, 'keyup', callback);

  function callback(e){
    if (mod(e)) return;
    var id = raf(function(){
      var str = selected();
      if (str) fn(e, str);
      raf.cancel(id);
    });
  }

  return function(){
    event.unbind(el, 'mouseup', callback);
    event.unbind(el, 'keyup', callback);
  }
};
Example #20
0
View.prototype.showMenu = function() {
  var menu = this.find('.menu');
  if (menu.classList.contains('hidden')) {
    menu.classList.remove('hidden');
    evnt.bind(document.documentElement, 'click', this.hideMenu.bind(this));
  } else {
    this.hideMenu();
  }
};
Example #21
0
module.exports = function (element) {
  ev.bind(element, 'input', function () {
    rows = parseInt(this.getAttribute('rows'));
    var scrollHeight = this.scrollHeight;
    var height = this.clientHeight;
    
    this.setAttribute('rows', Math.ceil(((scrollHeight * rows) / height)))
  });
};
exports.bind = function(el, selector, type, fn, capture){
  if (forceCaptureEvents.indexOf(type) !== -1) capture = true;

  return event.bind(el, type, function(e){
    var target = e.target || e.srcElement;
    e.delegateTarget = closest(target, selector, true, el);
    if (e.delegateTarget) fn.call(el, e);
  }, capture);
};
Example #23
0
Field.prototype.on = function (event) {
  var self = this;
  bind(this.el, event, function (e) {
    // don't validate an empty input on blur, that's annoying
    if ('blur' === event && !self.adapter.value(self.el)) return;
    self.validate();
  });
  return this;
};
Example #24
0
Days.prototype.monthMenu = function(){
  this.selectMonth = true;
  this.title.querySelector('.month').innerHTML = monthDropdown(this.locale.months);
  var self = this;
  events.bind(this.title.querySelector('.month .calendar-select'), 'change', function(){
    self.emit('month');
    return false;
  });
};
Example #25
0
Days.prototype.yearMenu = function(from, to){
  this.selectYear = true;
  this.title.querySelector('.year').innerHTML = yearDropdown(from, to);
  var self = this;
  events.bind(this.title.querySelector('.year .calendar-select'), 'change', function(){
    self.emit('year');
    return false;
  });
};
Example #26
0
Days.prototype.monthMenu = function(){
  this.selectMonth = true;
  byClass(this.title, 'month', true).innerHTML = monthDropdown();
  var self = this;
  ev.bind(this._calendarSelect('month'), 'change', function(){
    self.emit('month');
    return false;
  });
};
Example #27
0
        init: function(parentList) {
            list = parentList;

            events.bind(getByClass(list.listContainer, options.searchClass), 'keyup', function(e) {
                var target = e.target || e.srcElement; // IE have srcElement
                list.search(target.value, fuzzySearch.search);
            });

            return;
        },
Example #28
0
exports.plugin = function (cal, options) {
    
    options = options || {};
    
    var template = templateEl.cloneNode(true);
    
    template.querySelector('.month-select').innerHTML = genMonthSelect();
    template.querySelector('.year-select').innerHTML = genYearSelect(options.fromYear || cal._date.getFullYear() - 10, options.toYear || cal._date.getFullYear() + 10);
    
    var monthSelect = template.querySelector('.month-select select')
      , yearSelect = template.querySelector('.year-select select')
    ;
    
    events.bind(template.querySelector('.prev-month'), 'click', function () {
        cal.prevMonth();
    });
    
    events.bind(template.querySelector('.next-month'), 'click', function () {
        cal.nextMonth();
    });
    
    events.bind(monthSelect, 'change', function (e) {
        cal.setMonth(e.target.value);
    });
    
    events.bind(yearSelect, 'change', function (e) {
        cal.setYear(e.target.value);
    });
    
    cal
      .on('change month', function (month) {
          monthSelect.value = month;
      })
      .on('change year', function (year) {
          yearSelect.value = year;
      })
    ;
    
    cal.initEmit();
    
    cal._head.insertBefore(template, cal._head.firstChild);
    
};
Example #29
0
 subs.forEach(function(arr) {
   var el = arr[0];
   var type = arr[1];
   var method = arr[2];
   var fn = ctx[method] ? ctx[method].bind(ctx) : function(){};
   events.bind(el, type, fn);
   unbinds.push(function() {
     events.unbind(el, type, fn);
   })
 })
Example #30
0
Days.prototype.yearMenu = function(from, to){
  this.selectYear = true;
  var title = this.head.getElementsByTagName('td')[1];
  byClass(this.title, 'year', true).innerHTML = yearDropdown(from, to);
  var self = this;
  ev.bind(this._calendarSelect('year'), 'change', function(){
    self.emit('year');
    return false;
  });
};