{I"
class:ETI"ProcessedAsset;�FI"logical_path;�TI" mercury/regions/snippets.js;�FI"
pathname;�TI"�/home/edik/.rvm/gems/ruby-2.0.0-p247@very_simple_cms/bundler/gems/mercury-3e0245e33195/app/assets/javascripts/mercury/regions/snippets.js.coffee;�FI"content_type;�TI"application/javascript;�TI"
mtime;�Tl+��9RI"length;�TiI"digest;�TI"%c06807159208f2caeea2c48ad4040fa8;�FI"source;�TI"(function() {
  var __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  this.Mercury.Regions.Snippets = (function(_super) {
    var type;

    __extends(Snippets, _super);

    Snippets.supported = document.getElementById;

    Snippets.supportedText = "Chrome 10+, Firefox 4+, IE 7+, Safari 5+, Opera 8+";

    type = 'snippets';

    Snippets.prototype.type = function() {
      return type;
    };

    function Snippets(element, window, options) {
      this.element = element;
      this.window = window;
      this.options = options != null ? options : {};
      Mercury.log("building " + type, this.element, this.options);
      Snippets.__super__.constructor.apply(this, arguments);
      this.makeSortable();
    }

    Snippets.prototype.build = function() {
      var snippet, _i, _len, _ref;
      _ref = this.element.find('[data-snippet]');
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        snippet = _ref[_i];
        jQuery(snippet).attr('data-version', 0);
      }
      if (this.element.css('minHeight') === '0px') {
        return this.element.css({
          minHeight: 20
        });
      }
    };

    Snippets.prototype.bindEvents = function() {
      var _this = this;
      Snippets.__super__.bindEvents.apply(this, arguments);
      Mercury.on('unfocus:regions', function(event) {
        if (_this.previewing) {
          return;
        }
        if (Mercury.region === _this) {
          _this.element.removeClass('focus');
          _this.element.sortable('destroy');
          return Mercury.trigger('region:blurred', {
            region: _this
          });
        }
      });
      Mercury.on('focus:window', function(event) {
        if (_this.previewing) {
          return;
        }
        if (Mercury.region === _this) {
          _this.element.removeClass('focus');
          _this.element.sortable('destroy');
          return Mercury.trigger('region:blurred', {
            region: _this
          });
        }
      });
      this.element.on('mouseup', function() {
        if (_this.previewing) {
          return;
        }
        _this.focus();
        return Mercury.trigger('region:focused', {
          region: _this
        });
      });
      this.element.on('dragover', function(event) {
        if (_this.previewing) {
          return;
        }
        event.preventDefault();
        return event.originalEvent.dataTransfer.dropEffect = 'copy';
      });
      this.element.on('drop', function(event) {
        if (_this.previewing || !Mercury.snippet) {
          return;
        }
        _this.focus();
        event.preventDefault();
        return Mercury.Snippet.displayOptionsFor(Mercury.snippet.name, {}, Mercury.snippet.hasOptions);
      });
      jQuery(this.document).on('keydown', function(event) {
        if (_this.previewing || Mercury.region !== _this) {
          return;
        }
        switch (event.keyCode) {
          case 90:
            if (!event.metaKey) {
              return;
            }
            event.preventDefault();
            if (event.shiftKey) {
              return _this.execCommand('redo');
            } else {
              return _this.execCommand('undo');
            }
        }
      });
      return jQuery(this.document).on('keyup', function() {
        if (_this.previewing || Mercury.region !== _this) {
          return;
        }
        return Mercury.changes = true;
      });
    };

    Snippets.prototype.focus = function() {
      Mercury.region = this;
      this.makeSortable();
      return this.element.addClass('focus');
    };

    Snippets.prototype.togglePreview = function() {
      if (this.previewing) {
        this.makeSortable();
      } else {
        this.element.sortable('destroy');
        this.element.removeClass('focus');
      }
      return Snippets.__super__.togglePreview.apply(this, arguments);
    };

    Snippets.prototype.execCommand = function(action, options) {
      var handler;
      if (options == null) {
        options = {};
      }
      Snippets.__super__.execCommand.apply(this, arguments);
      if (handler = Mercury.Regions.Snippets.actions[action]) {
        return handler.call(this, options);
      }
    };

    Snippets.prototype.makeSortable = function() {
      var _this = this;
      return this.element.sortable('destroy').sortable({
        document: this.document,
        scroll: false,
        containment: 'parent',
        items: '[data-snippet]',
        opacity: 0.4,
        revert: 100,
        tolerance: 'pointer',
        beforeStop: function() {
          Mercury.trigger('hide:toolbar', {
            type: 'snippet',
            immediately: true
          });
          return true;
        },
        stop: function() {
          setTimeout((function() {
            return _this.pushHistory();
          }), 100);
          return true;
        }
      });
    };

    Snippets.actions = {
      undo: function() {
        return this.content(this.history.undo());
      },
      redo: function() {
        return this.content(this.history.redo());
      },
      insertSnippet: function(options) {
        var existing, snippet,
          _this = this;
        snippet = options.value;
        if ((existing = this.element.find("[data-snippet=" + snippet.identity + "]")).length) {
          return existing.replaceWith(snippet.getHTML(this.document, function() {
            return _this.pushHistory();
          }));
        } else {
          return this.element.append(snippet.getHTML(this.document, function() {
            return _this.pushHistory();
          }));
        }
      },
      editSnippet: function() {
        var snippet;
        if (!this.snippet) {
          return;
        }
        snippet = Mercury.Snippet.find(this.snippet.data('snippet'));
        return snippet.displayOptions();
      },
      removeSnippet: function() {
        if (this.snippet) {
          this.snippet.remove();
        }
        return Mercury.trigger('hide:toolbar', {
          type: 'snippet',
          immediately: true
        });
      }
    };

    return Snippets;

  })(Mercury.Region);

}).call(this);
;�TI"dependency_digest;�TI"%1de41ea0f04e3ed4e620493b32565a2b;�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/regions/snippets.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/regions/snippets.js.coffee;�FI"
mtime;�TI"2013-09-18T16:51:09+04:00;�TI"digest;�TI"%9bfde77ed99f3de14c49a1b1381d388f;�FI"
_version;�TI"%2cf3622cbba861b85d33ffabfa420c13;�F