View file xmyx.ru/files/radio/click_manager.js

File size: 1.8Kb
function ClickManager() {
  this.events = {};

  if (window.navigator.msPointerEnabled) {
    //Internet Explorer 10 style
    this.eventTouchstart    = "MSPointerDown";
    this.eventTouchmove     = "MSPointerMove";
    this.eventTouchend      = "MSPointerUp";
  } else {
    this.eventTouchstart    = "touchstart";
    this.eventTouchmove     = "touchmove";
    this.eventTouchend      = "touchend";
  }
  
  this.listen();
}

ClickManager.prototype.on = function (event, callback, n) {
  if (!this.events[event]) {
    this.events[event] = [];
  }
  this.events[event].push(callback);
};

ClickManager.prototype.emit = function (event, data, n ) {
  var callbacks = this.events[event];
  if (callbacks) {
    callbacks.forEach(function (callback) {
      callback(data, n);
    });
  }
};

ClickManager.prototype.listen = function () {
    var self = this;
	this.bindButtonPress("div.audioPlay", this.audioPlayPause);
	this.bindButtonPress("td.aic_progress_wrap div.aic_line", this.audioSetPosition);
	this.bindButtonPress("td.aic_volume_wrap div.aic_line", this.audioSetVolume);
};

ClickManager.prototype.audioPlayPause = function (event) {
    if ("ai_play" == event.target.className || "i_play" == event.target.className)
    {
        event.preventDefault();
        this.emit("audioPlayPause", $(event.currentTarget));
    }
};

ClickManager.prototype.audioSetPosition = function (event) {
    event.preventDefault();
    this.emit("audioSetPosition", event);
};

ClickManager.prototype.audioSetVolume = function (event) {
    event.preventDefault();
    this.emit("audioSetVolume", event);
};

ClickManager.prototype.bindButtonPress = function (selector, fn) {
  var button = $(selector);
  button.click(fn.bind(this));
  //button.on(this.eventTouchend, fn.bind(this));
};