{I"
class:ETI"BundledAsset;�FI"logical_path;�TI"mercury/modal.js;�FI"
pathname;�TI"�/home/edik/.rvm/gems/ruby-2.0.0-p247@very_simple_cms/bundler/gems/mercury-3e0245e33195/app/assets/javascripts/mercury/modal.js.coffee;�FI"content_type;�TI"application/javascript;�TI"
mtime;�Tl+��9RI"length;�Ti+I"digest;�TI"%0e29da2ab09f2f0e1e096375f4858f6a;�FI"source;�TI"+(function() {
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

  this.Mercury.modal = function(url, options) {
    var instance;
    if (options == null) {
      options = {};
    }
    instance = new Mercury.Modal(url, options);
    instance.show();
    return instance;
  };

  this.Mercury.Modal = (function() {
    function Modal(url, options) {
      this.url = url;
      this.options = options != null ? options : {};
      this.hide = __bind(this.hide, this);
    }

    Modal.prototype.show = function(url, options) {
      var _base,
        _this = this;
      if (url == null) {
        url = null;
      }
      if (options == null) {
        options = null;
      }
      this.url = url || this.url;
      this.options = options || this.options;
      (_base = this.options).minWidth || (_base.minWidth = 400);
      if (this.options.ujsHandling !== false) {
        this.options.ujsHandling = true;
      }
      Mercury.trigger('focus:window');
      this.initializeModal();
      if (this.visible) {
        this.update();
      } else {
        this.appear();
      }
      if (this.options.content) {
        return setTimeout((function() {
          return _this.loadContent(_this.options.content);
        }), 500);
      }
    };

    Modal.prototype.initializeModal = function() {
      if (this.initialized) {
        return;
      }
      this.build();
      this.bindEvents();
      return this.initialized = true;
    };

    Modal.prototype.build = function() {
      var _ref, _ref1;
      this.element = jQuery('.mercury-modal');
      this.overlay = jQuery('.mercury-modal-overlay');
      if (!(this.element.get(0) && this.overlay.get(0))) {
        this.element = jQuery('<div>', {
          "class": 'mercury-modal loading'
        });
        this.element.html('<h1 class="mercury-modal-title"><span></span><a>&times;</a></h1>');
        this.element.append('<div class="mercury-modal-content-container"><div class="mercury-modal-content"></div></div>');
        this.overlay = jQuery('<div>', {
          "class": 'mercury-modal-overlay'
        });
        this.element.appendTo((_ref = jQuery(this.options.appendTo).get(0)) != null ? _ref : 'body');
        this.overlay.appendTo((_ref1 = jQuery(this.options.appendTo).get(0)) != null ? _ref1 : 'body');
      }
      this.titleElement = this.element.find('.mercury-modal-title');
      this.contentContainerElement = this.element.find('.mercury-modal-content-container');
      return this.contentElement = this.element.find('.mercury-modal-content');
    };

    Modal.prototype.bindEvents = function() {
      var _this = this;
      Mercury.on('refresh', function() {
        return _this.resize(true);
      });
      Mercury.on('resize', function() {
        return _this.position();
      });
      this.overlay.on('click', function() {
        if (_this.options.allowHideUsingOverlay) {
          return _this.hide();
        }
      });
      this.titleElement.find('a').on('click', function() {
        return _this.hide();
      });
      if (this.options.ujsHandling) {
        this.element.on('ajax:beforeSend', function(event, xhr, options) {
          return options.success = function(content) {
            return _this.loadContent(content);
          };
        });
      }
      return jQuery(document).on('keydown', function(event) {
        if (event.keyCode === 27 && _this.visible) {
          return _this.hide();
        }
      });
    };

    Modal.prototype.appear = function() {
      var _this = this;
      this.showing = true;
      this.position();
      this.overlay.show();
      return this.overlay.animate({
        opacity: 1
      }, 200, 'easeInOutSine', function() {
        _this.element.css({
          top: -_this.element.height()
        });
        _this.setTitle();
        _this.element.show();
        return _this.element.animate({
          top: 0
        }, 200, 'easeInOutSine', function() {
          _this.visible = true;
          _this.showing = false;
          return _this.load();
        });
      });
    };

    Modal.prototype.resize = function(keepVisible) {
      var height, titleHeight, visibility, width,
        _this = this;
      visibility = keepVisible ? 'visible' : 'hidden';
      titleHeight = this.titleElement.outerHeight();
      width = this.contentElement.outerWidth();
      if (this.contentPane) {
        this.contentPane.css({
          height: 'auto'
        });
      }
      this.contentElement.css({
        height: 'auto',
        visibility: visibility,
        display: 'block'
      });
      height = this.contentElement.outerHeight() + titleHeight;
      if (width < this.options.minWidth) {
        width = this.options.minWidth;
      }
      if (height > Mercury.displayRect.fullHeight || this.options.fullHeight) {
        height = Mercury.displayRect.fullHeight;
      }
      return this.element.stop().animate({
        left: (Mercury.displayRect.width - width) / 2,
        width: width,
        height: height
      }, 200, 'easeInOutSine', function() {
        var controlHeight;
        _this.contentElement.css({
          visibility: 'visible',
          display: 'block'
        });
        if (_this.contentPane.length) {
          _this.contentElement.css({
            height: height - titleHeight,
            overflow: 'visible'
          });
          controlHeight = _this.contentControl.length ? _this.contentControl.outerHeight() + 10 : 0;
          _this.contentPane.css({
            height: height - titleHeight - controlHeight - 20
          });
          return _this.contentPane.find('.mercury-display-pane').css({
            width: width - 20
          });
        } else {
          return _this.contentElement.css({
            height: height - titleHeight,
            overflow: 'auto'
          });
        }
      });
    };

    Modal.prototype.position = function() {
      var controlHeight, height, titleHeight, viewportWidth, width;
      viewportWidth = Mercury.displayRect.width;
      if (this.contentPane) {
        this.contentPane.css({
          height: 'auto'
        });
      }
      this.contentElement.css({
        height: 'auto'
      });
      this.element.css({
        width: 'auto',
        height: 'auto',
        display: 'block',
        visibility: 'hidden'
      });
      width = this.element.width();
      height = this.element.height();
      if (width < this.options.minWidth) {
        width = this.options.minWidth;
      }
      if (height > Mercury.displayRect.fullHeight || this.options.fullHeight) {
        height = Mercury.displayRect.fullHeight;
      }
      titleHeight = this.titleElement.outerHeight();
      if (this.contentPane && this.contentPane.length) {
        this.contentElement.css({
          height: height - titleHeight,
          overflow: 'visible'
        });
        controlHeight = this.contentControl.length ? this.contentControl.outerHeight() + 10 : 0;
        this.contentPane.css({
          height: height - titleHeight - controlHeight - 20
        });
        this.contentPane.find('.mercury-display-pane').css({
          width: width - 20
        });
      } else {
        this.contentElement.css({
          height: height - titleHeight,
          overflow: 'auto'
        });
      }
      return this.element.css({
        left: (viewportWidth - width) / 2,
        width: width,
        height: height,
        display: this.visible ? 'block' : 'none',
        visibility: 'visible'
      });
    };

    Modal.prototype.update = function() {
      this.reset();
      this.resize();
      return this.load();
    };

    Modal.prototype.load = function() {
      var _this = this;
      this.setTitle();
      if (!this.url) {
        return;
      }
      this.element.addClass('loading');
      if (Mercury.preloadedViews[this.url]) {
        return setTimeout((function() {
          return _this.loadContent(Mercury.preloadedViews[_this.url]);
        }), 10);
      } else {
        return jQuery.ajax(this.url, {
          headers: Mercury.ajaxHeaders(),
          type: this.options.loadType || 'GET',
          data: this.options.loadData,
          success: function(data) {
            return _this.loadContent(data);
          },
          error: function() {
            _this.hide();
            return Mercury.notify("Mercury was unable to load %s for the modal.", _this.url);
          }
        });
      }
    };

    Modal.prototype.loadContent = function(data, options) {
      if (options == null) {
        options = null;
      }
      this.initializeModal();
      this.options = options || this.options;
      this.setTitle();
      this.loaded = true;
      this.element.removeClass('loading');
      this.contentElement.html(data);
      this.contentElement.css({
        display: 'none',
        visibility: 'hidden'
      });
      this.contentPane = this.element.find('.mercury-display-pane-container');
      this.contentControl = this.element.find('.mercury-display-controls');
      if (this.options.afterLoad) {
        this.options.afterLoad.call(this);
      }
      if (this.options.handler) {
        if (Mercury.modalHandlers[this.options.handler]) {
          if (typeof Mercury.modalHandlers[this.options.handler] === 'function') {
            Mercury.modalHandlers[this.options.handler].call(this);
          } else {
            jQuery.extend(this, Mercury.modalHandlers[this.options.handler]);
            this.initialize();
          }
        } else if (Mercury.lightviewHandlers[this.options.handler]) {
          if (typeof Mercury.lightviewHandlers[this.options.handler] === 'function') {
            Mercury.lightviewHandlers[this.options.handler].call(this);
          } else {
            jQuery.extend(this, Mercury.lightviewHandlers[this.options.handler]);
            this.initialize();
          }
        }
      }
      if (Mercury.config.localization.enabled) {
        this.element.localize(Mercury.locale());
      }
      this.element.find('.modal-close').on('click', this.hide);
      return this.resize();
    };

    Modal.prototype.setTitle = function() {
      var closeButton;
      this.titleElement.find('span').html(Mercury.I18n(this.options.title));
      closeButton = this.titleElement.find('a');
      if (this.options.closeButton === false) {
        return closeButton.hide();
      } else {
        return closeButton.show();
      }
    };

    Modal.prototype.serializeForm = function() {
      return this.element.find('form').serializeObject() || {};
    };

    Modal.prototype.reset = function() {
      this.titleElement.find('span').html('');
      return this.contentElement.html('');
    };

    Modal.prototype.hide = function() {
      if (this.showing) {
        return;
      }
      this.options = {};
      Mercury.trigger('focus:frame');
      this.element.hide();
      this.overlay.hide();
      this.reset();
      return this.visible = false;
    };

    return Modal;

  })();

}).call(this);
;�TI"required_assets_digest;�TI"%5a8c5a78a42aaa97a89c4289c4a75649;�FI"
_version;�TI"%2cf3622cbba861b85d33ffabfa420c13;�F