-
-
Save viralsolani/24415f2657baabfd58ebaf544380aaa4 to your computer and use it in GitHub Desktop.
Example of Vanila Js and IIFEs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(window) | |
{ | |
FTXCommon.ProductAttribute = { | |
selectors: { | |
accountSelect: document.querySelector('[name="account_id"]'), | |
attributeSetSelect: document.querySelector('.attributeSetSelect') | |
}, | |
/** | |
* Initialize | |
* | |
*/ | |
init: function() | |
{ | |
this.addHandlers(); | |
}, | |
/** | |
* Add Handlers | |
* | |
*/ | |
addHandlers: function() | |
{ | |
var context = this; | |
if(this.selectors.accountSelect) | |
{ | |
this.selectors.accountSelect.onchange = function(event) | |
{ | |
context.getAttributeSet(); | |
}; | |
} | |
}, | |
/** | |
* Get Attribute Set | |
* | |
*/ | |
getAttributeSet: function() | |
{ | |
var accountId = this.selectors.accountSelect.value; | |
FTXCommon.Utils.emptySelect2(this.selectors.attributeSetSelect); | |
// Add select box for finding department groups | |
FTXCommon.Utils.addAjaxSelect2(this.selectors.attributeSetSelect, moduleConfig.attributeSetFindUrl, { placeholder: "Select Attribute Set"}, function(params) | |
{ | |
return { | |
q: params.term, | |
account_id: accountId, | |
page: params.page | |
}; | |
}); | |
}, | |
/** | |
* Set AttributeSet Value | |
* | |
*/ | |
setAttributeSetValue: function(value) | |
{ | |
this.selectors.attributeSetSelect.value = value; | |
var accountId = this.selectors.accountSelect.value; | |
// Add select box for finding department groups | |
FTXCommon.Utils.addAjaxSelect2(this.selectors.attributeSetSelect, moduleConfig.attributeSetFindUrl, {}, function(params) | |
{ | |
return { | |
q: params.term, | |
account_id: accountId, | |
page: params.page | |
}; | |
}); | |
} | |
} | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment