LarryBattle / Ratio.js

Rational numbers for Javascript
http://larrybattle.github.com/Ratio.js/
MIT License
113 stars 9 forks source link

Ratio object visibility #41

Closed vshjxyz closed 11 years ago

vshjxyz commented 11 years ago

Hello,

I've noticed that this library has the same issue as this one: https://github.com/makeusabrew/bootbox/issues/71

TL;DR: Ratio object is not directly attached to the window so I can't see it in production

this code resolves the problem

// Adds npm support
if (typeof exports !== 'undefined') {
    if (typeof module !== 'undefined' && module.exports) {
        exports = module.exports = Ratio;
    }
    exports.Ratio = Ratio;
} else {
    window.Ratio = Ratio;
}
LarryBattle commented 11 years ago

Could you give me more information on your production setup and how ratio.js is included?

vshjxyz commented 11 years ago

Many production systems are wrapping the JS libraries into a function(){}(this) for security reasons (see django-pipeline) so basically I think that if NPM is disabled (typeof exports == 'undefined') then we should inject the ratio object to the window (iScroll, bootbox and more libs are behaving this way)

LarryBattle commented 11 years ago

I updated this in the dev branch and will merge with the master within this week. Thanks for your help.

LarryBattle commented 11 years ago

Fixed in Version 0.4