Sha256: d5178afe0098395f2741ccca4f3fd400b2a04cb8b1bd2c2a2d01fd90d4926d86

Contents?: true

Size: 1.52 KB

Versions: 8

Compression:

Stored size: 1.52 KB

Contents

// 
// Markup
// 
Rad.Markup = new Class({
  initialize: function(e){
    this.element = e;
    this.allignImagesToLeft();
    this.showImagesInDialog();
  },
  
  // Images by default should be alligned to the left (wrapped inside .left div)
  allignImagesToLeft: function(){
    var images;
    images = this.element.getElements('img');
    // skipping images inside :div's with custom styles
    images = images.reject(function(img){
      var parent;
      parent = img.getParents('div').first();
      return (parent.get('tag') === 'div') && !parent.hasClass('m_markup');
    });
    images.each(function(img){
      // wrapping image with outer link
      img = img.getParent('a') || img;
      (new Element('div.left')).wraps(img);
    });
  },
  
  showImagesInDialog: function(){
    var imageUrls, links, skip_classes;
    skip_classes = ['_nobox', '_video'];

    // selecting links with images
    links = this.element.getElements('a').filter(function(a){
      var child, children;
      children = a.getChildren();
      child = children.first();
      return (children.size() === 1) && (child.get('tag') === 'img') && skip_classes.none(function(cls){return a.hasClass(cls);});
    });
    imageUrls = links.map(function(link){return link.get('href');});
    
    // adding events
    links.each(function(link, i){
      link.addEvent('click', function(event){
        var dialog;
        event.stop();
        dialog = new Rad.ImageDialog({
          images: imageUrls
        });
        dialog.show(imageUrls[i]);
      });
    });
  }
});

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rad_common_interface-0.0.14 app/static/face/markup.js
rad_common_interface-0.0.13 app/static/face/markup.js
rad_common_interface-0.0.12 app/static/face/markup.js
rad_common_interface-0.0.11 app/static/face/markup.js
rad_common_interface-0.0.10 app/static/face/markup.js
rad_common_interface-0.0.9 app/static/face/markup.js
rad_common_interface-0.0.8 app/static/face/markup.js
rad_common_interface-0.0.7 app/static/face/markup.js