/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, {
/******/ 				configurable: false,
/******/ 				enumerable: true,
/******/ 				get: getter
/******/ 			});
/******/ 		}
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 113);
/******/ })
/************************************************************************/
/******/ ({

/***/ 10:
/***/ (function(module, exports) {

var FontLoader, fl, readyDef, readyPromise,
  bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  slice = [].slice;

readyDef = new $.Deferred;

readyPromise = readyDef.promise();

FontLoader = (function() {
  FontLoader.prototype.fontList = {};

  function FontLoader() {
    this._getFontList = bind(this._getFontList, this);
    this.loadFontList = bind(this.loadFontList, this);
    this.loadGoogleFont = bind(this.loadGoogleFont, this);
    this.loadFontLoader();
  }

  FontLoader.prototype.loadFontLoader = function() {
    var s, wf;
    wf = document.createElement('script');
    wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js';
    wf.type = 'text/javascript';
    wf.async = 'true';
    wf.onload = function() {
      return readyDef.resolve();
    };
    s = document.getElementsByTagName('script')[0];
    return s.parentNode.insertBefore(wf, s);
  };

  FontLoader.prototype.load = function(options, context, source) {
    if (options == null) {
      options = {};
    }
    if (context == null) {
      context = window;
    }
    return readyPromise.then(function() {
      var fontFamily;
      fontFamily = options.families[0];
      source || (source = options.source || 'google');
      if ((context.fontDefs != null) && (context.fontDefs[fontFamily] != null)) {
        return context.fontDefs[fontFamily];
      }
      context.fontDefs || (context.fontDefs = {});
      if (source === 'local') {
        return context.fontDefs[fontFamily] = (new $.Deferred).resolve().promise();
      }
      return context.fontDefs[fontFamily] = fl.loadGoogleFont(options, context);
    });
  };

  FontLoader.prototype.loadGoogleFont = function(options, context) {
    var def;
    def = new $.Deferred;
    WebFont.load({
      google: options,
      context: context,
      fontactive: (function(def) {
        return function() {
          return def.resolve(arguments);
        };
      })(def),
      fontinactive: (function(def) {
        return function() {
          return def.resolve(arguments);
        };
      })(def),
      timeout: 600
    });
    return def.promise();
  };

  FontLoader.prototype.loadFontList = function() {
    var def;
    if (this.fontListRdy != null) {
      return this.fontListRdy;
    }
    def = Blogvio.Aye.defer();
    this._getFontList().then((function(_this) {
      return function() {
        var _, f;
        return def.resolve($.extend.apply($, [{}].concat(slice.call((function() {
          var ref, results;
          ref = this.fontList;
          results = [];
          for (_ in ref) {
            f = ref[_];
            results.push(f);
          }
          return results;
        }).call(_this)))));
      };
    })(this));
    return this.fontListRdy = def.promise;
  };

  FontLoader.prototype._getFontList = function() {
    var def, rdy;
    def = new $.Deferred;
    rdy = function(source, fonts) {
      var font, opts;
      if (source) {
        for (font in fonts) {
          opts = fonts[font];
          fonts[font].source = source;
        }
        this.fontList[source] = fonts;
      } else {
        this.fontList = $.extend({}, this.fontList, fonts);
      }
      if ((this.fontList.google != null) && (this.fontList.local != null)) {
        return def.resolve();
      }
    };
    $.getJSON('/fonts-list').then(rdy.bind(this, null));
    $.getJSON('/fonts.json').then(rdy.bind(this, 'local'));
    return def.promise();
  };

  return FontLoader;

})();

module.exports = fl = new FontLoader;


/***/ }),

/***/ 100:
/***/ (function(module, exports, __webpack_require__) {

var Content, Helper, Model, defaultAtts, isArray,
  bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  extend = 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; },
  hasProp = {}.hasOwnProperty;

Model = window.require('spine/model');

Helper = window.require('spine/utils/helper');

isArray = Helper.isArray;

defaultAtts = ['order', 'metadata', 'composition_id', '_isDemoContent'];

Content = (function(superClass) {
  extend(Content, superClass);

  Content.records = [];

  Content.irecords = {};

  Content.crecords = {};

  Content.configure('Content');


  /*
  	Sort function used to sort items
   */

  Content.comparator = function(a, b) {
    return (a.order || a.id) - (b.order || b.id);
  };

  function Content(atts) {
    var attr, mattr;
    if (atts == null) {
      atts = {};
    }
    this.attrMeta = bind(this.attrMeta, this);
    this.editedMeta = bind(this.editedMeta, this);
    this._metadata = bind(this._metadata, this);
    if (!atts.composition_id) {
      throw new Error('Content must be associated to a composition.');
    }
    this.composition_id = atts.composition_id;
    this._meta = atts._meta;
    for (attr in (mattr = this.meta().attributes)) {
      if ((atts[attr] == null) && (mattr[attr] != null)) {
        atts[attr] = mattr[attr].options["default"];
      }
    }
    Content.__super__.constructor.call(this, atts);
    this.id || (this.id = this.cid);
  }

  Content.prototype.meta = function() {
    return this._meta || (this._meta = this.composition().contentMeta());
  };

  Content.prototype.composition = function() {
    return (__webpack_require__(41)).find(this.composition_id);
  };

  Content.prototype.attributes = function() {
    var attribute, attributes, i, key, len, meta_attributes, options, result;
    attributes = defaultAtts.slice(0);
    meta_attributes = (function() {
      var ref, results;
      ref = this.meta().attributes;
      results = [];
      for (attribute in ref) {
        options = ref[attribute];
        results.push(attribute);
      }
      return results;
    }).call(this);
    attributes.push.apply(attributes, meta_attributes);
    result = {};
    for (i = 0, len = attributes.length; i < len; i++) {
      key = attributes[i];
      if (key in this) {
        if (typeof this[key] === 'function') {
          result[key] = this[key]();
        } else {
          result[key] = this[key];
        }
      }
    }
    if (this.id) {
      result.id = this.id;
    }
    if (this._meta) {
      result._meta = this._meta;
    }
    return result;
  };

  Content.prototype._metadata = function(key, value, options) {
    if (options == null) {
      options = {};
    }
    if (key == null) {
      return this.metadata || (this.metadata = {});
    }
    if (value == null) {
      return this._metadata()[key];
    }
    if (this._metadata()[key] === value) {
      return this._metadata()[key];
    }
    this._metadata()[key] = value;
    options.attribute = 'metadata';
    return this.updateAttribute('metadata', this.metadata, options);
  };

  Content.prototype.editedMeta = function(attr, set) {
    var editedMeta;
    if (attr == null) {
      return this._metadata('edited') || [];
    }
    if (attr && (set == null)) {
      return 1 + this.editedMeta().indexOf(attr);
    }
    if (!(attr && (set != null))) {
      return;
    }
    editedMeta = this.editedMeta().concat(attr).filter((function(_this) {
      return function(f) {
        return set || f !== attr;
      };
    })(this));
    return this._metadata('edited', editedMeta);
  };

  Content.prototype.attrMeta = function(attr, value, options) {
    var attr_meta;
    if (attr == null) {
      return this._metadata('attr_meta') || {};
    }
    if ((attr != null) && (value == null)) {
      return this.attrMeta()[attr];
    }
    if ((attr != null) && (value != null)) {
      (attr_meta = this.attrMeta())[attr] = value;
      return this._metadata('attr_meta', attr_meta, options);
    }
  };

  Content.prototype.toJSON = function() {
    var result;
    result = Content.__super__.toJSON.apply(this, arguments);
    delete result._meta;
    return result;
  };

  return Content;

})(Model);

module.exports = Content;


/***/ }),

/***/ 113:
/***/ (function(module, exports, __webpack_require__) {

var define = function define(m) {
  return function (_, __, module) {
    module.exports = m;
  };
};
window.require.define({
  // models
  'core/models/content': define(__webpack_require__(100)),
  'core/models/composition': define(__webpack_require__(41)),
  'core/models/widget': define(__webpack_require__(36)),
  'core/models/skin': define(__webpack_require__(42)),
  'core/models/user': define(__webpack_require__(115)),
  // widget stuff
  'core/widget': define(__webpack_require__(116)),
  'core/controller/overlay': define(__webpack_require__(117)),
  'core/controller/font-loader': define(__webpack_require__(10))
});

/***/ }),

/***/ 114:
/***/ (function(module, exports) {

var Api;

Api = {
  enabled: true,
  app_id: '528495b81d8a0c3130000000_5zjgq5bllucc4ok88404occgcgsckswcc40g8ggs08ckswc4kw',
  redirect_uri: "http://local.blogvio.com/connect/blogvio.html",

  /*
  	Runs a callback with the API disabled
  
  	This allows changes to models without triggering persist
   */
  disable: function(callback) {
    var e;
    if (this.enabled) {
      this.enabled = false;
      try {
        return callback();
      } catch (error) {
        e = error;
        throw e;
      } finally {
        this.enabled = true;
      }
    } else {
      return callback();
    }
  }
};

module.exports = Api;


/***/ }),

/***/ 115:
/***/ (function(module, exports, __webpack_require__) {

var AjaxMixin, Model, User,
  extend = 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; },
  hasProp = {}.hasOwnProperty;

Model = window.require('spine/model');

AjaxMixin = __webpack_require__(35);

User = (function(superClass) {
  extend(User, superClass);

  function User() {
    return User.__super__.constructor.apply(this, arguments);
  }

  User.extend(AjaxMixin);

  User.configure('User', 'loggedIn', 'email', 'max_allowed_hosts', 'hosts', 'name', 'lastname', 'username', 'subscription');

  return User;

})(Model);

module.exports = User;


/***/ }),

/***/ 116:
/***/ (function(module, exports) {

var Container, Controller, Widget, console,
  extend = 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; },
  hasProp = {}.hasOwnProperty;

console = window.require('spine/utils/console');

Controller = window.require('spine/controller');

Container = window.require('spine/controller/container');


/*
Base class for all widgets
 */

Widget = (function(superClass) {
  extend(Widget, superClass);

  Widget.prototype.className = 'blogvio-widget';

  Widget.include(Container);

  function Widget(opts, skin, content) {
    Widget.__super__.constructor.apply(this, arguments);
    if (this.VERSION) {
      this.el.attr('data-version', this.VERSION);
    }
    console.group('WidgetController:constructor');
    this.style = $('<style>');
    if (skin != null) {
      this.setSkin(skin);
    }
    if (content != null) {
      this.setContent(content);
    }
    this.append(this.style);
    console.groupEnd('WidgetController:constructor');
  }


  /*
  	Set the current skin
   */

  Widget.prototype.setSkin = function(skin) {
    console.group('WidgetController:setSkin');
    console.debug(skin);
    this.stopListening(this.skin);
    this.stopListening(skin);
    this.skin = skin;
    if (this.skin.bind != null) {
      this.listenTo(this.skin, 'update', (function(_this) {
        return function() {
          console.group('WidgetController:changeSkin');
          _this.changeSkin.apply(_this, arguments);
          return console.groupEnd('WidgetController:changeSkin');
        };
      })(this));
    }
    this.changeSkin(skin);
    console.groupEnd('WidgetController:setSkin');
    return this;
  };

  Widget.prototype.changeSkin = function(skin) {};


  /*
  	Set current content
   */

  Widget.prototype.setContent = function(content) {
    var i, item, len;
    if (content == null) {
      content = [];
    }
    console.group('WidgetController:setContent');
    console.table(content);
    this.content = content;
    this.clearContent();
    for (i = 0, len = content.length; i < len; i++) {
      item = content[i];
      this.addContent(item);
    }
    console.groupEnd('WidgetController:setContent');
    return this;
  };


  /*
  	Add one content item
   */

  Widget.prototype.addContent = function(item) {
    return this;
  };


  /*
  	Remove all content from the widget
   */

  Widget.prototype.clearContent = function() {
    return this;
  };

  Widget.prototype.resize = function(w, h) {};

  return Widget;

})(Controller);

module.exports = Widget;


/***/ }),

/***/ 117:
/***/ (function(module, exports) {

var Controller, Overlay,
  bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  extend = 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; },
  hasProp = {}.hasOwnProperty;

Controller = window.require('spine/controller');

Overlay = (function(superClass) {
  extend(Overlay, superClass);

  Overlay.prototype.className = 'overlay';

  function Overlay(options) {
    if (options == null) {
      options = {};
    }
    this._hide = bind(this._hide, this);
    this._show = bind(this._show, this);
    if (!options.parent) {
      throw new Error('The parent option is missing!');
    }
    if (!options.events) {
      throw new Error('The events option is missing!');
    }
    Overlay.__super__.constructor.apply(this, arguments);
  }

  Overlay.prototype.delegateEvents = function(events) {
    var eventName, key, match, method, results, selector;
    if (events == null) {
      events = this.events;
    }
    this.eventsDelegated = true;
    results = [];
    for (key in events) {
      method = events[key];
      if (this.parent[method]) {
        match = key.match(this.eventSplitter);
        eventName = match[1];
        selector = match[2];
        method = (function(_this) {
          return function(method) {
            return function() {
              var ref;
              (ref = _this.parent)[method].apply(ref, arguments);
              return true;
            };
          };
        })(this)(method);
      }
      if (selector === '') {
        results.push(this.el.bind(eventName, method));
      } else {
        results.push(this.el.on(eventName, selector, method));
      }
    }
    return results;
  };

  Overlay.prototype.append = function(el) {
    if (el.el) {
      el = el.el;
    }
    return this.el.append(el);
  };

  Overlay.prototype.preload = function() {
    return this._createPopup();
  };

  Overlay.prototype.toggle = function() {
    return this._createPopup().then((function(_this) {
      return function() {
        if (_this.popup.visible) {
          return _this._hide();
        } else {
          return _this._show();
        }
      };
    })(this));
  };

  Overlay.prototype.show = function() {
    return this._createPopup().then(this._show);
  };

  Overlay.prototype.hide = function() {
    return this._createPopup().then(this._hide);
  };

  Overlay.prototype.style = function(style) {
    if (style) {
      this.styleCache = style;
    }
    if (!this.popup) {
      return;
    }
    return this.popup.style(this.styleCache);
  };

  Overlay.prototype.release = function() {
    Overlay.__super__.release.apply(this, arguments);
    this.eventsDelegated = false;
    this.popupPromise = null;
    this.popup.release();
    return this;
  };

  Overlay.prototype._show = function() {
    return this.popup.show().then((function(_this) {
      return function() {
        return _this.el.trigger('overlay-shown');
      };
    })(this));
  };

  Overlay.prototype._hide = function() {
    return this.popup.hide().then((function(_this) {
      return function() {
        return _this.el.trigger('overlay-hidden');
      };
    })(this));
  };

  Overlay.prototype._createPopup = function() {
    if (this.popupPromise) {
      return this.popupPromise;
    }
    return this.popupPromise = Blogvio.UI.popup["new"]({
      type: 'overlay'
    }).then((function(_this) {
      return function(popup) {
        _this.popup = popup;
        _this.style();
        _this.popup.append(_this.el);
        if (!_this.eventsDelegated) {
          return _this.delegateEvents();
        }
      };
    })(this)).fail(function(err) {
      return console.error(err.stack);
    });
  };

  return Overlay;

})(Controller);

module.exports = Overlay;


/***/ }),

/***/ 35:
/***/ (function(module, exports, __webpack_require__) {

var Api, Base, Collection, Extend, Helper, Include, Mixin, Singleton, stringify, url,
  bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  extend = 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; },
  hasProp = {}.hasOwnProperty;

Api = __webpack_require__(114);

stringify = Widgetic.JSON.stringify;

Helper = window.require('spine/utils/helper');

url = function(object, id) {
  var u;
  if (id == null) {
    id = true;
  }
  u = (object.className || object.constructor.className).toLowerCase() + 's';
  if (id && object.id && (!/^c\-[\d]+/.test(object.id))) {
    u += '/' + encodeURIComponent(object.id);
  }
  return u;
};

Base = (function() {
  function Base() {}

  Base.prototype.request = function() {
    var def;
    if (Api.enabled) {
      return Widgetic.api.apply(Widgetic, arguments);
    }
    def = Widgetic.Aye.defer();
    def.reject('Widgetic API is disabled.');
    return def.promise;
  };

  return Base;

})();

Singleton = (function(superClass) {
  extend(Singleton, superClass);

  function Singleton(record1) {
    this.record = record1;
    this.failedWithData = bind(this.failedWithData, this);
    this.recordResponse = bind(this.recordResponse, this);
    this.model = this.record.constructor;
  }

  Singleton.prototype.reload = function(options) {
    return this.request(url(this.record)).then(this.recordResponse(options), this.failedReload(options));
  };

  Singleton.prototype.create = function(options) {
    return this.request(url(this.record, false), 'POST', stringify(this.record)).then(this.recordResponse(options), this.failedWithData(options));
  };

  Singleton.prototype.update = function(options) {
    var isNew;
    isNew = /^c\-[\d]+/.test(this.record.id);
    return this.request(url(this.record, !isNew), (isNew ? 'POST' : 'PUT'), stringify(this.record)).then(this.recordResponse(options), this.failedWithData(options));
  };

  Singleton.prototype.destroy = function(options) {
    return this.request(url(this.record), 'DELETE').then(this.recordResponse(options), this.failedWithData(options));
  };

  Singleton.prototype.recordResponse = function(options) {
    if (options == null) {
      options = {};
    }
    return (function(_this) {
      return function(data) {
        var blank, ref;
        if ((data = (blank = Helper.isBlank(data)) ? false : _this.model.fromJSON(data))) {
          Api.disable(function() {
            if (data.id && _this.record.id !== data.id) {
              _this.record.changeID(data.id);
            }
            return _this.record.updateAttributes({
              id: data.id
            }, {
              fromApi: true
            });
          });
        }
        _this.record.trigger('apiSuccess', data);
        if ((ref = options.done) != null) {
          ref.apply(_this.record, arguments);
        }
        return _this.record;
      };
    })(this);
  };

  Singleton.prototype.failedWithData = function(options) {
    if (options == null) {
      options = {};
    }
    return (function(_this) {
      return function(error) {
        var ref;
        _this.record.trigger('apiError', error);
        if ((ref = options.fail) != null) {
          ref.apply(_this.record, arguments);
        }
        throw error;
      };
    })(this);
  };

  return Singleton;

})(Base);

Collection = (function(superClass) {
  extend(Collection, superClass);

  function Collection(model) {
    this.model = model;
    this.failResponse = bind(this.failResponse, this);
    this.recordsResponse = bind(this.recordsResponse, this);
  }

  Collection.prototype.find = function(id, params) {
    if (params == null) {
      params = {};
    }
    return this.request(url(new this.model({
      id: id
    })), null, params).then(this.recordsResponse, this.failResponse);
  };

  Collection.prototype.all = function(params) {
    if (params == null) {
      params = {};
    }
    return this.request(url(this.model), false, params).then(this.recordsResponse, this.failResponse);
  };

  Collection.prototype.fetch = function(params, options) {
    var id;
    if (params == null) {
      params = {};
    }
    if (options == null) {
      options = {};
    }
    if (id = params.id) {
      delete params.id;
    }
    return (id ? this.find(id, params) : this.all(params)).then((function(_this) {
      return function(record) {
        return _this.model.refresh(record, options);
      };
    })(this));
  };

  Collection.prototype.recordsResponse = function(data) {
    this.model.trigger('apiSuccess');
    return data;
  };

  Collection.prototype.failResponse = function(error) {
    this.model.trigger('apiError', null, error);
    throw new Error(error.message);
  };

  return Collection;

})(Base);

Include = {
  ajax: function() {
    return new Singleton(this);
  }
};

Extend = {
  ajax: function() {
    return new Collection(this);
  }
};

Mixin = {
  extended: function() {
    this.extend(Extend);
    return this.include(Include);
  },
  ajaxFetch: function() {
    var ref;
    return (ref = this.ajax()).fetch.apply(ref, arguments);
  },
  ajaxChange: function(record, type, options) {
    if (options == null) {
      options = {};
    }
    if (options.ajax === false) {
      return;
    }
    return record.ajax()[type](options);
  }
};

module.exports = Mixin;


/***/ }),

/***/ 36:
/***/ (function(module, exports, __webpack_require__) {

var AjaxMixin, Model, Skin, Widget, _loadSkins, console, hasRequiredFields,
  extend = 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; },
  hasProp = {}.hasOwnProperty;

console = window.require('spine/utils/console');

Model = window.require('spine/model');

Skin = __webpack_require__(42);

AjaxMixin = __webpack_require__(35);

_loadSkins = function(widget) {
  if (widget.hasAllSkins) {
    Skin.refresh(widget.skins);
    return widget;
  } else {
    return Skin.ajaxFetch({
      widget_id: widget.id
    }).then(function(data) {
      Skin.refresh(data);
      widget.updateAttribute('hasAllSkins', true);
      return widget;
    });
  }
};

hasRequiredFields = function(w, fields) {
  var field, i, len;
  for (i = 0, len = fields.length; i < len; i++) {
    field = fields[i];
    if (!w[field]) {
      return false;
    }
  }
  return true;
};

Widget = (function(superClass) {
  extend(Widget, superClass);

  function Widget() {
    return Widget.__super__.constructor.apply(this, arguments);
  }

  Widget.extend(AjaxMixin);

  Widget.configure('Widget', 'name', 'module', 'category', 'slug', 'skinMeta', 'contentMeta', 'skins', 'content', 'css', 'js', 'width', 'height', 'hasAllSkins');

  Widget.current = null;

  Widget.load = function(id, options) {
    var e, fields, hasLoaded, process, w;
    fields = options != null ? options.fields : void 0;
    hasLoaded = Blogvio.Aye.defer();
    process = Blogvio.Aye.defer();
    process.promise.then(_loadSkins).fail(hasLoaded.reject).then(hasLoaded.resolve);
    try {
      w = Widget.find(id);
      if (fields && !hasRequiredFields(w, fields)) {
        throw new Error("Widget[" + id + "] does not have all required fields: " + fields);
      }
      process.resolve(w);
    } catch (error) {
      e = error;
      console.warn(e);
      this.ajax().fetch({
        id: id
      }).then(function(widgets) {
        return widgets[0];
      }).then(process.resolve).fail(process.reject);
    }
    return hasLoaded.promise;
  };

  Widget.prototype.getSkins = function() {
    return Skin.findAllByAttribute('widget_id', this.id);
  };

  return Widget;

})(Model);

module.exports = Widget;


/***/ }),

/***/ 41:
/***/ (function(module, exports, __webpack_require__) {

var AjaxMixin, Composition, Content, Model, Skin, Widget, _loadWidget, console,
  bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  extend = 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; },
  hasProp = {}.hasOwnProperty;

console = window.require('spine/utils/console');

Model = window.require('spine/model');

AjaxMixin = __webpack_require__(35);

Skin = __webpack_require__(42);

Widget = __webpack_require__(36);

Content = __webpack_require__(100);

_loadWidget = function(composition) {
  return Widget.load(composition.widget_id).then(function() {
    return composition;
  });
};

Composition = (function(superClass) {
  extend(Composition, superClass);

  Composition.extend(AjaxMixin);

  Composition.configure("Composition", 'name', 'content', 'bulk_content', 'skin_id', 'widget_id', 'width', 'height', 'widget_category', 'user_id', 'metadata');

  Composition.fetch(Composition.ajaxFetch);

  function Composition(atts) {
    if (atts == null) {
      atts = {};
    }
    this._onContentChange = bind(this._onContentChange, this);
    this._metadata = bind(this._metadata, this);
    this.listen = bind(this.listen, this);
    this.bulkContent = bind(this.bulkContent, this);
    this.maxFreeErrorMsg = bind(this.maxFreeErrorMsg, this);
    this.maxErrorMsg = bind(this.maxErrorMsg, this);
    this.minErrorMsg = bind(this.minErrorMsg, this);
    this.opts = bind(this.opts, this);
    console.group('Composition:constructor');
    atts.name || (atts.name = 'Untitled Composition');
    atts.width || (atts.width = 500);
    atts.height || (atts.height = 500);
    Composition.__super__.constructor.call(this, atts);
    console.groupEnd('Composition:constructor');
  }

  Composition.prototype.opts = function() {
    var max, min, ref, ref1;
    return this._opts || (this._opts = {
      min: ((min = (ref = this.contentMeta().options) != null ? ref.min : void 0) != null) && min || 1,
      max: ((max = (ref1 = this.contentMeta().options) != null ? ref1.max : void 0) != null) && max || 999
    });
  };

  Composition.prototype.minErrorMsg = function() {
    return this.contentMeta().options.notification.min || 'Please add at least one item!';
  };

  Composition.prototype.maxErrorMsg = function() {
    return this.contentMeta().options.notification.max || 'You reached the maximum number of items!';
  };

  Composition.prototype.maxFreeErrorMsg = function() {
    return 'Upgrade to add more items, and get more features!';
  };

  Composition.prototype.toJSON = function() {
    var base, result;
    result = Composition.__super__.toJSON.apply(this, arguments);
    if (!result.content) {
      result.content = this.getContent();
    }
    if (this.contentMeta().bulkEditor) {
      result.bulk_content = typeof (base = this.bulkContent()).toJSON === "function" ? base.toJSON() : void 0;
    }
    return result;
  };

  Composition.prototype.changeID = function(id) {
    var oldId;
    oldId = this.id;
    Composition.__super__.changeID.apply(this, arguments);
    return Content.findAllByAttribute('composition_id', oldId).forEach((function(_this) {
      return function(c) {
        return c.updateAttribute('composition_id', _this.id, {
          attribute: 'composition_id'
        });
      };
    })(this));
  };

  Composition.prototype.validateLength = function(options) {
    var error, errorMsg, name, valid;
    if (options == null) {
      options = {};
    }
    valid = this.hasEnoughContent();
    error = !valid && (this.maxContentReached() ? 'max' : 'min');
    errorMsg = typeof this[name = error + 'ErrorMsg'] === "function" ? this[name]() : void 0;
    return {
      valid: valid,
      error: error,
      errorMsg: errorMsg
    };
  };

  Composition.prototype.getWidget = function() {
    var e;
    if (!this.widget_id) {
      throw new Error('This composition is missing the widget_id.');
    }
    try {
      return (__webpack_require__(36)).find(this.widget_id);
    } catch (error1) {
      e = error1;
      throw new Error("The widget " + this.widget_id + " is not loaded");
    }
  };

  Composition.prototype.setWidgetId = function(widget_id) {
    this.widget_id = widget_id;
    this.save({
      ajax: false
    });
    return this;
  };

  Composition.prototype.getSkin = function() {
    var e;
    try {
      return Skin.find(this.skin_id);
    } catch (error1) {
      e = error1;
      return false;
    }
  };

  Composition.prototype.getContent = function(filter) {
    if (filter == null) {
      filter = function(c) {
        return !c._isDemoContent;
      };
    }
    return Content.findAllByAttribute('composition_id', this.id).filter(filter).sort(function(a, b) {
      return a.order - b.order;
    });
  };

  Composition.prototype.contentMeta = function() {
    var widget;
    widget = this.getWidget();
    return widget != null ? widget.contentMeta : void 0;
  };

  Composition.prototype.bulkContent = function() {
    var _meta, attr, attributes, i, len, ref;
    if (this._bkc != null) {
      return this._bkc;
    }
    _meta = this.contentMeta();
    attributes = {};
    ref = _meta.bulkEditor.attributes;
    for (i = 0, len = ref.length; i < len; i++) {
      attr = ref[i];
      attributes[attr] = _meta.attributes[attr];
    }
    _meta = $.extend({}, _meta, {
      attributes: attributes
    });
    this.bulk_content = $.extend(this.bulk_content || {}, {
      _meta: _meta,
      composition_id: 1
    });
    return this._bkc = Content.refresh(this.bulk_content)[0];
  };


  /*
  	Test if the composition has less than maximum content
   */

  Composition.prototype.maxContentReached = function(max) {
    if (max == null) {
      max = this.opts().max;
    }
    return this.getContent().length >= max;
  };

  Composition.prototype.hasEnoughContent = function() {
    var ref;
    return (this.opts().min <= (ref = this.getContent().length) && ref <= this.opts().max);
  };

  Composition.prototype.persist = function() {
    var promise;
    console.log('%c PERSIST!!!', 'background-color: red; color:white');
    this._stopListen();
    if (this.isPersisted()) {
      promise = this.ajax().update();
    } else {
      promise = this.ajax().create();
    }
    return promise.then(this.listen);
  };

  Composition.prototype.isPersisted = function() {
    return this.id.slice(0, 1) !== 'c';
  };

  Composition.prototype.listen = function() {
    this._stopListen();
    console.log('%c listen!!!', 'background-color: green; color:white');
    this.listenTo(Content, 'change', this._onContentChange);
    return this;
  };

  Composition.prototype._stopListen = function() {
    console.log('%c stoplisten!!!', 'background-color: blue; color:white');
    this.stopListening(Content, 'change', this._onContentChange);
    return this;
  };

  Composition.prototype.embed = function() {
    return ("<span>&lt;script async src=&quot;http://blogvio.com/embedder.js&quot;</span><br/> <span>data-blogvio-composition=&quot;" + this.id + "&quot;</span><br/> ") + ("<span>data-width=&quot;" + this.width + "&quot; data-height=&quot;" + this.height + "&quot;&gt;&lt;/script&gt;</span>");
  };

  Composition.prototype._metadata = function(key, value, options) {
    if (options == null) {
      options = {};
    }
    if (key == null) {
      return this.metadata || (this.metadata = {});
    }
    if (value == null) {
      return this._metadata()[key];
    }
    this._metadata()[key] = value;
    options.attribute = 'metadata';
    return this.updateAttribute('metadata', this.metadata, options);
  };

  Composition.load = function(id) {
    var e, hasLoaded, process;
    hasLoaded = Blogvio.Aye.defer();
    process = Blogvio.Aye.defer();
    process.promise.then(_loadWidget).then(function(composition) {
      return composition._stopListen();
    }).then(function(composition) {
      composition.listen();
      return composition;
    }).fail(hasLoaded.reject).then(hasLoaded.resolve);
    try {
      process.resolve(Composition.find(id));
    } catch (error1) {
      e = error1;
      this.ajax().fetch({
        id: id
      }).then(function(compositions) {
        return compositions[0];
      }).then(process.resolve).fail(process.reject);
    }
    return hasLoaded.promise;
  };

  Composition.prototype._onContentChange = function(model, type, options) {
    console.group('Composition:_onContentChange');
    this.updateAttribute('content', this.getContent(), {
      ajax: false
    });
    return console.groupEnd('Composition:_onContentChange');
  };

  return Composition;

})(Model);

Composition.bind('destroy', function(item) {
  var skin;
  try {
    skin = Skin.find(item.skin_id);
    return skin != null ? skin.used() : void 0;
  } catch (error1) {}
});

module.exports = Composition;


/***/ }),

/***/ 42:
/***/ (function(module, exports, __webpack_require__) {

var AjaxMixin, Helper, Model, Skin, console, defaultAtts, isArray,
  extend = 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; },
  hasProp = {}.hasOwnProperty,
  slice = [].slice;

console = window.require('spine/utils/console');

Model = window.require('spine/model');

AjaxMixin = __webpack_require__(35);

Helper = window.require('spine/utils/helper');

isArray = Helper.isArray;

defaultAtts = ["name", "user_id", 'uses', "metas", "widget_id"];

Skin = (function(superClass) {
  extend(Skin, superClass);

  Skin.extend(AjaxMixin);

  Skin.configure('Skin');

  Skin.change(AjaxMixin.ajaxChange);

  Skin.meta = function(widget_id) {
    return (__webpack_require__(36)).find(widget_id).skinMeta;
  };

  function Skin(atts) {
    if (atts == null) {
      atts = {};
    }
    atts.name || (atts.name = 'Untitled Skin');
    atts.uses || (atts.uses = 0);
    atts.metas || (atts.metas = {});
    Skin.__super__.constructor.call(this, atts);
  }

  Skin.prototype.attributes = function() {
    var attributes, atts, i, key, len, meta_attributes, meta_props, result, tab, tabs, value;
    attributes = defaultAtts.slice(0);
    try {
      tabs = this.constructor.meta(this.widget_id).tabs;
      if (!tabs) {
        throw new Error("Widget[" + this.widget_id + "].tabs is not loaded.");
      }
      meta_props = (function() {
        var results;
        results = [];
        for (tab in tabs) {
          atts = tabs[tab];
          results.push($.extend({}, atts));
        }
        return results;
      })();
      meta_attributes = $.extend.apply($, [{}].concat(slice.call(meta_props)));
      attributes.push.apply(attributes, (function() {
        var results;
        results = [];
        for (key in meta_attributes) {
          value = meta_attributes[key];
          results.push(key);
        }
        return results;
      })());
    } catch (error) {
      attributes = Object.keys(this);
      if (Object.getPrototypeOf(this) instanceof Skin) {
        attributes = $.extend([], attributes, Object.keys(Object.getPrototypeOf(this)));
      }
    }
    result = {};
    for (i = 0, len = attributes.length; i < len; i++) {
      key = attributes[i];
      if (key in this) {
        if (typeof this[key] !== 'function') {
          result[key] = this[key];
        }
      }
    }
    if (this.id) {
      result.id = this.id;
    }
    return result;
  };

  Skin.prototype.used = function(inc) {
    if (inc == null) {
      inc = -1;
    }
    console.group('SkinModel:used ' + inc);
    this.updateAttribute('uses', Math.max((this.uses >> 0) + inc, 0), {
      used: true
    });
    return console.groupEnd('SkinModel:used ' + inc);
  };

  Skin.prototype.updateAttributes = function(atts, options) {
    if (options == null) {
      options = {};
    }
    options.ajax = false;
    return Skin.__super__.updateAttributes.apply(this, arguments);
  };

  Skin.prototype.changeID = function(id) {
    var Composition, comps, oldId;
    Composition = __webpack_require__(41);
    oldId = this.id;
    Skin.__super__.changeID.apply(this, arguments);
    comps = Composition.findAllByAttribute('skin_id', oldId);
    comps.forEach((function(_this) {
      return function(comp) {
        return comp.updateAttribute('skin_id', _this.id);
      };
    })(this));
    return this.used(comps.length);
  };

  Skin.prototype.freeze = function() {
    console.group('SkinModel:freeze');
    this.original = this.attributes();
    this.original.id = null;
    delete this.original.uses;
    delete this.original.id;
    return console.groupEnd('SkinModel:freeze');
  };

  Skin.prototype.reset = function() {
    console.group('SkinModel:reset');
    this.updateAttributes(this.original, {
      ajax: false
    });
    return console.groupEnd('SkinModel:reset');
  };

  Skin.prototype.isPersisted = function() {
    if (!this.id) {
      return false;
    }
    return this.id.slice(0, 1) !== 'c';
  };

  Skin.prototype.isPreset = function() {
    return !this.user_id;
  };

  Skin.prototype.persist = function() {
    var promise;
    console.log('%c SKIN PERSIST!!!', 'background-color: red; color:white');
    if (this.isPersisted()) {
      promise = this.ajax().update();
    } else {
      promise = this.ajax().create();
    }
    return promise;
  };

  return Skin;

})(Model);

module.exports = Skin;


/***/ })

/******/ });