Created
April 16, 2015 02:14
-
-
Save corpsefilth/5ca7baf2bf2d1b140cd9 to your computer and use it in GitHub Desktop.
configurable swatches magento 1.9.1, make first option selected by default -- BETA -- not for production, you will need to make slight mods.
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 fireEvent(element,event) | |
{ | |
if (document.createEventObject) | |
{ | |
// dispatch for IE | |
var evt = document.createEventObject(); | |
return element.fireEvent('on'+event,evt); | |
} | |
else | |
{ | |
// dispatch for firefox + others | |
var evt = document.createEvent("HTMLEvents"); | |
evt.initEvent(event, true, true ); | |
return !element.dispatchEvent(evt); | |
} | |
} | |
function setDefaultConfigOptions() | |
{ | |
if (spConfigIndex >= spConfig.settings.length) | |
{ | |
return; // stop | |
} | |
spConfig.settings[spConfigIndex].selectedIndex = 1; | |
var obj = spConfig.settings[spConfigIndex]; | |
++spConfigIndex; | |
Event.observe(obj,'change',function(){}); | |
fireEvent(obj,'change'); | |
window.setTimeout("setDefaultConfigOptions()", 1); // Add a small delay before moving onto the next option | |
} | |
var spConfigIndex = 0; | |
Event.observe(window, 'load', function() { | |
setDefaultConfigOptions(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment