Skip to content

Instantly share code, notes, and snippets.

@ourmaninamsterdam
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ourmaninamsterdam/a7b4a84ddbea4c41539d to your computer and use it in GitHub Desktop.
Save ourmaninamsterdam/a7b4a84ddbea4c41539d to your computer and use it in GitHub Desktop.
Initialising 3rd-party components in Dough
<div data-dough-component="External"
data-dough-external-component="Taggle"
data-dough-external-component-config='{"tags": ["Rye","Granary","Pumpernickel"], "tabIndex": 0}'
>
<div data-dough-external-node="list"></div>
<input data-dough-external-node="input" value="">
</div>
define('ExternalComponent', ['jquery', 'DoughBaseComponent'], function($, DoughBaseComponent){
'use strict';
var defaultConfig = {},
/**
* Call base constructor
* @constructor
*/
ExternalComponent = function($el, config) {
ExternalComponent.baseConstructor.call(this, $el, config, defaultConfig);
this.init();
};
DoughBaseComponent.extend(ExternalComponent);
ExternalComponent.prototype.init = function() {
// The loading of the external component's wrapper will need some thought
// Some how we would need to pass the componentId into here or load it first.
this.instance = this.someMethodWhichRequiresAndInitsTheDependency(componentId, $el, config);
};
return ExternalComponent;
});
define('FastClickWrapper',['FastClick'], function(FastClick) {
return function($el, config){
FastClick.attach($el[0]);
return FastClick; // Can return whatever we like here
};
}
});
define('TaggleWrapper',['Taggle'], function(Taggle) {
return function($el, config){
return new Taggle(config.els.$target, config.els.$trigger, {
tags: config.libParams.tags,
tabIndex: config.libParams.tabIndex
});
};
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment