less.js icon indicating copy to clipboard operation
less.js copied to clipboard

modifyVars Not Working

Open srsgores opened this issue 13 years ago • 7 comments

I'm working on a live previewing feature for my upcoming UI framework, and updateVars appears to not be working as expected. Here is my code:

function updateVars()
    {
        if (checkLess() == true)
        {
            var $form = $(formContainer);
            $fields = $form.find("input").on('blur', function (e)
            {
                var $dataUnit = $(this).attr("data-unit"),
                    $id = "@" + $(this).attr("id"),
                    $value = $(this).val();
                console.log("about to set value of " + $value + $dataUnit + " for variable " + $id);
                if (typeof $dataUnit != "undefined")
                {
                    less.modifyVars({$id: $value + $dataUnit});
                }
                else
                {
                    less.modifyVars({$id: $value});
                }
            });
        }
    }

Once a variable is modified, and the method is triggered, the page will refresh, but the font will be incorrect, and the margins will be removed. see more here.

Any help would be appreciated.

srsgores avatar May 21 '13 05:05 srsgores

Have you tried this with the latest master? I made some changes a while ago that may have fixed this.. I can help you help us and help you.. or did you get this sorted? are you still interested?

lukeapage avatar Oct 21 '13 10:10 lukeapage

Ummmmm I dont know if this is relevant but I wrote a JS lib which keeps a track of what changes to the less you have made and applies them with modifyVars.

At the moment though its kinda tied in to editing Bootstrap, or atleast the less files included which the example edits is less.

It could be easily used in a similar project though, all you would have to do is load a .less file which you want to modify, then use the functions the API provided to do the editing.

Anyway, I have noticed that when you call modifyVars, you need to provided it with multiple vars, or it will only modify one var and then refreshed the page. Hence why I keep a track of what vars have been modified!

So I dont think this is a bug with less, I guess modifyVars just doesnt work as you would hope it would? :)

Anyway if your interested the repo is Cluckles.

ilikeprograms avatar Jul 10 '14 14:07 ilikeprograms

@ilikeprograms seems like you solve the issue, can this issue be closed?

levithomason avatar Oct 16 '14 05:10 levithomason

@levithomason Yeah modifyVars seems to work perfectly for me! Im happy for you to close the issue. Im sure @srsgores would probably say the same thing.

ilikeprograms avatar Oct 16 '14 08:10 ilikeprograms

@ilikeprograms not quite. I still need to check integration with chuckles. Please leave open until I confirm.

srsgores avatar Oct 16 '14 08:10 srsgores

@srsgores If you need any help with this then let me know!

See the following for the applyModifications method for where modifyVars is used. I just pass it an https://github.com/ilikeprograms/Cluckles/blob/master/src/Cluckles/cluckles.editor.js#L375

Object Literal with @variable names and values.

ilikeprograms avatar Oct 16 '14 08:10 ilikeprograms

I will close.. please create a new issue if you find one

lukeapage avatar Oct 26 '14 17:10 lukeapage