Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/system/assets/js/build/system.js

Large diffs are not rendered by default.

28 changes: 24 additions & 4 deletions modules/system/assets/js/snowboard/abstracts/PluginBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ export default class PluginBase {
/**
* Constructor.
*
* The constructor is provided the Snowboard framework instance.
* The constructor is provided the Snowboard framework instance, and should not be overwritten
* unless you absolutely know what you're doing.
*
* @param {Snowboard} snowboard
*/
constructor(snowboard) {
this.snowboard = snowboard;
}

/**
* Plugin constructor.
*
* This method should be treated as the true constructor of a plugin, and can be overwritten.
* It will be called straight after construction.
*/
construct() {
}

/**
* Defines the required plugins for this specific module to work.
*
Expand All @@ -37,12 +47,22 @@ export default class PluginBase {
}

/**
* Destructor.
* Plugin destructor.
*
* Fired when this plugin is removed.
* Fired when this plugin is removed. Can be manually called if you have another scenario for
* destruction, ie. the element attached to the plugin is removed or changed.
*/
destructor() {
destruct() {
this.detach();
delete this.snowboard;
}

/**
* Plugin destructor (old method name).
*
* Allows previous usage of the "destructor" method to still work.
*/
destructor() {
this.destruct();
}
}
8 changes: 4 additions & 4 deletions modules/system/assets/js/snowboard/ajax/Request.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ class Request extends Snowboard.PluginBase {
/**
* Constructor.
*
* @param {Snowboard} snowboard
* @param {HTMLElement|string} element
* @param {string} handler
* @param {Object} options
*/
constructor(snowboard, element, handler, options) {
super(snowboard);

construct(element, handler, options) {
if (typeof element === 'string') {
const matchedElement = document.querySelector(element);
if (matchedElement === null) {
Expand Down Expand Up @@ -682,6 +679,9 @@ class Request extends Snowboard.PluginBase {
event.responseError = this.responseError;
this.element.dispatchEvent(event);
}

// Fire off the destructor
this.destruct();
}

get form() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ class AttributeRequest extends Snowboard.Singleton {
*
* Detaches all handlers.
*/
destructor() {
destruct() {
this.detachHandlers();

super.destructor();
super.destruct();
}

/**
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion modules/system/assets/js/snowboard/build/snowboard.base.js

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions modules/system/assets/js/snowboard/extras/DataConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ export default class DataConfig extends Snowboard.PluginBase {
/**
* Constructor.
*
* @param {Snowboard} snowboard
* @param {Snowboard.PluginBase} instance
* @param {HTMLElement} element
*/
constructor(snowboard, instance, element) {
super(snowboard);

construct(instance, element) {
if (instance instanceof Snowboard.PluginBase === false) {
throw new Error('You must provide a Snowboard plugin to enable data configuration');
}
Expand Down
11 changes: 4 additions & 7 deletions modules/system/assets/js/snowboard/extras/Flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ export default class Flash extends Snowboard.PluginBase {
/**
* Constructor.
*
* @param {Snowboard} snowboard
* @param {string} message
* @param {string} type
* @param {Number} duration
*/
constructor(snowboard, message, type, duration) {
super(snowboard);

construct(message, type, duration) {
this.message = message;
this.type = type || 'default';
this.duration = Number(duration || 7);
Expand Down Expand Up @@ -55,7 +52,7 @@ export default class Flash extends Snowboard.PluginBase {
*
* This will ensure the flash message is removed and timeout is cleared if the module is removed.
*/
destructor() {
destruct() {
if (this.timer !== null) {
window.clearTimeout(this.timer);
}
Expand All @@ -70,7 +67,7 @@ export default class Flash extends Snowboard.PluginBase {
this.flashTimer = null;
}

super.destructor();
super.destruct();
}

/**
Expand Down Expand Up @@ -114,7 +111,7 @@ export default class Flash extends Snowboard.PluginBase {
this.snowboard.transition(this.flash, 'hide', () => {
this.flash.remove();
this.flash = null;
this.destructor();
this.destruct();
});
}

Expand Down
12 changes: 5 additions & 7 deletions modules/system/assets/js/snowboard/extras/Transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ export default class Transition extends Snowboard.PluginBase {
/**
* Constructor.
*
* @param {Snowboard} snowboard
* @param {HTMLElement} element The element to transition
* @param {string} transition The name of the transition, this prefixes the stages of transition.
* @param {Function} callback An optional callback to call when the transition ends.
* @param {Number} duration An optional override on the transition duration. Must be specified as 's' (secs) or 'ms' (msecs).
* @param {Boolean} trailTo If true, the "out" class will remain after the end of the transition.
*/
constructor(snowboard, element, transition, callback, duration, trailTo) {
super(snowboard);

construct(element, transition, callback, duration, trailTo) {
if (element instanceof HTMLElement === false) {
throw new Error('A HTMLElement must be provided for transitioning');
}
Expand Down Expand Up @@ -126,7 +123,7 @@ export default class Transition extends Snowboard.PluginBase {
this.callback.apply(this.element);
}

this.destructor();
this.destruct();
}
});
}
Expand All @@ -152,7 +149,7 @@ export default class Transition extends Snowboard.PluginBase {
this.element.style.transitionDuration = null;
}

this.destructor();
this.destruct();
}

/**
Expand All @@ -172,7 +169,8 @@ export default class Transition extends Snowboard.PluginBase {
this.element.style.transitionDuration = null;
}

this.destructor();
// Call destructor
this.destruct();
}

/**
Expand Down
10 changes: 6 additions & 4 deletions modules/system/assets/js/snowboard/main/PluginLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class PluginLoader {
}
if (this.isSingleton()) {
if (this.instances.length === 0) {
this.initialiseSingleton();
this.initialiseSingleton(...parameters);
}

// Apply mocked methods
Expand Down Expand Up @@ -115,8 +115,9 @@ export default class PluginLoader {

const newInstance = new this.instance(this.snowboard, ...parameters);
newInstance.detach = () => this.instances.splice(this.instances.indexOf(newInstance), 1);

newInstance.construct(...parameters);
this.instances.push(newInstance);

return newInstance;
}

Expand Down Expand Up @@ -169,13 +170,14 @@ export default class PluginLoader {
*
* @returns {void}
*/
initialiseSingleton() {
initialiseSingleton(...parameters) {
if (!this.isSingleton()) {
return;
}

const newInstance = new this.instance(this.snowboard);
const newInstance = new this.instance(this.snowboard, ...parameters);
newInstance.detach = () => this.instances.splice(this.instances.indexOf(newInstance), 1);
newInstance.construct(...parameters);
this.instances.push(newInstance);
this.initialised = true;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/system/assets/js/snowboard/main/Snowboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default class Snowboard {

// Call destructors for all instances
this.plugins[lowerName].getInstances().forEach((instance) => {
instance.destructor();
instance.destruct();
});

delete this.plugins[lowerName];
Expand Down
4 changes: 1 addition & 3 deletions modules/system/assets/js/snowboard/utilities/Cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import Singleton from '../abstracts/Singleton';
* @author Ben Thomson <git@alfreido.com>
*/
export default class Cookie extends Singleton {
constructor(snowboard) {
super(snowboard);

construct() {
this.defaults = {
expires: null,
path: '/',
Expand Down
4 changes: 1 addition & 3 deletions modules/system/assets/js/snowboard/utilities/JsonParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import Singleton from '../abstracts/Singleton';
* @see https://github.com/octobercms/october/pull/4527
*/
export default class JsonParser extends Singleton {
constructor(snowboard) {
super(snowboard);

construct() {
// Add to global function for backwards compatibility
window.wnJSON = (json) => this.parse(json);
window.ocJSON = window.wnJSON;
Expand Down
4 changes: 1 addition & 3 deletions modules/system/assets/js/snowboard/utilities/Sanitizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import Singleton from '../abstracts/Singleton';
* @author Ben Thomson <git@alfreido.com>
*/
export default class Sanitizer extends Singleton {
constructor(snowboard) {
super(snowboard);

construct() {
// Add to global function for backwards compatibility
window.wnSanitize = (html) => this.sanitize(html);
window.ocSanitize = window.wnSanitize;
Expand Down
4 changes: 1 addition & 3 deletions modules/system/assets/js/snowboard/utilities/Url.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import Singleton from '../abstracts/Singleton';
* @author Ben Thomson <git@alfreido.com>
*/
export default class Url extends Singleton {
constructor(snowboard) {
super(snowboard);

construct() {
this.foundBaseUrl = null;
this.baseUrl();
}
Expand Down
4 changes: 1 addition & 3 deletions tests/js/fixtures/dataConfig/DataConfigFixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

((Snowboard) => {
class DataConfigFixture extends Snowboard.PluginBase {
constructor(snowboard, element) {
super(snowboard);

construct(element) {
this.element = element;
this.config = this.snowboard.dataConfig(this, element);
}
Expand Down