devote / HTML5-History-API

HTML5 History API expansion for browsers not supporting pushState, replaceState
http://spb-piksel.ru
MIT License
1.02k stars 182 forks source link

commonJS support? #75

Closed vvo closed 8 years ago

vvo commented 8 years ago

Hi, could we have commonJS support? thx

devote commented 8 years ago

Hi For polyfill need a browser. Why do you need a polyfill without a browser?

vvo commented 8 years ago

I mean something where I could do var History = require('html5-history-api') so that I do not overwrite the full window.history.

I am developing some code that should be able to be inserted in a lot of different website so I cannot just erase the full window.history.

devote commented 8 years ago

I do not quite understand. Can you describe in more detail your situation. Thank you!

vvo commented 8 years ago

I want to be able to require and use your library without it being inserted automatically in the global scope and replacing the original history object.

var History = require('html5-history-api')
History.pushState();
History.on('popstate')

// etc..
devote commented 8 years ago

You want this library to fully simulate the History-API without a browser?

flipchart commented 8 years ago

CommonJS is used within the browser via toolchains like Browserify and Webpack. I believe this is how @vvo will use the library. So instead of providing the global window.history.location, you would be able to use the library via var location = require("html5-history-api")

vvo commented 8 years ago

Exactly what @flipchart said :-). Why do this? Because if you are a library author you do not want to pollute the original document by providing a polyfill in window.history while the website author may have some scripts expecting it not to exists.

devote commented 8 years ago

Added support CommonJS