Sha256: 2e4a4469fc948d80fc8a2e7a7c199e997c701664fa0f40d5441b9bb5b2bca506

Contents?: true

Size: 1.92 KB

Versions: 14

Compression:

Stored size: 1.92 KB

Contents

pageflow.externalLinks.ListItemEmbeddedView = Backbone.Marionette.ItemView.extend({
  template: 'pageflow/external_links/editor/templates/embedded/list_item',

  tagName: 'a',
  className: 'link-item',

  ui: {
    title: '.link-title',
    description: '.link-description',
    thumbnail: '.link-thumbnail',
    tooltip: '.tooltip'
  },

  events: {
    'click': function(event) {
      if (event.currentTarget.target) {
        event.stopPropagation();
      }
      else {
        this.ui.tooltip.show();
        return false;
      }
    },

    'mouseleave': function() {
      this.ui.tooltip.hide();
    },

    'click .tooltip': function() {
      window.open(this.$el.attr('href'), '_blank');
      this.ui.tooltip.hide();
      return false;
    }
  },

  onRender: function() {
    this.listenTo(this.model.get('site'), 'change', this.update);
    this.update();
  },

  update: function() {
    var site = this.model.get('site');

    this.ui.title.text(site.get('title'));
    this.ui.description.html(site.get('description'));
    this.ui.tooltip.hide();

    this.$el.toggleClass('no_text', blank(site.get('title')) && blank(site.get('description')));

    this.$el.attr('href', site.get('url'));
    this.$el.attr('target', site.get('open_in_new_tab') ? '_blank' : null);

    this.updateThumbnailView(site);

    function blank(text) {
      return !text || text.replace(/\s+/g, '').replace(/ /g, '') === '';
    }
  },

  updateThumbnailView: function(site) {
    var thumbnail = site.thumbnailFile();

    if (this.currentThumbnail !== thumbnail) {
      this.currentThumbnail = thumbnail;

      if (this.thumbnailView) {
        this.thumbnailView.close();
      }

      if (thumbnail) {
        this.thumbnailView = this.subview(new pageflow.FileThumbnailView({
          model: thumbnail,
          imageUrlPropertyName: 'link_thumbnail_url'
        }));

        this.ui.thumbnail.append(this.thumbnailView.el);
      }
    }
  },
});

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
pageflow-external-links-2.6.0 app/assets/javascripts/pageflow/external_links/editor/views/embedded/list_item_embedded_view.js
pageflow-external-links-2.5.0 app/assets/javascripts/pageflow/external_links/editor/views/embedded/list_item_embedded_view.js
pageflow-external-links-2.4.1 app/assets/javascripts/pageflow/external_links/editor/views/embedded/list_item_embedded_view.js
pageflow-external-links-2.4.0 app/assets/javascripts/pageflow/external_links/editor/views/embedded/list_item_embedded_view.js
pageflow-external-links-2.3.0 app/assets/javascripts/pageflow/external_links/editor/views/embedded/list_item_embedded_view.js
pageflow-external-links-2.2.1 app/assets/javascripts/pageflow/external_links/editor/views/embedded/list_item_embedded_view.js
pageflow-external-links-2.2.0 app/assets/javascripts/pageflow/external_links/editor/views/embedded/list_item_embedded_view.js
pageflow-external-links-2.1.0 app/assets/javascripts/pageflow/external_links/editor/views/embedded/list_item_embedded_view.js
pageflow-external-links-1.1.0 app/assets/javascripts/pageflow/external_links/editor/views/embedded/list_item_embedded_view.js
pageflow-external-links-2.0.0 app/assets/javascripts/pageflow/external_links/editor/views/embedded/list_item_embedded_view.js
pageflow-external-links-2.0.0.beta1 app/assets/javascripts/pageflow/external_links/editor/views/embedded/list_item_embedded_view.js
pageflow-external-links-1.0.0 app/assets/javascripts/pageflow/external_links/editor/views/embedded/list_item_embedded_view.js
pageflow-external-links-0.4.0 app/assets/javascripts/pageflow/external_links/editor/views/embedded/list_item_embedded_view.js
pageflow-external-links-0.3.0 app/assets/javascripts/pageflow/external_links/editor/views/embedded/list_item_embedded_view.js