App-Alice

 view release on metacpan or  search on metacpan

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

    var windows = this.windows();
    for (var i=0; i < windows.length; i++) {
      if (windows[i].active) return windows[i];
    }
    if (windows[0]) return windows[0];
  },

  addFilters: function(list) {
    this.filters = this.filters.concat(list);
  },

  applyFilters: function(content) {
    return this.filters.inject(content, function(value, filter) {
      return filter(value);
    });
  },

  nextWindow: function() {
    var active = this.activeWindow();

    var nextTab = active.tab.next();
    if (!nextTab)
      nextTab = $$('ul#tabs li').first();
    if (!nextTab) return;

    var id = nextTab.id.replace('_tab','');
    if (id != active.id) {
      this.getWindow(id).focus();
    }
  },

  focusLast: function() {
    if (this.previousFocus && this.previousFocus.id != this.activeWindow().id)
      this.previousFocus.focus();
    else
      this.previousWindow();
  },

  previousWindow: function() {
    var active = this.activeWindow();

    var previousTab = this.activeWindow().tab.previous();
    if (!previousTab)
      previousTab = $$('ul#tabs li').last();
    if (!previousTab) return;

    var id = previousTab.id.replace('_tab','');
    if (id != active.id)
      this.getWindow(id).focus();
  },

  closeWindow: function(windowId) {
    var win = this.getWindow(windowId);
    if (win) win.close();
  },

  insertWindow: function(windowId, html) {
    if (!$(windowId)) {
      $('windows').insert(html['window']);
      $('tabs').insert(html.tab);
      $('tab_overflow_overlay').insert(html.select);
      $(windowId+"_tab_overflow_button").selected = false;
      this.activeWindow().tabOverflowButton.selected = true;
      this.makeSortable();
    }
  },

  highlightChannelSelect: function() {
    $('tab_overflow_button').addClassName('unread');
  },

  unHighlightChannelSelect: function() {
    $('tab_overflow_button').removeClassName('unread');
  },

  updateChannelSelect: function() {
    var windows = this.windows();
    for (var i=0; i < windows.length; i++) {
      var win = windows[i];
      if ((win.tab.hasClassName('unread') || win.tab.hasClassName('highlight')) && win.isTabWrapped()) {
        this.highlightChannelSelect();
        return;
      }
    }
    this.unHighlightChannelSelect();
  },

  handleAction: function(action) {
    if (this.actionHandlers[action.event]) {
      this.actionHandlers[action.event].call(this,action);
    }
  },

  displayMessage: function(message) {
    var win = this.getWindow(message['window'].id);
    if (win) {
      win.addMessage(message);
    } else {
      this.connection.requestWindow(
        message['window'].title, message['window'].id, message
      );
    }
  },

  focusHash: function(hash) {
    if (!hash) hash = window.location.hash;
    if (hash) {
      hash = decodeURIComponent(hash);
      hash = hash.replace(/^#/, "");
      var windows = this.windows();
      for (var i = 0; i < windows.length; i++) {
        var win = windows[i];
        if (win.hashtag == hash) {
          if (win && !win.active) win.focus();
          return;
        }
      }
    }
  },

  makeSortable: function() {

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

    window.alice = alice;

    var options = {
      images: 'show',
      avatars: 'show',
      timeformat: '12'
    };

    var js = /alice\.js\?(.*)?$/;
    $$('script[src]').findAll(function(s) {
      return s.src.match(js);
    }).each(function(s) {
      var params = s.src.match(js)[1];
      params.split("&").each(function(o) {
        var kv = o.split("=");
        options[kv[0]] = kv[1];
      });
    });

    alice.options = options;

    if (navigator.platform.match(/iphone/i)) {
      alice.options.images = "hide";
    }

    var orig_console;
    if (window.console) {
     orig_console = window.console;
     window.console = {};
    } else {
      window.console = {};
    }

    window.console.log = function () {
      var win = alice.activeWindow();
      for (var i=0; i < arguments.length; i++) {
        if (orig_console && orig_console.log)
          orig_console.log(arguments[i]);
        if (win && options.debug == "true")
          win.addMessage({
            html: '<li class="message monospace"><div class="left">console</div><div class="msg">'+arguments[i].toString()+'</div></li>'
          });
      }
    };

    $$('ul.messages li.avatar:not(.consecutive) + li.consecutive').each(function (li) {
      li.previous().down('div.msg').setStyle({minHeight:'0px'});
    });

    $$('span.timestamp').each(function(elem) {
      if (elem.innerHTML) {
        elem.innerHTML = Alice.epochToLocal(elem.innerHTML.strip(), alice.options.timeformat);
        elem.style.opacity = 1;
      }
    });


    $('helpclose').observe("click", function () { $('help').hide(); });


    $$('#config_overlay option').each(function(opt){opt.selected = false});
    $('tab_overflow_overlay').observe("change", function (e) {
      var win = alice.getWindow($('tab_overflow_overlay').value);
      if (win) win.focus();
    });
    $('config_overlay').observe("change", function (e) {
      switch ($('config_overlay').value) {
        case "Logs":
          alice.toggleLogs(e);
          break;
        case "Connections":
          alice.toggleConfig(e);
          break;
        case "Preferences":
          alice.togglePrefs(e);
          break;
        case "Logout":
          if (confirm("Logout?")) window.location = "/logout";
          break;
        case "Help":
          alice.toggleHelp();
          break;
      }
      $$('#config_overlay option').each(function(opt){opt.selected = false});
    });


    window.onkeydown = function (e) {
      var win = alice.activeWindow();
      if (win && !$('config') && !Alice.isSpecialKey(e.which))
        win.input.focus();
    };

    window.onresize = function () {
      if (alice.activeWindow()) {
        if (Prototype.Browser.Gecko) alice.activeWindow().resizeMessagearea();
          alice.activeWindow().scrollToBottom();
      }
    };

    window.onfocus = function () {
      if (!alice.isMobile)
        window.document.body.removeClassName("blurred");

      if (alice.activeWindow())
        alice.activeWindow().input.focus();

      alice.isFocused = true
      alice.clearMissed();
    };

    window.status = " ";
    window.onblur = function () {
      if (!alice.isMobile)
        window.document.body.addClassName("blurred");
      alice.isFocused = false
    };
    window.onhashchange = alice.focusHash.bind(alice);

    window.onorientationchange = function() {
      alice.activeWindow().scrollToBottom(true);
    };


    alice.addFilters([
      function(content) {
        var filtered = content;
        filtered = filtered.replace(
          /(<a href=\"(:?.*?\.(:?wav|mp3|ogg|aiff|m4a))")/gi,
          "<img src=\"/static/image/play.png\" " +
          "onclick=\"Alice.playAudio(this)\" class=\"audio\"/>$1");
        return filtered;
      },
      function (content) {
        var filtered = content;
        if (alice.options.images == "show") {
          filtered = filtered.replace(
            /(<a[^>]*>)([^<]*\.(:?jpe?g|gif|png|bmp|svg)(:?\?v=0)?)</gi,
            "$1<img src=\"http://i.usealice.org/$2\" onload=\"Alice.loadInlineImage(this)\" " +
            "alt=\"Loading Image...\" title=\"$2\" style=\"display:none\"/><");
        }
        return filtered;
      }
    ]);



( run in 0.609 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )