Sha256: 94aef5203557fafe1fdb46d70cd84cf312d6e6722cf44c938b18f7bb8c633ac2

Contents?: true

Size: 1.44 KB

Versions: 7

Compression:

Stored size: 1.44 KB

Contents

Campfire.NewRelicChartExpander = Class.create({
  initialize: function(chat) {
    this.chat = chat;
    var messages = this.chat.transcript.messages;
    for (var i = 0; i < messages.length; i++) {
      this.detectNewRelicChartURL(messages[i]);
    }
    this.chat.windowmanager.scrollToBottom();
  },

  detectNewRelicChartURL: function(message) {
    if (!message.pending() && message.kind === 'text') {
      var iframe = null, elem, height = 200;

      var charts = message.bodyElement().select('a[href*="rpm.newrelic.com/public/charts"]');

      if (charts.length == 1) {
        elem = charts[0];
        var href = elem.getAttribute('href');
        iframe = href;
      }

      if (!iframe || IFRAME_HATERS.include(this.chat.username)) return;
      message.bodyCell.insert({bottom:"<iframe style='border:0; margin-top: 5px' height='"+height+"' width='98%' src='"+iframe+"'></iframe>"});
    }
  },

  onMessagesInsertedBeforeDisplay: function(messages) {
    var scrolledToBottom = this.chat.windowmanager.isScrolledToBottom();
    for (var i = 0; i < messages.length; i++) {
      this.detectNewRelicChartURL(messages[i]);
    }
    if (scrolledToBottom) {
      this.chat.windowmanager.scrollToBottom();
    }
  },

  onMessageAccepted: function(message, messageID) {
    this.detectNewRelicChartURL(message);
  }
});

Campfire.Responders.push("NewRelicChartExpander");
window.chat.installPropaneResponder("NewRelicChartExpander", "newrelicchartexpander");

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
caveat_patch_kids-0.0.8 scripts/caveat_patch_kids/unsupported/display_newrelic_charts.js
caveat_patch_kids-0.0.7 scripts/caveat_patch_kids/unsupported/display_newrelic_charts.js
caveat_patch_kids-0.0.5 scripts/caveat_patch_kids/unsupported/display_newrelic_charts.js
caveat_patch_kids-0.0.4 scripts/caveat_patch_kids/unsupported/display_newrelic_charts.js
caveat_patch_kids-0.0.3 scripts/caveat_patch_kids/unsupported/display_newrelic_charts.js
caveat_patch_kids-0.0.2 scripts/caveat_patch_kids/unsupported/display_newrelic_charts.js
caveat_patch_kids-0.0.1 scripts/caveat_patch_kids/unsupported/display_newrelic_charts.js