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.

48 lines
1.2 KiB

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