Alice

 view release on metacpan or  search on metacpan

share/static/alice.js  view on Meta::CPAN

  },

  addMessage: function(message) {
    if (!message.html || message.msgid <= this.msgid) return;

    if (message.msgid) this.msgid = message.msgid;
    if (message.nicks) this.updateNicks(message.nicks);

    var position = this.captureScrollPosition();

    this.messages.insert(message.html);
    this.trimMessages();

    this.scrollToPosition(position);

    var li = this.messages.select("li").last();
    this.application.applyFilters(li, this);

    this.scrollToPosition(position);

    if (message.event == "topic") {
      this.topic = message.body;
      if (this.active) this.application.displayTopic(this.topic);
    }

    this.element.redraw();
    this.promoteNick(message.nick);
  },

  promoteNick: function(nick) {
    if (this.nicks_order.last() == nick) return;

    var index = this.nicks_order.indexOf(nick);
    if (index > -1) this.nicks_order.splice(index, 1);

    this.nicks_order.push(nick);
  },

  captureScrollPosition: function() {
    if (!this.active) return;
    if (this.forceScroll) return 0;

    var bottom = this.element.scrollTop + this.element.offsetHeight;
    var height = this.element.scrollHeight;

    return height - bottom;
  },

  scrollToPosition: function(position) {
    if (!this.active) return;
    this.element.scrollTop = this.element.scrollHeight - this.element.offsetHeight - position;
  },

  getNicknames: function () {
    return this.nicks.sort(function(a, b) {

      var pos_a = this.nicks_order.indexOf(a),
          pos_b = this.nicks_order.indexOf(b);

      if (pos_a == pos_b)
        return a.toLowerCase().localeCompare(b.toLowerCase());
      else if (pos_a > pos_b)
        return -1;
      else if (pos_a < pos_b)
        return 1;

    }.bind(this));
  },

  updateNicks: function(nicks) {
    this.nicks = nicks;
    if (this.active) this.application.displayNicks(this.nicks);
  },

  removeImage: function(e) {
    e.stop();
    var div = e.findElement('div.image');
    if (div) {
      var a = div.down("a");
      var id = a.identify();
      a.update(a.href);
      a.style.display = "inline";
      div.replace(a);
      var contain = a.up();
      contain.innerHTML = contain.innerHTML.replace("\n", "");
      var a = $(id);
      a.observe("click", function(e){e.stop();this.inlineImage(a)}.bind(this));
    }
  },

  inlineImage: function(a) {
    a.stopObserving("click");
    var src = a.readAttribute("img") || a.innerHTML;
    var prefix = alice.options.image_prefix;

    var img = new Element("IMG", {src: prefix + src});
    img.hide();

    img.observe("load", function(){
      var wrap = new Element("DIV", {"class": "image"});
      var hide = new Element("A", {"class": "hideimg"});
      var position = this.captureScrollPosition();

      img.show();
      a.replace(wrap);
      wrap.insert(a);
      a.update(img);
      a.insert(hide);
      a.style.display = "inline-block";
      hide.observe("click", this.removeImage.bind(this));
      hide.update("hide");

      this.scrollToPosition(position);
    }.bind(this));

    a.insert({after: img});
  }
});

Alice.Toolbar = Class.create(WysiHat.Toolbar, {
  createButtonElement: function(toolbar, options) {



( run in 2.702 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )