{I"
class:ETI"ProcessedAsset;�FI"logical_path;�TI"mercury/region.js;�FI"
pathname;�TI"�/home/edik/.rvm/gems/ruby-2.0.0-p247@very_simple_cms/bundler/gems/mercury-3e0245e33195/app/assets/javascripts/mercury/region.js.coffee;�FI"content_type;�TI"application/javascript;�TI"
mtime;�Tl+��9RI"length;�Ti�I"digest;�TI"%194539f03264b6a5e9b83641352359d4;�FI"source;�TI"�(function() {
  this.Mercury.Region = (function() {
    function Region(element, window, options) {
      this.element = element;
      this.window = window;
      this.options = options != null ? options : {};
      Mercury.log("building " + (this.type()), this.element, this.options);
      this.document = this.window.document;
      this.name = this.element.attr(Mercury.config.regions.identifier);
      this.history = new Mercury.HistoryBuffer();
      this.build();
      this.bindEvents();
      this.pushHistory();
      this.element.data('region', this);
    }

    Region.prototype.type = function() {
      return 'unknown';
    };

    Region.prototype.build = function() {};

    Region.prototype.focus = function() {};

    Region.prototype.bindEvents = function() {
      var _this = this;
      Mercury.on('mode', function(event, options) {
        if (options.mode === 'preview') {
          return _this.togglePreview();
        }
      });
      Mercury.on('focus:frame', function() {
        if (_this.previewing || Mercury.region !== _this) {
          return;
        }
        return _this.focus();
      });
      Mercury.on('action', function(event, options) {
        if (_this.previewing || Mercury.region !== _this || event.isDefaultPrevented()) {
          return;
        }
        if (options.action) {
          return _this.execCommand(options.action, options);
        }
      });
      this.element.on('mousemove', function(event) {
        var snippet;
        if (_this.previewing || Mercury.region !== _this) {
          return;
        }
        snippet = jQuery(event.target).closest('[data-snippet]');
        if (snippet.length) {
          _this.snippet = snippet;
          if (_this.snippet.data('snippet')) {
            return Mercury.trigger('show:toolbar', {
              type: 'snippet',
              snippet: _this.snippet
            });
          }
        }
      });
      return this.element.on('mouseout', function() {
        if (_this.previewing) {
          return;
        }
        return Mercury.trigger('hide:toolbar', {
          type: 'snippet',
          immediately: false
        });
      });
    };

    Region.prototype.content = function(value, filterSnippets) {
      var container, snippet, _i, _len, _ref;
      if (value == null) {
        value = null;
      }
      if (filterSnippets == null) {
        filterSnippets = false;
      }
      if (value !== null) {
        return this.element.html(value);
      } else {
        container = document.createElement('div');
        container.innerHTML = this.element.html().replace(/^\s+|\s+$/g, '');
        container = $(container);
        if (filterSnippets) {
          _ref = container.find('[data-snippet]');
          for (_i = 0, _len = _ref.length; _i < _len; _i++) {
            snippet = _ref[_i];
            snippet = jQuery(snippet);
            snippet.attr({
              contenteditable: null,
              'data-version': null
            });
            snippet.html("[" + (snippet.data('snippet')) + "]");
          }
        }
        return container.html();
      }
    };

    Region.prototype.togglePreview = function() {
      if (this.previewing) {
        this.previewing = false;
        this.element.attr(Mercury.config.regions.attribute, this.type());
        if (Mercury.region === this) {
          return this.focus();
        }
      } else {
        this.previewing = true;
        this.element.removeAttr(Mercury.config.regions.attribute);
        return Mercury.trigger('region:blurred', {
          region: this
        });
      }
    };

    Region.prototype.execCommand = function(action, options) {
      if (options == null) {
        options = {};
      }
      this.focus();
      if (action !== 'redo') {
        this.pushHistory();
      }
      Mercury.log('execCommand', action, options.value);
      return Mercury.changes = true;
    };

    Region.prototype.pushHistory = function() {
      return this.history.push(this.content());
    };

    Region.prototype.snippets = function() {
      var element, snippet, snippets, _i, _len, _ref;
      snippets = {};
      _ref = this.element.find('[data-snippet]');
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        element = _ref[_i];
        snippet = Mercury.Snippet.find(jQuery(element).data('snippet'));
        if (!snippet) {
          continue;
        }
        snippets[snippet.identity] = snippet.serialize();
      }
      return snippets;
    };

    Region.prototype.dataAttributes = function() {
      var attr, data, _i, _len, _ref;
      data = {};
      _ref = Mercury.config.regions.dataAttributes;
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        attr = _ref[_i];
        data[attr] = (this.container || this.element).attr('data-' + attr);
      }
      return data;
    };

    Region.prototype.serialize = function() {
      return {
        type: this.type(),
        data: this.dataAttributes(),
        value: this.content(null, true),
        snippets: this.snippets()
      };
    };

    return Region;

  })();

}).call(this);
;�TI"dependency_digest;�TI"%16b13e8b0c48320944cdcaf202c00cab;�FI"required_paths;�T[I"�/home/edik/.rvm/gems/ruby-2.0.0-p247@very_simple_cms/bundler/gems/mercury-3e0245e33195/app/assets/javascripts/mercury/region.js.coffee;�FI"dependency_paths;�T[{I"	path;�TI"�/home/edik/.rvm/gems/ruby-2.0.0-p247@very_simple_cms/bundler/gems/mercury-3e0245e33195/app/assets/javascripts/mercury/region.js.coffee;�FI"
mtime;�TI"2013-09-18T16:51:09+04:00;�TI"digest;�TI"%bfc1d79f1f65a556ced4e1f14d3db968;�FI"
_version;�TI"%2cf3622cbba861b85d33ffabfa420c13;�F