Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ddslick method onSelected is running right away

Im using ddSlick plugin for jQuery and the method onSelected should only run when I have chosen an option from the created Dropdown.

Only problem is that the following code I have seems to run the onSelected as soon as the page loads.

Can anyone point me in the right direction?

$('#flag').ddslick({
    imagePosition:"left",
    background:"none",
    width:"66px",
    onSelected: function(data){
        var chosenCountry = data.selectedData.value;
        chosenCountry = chosenCountry.toLowerCase();
        if(data.selectedIndex > 0) {
            if( new_url[1] in oc(['de', 'es','fr','it']) ) {
                console.log("translated pages");
            }
        } else {
            console.log("English site");
        }
    }   
});

jsFiddle

Thanks

like image 986
ngplayground Avatar asked Nov 06 '12 14:11

ngplayground


1 Answers

I have invented a solution after hours of figuring out whats the problem.

I directly change something on the code.

Note: you need to use the unminified version to follow this instructions.


on line 220

find:

function selectIndex(obj, index) {

change it to:

function selectIndex(obj, index, a) {

Line 270

find:

if (typeof settings.onSelected == 'function') {
   settings.onSelected.call(this, pluginData);
}

change it to:

if (typeof settings.onSelected == 'function') {
    if (a !== true) settings.onSelected.call(this, pluginData);
}

And finally on line 146

find

selectIndex(obj, index)

then change it to

selectIndex(obj, index, true)

Hope that helps!

like image 51
Leysam Rosario Avatar answered Sep 29 '22 12:09

Leysam Rosario