[PATCH] hgweb: add line wrapping switch with javascript

Martin Geisler martin at geisler.net
Mon Jul 15 02:28:27 CDT 2013


Alexander Plavin <me at aplavin.ru> writes:

> 2013/7/12 Martin Geisler <martin at geisler.net>:
>> Alexander Plavin <me at aplavin.ru> writes:
>>
>>> +    var links = document.getElementsByClassName('linewraplink');
>>
>> I would prefer something like
>>
>>        var not_flag = flag == 'on' ? 'off' : 'on';
>>> +    for (var i = 0; i < links.length; i++) {
>>            links[i].innerHTML = flag;
>>            links[i].href = 'javascript:setLinewrap("' + not_flag + '");'
>>> +    }
>>> +}
>>
>> Alternatively, and probably better: avoid the flag parameter and let
>> the DOM keep the state instead. That is, if the "wrap" class is
>> there, then remove it and update the innerHTML appropriatedly --
>> there is then no need to update the link since toggleLinewrap (new
>> name for the function) would work without any arguments.
>
> Yes, this really looks better :)
>
> Thanks for your comments here. Sent a new version considering these
> suggestions.

I was just thinking out loud, so I'm glad you liked the suggestions and
thanks for turning them into a proper patch :)

-- 
Martin Geisler


More information about the Mercurial-devel mailing list