Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Parse CSS styles and swap background position value Date: Tue, 03 Feb 2015 12:44:56 +0100 Organization: PointedEars Software (PES) Lines: 26 Message-ID: <2049578.4vjSuc16jt@PointedEars.de> References: <8be9bcae-a221-46e1-8e0f-ec41632517a4@googlegroups.com> <54cf68f5$0$2870$e4fe514c@news2.news.xs4all.nl> <1609092.d9bYY2oEu8@PointedEars.de> <54cf7dfa$0$2962$e4fe514c@news2.news.xs4all.nl> <7622963.yZKU775dzf@PointedEars.de> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1422963936 32259 eJwNyMkBwCAIBMCW5FjAcgy4/Zdg5jmwkOj0QDgIevtec8LORVGtMam3ZYocqYSC1JG/9rcyHyYbEWo= (3 Feb 2015 11:45:36 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Tue, 3 Feb 2015 11:45:36 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwNy8EBwCAMAsCVgiRox6Fq9h+hvf8VBe2ZKmV1tZGi7QgTTvveMcnFXj37YNQjnNOBP0bAr7U3GXhz5R0fUXgVKA== Cancel-Lock: sha1:aY+3iXS+n80RGUGyfeyXI23DVWQ= X-NNTP-Posting-Host: eJwFwQkBwDAIA0BLpSSUyeH1L2F3VBOrB6OBy03VRlkW0m3aP+TC1/XeMwJJZavwTLyI4Pwi6RFU Xref: csiph.com comp.lang.javascript:26781 Thomas 'PointedEars' Lahn wrote: > […] Again, *iff* you can make sure that *all* percentages in the matched > property values relate to horizontal background-position (which usually is > _not_ the case: […]), then you could use > > … = value.replace(/\b(?:(left)|(right)|(\d+)%)\b/gi, > function (match, left, right, percentage) { > return (left > ? "right" > : (right ? "left" : (100 - percentage) + "%"))); ^ > }); > > But this does not work already in the case of > > background: url(example1.png) repeat-x right 50%; Bad example :) It would work here (after the extra parenthesis was removed), but only because of 100 − 50 = 50. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.