mirror of
https://github.com/flarum/framework.git
synced 2024-12-12 06:03:39 +08:00
Automatically hook up onload/config functions
So that every component's DOM can be config'd by extensions
This commit is contained in:
parent
f2c07218b0
commit
d85ae8745e
|
@ -18,6 +18,14 @@ export default class Component {
|
||||||
return selector ? $(this.element()).find(selector) : $(this.element());
|
return selector ? $(this.element()).find(selector) : $(this.element());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onload(element) {
|
||||||
|
this.element(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
config() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
@ -28,7 +36,18 @@ export default class Component {
|
||||||
}
|
}
|
||||||
var view = function(component) {
|
var view = function(component) {
|
||||||
component.props = props;
|
component.props = props;
|
||||||
return component.view();
|
var vdom = component.view();
|
||||||
|
vdom.attrs = vdom.attrs || {};
|
||||||
|
if (!vdom.attrs.config) {
|
||||||
|
vdom.attrs.config = function() {
|
||||||
|
var args = [].slice.apply(arguments);
|
||||||
|
if (!args[1]) {
|
||||||
|
component.onload.apply(component, args);
|
||||||
|
}
|
||||||
|
component.config.apply(component, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vdom;
|
||||||
};
|
};
|
||||||
view.$original = this.prototype.view;
|
view.$original = this.prototype.view;
|
||||||
var output = {
|
var output = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user