evertiro / historical-redux2

A simple, easily extendable options framework for WordPress based on NHP Theme Options Framework.
http://reduxframework.com
Other
105 stars 43 forks source link

"Option changed warning" is showing all time #17

Closed denis0706 closed 11 years ago

denis0706 commented 11 years ago

"Option changed warning" is showing while some input, textarea or select are changed. (options / js / options.js line 51)

And we get this warning all time, cause trigger "change" fires at options / fields / google_webfonts / jquery.fontselect.js at document ready.

So we shouldn't change fields before user does to prevent warning to be shown wrong.

jashwant commented 11 years ago

I am experiencing the same problem.

input type for google webfonts is firing change and thus causing this strange issue.

A temporary fix can be,

Changing,

jQuery('input, textarea, select').change(function () { jQuery('#redux-opts-save-warn').slideDown('slow'); });

to

jQuery('input[id!="google_webfonts"], textarea, select').change(function () { jQuery('#redux-opts-save-warn').slideDown('slow'); });

at line 51 in js/options.js

jashwant commented 11 years ago

or a better option to change the code to something like this,

jQuery('input, textarea, select').change(function () { if(this.id === 'google_webfonts' && this.value === '') return; jQuery('#redux-opts-save-warn').slideDown('slow'); });

evertiro commented 11 years ago

Should be fixed now, thanks for catching it!

denis0706 commented 11 years ago

It doesn't solve a problem. In jashwant code if input has value "Option changed warning" will be shown.

jashwant commented 11 years ago

Yes, it does not solve the problem. I thought it after posting this. A dirty/temp solution could be,

jQuery('input, textarea, select').change(function () { var $this = $(this); if( $this.attr('id') === 'google_webfonts' && $this.data('first') !== true) { $this.data('first') = true; return; } jQuery('#redux-opts-save-warn').slideDown('slow'); });

jashwant commented 11 years ago

And this should be the solution,

Remove the change function from the document's ready event and place it on window load event (As google fonts scripts loads after ready event.

jQuery(window).load(function () { jQuery('input, textarea, select').change(function () { jQuery('#redux-opts-save-warn').slideDown('slow'); }); });

denis0706 commented 11 years ago

I have another solution, unlike jashwant one, we should edit jquery.fontselect.js Just move change handler code into a function and call it on document ready

    var googlefont = jQuery('.font').fontselect();
    fontset (googlefont);

    googlefont.change(function() {
        fontset($(this));
    });

    function fontset(googlefont){
        var relid = googlefont.attr('id');

        // replace + signs with spaces for css
        var font = googlefont.val().replace(/\+/g, ' ');

        // split font into family and weight
        font = font.split(':');

        // set family on example
        jQuery('#'+relid+'.example').css('font-family', font[0]);
    }
evertiro commented 11 years ago

I have yet to reproduce the issue, and I don't want to continue doing commits that work for me, but not for others. Can someone who is experiencing this issue please make a pull request with a patch that works for them?

pcescato commented 11 years ago

I've tried denis0706 solution, works for me.

evertiro commented 11 years ago

I tried his solution and it wouldn't load at all >_< One of you want to submit a pull request with a working copy?

pcescato commented 11 years ago

Le 04/01/2013 01:06, Ghost1227 a écrit :

I tried his solution and it wouldn't load at all >_< One of you want to submit a pull request with a working copy?

— Reply to this email directly or view it on GitHub https://github.com/ghost1227/Redux-Framework/issues/17#issuecomment-11866962.

with this code? On my own install everything is ok... fonts are loaded, warning isn't anymore, options are registered. So, I didn't saw any problem.

jQuery(document).ready(function( $ ) {

 var googlefont = jQuery('.font').fontselect();
 fontset (googlefont);

 googlefont.change(function() {
     fontset($(this));
 });

 function fontset(googlefont){
     var relid = googlefont.attr('id');

     // replace + signs with spaces for css
     var font = googlefont.val().replace(/\+/g, ' ');

     // split font into family and weight
     font = font.split(':');

     // set family on example

jQuery('#'+relid+'.example').css('font-family', font[0]); }

});

/*

evertiro commented 11 years ago

Seems I can't type. My third attempt at copying this worked.