o: ActiveSupport::Cache::Entry	:@compressedF:@expires_in0:@created_atf1355470625.3605812:@value"o{I"
class:EFI"BundledAsset;�FI"logical_path;�FI"mercury/snippet.js;�FI"
pathname;�FI"y/Users/brownjohn/.rvm/gems/ruby-1.9.3-p194/gems/mercury-rails-0.8.0/app/assets/javascripts/mercury/snippet.js.coffee;�FI"content_type;�FI"application/javascript;�FI"
mtime;�FI"2012-08-08T16:13:36+08:00;�FI"length;�FisI"digest;�F"%dfa659ac5d9495f201227aded7b9d98bI"source;�FI"s(function() {
  var __hasProp = {}.hasOwnProperty;

  this.Mercury.Snippet = (function() {

    Snippet.all = [];

    Snippet.displayOptionsFor = function(name, options) {
      if (options == null) {
        options = {};
      }
      Mercury.modal(Mercury.config.snippets.optionsUrl.replace(':name', name), jQuery.extend({
        title: 'Snippet Options',
        handler: 'insertSnippet',
        snippetName: name
      }, options));
      return Mercury.snippet = null;
    };

    Snippet.create = function(name, options) {
      var i, identity, instance, snippet, _i, _len, _ref;
      if (this.all.length > 0) {
        identity = "snippet_0";
        _ref = this.all;
        for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
          snippet = _ref[i];
          if (snippet.identity === identity) {
            identity = "snippet_" + (i + 1);
          }
        }
      } else {
        identity = "snippet_" + this.all.length;
      }
      instance = new Mercury.Snippet(name, identity, options);
      this.all.push(instance);
      return instance;
    };

    Snippet.find = function(identity) {
      var snippet, _i, _len, _ref;
      _ref = this.all;
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        snippet = _ref[_i];
        if (snippet.identity === identity) {
          return snippet;
        }
      }
      return null;
    };

    Snippet.load = function(snippets) {
      var details, identity, instance, _results;
      _results = [];
      for (identity in snippets) {
        if (!__hasProp.call(snippets, identity)) continue;
        details = snippets[identity];
        instance = new Mercury.Snippet(details.name, identity, details.options);
        _results.push(this.all.push(instance));
      }
      return _results;
    };

    Snippet.clearAll = function() {
      delete this.all;
      return this.all = [];
    };

    function Snippet(name, identity, options) {
      this.name = name;
      this.identity = identity;
      if (options == null) {
        options = {};
      }
      this.version = 0;
      this.data = '';
      this.wrapperTag = 'div';
      this.history = new Mercury.HistoryBuffer();
      this.setOptions(options);
    }

    Snippet.prototype.getHTML = function(context, callback) {
      var element;
      if (callback == null) {
        callback = null;
      }
      element = jQuery("<" + this.wrapperTag + ">", {
        "class": "" + this.name + "-snippet",
        contenteditable: "false",
        'data-snippet': this.identity,
        'data-version': this.version
      }, context);
      element.html("[" + this.identity + "]");
      this.loadPreview(element, callback);
      return element;
    };

    Snippet.prototype.getText = function(callback) {
      return "[--" + this.identity + "--]";
    };

    Snippet.prototype.loadPreview = function(element, callback) {
      var _this = this;
      if (callback == null) {
        callback = null;
      }
      return jQuery.ajax(Mercury.config.snippets.previewUrl.replace(':name', this.name), {
        headers: Mercury.ajaxHeaders(),
        type: Mercury.config.snippets.method,
        data: this.options,
        success: function(data) {
          _this.data = data;
          element.html(data);
          if (callback) {
            return callback();
          }
        },
        error: function() {
          return Mercury.notify('Error loading the preview for the \"%s\" snippet.', _this.name);
        }
      });
    };

    Snippet.prototype.displayOptions = function() {
      Mercury.snippet = this;
      return Mercury.modal(Mercury.config.snippets.optionsUrl.replace(':name', this.name), {
        title: 'Snippet Options',
        handler: 'insertSnippet',
        loadType: Mercury.config.snippets.method,
        loadData: this.options
      });
    };

    Snippet.prototype.setOptions = function(options) {
      this.options = options;
      delete this.options['authenticity_token'];
      delete this.options['utf8'];
      if (this.options.wrapperTag) {
        this.wrapperTag = this.options.wrapperTag;
      }
      this.version += 1;
      return this.history.push(this.options);
    };

    Snippet.prototype.setVersion = function(version) {
      if (version == null) {
        version = null;
      }
      version = parseInt(version);
      if (version && this.history.stack[version - 1]) {
        this.version = version;
        this.options = this.history.stack[version - 1];
        return true;
      }
      return false;
    };

    Snippet.prototype.serialize = function() {
      return {
        name: this.name,
        options: this.options
      };
    };

    return Snippet;

  })();

}).call(this);
;�FI"required_assets_digest;�F"%99a9e81b88073dc61ce66b599eb42068I"
_version;�F"%9f3b95dd7ea3030dc35985c0a8020862