Join TSR now and chat about whatever you’re intoSign up now
    • Thread Starter
    Offline

    18
    ReputationRep:
    'Sup y'all. I built this calc() polyfill for websites, obviously written in JS. Thought some of you might be interested considering I don't believe there is one out there yet. It works with external stylesheets, internal stylesheets, and the style attribute in one or two browsers (IE removes properties it doesn't understand from the attribute for some reason).

    This currently works only with dimensions (px, %, em, rem, in, pt, pc, mm, cm), so you can't calc(1000kHz + 100Hz) just yet. Additionally, it can be used to support the rem unit for browsers that do not have it, but there's probably a better polyfill for that out there.
    Another note. Because of the parser it uses (not my own), properties that contain more than one value such as margin and border are unsupported. You'll need to use margin-x and border-width. It also does not support the attr().

    Also, I believe it's the first polyfill of its kind, so I'm proud of it.

    You can grab it from here: https://github.com/CJKay/PolyCalc/bl...er/polycalc.js
    • TSR Group Staff
    Offline

    18
    ReputationRep:
    Why does it require Modernizr, it doesn't seem to have any references to it?

    You also shouldn't assume that $ = jQuery as that's not always the case, use a wrapper function to reference $.

    Overall it looks a bit sluggish, but then again CSS expressions are pretty damn sluggish to begin with, so I guess speed isn't going to be a major concern for something like this.
    • Thread Starter
    Offline

    18
    ReputationRep:
    The Modernizr requirement was due to my using it to test it. I haven't (yet) written a way of testing for calc() support, although I should remove the check. It is still very early and I am considering completely removing the need for the parser as well. Most of my time has literally been spent getting it to do the very basics rather than to make sure it works in as many places as possible.

    Also yes, you are right about jQuery. My mistake.
    In general, it is not really sluggish at all. On my laptop using IE7 I see no slowdowns despite the AJAX (and having to download external scripts twice). Most of the time in the script is spent inside jQuery functions.
    • TSR Group Staff
    Offline

    18
    ReputationRep:
    (Original post by CJKay)
    The Modernizr requirement was due to my using it to test it. I haven't (yet) written a way of testing for calc() support, although I should remove the check. It is still very early and I am considering completely removing the need for the parser as well. Most of my time has literally been spent getting it to do the very basics rather than to make sure it works in as many places as possible.

    Also yes, you are right about jQuery. My mistake.
    In general, it is not really sluggish at all. On my laptop using IE7 I see no slowdowns despite the AJAX (and having to download external scripts twice). Most of the time in the script is spent inside jQuery functions.
    I suppose you could have a look at Modernizr's source and nick their support test. I guess it won't generally be much slower to use a polyfill like this compared to the original calc() expression, since they're both basically JavaScript. I'd steer well clear of both personally though, speed is just too important for the work I do.
 
 
 
Reply
Submit reply
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Updated: March 14, 2013
Poll
Which Fantasy Franchise is the best?
Useful resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Quick reply
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.