You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB

  1. /**
  2. * Copyright 2013 Matthieu Moquet
  3. * Copyright 2016-2017 LasLabs Inc.
  4. * License MIT (https://opensource.org/licenses/MIT)
  5. **/
  6. (function() {
  7. 'use strict';
  8. Darkroom.Plugin = Plugin;
  9. // Define a plugin object. This is the (abstract) parent class which
  10. // has to be extended for each plugin.
  11. function Plugin(darkroom, options) {
  12. this.darkroom = darkroom;
  13. this.options = Darkroom.Utils.extend(options, this.defaults);
  14. this.initialize();
  15. }
  16. Plugin.prototype = {
  17. defaults: {},
  18. initialize: function() { /* no-op */ }
  19. };
  20. // Inspired by Backbone.js extend capability.
  21. Plugin.extend = function(protoProps) {
  22. var parent = this;
  23. var child;
  24. if (protoProps && protoProps.hasOwnProperty('constructor')) {
  25. child = protoProps.constructor;
  26. } else {
  27. child = function() { return parent.apply(this, arguments); };
  28. }
  29. Darkroom.Utils.extend(child, parent);
  30. var Surrogate = function() { this.constructor = child; };
  31. Surrogate.prototype = parent.prototype;
  32. child.prototype = new Surrogate();
  33. if (protoProps) Darkroom.Utils.extend(child.prototype, protoProps);
  34. child.__super__ = parent.prototype;
  35. return child;
  36. };
  37. })();