big big big update
Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
parent
fb30fe966e
commit
3b4f1e024f
4993
images/search.ai
Normal file
4993
images/search.ai
Normal file
File diff suppressed because one or more lines are too long
BIN
images/search.png
Normal file
BIN
images/search.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 399 B |
BIN
js/libraries/balupton-history.js-e84ad00.zip
Normal file
BIN
js/libraries/balupton-history.js-e84ad00.zip
Normal file
Binary file not shown.
1
js/libraries/balupton-history/.gitignore
vendored
Executable file
1
js/libraries/balupton-history/.gitignore
vendored
Executable file
@ -0,0 +1 @@
|
||||
.build
|
76
js/libraries/balupton-history/History.md
Executable file
76
js/libraries/balupton-history/History.md
Executable file
@ -0,0 +1,76 @@
|
||||
## History
|
||||
|
||||
- v1.7.1 - October 4 2011
|
||||
- Added a new native adapter which is framework agnostic (can be used with, or without any framework)
|
||||
- Provided bundled files
|
||||
- Added RightJS adapter
|
||||
- Updated supported browser listing
|
||||
- Added sessionStorage support in core instead of optional Amplify.js Store support
|
||||
- Fixed issue with state id generation growing slower over time
|
||||
- Closes #104, #95, #102, #92, #81, #90, #94, #93, #91, #67, #83, #54, #45
|
||||
|
||||
- v1.7.0 - April 1 2011
|
||||
- Added `History.enabled` property (refer to usage section). This reflects whether or not History.js is enabled for our particular browser. For instance, if we have not included support for a HTML4 browser and we are accessing through a HTML4 browser then `History.enabled` will be `false`.
|
||||
- Added (optional but recommended) Data Persistance and Synchronisation Support thanks to [AppendTo's](http://appendto.com/) [Amplify.js](http://amplifyjs.com/) (refer to installation and compatibility sections for details)
|
||||
- Made HTML5 SUIDs more transparent - [Reported](https://github.com/balupton/history.js/issues#issue/34) by [azago](https://github.com/azago) and [Mark Jaquith](http://markjaquith.com/)
|
||||
- Fixed Session Storage Issue - Reported by a whole bunch of different people; [one](https://github.com/balupton/history.js/issues#issue/36), [two](https://github.com/balupton/history.js/issues#issue/37), [three](http://getsatisfaction.com/balupton/topics/history_js_1_6_losing_state_after_manual_page_reload)
|
||||
- Fixed URL Encoding Issue - [Reported](https://github.com/balupton/history.js/issues/#issue/33) by [Rob Madole](http://robmadole.com/)
|
||||
- Disabled support for IE6,7,8 when using the Prototype Adapter (there is nothing we can do about this, it is due to a bug in the prototype library) - [Reported](https://github.com/balupton/history.js/issues#issue/39) by [Sindre Wimberger](http://sindre.at/)
|
||||
- URLs in the State Hashes for HTML4 Browsers are now even shorter - [Discussion](https://github.com/balupton/history.js/issues#issue/28)
|
||||
- Fixed a issue with the MooTools Adapter and JSON with IE7 and IE8
|
||||
|
||||
- v1.6.0 - March 22 2011
|
||||
- Added Zepto adapter thanks to [Matt Garrett](http://twitter.com/#!/matthewgarrett)
|
||||
- The readme now references the supported versions of the libraries we use
|
||||
- Updated vendors to the most recent versions. jQuery 1.5.1 and Mootools 1.3.1
|
||||
- Reverted versions of Safari iOS prior to version 4.3 to be HTML4 browsers, Safari iOS 4.3 is a HTML5 browser
|
||||
- Refined code in History.js and its adapters
|
||||
- Fixed issue with extra state being inserted on Safari 5 requiring an extra click on the back button to go home - [Reported](https://github.com/balupton/history.js/issues#issue/17) by [Rob Madole](http://robmadole.com/)
|
||||
- Fixed issue with Safari 5 and Safari iOS 4 sometimes failing to apply the state change under busy conditions - Solution conceived with [Matt Garrett](http://twitter.com/matthewgarrett)
|
||||
- Fixed issue with HTML4 browsers requiring a query-string in the urls of states - [Reported](https://github.com/balupton/history.js/issues#issue/26) by [azago](https://github.com/azago)
|
||||
- Fixed issue with HTML4 browsers requiring title in the states in order to use state data - [Reported](https://github.com/balupton/history.js/issues#issue/25) by [Jonathan McLaughlin](http://system-werks.com/)
|
||||
- Fixed issue with HTML4 browsers failing is a state is pushed/replaced twice in a row - [Reported](https://github.com/balupton/history.js/issues#issue/17) by [Joey Baker](http://byjoeybaker.com/)
|
||||
- **B/C BREAK:** The `statechange` event now only fires if the state has changed; it no longer fires on page initialisation. This is following the [Firefox 4 History API Changes](http://hacks.mozilla.org/2011/03/history-api-changes-in-firefox-4/) which we agree with - this breaks standard, but makes more sense.
|
||||
|
||||
- v1.5.0 - February 12 2011
|
||||
- Moved to UglifyJS instead of Google Closure
|
||||
- Split HTML4 functionality from HTML5 functionality
|
||||
- Installation details have changed (the filenames are different)
|
||||
|
||||
- v1.4.1 - February 10 2011
|
||||
- Added HTML History API Support for Safari 5 and Safari iOS 4.2.1
|
||||
- Cleaned code a bit (mostly with unit tests)
|
||||
|
||||
- v1.4.0 - February 10 2011
|
||||
- Unit Testing now uses [QUnit](http://docs.jquery.com/Qunit)
|
||||
- Corrected Safari 5 Support
|
||||
- Now uses queues instead of timeouts
|
||||
- This means the API works exactly as expected, no more need to wrap calls in timeouts
|
||||
- Included a Subscribe Form in the Demo for Version Updates via Email
|
||||
- Small updates to Documentation
|
||||
|
||||
- v1.3.1 - February 4 2011
|
||||
- Improved Documentation
|
||||
|
||||
- v1.3.0 - January 31 2011
|
||||
- Support for cleaner HTML4 States
|
||||
|
||||
- v1.2.1 - January 30 2011
|
||||
- Fixed History.log always being called - [reported by dlee](https://github.com/balupton/history.js/issues/#issue/2)
|
||||
- Re-Added `History.go(index)` support
|
||||
|
||||
- v1.2.0 - January 25 2011
|
||||
- Support for HTML4 States in HTML5 Browsers (added test)
|
||||
- Updates of Documentation
|
||||
|
||||
- v1.1.0 - January 24 2011
|
||||
- Developed a series of automated test cases
|
||||
- Fixed issue with traditional anchors
|
||||
- Fixed issue with differing replaceState functionality in HTML4 Browsers
|
||||
- Fixed issue with Google Chrome artefacts being carried over to the initial state
|
||||
- Provided `onstatechange` and `onanchorchange` events
|
||||
|
||||
- v1.0.0 - January 22 2011
|
||||
- Supported `History.pushState` and `History.replaceState` degradation
|
||||
- Supported jQuery, MooTools and Prototype Frameworks
|
||||
|
245
js/libraries/balupton-history/README.md
Executable file
245
js/libraries/balupton-history/README.md
Executable file
@ -0,0 +1,245 @@
|
||||
Welcome to History.js (v1.7.1 - October 4 2011)
|
||||
==================
|
||||
|
||||
[](https://flattr.com/submit/auto?user_id=balupton&url=https://github.com/balupton/history.js&title=History.js&language=&tags=github&category=software)
|
||||
|
||||
|
||||
This project is the successor of [jQuery History](http://balupton.com/projects/jquery-history), it aims to:
|
||||
|
||||
- Follow the [HTML5 History API](https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history) as much as possible
|
||||
- Provide a cross-compatible experience for all HTML5 Browsers (they all implement the HTML5 History API a little bit differently causing different behaviours and sometimes bugs - History.js fixes this ensuring the experience is as expected / the same / great throughout the HTML5 browsers)
|
||||
- Provide a backwards-compatible experience for all HTML4 Browsers using a hash-fallback (including continued support for the HTML5 History API's `data`, `title`, `pushState` and `replaceState`) with the option to [remove HTML4 support if it is not right for your application](https://github.com/balupton/history.js/wiki/Intelligent-State-Handling)
|
||||
- Provide a forwards-compatible experience for HTML4 States to HTML5 States (so if a hash-fallbacked url is accessed by a HTML5 browser it is naturally transformed into its non-hashed url equivalent)
|
||||
- Provide support for as many javascript frameworks as possible via adapters; especially [jQuery](http://jquery.com/), [MooTools](http://mootools.net/), [Prototype](http://www.prototypejs.org/) and [Zepto](http://zeptojs.com/)
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
### Working with History.js:
|
||||
|
||||
``` javascript
|
||||
(function(window,undefined){
|
||||
|
||||
// Prepare
|
||||
var History = window.History; // Note: We are using a capital H instead of a lower h
|
||||
if ( !History.enabled ) {
|
||||
// History.js is disabled for this browser.
|
||||
// This is because we can optionally choose to support HTML4 browsers or not.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Bind to StateChange Event
|
||||
History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
|
||||
var State = History.getState(); // Note: We are using History.getState() instead of event.state
|
||||
History.log(State.data, State.title, State.url);
|
||||
});
|
||||
|
||||
// Change our States
|
||||
History.pushState({state:1}, "State 1", "?state=1"); // logs {state:1}, "State 1", "?state=1"
|
||||
History.pushState({state:2}, "State 2", "?state=2"); // logs {state:2}, "State 2", "?state=2"
|
||||
History.replaceState({state:3}, "State 3", "?state=3"); // logs {state:3}, "State 3", "?state=3"
|
||||
History.pushState(null, null, "?state=4"); // logs {}, '', "?state=4"
|
||||
History.back(); // logs {state:3}, "State 3", "?state=3"
|
||||
History.back(); // logs {state:1}, "State 1", "?state=1"
|
||||
History.back(); // logs {}, "Home Page", "?"
|
||||
History.go(2); // logs {state:3}, "State 3", "?state=3"
|
||||
|
||||
})(window);
|
||||
```
|
||||
|
||||
To ajaxify your entire website with the HTML5 History API, History.js and jQuery [this snippet of code](https://gist.github.com/854622) is all you need. It's that easy.
|
||||
|
||||
### How would the above operations look in a HTML5 Browser?
|
||||
|
||||
1. www.mysite.com
|
||||
1. www.mysite.com/?state=1
|
||||
1. www.mysite.com/?state=2
|
||||
1. www.mysite.com/?state=3
|
||||
1. www.mysite.com/?state=4
|
||||
1. www.mysite.com/?state=3
|
||||
1. www.mysite.com/?state=1
|
||||
1. www.mysite.com
|
||||
1. www.mysite.com/?state=3
|
||||
|
||||
> Note: These urls also work in HTML4 browsers and Search Engines. So no need for the hashbang (`#!`) fragment-identifier that google ["recommends"](https://github.com/balupton/history.js/wiki/Intelligent-State-Handling).
|
||||
|
||||
### How would they look in a HTML4 Browser?
|
||||
|
||||
1. www.mysite.com
|
||||
1. www.mysite.com/#?state=1&_suid=1
|
||||
1. www.mysite.com/#?state=2&_suid=2
|
||||
1. www.mysite.com/#?state=3&_suid=3
|
||||
1. www.mysite.com/#?state=4
|
||||
1. www.mysite.com/#?state=3&_suid=3
|
||||
1. www.mysite.com/#?state=1&_suid=1
|
||||
1. www.mysite.com
|
||||
1. www.mysite.com/#?state=3&_suid=3
|
||||
|
||||
> Note 1: These urls also work in HTML5 browsers - we use `replaceState` to transform these HTML4 states into their HTML5 equivalents so the user won't even notice :-)
|
||||
>
|
||||
> Note 2: These urls will be automatically url-encoded in IE6 to prevent certain browser-specific bugs.
|
||||
>
|
||||
> Note 3: Support for HTML4 browsers (this hash fallback) is optional [- why supporting HTML4 browsers could be either good or bad based on my app's use cases](https://github.com/balupton/history.js/wiki/Intelligent-State-Handling)
|
||||
|
||||
### What's the deal with the SUIDs used in the HTML4 States?
|
||||
|
||||
- SUIDs (State Unique Identifiers) are used when we utilise a `title` and/or `data` in our state. Adding a SUID allows us to associate particular states with data and titles while keeping the urls as simple as possible (don't worry it's all tested, working and a lot smarter than I'm making it out to be).
|
||||
- If you aren't utilising `title` or `data` then we don't even include a SUID (as there is no need for it) - as seen by State 4 above :-)
|
||||
- We also shrink the urls to make sure that the smallest url will be used. For instance we will adjust `http://www.mysite.com/#http://www.mysite.com/projects/History.js` to become `http://www.mysite.com/#/projects/History.js` automatically. (again tested, working, and smarter).
|
||||
- It works with domains, subdomains, subdirectories, whatever - doesn't matter where you put it. It's smart.
|
||||
- Safari 5 will also have a SUID appended to the URL, it is entirely transparent but just a visible side-effect. It is required to fix a bug with Safari 5.
|
||||
|
||||
### Is there a working demo?
|
||||
|
||||
- Sure is, give it a download and navigate to the demo directory in your browser :-)
|
||||
- If you are after something a bit more adventurous than a end-user demo, open up the tests directory in your browser and editor - it'll rock your world and show all the vast use cases that History.js supports.
|
||||
|
||||
|
||||
## Download & Installation
|
||||
|
||||
- Download History.js and upload it to your webserver. Download links: [tar.gz](https://github.com/balupton/history.js/tarball/master) or [zip](https://github.com/balupton/history.js/zipball/master)
|
||||
|
||||
- Include History.js
|
||||
|
||||
- For [jQuery](http://jquery.com/) v1.3+
|
||||
|
||||
``` html
|
||||
<script src="http://www.yourwebsite.com/history.js/scripts/bundled/html4+html5/jquery.history.js"></script>
|
||||
```
|
||||
|
||||
- For [Mootools](http://mootools.net/) v1.3+
|
||||
|
||||
``` html
|
||||
<script src="http://www.yourwebsite.com/history.js/scripts/bundled/html4+html5/mootools.history.js"></script>
|
||||
```
|
||||
|
||||
- For [Right.js](http://rightjs.org/) v2.2+
|
||||
|
||||
``` html
|
||||
<script src="http://www.yourwebsite.com/history.js/scripts/bundled/html4+html5/right.history.js"></script>
|
||||
```
|
||||
|
||||
- For [Zepto](http://zeptojs.com/) v0.5+
|
||||
|
||||
``` html
|
||||
<script src="http://www.yourwebsite.com/history.js/scripts/bundled/html4+html5/zepto.history.js"></script>
|
||||
```
|
||||
|
||||
- For everything else
|
||||
|
||||
``` html
|
||||
<script src="http://www.yourwebsite.com/history.js/scripts/bundled/html4+html5/native.history.js"></script>
|
||||
```
|
||||
|
||||
> Note: If you want to only support HTML5 Browsers and not HTML4 Browsers (so no hash fallback support) then just change the `/html4+html5/` part in the urls to just `/html5/`. [Why supporting HTML4 browsers could be either good or bad based on my app's use cases](https://github.com/balupton/history.js/wiki/Intelligent-State-Handling)
|
||||
|
||||
|
||||
## Get Updates
|
||||
|
||||
- For Commit RSS/Atom Updates:
|
||||
- You can subscribe via the [GitHub Commit Atom Feed](http://feeds.feedburner.com/historyjs)
|
||||
- For GitHub News Feed Updates:
|
||||
- You can click the "watch" button up the top right of History.js's [GitHub Project Page](https://github.com/balupton/history.js)
|
||||
|
||||
|
||||
## Get Support
|
||||
|
||||
- History.js is maintained by people like you. If you find a bug, report it to the [GitHub Issue Tracker](https://github.com/balupton/history.js/issues). If you've fixed a bug submit a [Pull Request](https://github.com/balupton/history.js/pulls) and add your fork to the [Network Wiki Page](https://github.com/balupton/history.js/wiki/Network).
|
||||
|
||||
- If you would like paid support and trainings, or have job offers, then refer to the [Network Wiki Page](https://github.com/balupton/history.js/wiki/Network). If you are qualified with History.js, then be sure to add your details to that page too.
|
||||
|
||||
- If your company uses History.js on your projects, and would like to see it grow and prosper (better documentation, bugfixes, upgrades, maintenance, etc.) and would love to become a corporate sponsor then do email sponsor@bevry.me
|
||||
|
||||
- If you would like free support for History.js, then [post your question](http://stackoverflow.com/questions/ask) on [Stackoverflow](http://stackoverflow.com/about) and be sure to use the `history.js` tag when asking your question.
|
||||
|
||||
- If you've created a website that uses History.js, or know of one. Then be sure to add it to the [Showcase Wiki Page](https://github.com/balupton/history.js/wiki/Showcase).
|
||||
|
||||
- If you'd love to +1 or like this project, then be sure to tweet about it and click the "watch" button up the top of its [Project Page](https://github.com/balupton/history.js).
|
||||
|
||||
- For anything else, refer to the [History.js GitHub Wiki Site](https://github.com/balupton/history.js/wiki).
|
||||
|
||||
Thanks! every bit of help really does make a difference!
|
||||
|
||||
|
||||
## Browsers: Tested and Working In
|
||||
|
||||
### HTML5 Browsers
|
||||
|
||||
- Firefox 4+
|
||||
- Chrome 8+
|
||||
- Opera 11.5
|
||||
- Safari 5.0+
|
||||
- Safari iOS 4.3+
|
||||
|
||||
### HTML4 Browsers
|
||||
|
||||
- IE 6, 7, 8, 9
|
||||
- Firefox 3
|
||||
- Opera 10, 11.0
|
||||
- Safari 4
|
||||
- Safari iOS 4.2, 4.1, 4.0, 3.2
|
||||
|
||||
|
||||
## Exposed API
|
||||
|
||||
### Functions
|
||||
|
||||
- `History.pushState(data,title,url)` <br/> Pushes a new state to the browser; `data` can be null or an object, `title` can be null or a string, `url` must be a string
|
||||
- `History.replaceState(data,title,url)` <br/> Replaces the existing state with a new state to the browser; `data` can be null or an object, `title` can be null or a string, `url` must be a string
|
||||
- `History.getState()` <br/> Gets the current state of the browser, returns an object with `data`, `title` and `url`
|
||||
- `History.getHash()` <br/> Gets the current hash of the browser
|
||||
- `History.Adapter.bind(element,event,callback)` <br/> A framework independent event binder, you may either use this or your framework's native event binder.
|
||||
- `History.Adapter.trigger(element,event)` <br/> A framework independent event trigger, you may either use this or your framework's native event trigger.
|
||||
- `History.Adapter.onDomLoad(callback)` <br/> A framework independent onDomLoad binder, you may either use this or your framework's native onDomLoad binder.
|
||||
- `History.back()` <br/> Go back once through the history (same as hitting the browser's back button)
|
||||
- `History.forward()` <br/> Go forward once through the history (same as hitting the browser's forward button)
|
||||
- `History.go(X)` <br/> If X is negative go back through history X times, if X is positive go forwards through history X times
|
||||
- `History.log(...)` <br/> Logs messages to the console, the log element, and fallbacks to alert if neither of those two exist
|
||||
- `History.debug(...)` <br/> Same as `History.log` but only runs if `History.debug.enable === true`
|
||||
|
||||
### Events
|
||||
|
||||
- `window.onstatechange` <br/> Fired when the state of the page changes (does not include hash changes)
|
||||
- `window.onanchorchange` <br/> Fired when the anchor of the page changes (does not include state hashes)
|
||||
|
||||
|
||||
## Notes on Compatibility
|
||||
|
||||
- History.js **solves** the following browser bugs:
|
||||
- HTML5 Browsers
|
||||
- Chrome 8 sometimes does not contain the correct state data when traversing back to the initial state
|
||||
- Safari 5, Safari iOS 4 and Firefox 3 and 4 do not fire the `onhashchange` event when the page is loaded with a hash
|
||||
- Safari 5 and Safari iOS 4 do not fire the `onpopstate` event when the hash has changed unlike the other browsers
|
||||
- Safari 5 and Safari iOS 4 fail to return to the correct state once a hash is replaced by a `replaceState` call / [bug report](https://bugs.webkit.org/show_bug.cgi?id=56249)
|
||||
- Safari 5 and Safari iOS 4 sometimes fail to apply the state change under busy conditions / [bug report](https://bugs.webkit.org/show_bug.cgi?id=42940)
|
||||
- Google Chrome 8,9,10 and Firefox 4 prior to the RC will always fire `onpopstate` once the page has loaded / [change recommendation](http://hacks.mozilla.org/2011/03/history-api-changes-in-firefox-4/)
|
||||
- Safari iOS 4.0, 4.1, 4.2 have a working HTML5 History API - although the actual back buttons of the browsers do not work, therefore we treat them as HTML4 browsers
|
||||
- None of the HTML5 browsers actually utilise the `title` argument to the `pushState` and `replaceState` calls
|
||||
- HTML4 Browsers
|
||||
- Old browsers like MSIE 6,7 and Firefox 2 do not have a `onhashchange` event
|
||||
- MSIE 6 and 7 sometimes do not apply a hash even it was told to (requiring a second call to the apply function)
|
||||
- Non-Opera HTML4 browsers sometimes do not apply the hash when the hash is not `urlencoded`
|
||||
- All Browsers
|
||||
- State data and titles do not persist once the site is left and then returned (includes page refreshes)
|
||||
- State titles are never applied to the `document.title`
|
||||
- ReplaceState functionality is emulated in HTML4 browsers by discarding the replaced state, so when the discarded state is accessed it is skipped using the appropriate `History.back()` / `History.forward()` call
|
||||
- Data persistance and synchronisation works like so: Every second or so, the SUIDs and URLs of the states will synchronise between the store and the local session. When a new session opens a familiar state (via the SUID or the URL) and it is not found locally then it will attempt to load the last known stored state with that information.
|
||||
- URLs will be unescaped to the maximum, so for instance the URL `?key=a%20b%252c` will become `?key=a b c`. This is to ensure consistency between browser url encodings.
|
||||
- Changing the hash of the page causes `onpopstate` to fire (this is expected/standard functionality). To ensure correct compatibility between HTML5 and HTML4 browsers the following events have been created:
|
||||
- `window.onstatechange`: this is the same as the `onpopstate` event except it does not fire for traditional anchors
|
||||
- `window.onanchorchange`: this is the same as the `onhashchange` event except it does not fire for states
|
||||
- Known Issues
|
||||
- Opera 11 fails to create history entries when under stressful loads (events fire perfectly, just the history events fail) - there is nothing we can do about this
|
||||
- Mercury iOS fails to apply url changes (hashes and HTML5 History API states) - there is nothing we can do about this
|
||||
|
||||
|
||||
|
||||
## History
|
||||
|
||||
You can discover the history inside the [History.md](https://github.com/balupton/history.js/blob/master/History.md#files) file
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Licensed under the [New BSD License](http://opensource.org/licenses/BSD-3-Clause)
|
||||
<br/>Copyright © 2011-2012 [Benjamin Arthur Lupton](http://balupton.com)
|
281
js/libraries/balupton-history/buildr.coffee
Executable file
281
js/libraries/balupton-history/buildr.coffee
Executable file
@ -0,0 +1,281 @@
|
||||
# Requires
|
||||
buildr = require 'buildr'
|
||||
util = require 'util'
|
||||
|
||||
# Options
|
||||
options =
|
||||
watch: false
|
||||
compress: true
|
||||
|
||||
# Configs
|
||||
configs =
|
||||
standard:
|
||||
# Options
|
||||
name: 'standard'
|
||||
watch: options.watch
|
||||
|
||||
# Paths
|
||||
srcPath: __dirname+'/scripts/uncompressed'
|
||||
outPath: __dirname+'/scripts/compressed'
|
||||
|
||||
# Checking
|
||||
checkScripts: true
|
||||
jshintOptions:
|
||||
browser: true
|
||||
laxbreak: true
|
||||
boss: true
|
||||
undef: true
|
||||
onevar: true
|
||||
strict: true
|
||||
noarg: true
|
||||
|
||||
# Compression (without outPath only the generated bundle files are compressed)
|
||||
compressScripts: options.compress # Array or true or false
|
||||
|
||||
other: [
|
||||
|
||||
# -----------------------------
|
||||
# JQUERY
|
||||
|
||||
{
|
||||
# Options
|
||||
name: 'html4+html5+jquery'
|
||||
watch: options.watch
|
||||
|
||||
# Paths
|
||||
srcPath: __dirname+'/scripts/uncompressed'
|
||||
|
||||
# Compression (without outPath only the generated bundle files are compressed)
|
||||
compressScripts: options.compress # Array or true or false
|
||||
|
||||
# Order
|
||||
scriptsOrder: [
|
||||
'json2.js'
|
||||
'history.adapter.jquery.js'
|
||||
'history.html4.js'
|
||||
'history.js'
|
||||
]
|
||||
|
||||
# Bundling
|
||||
bundleScriptPath: __dirname+'/scripts/bundled/html4+html5/jquery.history.js'
|
||||
}
|
||||
{
|
||||
# Options
|
||||
name: 'html5+jquery'
|
||||
watch: options.watch
|
||||
|
||||
# Paths
|
||||
srcPath: __dirname+'/scripts/uncompressed'
|
||||
|
||||
# Compression (without outPath only the generated bundle files are compressed)
|
||||
compressScripts: options.compress # Array or true or false
|
||||
|
||||
# Order
|
||||
scriptsOrder: [
|
||||
'history.adapter.jquery.js'
|
||||
'history.js'
|
||||
]
|
||||
|
||||
# Bundling
|
||||
bundleScriptPath: __dirname+'/scripts/bundled/html5/jquery.history.js'
|
||||
}
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# MOOTOOLS
|
||||
|
||||
{
|
||||
# Options
|
||||
name: 'html4+html5+mootools'
|
||||
watch: options.watch
|
||||
|
||||
# Paths
|
||||
srcPath: __dirname+'/scripts/uncompressed'
|
||||
|
||||
# Compression (without outPath only the generated bundle files are compressed)
|
||||
compressScripts: options.compress # Array or true or false
|
||||
|
||||
# Order
|
||||
scriptsOrder: [
|
||||
'json2.js'
|
||||
'history.adapter.mootools.js'
|
||||
'history.html4.js'
|
||||
'history.js'
|
||||
]
|
||||
|
||||
# Bundling
|
||||
bundleScriptPath: __dirname+'/scripts/bundled/html4+html5/mootools.history.js'
|
||||
}
|
||||
{
|
||||
# Options
|
||||
name: 'html5+mootools'
|
||||
watch: options.watch
|
||||
|
||||
# Paths
|
||||
srcPath: __dirname+'/scripts/uncompressed'
|
||||
|
||||
# Compression (without outPath only the generated bundle files are compressed)
|
||||
compressScripts: options.compress # Array or true or false
|
||||
|
||||
# Order
|
||||
scriptsOrder: [
|
||||
'history.adapter.mootools.js'
|
||||
'history.js'
|
||||
]
|
||||
|
||||
# Bundling
|
||||
bundleScriptPath: __dirname+'/scripts/bundled/html5/mootools.history.js'
|
||||
}
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# NATIVE
|
||||
|
||||
{
|
||||
# Options
|
||||
name: 'html4+html5+native'
|
||||
watch: options.watch
|
||||
|
||||
# Paths
|
||||
srcPath: __dirname+'/scripts/uncompressed'
|
||||
|
||||
# Compression (without outPath only the generated bundle files are compressed)
|
||||
compressScripts: options.compress # Array or true or false
|
||||
|
||||
# Order
|
||||
scriptsOrder: [
|
||||
'json2.js'
|
||||
'history.adapter.native.js'
|
||||
'history.html4.js'
|
||||
'history.js'
|
||||
]
|
||||
|
||||
# Bundling
|
||||
bundleScriptPath: __dirname+'/scripts/bundled/html4+html5/native.history.js'
|
||||
}
|
||||
{
|
||||
# Options
|
||||
name: 'html5+native'
|
||||
watch: options.watch
|
||||
|
||||
# Paths
|
||||
srcPath: __dirname+'/scripts/uncompressed'
|
||||
|
||||
# Compression (without outPath only the generated bundle files are compressed)
|
||||
compressScripts: options.compress # Array or true or false
|
||||
|
||||
# Order
|
||||
scriptsOrder: [
|
||||
'history.adapter.native.js'
|
||||
'history.js'
|
||||
]
|
||||
|
||||
# Bundling
|
||||
bundleScriptPath: __dirname+'/scripts/bundled/html5/native.history.js'
|
||||
}
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# RIGHT.JS
|
||||
|
||||
{
|
||||
# Options
|
||||
name: 'html4+html5+right'
|
||||
watch: options.watch
|
||||
|
||||
# Paths
|
||||
srcPath: __dirname+'/scripts/uncompressed'
|
||||
|
||||
# Compression (without outPath only the generated bundle files are compressed)
|
||||
compressScripts: options.compress # Array or true or false
|
||||
|
||||
# Order
|
||||
scriptsOrder: [
|
||||
'json2.js'
|
||||
'history.adapter.right.js'
|
||||
'history.html4.js'
|
||||
'history.js'
|
||||
]
|
||||
|
||||
# Bundling
|
||||
bundleScriptPath: __dirname+'/scripts/bundled/html4+html5/right.history.js'
|
||||
}
|
||||
{
|
||||
# Options
|
||||
name: 'html5+right'
|
||||
watch: options.watch
|
||||
|
||||
# Paths
|
||||
srcPath: __dirname+'/scripts/uncompressed'
|
||||
|
||||
# Compression (without outPath only the generated bundle files are compressed)
|
||||
compressScripts: options.compress # Array or true or false
|
||||
|
||||
# Order
|
||||
scriptsOrder: [
|
||||
'history.adapter.right.js'
|
||||
'history.js'
|
||||
]
|
||||
|
||||
# Bundling
|
||||
bundleScriptPath: __dirname+'/scripts/bundled/html5/right.history.js'
|
||||
}
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# ZEPTO
|
||||
|
||||
{
|
||||
# Options
|
||||
name: 'html4+html5+zepto'
|
||||
watch: options.watch
|
||||
|
||||
# Paths
|
||||
srcPath: __dirname+'/scripts/uncompressed'
|
||||
|
||||
# Compression (without outPath only the generated bundle files are compressed)
|
||||
compressScripts: options.compress # Array or true or false
|
||||
|
||||
# Order
|
||||
scriptsOrder: [
|
||||
'json2.js'
|
||||
'history.adapter.zepto.js'
|
||||
'history.html4.js'
|
||||
'history.js'
|
||||
]
|
||||
|
||||
# Bundling
|
||||
bundleScriptPath: __dirname+'/scripts/bundled/html4+html5/zepto.history.js'
|
||||
}
|
||||
{
|
||||
# Options
|
||||
name: 'html5+zepto'
|
||||
watch: options.watch
|
||||
|
||||
# Paths
|
||||
srcPath: __dirname+'/scripts/uncompressed'
|
||||
|
||||
# Compression (without outPath only the generated bundle files are compressed)
|
||||
compressScripts: options.compress # Array or true or false
|
||||
|
||||
# Order
|
||||
scriptsOrder: [
|
||||
'history.adapter.zepto.js'
|
||||
'history.js'
|
||||
]
|
||||
|
||||
# Bundling
|
||||
bundleScriptPath: __dirname+'/scripts/bundled/html5/zepto.history.js'
|
||||
}
|
||||
]
|
||||
|
||||
# Standard
|
||||
standardConfig = configs.standard
|
||||
standardConfig.successHandler = ->
|
||||
for config in configs.other
|
||||
buildrInstance = buildr.createInstance config
|
||||
buildrInstance.process()
|
||||
|
||||
# Process
|
||||
standardBuildr = buildr.createInstance configs.standard
|
||||
standardBuildr.process()
|
58
js/libraries/balupton-history/demo/bcherry-orig.html
Executable file
58
js/libraries/balupton-history/demo/bcherry-orig.html
Executable file
@ -0,0 +1,58 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
|
||||
<title>WebKit is Dropping HTML5 "popstate" Events</title>
|
||||
|
||||
<link rel="stylesheet" href="/static/lib/css/blueprint/blueprint.min.css" media="screen, projection" />
|
||||
<link rel="stylesheet" href="/static/lib/css/blueprint/print.min.css" media="print" />
|
||||
<!--[if lt IE 8]>
|
||||
<link rel="stylesheet" href="/static/lib/css/blueprint/ie.min.css" media="screen, projection">
|
||||
<![endif]-->
|
||||
<link href="/static/lib/css/bcherry.css" rel="stylesheet" media="screen" />
|
||||
<style>
|
||||
#n {
|
||||
font-size: 48px;
|
||||
}
|
||||
p {
|
||||
padding: 0 20px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type="text/javascript" src="../vendor/jquery.js"></script>
|
||||
<script type="text/javascript" src="../scripts/uncompressed/history.adapter.jquery.js"></script>
|
||||
<script type="text/javascript" src="../scripts/uncompressed/history.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="n"></div>
|
||||
<p>There's a bug in the HTML5 "popstate" event, as implemented in WebKit (Safari and Chrome). View this page in one of those browsers. Your browser has had history entries added from #0 to #19 (you should start at #19). Hitting back/forward will navigate through these. On each URL, the large number above should reflect the hash value. If you hit back/forward quickly, you'll notice that your number gets out of sync with the URL. This is because WebKit is dropping popstate events (they are not firing). It seems to happen when outbound network requests are in progress when the user navigates in their browser happens. In this case, your browser is downloading an image that takes 1s to serve on every popstate, so you'll have to wait 1s between backs/forwards to have the feature work correctly. You could also cause constant network traffic by putting an image download in a setInterval, in which case your popstate events will never fire. This implementation simulates an AJAX application that makes a network request when you navigate between URLs using pushState/popstate. View the source for more info.</p>
|
||||
<p>This was filed as <a href="https://bugs.webkit.org/show_bug.cgi?id=42940">Bug 42940</a> with WebKit on July 24, 2010. The Firefox 4 beta does not have this bug, which is good news.</p>
|
||||
<p>This is put together by <a href="http://www.adequatelygood.com">Ben Cherry</a>. Ben is a front-end engineer at <a href="http://twitter.com/">Twitter</a>, and you can follow him at <a href="http://twitter.com/bcherry">@bcherry</a>.</p>
|
||||
<script>
|
||||
// Bind to popstate
|
||||
$(window).bind("popstate", function(e) {
|
||||
var State = e.state;
|
||||
|
||||
// log that this event was fired, and the current URL
|
||||
if (window.console && window.console.log) {
|
||||
console.log("popstate", State, window.location.href);
|
||||
}
|
||||
// update the page
|
||||
$("#n").text(typeof State.n !== 'undefined' ? State.n : document.location.href);
|
||||
|
||||
// Make an outbound image request that will take 1s. This request seems to be the cause of dropped popstates.
|
||||
// Removing this, or replacing it with something else, avoids the issue. Even if it's replaced with slow, blocking code (i.e. 1s of execution) events are not dropped.
|
||||
(new Image()).src = "http://www.bcherry.net/playground/pushstate.jpg";
|
||||
});
|
||||
|
||||
// Seed the browser history
|
||||
for (var i = 0; i < 20; i++) {
|
||||
window.history.pushState({n:i}, i, "?" + i);
|
||||
$("#n").text(i);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
62
js/libraries/balupton-history/demo/bcherry.html
Executable file
62
js/libraries/balupton-history/demo/bcherry.html
Executable file
@ -0,0 +1,62 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
|
||||
<title>WebKit is Dropping HTML5 "popstate" Events</title>
|
||||
|
||||
<link rel="stylesheet" href="/static/lib/css/blueprint/blueprint.min.css" media="screen, projection" />
|
||||
<link rel="stylesheet" href="/static/lib/css/blueprint/print.min.css" media="print" />
|
||||
<!--[if lt IE 8]>
|
||||
<link rel="stylesheet" href="/static/lib/css/blueprint/ie.min.css" media="screen, projection">
|
||||
<![endif]-->
|
||||
<link href="/static/lib/css/bcherry.css" rel="stylesheet" media="screen" />
|
||||
<style>
|
||||
#n {
|
||||
font-size: 48px;
|
||||
}
|
||||
p {
|
||||
padding: 0 20px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type="text/javascript" src="../vendor/jquery.js"></script>
|
||||
<script type="text/javascript" src="../scripts/uncompressed/history.adapter.jquery.js"></script>
|
||||
<script type="text/javascript" src="../scripts/uncompressed/history.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="n"></div>
|
||||
<p>There's a bug in the HTML5 "popstate" event, as implemented in WebKit (Safari and Chrome). View this page in one of those browsers. Your browser has had history entries added from #0 to #19 (you should start at #19). Hitting back/forward will navigate through these. On each URL, the large number above should reflect the hash value. If you hit back/forward quickly, you'll notice that your number gets out of sync with the URL. This is because WebKit is dropping popstate events (they are not firing). It seems to happen when outbound network requests are in progress when the user navigates in their browser happens. In this case, your browser is downloading an image that takes 1s to serve on every popstate, so you'll have to wait 1s between backs/forwards to have the feature work correctly. You could also cause constant network traffic by putting an image download in a setInterval, in which case your popstate events will never fire. This implementation simulates an AJAX application that makes a network request when you navigate between URLs using pushState/popstate. View the source for more info.</p>
|
||||
<p>This was filed as <a href="https://bugs.webkit.org/show_bug.cgi?id=42940">Bug 42940</a> with WebKit on July 24, 2010. The Firefox 4 beta does not have this bug, which is good news.</p>
|
||||
<p>This is put together by <a href="http://www.adequatelygood.com">Ben Cherry</a>. Ben is a front-end engineer at <a href="http://twitter.com/">Twitter</a>, and you can follow him at <a href="http://twitter.com/bcherry">@bcherry</a>.</p>
|
||||
<p>This bug was fixed in <a href="http://github.com/balupton/history.js">History.js</a> by <a href="http://balupton.com">Benjamin Lupton</a>. Benjamin is a freelance web 2.0 consultant, and you can follow him at <a href="http://twitter.com/balupton">@balupton</a>.</p>
|
||||
<script>
|
||||
// Prepare
|
||||
window.History.debug.enable = true;
|
||||
|
||||
// Bind to popstate
|
||||
$(window).bind("statechange", function(e) {
|
||||
var State = window.History.getState();
|
||||
|
||||
// log that this event was fired, and the current URL
|
||||
if (window.console && window.console.log) {
|
||||
console.log("popstate", State, window.location.href);
|
||||
}
|
||||
// update the page
|
||||
$("#n").text(typeof State.data.n !== 'undefined' ? State.data.n : State.url);
|
||||
|
||||
// Make an outbound image request that will take 1s. This request seems to be the cause of dropped popstates.
|
||||
// Removing this, or replacing it with something else, avoids the issue. Even if it's replaced with slow, blocking code (i.e. 1s of execution) events are not dropped.
|
||||
(new Image()).src = "http://www.bcherry.net/playground/pushstate.jpg";
|
||||
});
|
||||
|
||||
// Seed the browser history
|
||||
for (var i = 0; i < 20; i++) {
|
||||
window.History.pushState({n:i}, i, "?" + i);
|
||||
$("#n").text(i);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
37
js/libraries/balupton-history/demo/chrome.html
Executable file
37
js/libraries/balupton-history/demo/chrome.html
Executable file
@ -0,0 +1,37 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Chrome History API Data Artifact</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>This demo demonstrates an issue with Google Chrome versions 8-10 (possibly 11) where if you push a state with data, then do history.back to the initial state, the event.state will contain the pushed states data instead of being null.</p>
|
||||
<p>Note: The issue requires a clean history list, as such this should always be opened in a new tab/window where there are no prior history items.</p>
|
||||
<p>Reported by <a href="http://balupton.com">Benjamin Lupton</a> author of <a href="http://github.com/balupton/history.js">History.js</a></p>
|
||||
<button id="bug">bug</button>
|
||||
<button id="reset">reset</button>
|
||||
<textarea id="log" style="width:100%;height:200px;margin-top:1em;"></textarea>
|
||||
<script type="text/javascript">
|
||||
(function(){
|
||||
|
||||
window.onpopstate = function(event) {
|
||||
var message = ("onpopstate: location: " + document.location.href + ", data: " + JSON.stringify(event.state));
|
||||
document.getElementById('log').innerHTML += message+"\n\n";
|
||||
};
|
||||
|
||||
document.getElementById('bug').onclick = function(){
|
||||
setTimeout(function(){
|
||||
history.pushState({state:'new'},'New State','?new');
|
||||
},1e3);
|
||||
|
||||
setTimeout(function(){
|
||||
history.back();
|
||||
},2e3);
|
||||
};
|
||||
|
||||
document.getElementById('reset').onclick = function(){
|
||||
document.location.href = document.location.href.replace(/[\#\?].*/,"");
|
||||
};
|
||||
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
86
js/libraries/balupton-history/demo/index.html
Executable file
86
js/libraries/balupton-history/demo/index.html
Executable file
@ -0,0 +1,86 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>
|
||||
History.js
|
||||
</title>
|
||||
</head>
|
||||
<body style="padding-bottom:40px">
|
||||
<!-- Scripts -->
|
||||
<script>if ( typeof window.JSON === 'undefined' ) { document.write('<script src="../scripts/uncompressed/json2.js"><\/script>'); }</script>
|
||||
<script src="../vendor/jquery.js"></script>
|
||||
<script src="../scripts/bundled/html4+html5/jquery.history.js"></script>
|
||||
|
||||
<!-- HTML -->
|
||||
<div id="wrap">
|
||||
<!-- Intro -->
|
||||
<h1><a href="https://github.com/balupton/History.js">History.js</a> by <a href="http://balupton.com">Benjamin Lupton</a></h1>
|
||||
<p>History.js gracefully supports the <a href="https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history">HTML5 History/State APIs</a> (pushState, replaceState, onPopState) in all browsers. Including continued support for data, titles, replaceState. Supports <a href="http://jquery.com/">jQuery</a>, <a href="http://mootools.net">MooTools</a> and <a href="http://prototypejs.org">Prototype</a>. For HTML5 browsers this means that you can modify the URL directly, without needing to use hashes anymore. For HTML4 browsers it will revert back to using the old onhashchange functionality.</p>
|
||||
|
||||
<!-- Textarea for Logging -->
|
||||
<textarea id="log" style="width:100%;height:400px"></textarea>
|
||||
|
||||
<!-- Note -->
|
||||
<p>Click through the buttons in order and you'll get the results demonstrated in the <a href="../README.md">README.md</a> file.</p>
|
||||
|
||||
<!-- Buttons -->
|
||||
<ul id="buttons">
|
||||
</ul>
|
||||
|
||||
<!-- Our Script -->
|
||||
<script>
|
||||
(function(window,undefined){
|
||||
|
||||
// Check Location
|
||||
if ( document.location.protocol === 'file:' ) {
|
||||
alert('The HTML5 History API (and thus History.js) do not work on files, please upload it to a server.');
|
||||
}
|
||||
|
||||
// Establish Variables
|
||||
var
|
||||
History = window.History, // Note: We are using a capital H instead of a lower h
|
||||
State = History.getState(),
|
||||
$log = $('#log');
|
||||
|
||||
// Log Initial State
|
||||
History.log('initial:', State.data, State.title, State.url);
|
||||
|
||||
// Bind to State Change
|
||||
History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
|
||||
// Log the State
|
||||
var State = History.getState(); // Note: We are using History.getState() instead of event.state
|
||||
History.log('statechange:', State.data, State.title, State.url);
|
||||
});
|
||||
|
||||
// Prepare Buttons
|
||||
var
|
||||
buttons = document.getElementById('buttons'),
|
||||
scripts = [
|
||||
'History.pushState({state:1,rand:Math.random()}, "State 1", "?state=1"); // logs {state:1,rand:"some random value"}, "State 1", "?state=1"',
|
||||
'History.pushState({state:2,rand:Math.random()}, "State 2", "?state=2"); // logs {state:2,rand:"some random value"}, "State 2", "?state=2"',
|
||||
'History.replaceState({state:3,rand:Math.random()}, "State 3", "?state=3"); // logs {state:3,rand:"some random value"}, "State 3", "?state=3"',
|
||||
'History.pushState(null, null, "?state=4"); // logs {}, "", "?state=4"',
|
||||
'History.back(); // logs {state:3}, "State 3", "?state=3"',
|
||||
'History.back(); // logs {state:1}, "State 1", "?state=1"',
|
||||
'History.back(); // logs {}, "The page you started at", "?"',
|
||||
'History.go(2); // logs {state:3}, "State 3", "?state=3"'
|
||||
],
|
||||
buttonsHTML = ''
|
||||
;
|
||||
|
||||
// Add Buttons
|
||||
for ( var i=0,n=scripts.length; i<n; ++i ) {
|
||||
var _script = scripts[i];
|
||||
buttonsHTML +=
|
||||
'<li><button onclick=\'javascript:'+_script+'\'>'+_script+'</button></li>';
|
||||
}
|
||||
buttons.innerHTML = buttonsHTML;
|
||||
|
||||
})(window);
|
||||
</script>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
43
js/libraries/balupton-history/demo/native-auto.html
Executable file
43
js/libraries/balupton-history/demo/native-auto.html
Executable file
@ -0,0 +1,43 @@
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
(function(){
|
||||
|
||||
window.onpopstate = function(event) {
|
||||
console.log("onpopstate: location: " + document.location.href + ", data: " + JSON.stringify(event.state));
|
||||
};
|
||||
window.onhashchange = function(event) {
|
||||
console.log("onhashchange: location: " + document.location.href);
|
||||
};
|
||||
|
||||
setTimeout(function(){
|
||||
history.pushState({page: 1}, "title 1", "?page=1");
|
||||
},1e3);
|
||||
setTimeout(function(){
|
||||
history.pushState({page: 2}, "title 2", "?page=2");
|
||||
},2e3);
|
||||
setTimeout(function(){
|
||||
history.replaceState({page: 3}, "title 3", "?page=3");
|
||||
},3e3);
|
||||
setTimeout(function(){
|
||||
document.location.hash = 'asd';
|
||||
},4e3);
|
||||
setTimeout(function(){
|
||||
history.back(); // alerts "location: http://example.com/example.html?page=3#asd, state: {"page":3}"
|
||||
},5e3);
|
||||
setTimeout(function(){
|
||||
history.back(); // alerts "location: http://example.com/example.html?page=1, state: {"page":1}"
|
||||
},6e3);
|
||||
setTimeout(function(){
|
||||
history.back(); // alerts "location: http://example.com/example.html, state: null
|
||||
},7e3);
|
||||
setTimeout(function(){
|
||||
history.go(2); // alerts "location: http://example.com/example.html?page=3, state: {"page":3}
|
||||
},8e3);
|
||||
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
62
js/libraries/balupton-history/demo/native.html
Executable file
62
js/libraries/balupton-history/demo/native.html
Executable file
@ -0,0 +1,62 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>HTML5 History API Demo</title>
|
||||
</head>
|
||||
<body>
|
||||
<textarea id="log" style="width:100%;height:400px;margin:1em;"></textarea>
|
||||
<div id="url" style="border:1px black dotted;height:1em;margin:1em;"></div>
|
||||
<div id="buttons" style="margin:1em;"></div>
|
||||
<script type="text/javascript">
|
||||
var $url = document.getElementById('url'), $log = document.getElementById('log');
|
||||
|
||||
window.onpopstate = function(event) {
|
||||
var message =
|
||||
"onpopstate: "+
|
||||
"location: " + location.href + ", " +
|
||||
"data: " + JSON.stringify(event.state) +
|
||||
"\n\n"
|
||||
;
|
||||
|
||||
$url.innerHTML = location.href;
|
||||
$log.innerHTML += message;
|
||||
console.log(message);
|
||||
};
|
||||
|
||||
window.onhashchange = function(event) {
|
||||
var message =
|
||||
"onhashchange: "+
|
||||
"location: " + location.href + ", "+
|
||||
"hash: " + location.hash +
|
||||
"\n\n"
|
||||
;
|
||||
|
||||
$url.innerHTML = location.href;
|
||||
$log.innerHTML += message;
|
||||
console.log(message);
|
||||
};
|
||||
|
||||
// Prepare Buttons
|
||||
var
|
||||
buttons = document.getElementById('buttons'),
|
||||
scripts = [
|
||||
'history.pushState({state:1}, "State 1", "?state=1");',
|
||||
'history.pushState({state:2}, "State 2", "?state=2");',
|
||||
'history.replaceState({state:3}, "State 3", "?state=3");',
|
||||
'location.hash = Math.random();',
|
||||
'history.back();',
|
||||
'history.forward();',
|
||||
'document.location.href = document.location.href.replace(/[\#\?].*/,"");'
|
||||
],
|
||||
buttonsHTML = ''
|
||||
;
|
||||
|
||||
// Add Buttons
|
||||
for ( var i=0,n=scripts.length; i<n; ++i ) {
|
||||
var _script = scripts[i];
|
||||
buttonsHTML +=
|
||||
'<li><button onclick=\'javascript:'+_script+'\'>'+_script+'</button></li>';
|
||||
}
|
||||
buttons.innerHTML = buttonsHTML;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
23
js/libraries/balupton-history/demo/navigator.html
Executable file
23
js/libraries/balupton-history/demo/navigator.html
Executable file
@ -0,0 +1,23 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>
|
||||
Navigator Output
|
||||
</title>
|
||||
<style>
|
||||
label { font-weight:bold; }
|
||||
label:after { content: ":"; margin-right:5px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="nav"></div>
|
||||
<script>
|
||||
var nav = document.getElementById('nav'), i,v;
|
||||
for ( i in navigator ) {
|
||||
var v = navigator[i];
|
||||
nav.innerHTML += '<div><label>'+i+'</label>'+v+'</div>';
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
61
js/libraries/balupton-history/demo/safari.html
Executable file
61
js/libraries/balupton-history/demo/safari.html
Executable file
@ -0,0 +1,61 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Safari Hash ReplaceState History Traversal Bug</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>This demo demonstrates an issue with Safari 5.0.4 (6533.20.27) handing of hashes and replace state. When a hash is set, and then replaced using replaceState the history list are then broken, when traversing back the hash does not change.</p>
|
||||
<p>Note: The issue requires a clean history list, as such this should always be opened in a new tab/window where there are no prior history items.</p>
|
||||
<p>Reported by <a href="http://balupton.com">Benjamin Lupton</a> author of <a href="http://github.com/balupton/history.js">History.js</a></p>
|
||||
<button id="bug">bug</button>
|
||||
<button id="workaround">workaround</button>
|
||||
<button id="reset">reset</button>
|
||||
<textarea id="log" style="width:100%;height:200px;margin-top:1em;"></textarea>
|
||||
<script type="text/javascript">
|
||||
(function(){
|
||||
|
||||
window.onpopstate = function(event) {
|
||||
var message = ("onpopstate: location: " + document.location.href);
|
||||
document.getElementById('log').innerHTML += message+"\n\n";
|
||||
};
|
||||
|
||||
window.onhashchange = function(event) {
|
||||
var message = ("onhashchange: location: " + document.location.href);
|
||||
document.getElementById('log').innerHTML += message+"\n\n";
|
||||
};
|
||||
|
||||
document.getElementById('bug').onclick = function(){
|
||||
setTimeout(function(){
|
||||
document.location.hash = Math.random();
|
||||
},1e3);
|
||||
|
||||
setTimeout(function(){
|
||||
history.replaceState(null,'','?blah');
|
||||
},2e3);
|
||||
|
||||
setTimeout(function(){
|
||||
history.back(); // should take us to the initial page, it doesn't
|
||||
},3e3);
|
||||
};
|
||||
|
||||
document.getElementById('workaround').onclick = function(){
|
||||
setTimeout(function(){
|
||||
history.pushState(null,'','#'+Math.random());
|
||||
},1e3);
|
||||
|
||||
setTimeout(function(){
|
||||
history.replaceState(null,'','?blah');
|
||||
},2e3);
|
||||
|
||||
setTimeout(function(){
|
||||
history.back(); // will take us to the initial page
|
||||
},3e3);
|
||||
};
|
||||
|
||||
document.getElementById('reset').onclick = function(){
|
||||
document.location.href = document.location.href.replace(/[\#\?].*/,"");
|
||||
};
|
||||
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
10
js/libraries/balupton-history/license.txt
Executable file
10
js/libraries/balupton-history/license.txt
Executable file
@ -0,0 +1,10 @@
|
||||
Copyright (c) 2011, Benjamin Arthur Lupton
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
• Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
• Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
• Neither the name of Benjamin Arthur Lupton nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
57
js/libraries/balupton-history/package.json
Executable file
57
js/libraries/balupton-history/package.json
Executable file
@ -0,0 +1,57 @@
|
||||
{
|
||||
"name": "history.js",
|
||||
"version": "1.7.1-r2",
|
||||
"description": "History.js gracefully supports the HTML5 History/State APIs (pushState, replaceState, onPopState) in all browsers. Including continued support for data, titles, replaceState. Supports jQuery, MooTools and Prototype. For HTML5 browsers this means that you can modify the URL directly, without needing to use hashes anymore. For HTML4 browsers it will revert back to using the old onhashchange functionality.",
|
||||
"homepage": "https://github.com/balupton/history.js",
|
||||
"keywords": [
|
||||
"javascript",
|
||||
"html5 history api",
|
||||
"hashchange",
|
||||
"popstate",
|
||||
"pushstate",
|
||||
"replacestate",
|
||||
"hashes",
|
||||
"hashbang"
|
||||
],
|
||||
"author": {
|
||||
"name": "Benjamin Lupton",
|
||||
"email": "b@lupton.cc",
|
||||
"web": "http://balupton.com"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "Benjamin Lupton",
|
||||
"email": "b@lupton.cc",
|
||||
"web": "http://balupton.com"
|
||||
}
|
||||
],
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Benjamin Lupton",
|
||||
"email": "b@lupton.cc",
|
||||
"web": "http://balupton.com"
|
||||
}
|
||||
],
|
||||
"bugs": {
|
||||
"web": "https://github.com/balupton/history.js/issues"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"type": "New-BSD",
|
||||
"url": "http://creativecommons.org/licenses/BSD/"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "http://github.com/balupton/history.js.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"buildr": "0.8.x"
|
||||
},
|
||||
"engines": {
|
||||
},
|
||||
"directories": {
|
||||
"out": "./scripts/compressed",
|
||||
"src": "./scripts/uncompressed"
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
js/libraries/balupton-history/scripts/bundled/html5/jquery.history.js
Executable file
1
js/libraries/balupton-history/scripts/bundled/html5/jquery.history.js
Executable file
File diff suppressed because one or more lines are too long
1
js/libraries/balupton-history/scripts/bundled/html5/mootools.history.js
Executable file
1
js/libraries/balupton-history/scripts/bundled/html5/mootools.history.js
Executable file
File diff suppressed because one or more lines are too long
1
js/libraries/balupton-history/scripts/bundled/html5/native.history.js
Executable file
1
js/libraries/balupton-history/scripts/bundled/html5/native.history.js
Executable file
File diff suppressed because one or more lines are too long
1
js/libraries/balupton-history/scripts/bundled/html5/right.history.js
Executable file
1
js/libraries/balupton-history/scripts/bundled/html5/right.history.js
Executable file
File diff suppressed because one or more lines are too long
1
js/libraries/balupton-history/scripts/bundled/html5/zepto.history.js
Executable file
1
js/libraries/balupton-history/scripts/bundled/html5/zepto.history.js
Executable file
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@
|
||||
(function(a,b){"use strict";var c=a.History=a.History||{},d=a.jQuery;if(typeof c.Adapter!="undefined")throw new Error("History.js Adapter has already been loaded...");c.Adapter={bind:function(a,b,c){d(a).bind(b,c)},trigger:function(a,b,c){d(a).trigger(b,c)},extractEventData:function(a,c,d){var e=c&&c.originalEvent&&c.originalEvent[a]||d&&d[a]||b;return e},onDomLoad:function(a){d(a)}},typeof c.init!="undefined"&&c.init()})(window)
|
@ -0,0 +1 @@
|
||||
(function(a,b){"use strict";var c=a.History=a.History||{},d=a.MooTools,e=a.Element;if(typeof c.Adapter!="undefined")throw new Error("History.js Adapter has already been loaded...");Object.append(e.NativeEvents,{popstate:2,hashchange:2}),c.Adapter={bind:function(a,b,c){var d=typeof a=="string"?document.id(a):a;d.addEvent(b,c)},trigger:function(a,b,c){var d=typeof a=="string"?document.id(a):a;d.fireEvent(b,c)},extractEventData:function(a,c){var d=c&&c.event&&c.event[a]||c&&c[a]||b;return d},onDomLoad:function(b){a.addEvent("domready",b)}},typeof c.init!="undefined"&&c.init()})(window)
|
@ -0,0 +1 @@
|
||||
(function(a,b){"use strict";var c=a.History=a.History||{};if(typeof c.Adapter!="undefined")throw new Error("History.js Adapter has already been loaded...");c.Adapter={handlers:{},_uid:1,uid:function(a){return a._uid||(a._uid=c.Adapter._uid++)},bind:function(a,b,d){var e=c.Adapter.uid(a);c.Adapter.handlers[e]=c.Adapter.handlers[e]||{},c.Adapter.handlers[e][b]=c.Adapter.handlers[e][b]||[],c.Adapter.handlers[e][b].push(d),a["on"+b]=function(a,b){return function(d){c.Adapter.trigger(a,b,d)}}(a,b)},trigger:function(a,b,d){d=d||{};var e=c.Adapter.uid(a),f,g;c.Adapter.handlers[e]=c.Adapter.handlers[e]||{},c.Adapter.handlers[e][b]=c.Adapter.handlers[e][b]||[];for(f=0,g=c.Adapter.handlers[e][b].length;f<g;++f)c.Adapter.handlers[e][b][f].apply(this,[d])},extractEventData:function(a,c){var d=c&&c[a]||b;return d},onDomLoad:function(b){var c=a.setTimeout(function(){b()},2e3);a.onload=function(){clearTimeout(c),b()}}},typeof c.init!="undefined"&&c.init()})(window)
|
@ -0,0 +1 @@
|
||||
(function(a,b){"use strict";var c=a.History=a.History||{},d=a.document,e=a.RightJS,f=e.$;if(typeof c.Adapter!="undefined")throw new Error("History.js Adapter has already been loaded...");c.Adapter={bind:function(a,b,c){f(a).on(b,c)},trigger:function(a,b,c){f(a).fire(b,c)},extractEventData:function(a,c){var d=c&&c._&&c._[a]||b;return d},onDomLoad:function(a){f(d).onReady(a)}},typeof c.init!="undefined"&&c.init()})(window)
|
@ -0,0 +1 @@
|
||||
(function(a,b){"use strict";var c=a.History=a.History||{},d=a.Zepto;if(typeof c.Adapter!="undefined")throw new Error("History.js Adapter has already been loaded...");c.Adapter={bind:function(a,b,c){(new d(a)).bind(b,c)},trigger:function(a,b){(new d(a)).trigger(b)},extractEventData:function(a,c){var d=c&&c[a]||b;return d},onDomLoad:function(a){new d(a)}},typeof c.init!="undefined"&&c.init()})(window)
|
1
js/libraries/balupton-history/scripts/compressed/history.html4.js
Executable file
1
js/libraries/balupton-history/scripts/compressed/history.html4.js
Executable file
@ -0,0 +1 @@
|
||||
(function(a,b){"use strict";var c=a.document,d=a.setTimeout||d,e=a.clearTimeout||e,f=a.setInterval||f,g=a.History=a.History||{};if(typeof g.initHtml4!="undefined")throw new Error("History.js HTML4 Support has already been loaded...");g.initHtml4=function(){if(typeof g.initHtml4.initialized!="undefined")return!1;g.initHtml4.initialized=!0,g.enabled=!0,g.savedHashes=[],g.isLastHash=function(a){var b=g.getHashByIndex(),c;return c=a===b,c},g.saveHash=function(a){return g.isLastHash(a)?!1:(g.savedHashes.push(a),!0)},g.getHashByIndex=function(a){var b=null;return typeof a=="undefined"?b=g.savedHashes[g.savedHashes.length-1]:a<0?b=g.savedHashes[g.savedHashes.length+a]:b=g.savedHashes[a],b},g.discardedHashes={},g.discardedStates={},g.discardState=function(a,b,c){var d=g.getHashByState(a),e;return e={discardedState:a,backState:c,forwardState:b},g.discardedStates[d]=e,!0},g.discardHash=function(a,b,c){var d={discardedHash:a,backState:c,forwardState:b};return g.discardedHashes[a]=d,!0},g.discardedState=function(a){var b=g.getHashByState(a),c;return c=g.discardedStates[b]||!1,c},g.discardedHash=function(a){var b=g.discardedHashes[a]||!1;return b},g.recycleState=function(a){var b=g.getHashByState(a);return g.discardedState(a)&&delete g.discardedStates[b],!0},g.emulated.hashChange&&(g.hashChangeInit=function(){g.checkerFunction=null;var b="",d,e,h,i;return g.isInternetExplorer()?(d="historyjs-iframe",e=c.createElement("iframe"),e.setAttribute("id",d),e.style.display="none",c.body.appendChild(e),e.contentWindow.document.open(),e.contentWindow.document.close(),h="",i=!1,g.checkerFunction=function(){if(i)return!1;i=!0;var c=g.getHash()||"",d=g.unescapeHash(e.contentWindow.document.location.hash)||"";return c!==b?(b=c,d!==c&&(h=d=c,e.contentWindow.document.open(),e.contentWindow.document.close(),e.contentWindow.document.location.hash=g.escapeHash(c)),g.Adapter.trigger(a,"hashchange")):d!==h&&(h=d,g.setHash(d,!1)),i=!1,!0}):g.checkerFunction=function(){var c=g.getHash();return c!==b&&(b=c,g.Adapter.trigger(a,"hashchange")),!0},g.intervalList.push(f(g.checkerFunction,g.options.hashChangeInterval)),!0},g.Adapter.onDomLoad(g.hashChangeInit)),g.emulated.pushState&&(g.onHashChange=function(b){var d=b&&b.newURL||c.location.href,e=g.getHashByUrl(d),f=null,h=null,i=null,j;return g.isLastHash(e)?(g.busy(!1),!1):(g.doubleCheckComplete(),g.saveHash(e),e&&g.isTraditionalAnchor(e)?(g.Adapter.trigger(a,"anchorchange"),g.busy(!1),!1):(f=g.extractState(g.getFullUrl(e||c.location.href,!1),!0),g.isLastSavedState(f)?(g.busy(!1),!1):(h=g.getHashByState(f),j=g.discardedState(f),j?(g.getHashByIndex(-2)===g.getHashByState(j.forwardState)?g.back(!1):g.forward(!1),!1):(g.pushState(f.data,f.title,f.url,!1),!0))))},g.Adapter.bind(a,"hashchange",g.onHashChange),g.pushState=function(b,d,e,f){if(g.getHashByUrl(e))throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(f!==!1&&g.busy())return g.pushQueue({scope:g,callback:g.pushState,args:arguments,queue:f}),!1;g.busy(!0);var h=g.createStateObject(b,d,e),i=g.getHashByState(h),j=g.getState(!1),k=g.getHashByState(j),l=g.getHash();return g.storeState(h),g.expectedStateId=h.id,g.recycleState(h),g.setTitle(h),i===k?(g.busy(!1),!1):i!==l&&i!==g.getShortUrl(c.location.href)?(g.setHash(i,!1),!1):(g.saveState(h),g.Adapter.trigger(a,"statechange"),g.busy(!1),!0)},g.replaceState=function(a,b,c,d){if(g.getHashByUrl(c))throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(d!==!1&&g.busy())return g.pushQueue({scope:g,callback:g.replaceState,args:arguments,queue:d}),!1;g.busy(!0);var e=g.createStateObject(a,b,c),f=g.getState(!1),h=g.getStateByIndex(-2);return g.discardState(f,e,h),g.pushState(e.data,e.title,e.url,!1),!0}),g.emulated.pushState&&g.getHash()&&!g.emulated.hashChange&&g.Adapter.onDomLoad(function(){g.Adapter.trigger(a,"hashchange")})},typeof g.init!="undefined"&&g.init()})(window)
|
1
js/libraries/balupton-history/scripts/compressed/history.js
Executable file
1
js/libraries/balupton-history/scripts/compressed/history.js
Executable file
File diff suppressed because one or more lines are too long
1
js/libraries/balupton-history/scripts/compressed/json2.js
Executable file
1
js/libraries/balupton-history/scripts/compressed/json2.js
Executable file
@ -0,0 +1 @@
|
||||
window.JSON||(window.JSON={}),function(){function f(a){return a<10?"0"+a:a}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return typeof b=="string"?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g=gap,h,i=b[a];i&&typeof i=="object"&&typeof i.toJSON=="function"&&(i=i.toJSON(a)),typeof rep=="function"&&(i=rep.call(b,a,i));switch(typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";gap+=indent,h=[];if(Object.prototype.toString.apply(i)==="[object Array]"){f=i.length;for(c=0;c<f;c+=1)h[c]=str(c,i)||"null";return e=h.length===0?"[]":gap?"[\n"+gap+h.join(",\n"+gap)+"\n"+g+"]":"["+h.join(",")+"]",gap=g,e}if(rep&&typeof rep=="object"){f=rep.length;for(c=0;c<f;c+=1)d=rep[c],typeof d=="string"&&(e=str(d,i),e&&h.push(quote(d)+(gap?": ":":")+e))}else for(d in i)Object.hasOwnProperty.call(i,d)&&(e=str(d,i),e&&h.push(quote(d)+(gap?": ":":")+e));return e=h.length===0?"{}":gap?"{\n"+gap+h.join(",\n"+gap)+"\n"+g+"}":"{"+h.join(",")+"}",gap=g,e}}"use strict",typeof Date.prototype.toJSON!="function"&&(Date.prototype.toJSON=function(a){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(a){return this.valueOf()});var JSON=window.JSON,cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;typeof JSON.stringify!="function"&&(JSON.stringify=function(a,b,c){var d;gap="",indent="";if(typeof c=="number")for(d=0;d<c;d+=1)indent+=" ";else typeof c=="string"&&(indent=c);rep=b;if(!b||typeof b=="function"||typeof b=="object"&&typeof b.length=="number")return str("",{"":a});throw new Error("JSON.stringify")}),typeof JSON.parse!="function"&&(JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&typeof e=="object")for(c in e)Object.hasOwnProperty.call(e,c)&&(d=walk(e,c),d!==undefined?e[c]=d:delete e[c]);return reviver.call(a,b,e)}var j;text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)}));if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return j=eval("("+text+")"),typeof reviver=="function"?walk({"":j},""):j;throw new SyntaxError("JSON.parse")})}()
|
77
js/libraries/balupton-history/scripts/uncompressed/history.adapter.jquery.js
Executable file
77
js/libraries/balupton-history/scripts/uncompressed/history.adapter.jquery.js
Executable file
@ -0,0 +1,77 @@
|
||||
/**
|
||||
* History.js jQuery Adapter
|
||||
* @author Benjamin Arthur Lupton <contact@balupton.com>
|
||||
* @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
||||
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
||||
*/
|
||||
|
||||
// Closure
|
||||
(function(window,undefined){
|
||||
"use strict";
|
||||
|
||||
// Localise Globals
|
||||
var
|
||||
History = window.History = window.History||{},
|
||||
jQuery = window.jQuery;
|
||||
|
||||
// Check Existence
|
||||
if ( typeof History.Adapter !== 'undefined' ) {
|
||||
throw new Error('History.js Adapter has already been loaded...');
|
||||
}
|
||||
|
||||
// Add the Adapter
|
||||
History.Adapter = {
|
||||
/**
|
||||
* History.Adapter.bind(el,event,callback)
|
||||
* @param {Element|string} el
|
||||
* @param {string} event - custom and standard events
|
||||
* @param {function} callback
|
||||
* @return {void}
|
||||
*/
|
||||
bind: function(el,event,callback){
|
||||
jQuery(el).bind(event,callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* History.Adapter.trigger(el,event)
|
||||
* @param {Element|string} el
|
||||
* @param {string} event - custom and standard events
|
||||
* @param {Object=} extra - a object of extra event data (optional)
|
||||
* @return {void}
|
||||
*/
|
||||
trigger: function(el,event,extra){
|
||||
jQuery(el).trigger(event,extra);
|
||||
},
|
||||
|
||||
/**
|
||||
* History.Adapter.extractEventData(key,event,extra)
|
||||
* @param {string} key - key for the event data to extract
|
||||
* @param {string} event - custom and standard events
|
||||
* @param {Object=} extra - a object of extra event data (optional)
|
||||
* @return {mixed}
|
||||
*/
|
||||
extractEventData: function(key,event,extra){
|
||||
// jQuery Native then jQuery Custom
|
||||
var result = (event && event.originalEvent && event.originalEvent[key]) || (extra && extra[key]) || undefined;
|
||||
|
||||
// Return
|
||||
return result;
|
||||
},
|
||||
|
||||
/**
|
||||
* History.Adapter.onDomLoad(callback)
|
||||
* @param {function} callback
|
||||
* @return {void}
|
||||
*/
|
||||
onDomLoad: function(callback) {
|
||||
jQuery(callback);
|
||||
}
|
||||
};
|
||||
|
||||
// Try and Initialise History
|
||||
if ( typeof History.init !== 'undefined' ) {
|
||||
History.init();
|
||||
}
|
||||
|
||||
})(window);
|
||||
|
@ -0,0 +1,84 @@
|
||||
/**
|
||||
* History.js MooTools Adapter
|
||||
* @author Benjamin Arthur Lupton <contact@balupton.com>
|
||||
* @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
||||
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
||||
*/
|
||||
|
||||
// Closure
|
||||
(function(window,undefined){
|
||||
"use strict";
|
||||
|
||||
// Localise Globals
|
||||
var
|
||||
History = window.History = window.History||{},
|
||||
MooTools = window.MooTools,
|
||||
Element = window.Element;
|
||||
|
||||
// Check Existence
|
||||
if ( typeof History.Adapter !== 'undefined' ) {
|
||||
throw new Error('History.js Adapter has already been loaded...');
|
||||
}
|
||||
|
||||
// Make MooTools aware of History.js Events
|
||||
Object.append(Element.NativeEvents,{
|
||||
'popstate':2,
|
||||
'hashchange':2
|
||||
});
|
||||
|
||||
// Add the Adapter
|
||||
History.Adapter = {
|
||||
/**
|
||||
* History.Adapter.bind(el,event,callback)
|
||||
* @param {Element|string} el
|
||||
* @param {string} event - custom and standard events
|
||||
* @param {function} callback
|
||||
* @return {void}
|
||||
*/
|
||||
bind: function(el,event,callback){
|
||||
var El = typeof el === 'string' ? document.id(el) : el;
|
||||
El.addEvent(event,callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* History.Adapter.trigger(el,event)
|
||||
* @param {Element|string} el
|
||||
* @param {string} event - custom and standard events
|
||||
* @param {Object=} extra - a object of extra event data (optional)
|
||||
* @return void
|
||||
*/
|
||||
trigger: function(el,event,extra){
|
||||
var El = typeof el === 'string' ? document.id(el) : el;
|
||||
El.fireEvent(event,extra);
|
||||
},
|
||||
|
||||
/**
|
||||
* History.Adapter.extractEventData(key,event,extra)
|
||||
* @param {string} key - key for the event data to extract
|
||||
* @param {string} event - custom and standard events
|
||||
* @return {mixed}
|
||||
*/
|
||||
extractEventData: function(key,event){
|
||||
// MooTools Native then MooTools Custom
|
||||
var result = (event && event.event && event.event[key]) || (event && event[key]) || undefined;
|
||||
|
||||
// Return
|
||||
return result;
|
||||
},
|
||||
|
||||
/**
|
||||
* History.Adapter.onDomLoad(callback)
|
||||
* @param {function} callback
|
||||
* @return {void}
|
||||
*/
|
||||
onDomLoad: function(callback) {
|
||||
window.addEvent('domready',callback);
|
||||
}
|
||||
};
|
||||
|
||||
// Try and Initialise History
|
||||
if ( typeof History.init !== 'undefined' ) {
|
||||
History.init();
|
||||
}
|
||||
|
||||
})(window);
|
121
js/libraries/balupton-history/scripts/uncompressed/history.adapter.native.js
Executable file
121
js/libraries/balupton-history/scripts/uncompressed/history.adapter.native.js
Executable file
@ -0,0 +1,121 @@
|
||||
/**
|
||||
* History.js Native Adapter
|
||||
* @author Benjamin Arthur Lupton <contact@balupton.com>
|
||||
* @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
||||
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
||||
*/
|
||||
|
||||
// Closure
|
||||
(function(window,undefined){
|
||||
"use strict";
|
||||
|
||||
// Localise Globals
|
||||
var History = window.History = window.History||{};
|
||||
|
||||
// Check Existence
|
||||
if ( typeof History.Adapter !== 'undefined' ) {
|
||||
throw new Error('History.js Adapter has already been loaded...');
|
||||
}
|
||||
|
||||
// Add the Adapter
|
||||
History.Adapter = {
|
||||
/**
|
||||
* History.Adapter.handlers[uid][eventName] = Array
|
||||
*/
|
||||
handlers: {},
|
||||
|
||||
/**
|
||||
* History.Adapter._uid
|
||||
* The current element unique identifier
|
||||
*/
|
||||
_uid: 1,
|
||||
|
||||
/**
|
||||
* History.Adapter.uid(element)
|
||||
* @param {Element} element
|
||||
* @return {String} uid
|
||||
*/
|
||||
uid: function(element){
|
||||
return element._uid || (element._uid = History.Adapter._uid++);
|
||||
},
|
||||
|
||||
/**
|
||||
* History.Adapter.bind(el,event,callback)
|
||||
* @param {Element} element
|
||||
* @param {String} eventName - custom and standard events
|
||||
* @param {Function} callback
|
||||
* @return
|
||||
*/
|
||||
bind: function(element,eventName,callback){
|
||||
// Prepare
|
||||
var uid = History.Adapter.uid(element);
|
||||
|
||||
// Apply Listener
|
||||
History.Adapter.handlers[uid] = History.Adapter.handlers[uid] || {};
|
||||
History.Adapter.handlers[uid][eventName] = History.Adapter.handlers[uid][eventName] || [];
|
||||
History.Adapter.handlers[uid][eventName].push(callback);
|
||||
|
||||
// Bind Global Listener
|
||||
element['on'+eventName] = (function(element,eventName){
|
||||
return function(event){
|
||||
History.Adapter.trigger(element,eventName,event);
|
||||
};
|
||||
})(element,eventName);
|
||||
},
|
||||
|
||||
/**
|
||||
* History.Adapter.trigger(el,event)
|
||||
* @param {Element} element
|
||||
* @param {String} eventName - custom and standard events
|
||||
* @param {Object} event - a object of event data
|
||||
* @return
|
||||
*/
|
||||
trigger: function(element,eventName,event){
|
||||
// Prepare
|
||||
event = event || {};
|
||||
var uid = History.Adapter.uid(element),
|
||||
i,n;
|
||||
|
||||
// Apply Listener
|
||||
History.Adapter.handlers[uid] = History.Adapter.handlers[uid] || {};
|
||||
History.Adapter.handlers[uid][eventName] = History.Adapter.handlers[uid][eventName] || [];
|
||||
|
||||
// Fire Listeners
|
||||
for ( i=0,n=History.Adapter.handlers[uid][eventName].length; i<n; ++i ) {
|
||||
History.Adapter.handlers[uid][eventName][i].apply(this,[event]);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* History.Adapter.extractEventData(key,event,extra)
|
||||
* @param {String} key - key for the event data to extract
|
||||
* @param {String} event - custom and standard events
|
||||
* @return {mixed}
|
||||
*/
|
||||
extractEventData: function(key,event){
|
||||
var result = (event && event[key]) || undefined;
|
||||
return result;
|
||||
},
|
||||
|
||||
/**
|
||||
* History.Adapter.onDomLoad(callback)
|
||||
* @param {Function} callback
|
||||
* @return
|
||||
*/
|
||||
onDomLoad: function(callback) {
|
||||
var timeout = window.setTimeout(function(){
|
||||
callback();
|
||||
},2000);
|
||||
window.onload = function(){
|
||||
clearTimeout(timeout);
|
||||
callback();
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// Try and Initialise History
|
||||
if ( typeof History.init !== 'undefined' ) {
|
||||
History.init();
|
||||
}
|
||||
|
||||
})(window);
|
78
js/libraries/balupton-history/scripts/uncompressed/history.adapter.right.js
Executable file
78
js/libraries/balupton-history/scripts/uncompressed/history.adapter.right.js
Executable file
@ -0,0 +1,78 @@
|
||||
/**
|
||||
* History.js RightJS Adapter
|
||||
* @author Benjamin Arthur Lupton <contact@balupton.com>
|
||||
* @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
||||
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
||||
*/
|
||||
|
||||
// Closure
|
||||
(function(window,undefined){
|
||||
"use strict";
|
||||
|
||||
// Localise Globals
|
||||
var
|
||||
History = window.History = window.History||{},
|
||||
document = window.document,
|
||||
RightJS = window.RightJS,
|
||||
$ = RightJS.$;
|
||||
|
||||
// Check Existence
|
||||
if ( typeof History.Adapter !== 'undefined' ) {
|
||||
throw new Error('History.js Adapter has already been loaded...');
|
||||
}
|
||||
|
||||
// Add the Adapter
|
||||
History.Adapter = {
|
||||
/**
|
||||
* History.Adapter.bind(el,event,callback)
|
||||
* @param {Element|Selector} el
|
||||
* @param {String} event - custom and standard events
|
||||
* @param {Function} callback
|
||||
* @return
|
||||
*/
|
||||
bind: function(el,event,callback){
|
||||
$(el).on(event,callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* History.Adapter.trigger(el,event)
|
||||
* @param {Element|Selector} el
|
||||
* @param {String} event - custom and standard events
|
||||
* @param {Object} extraEventData - a object of extra event data
|
||||
* @return
|
||||
*/
|
||||
trigger: function(el,event,extraEventData){
|
||||
$(el).fire(event,extraEventData);
|
||||
},
|
||||
|
||||
/**
|
||||
* History.Adapter.extractEventData(key,event,extra)
|
||||
* @param {String} key - key for the event data to extract
|
||||
* @param {String} event - custom and standard events
|
||||
* @return {mixed}
|
||||
*/
|
||||
extractEventData: function(key,event){
|
||||
// Right.js Native
|
||||
// Right.js Custom
|
||||
var result = (event && event._ && event._[key]) || undefined;
|
||||
|
||||
// Return
|
||||
return result;
|
||||
},
|
||||
|
||||
/**
|
||||
* History.Adapter.onDomLoad(callback)
|
||||
* @param {Function} callback
|
||||
* @return
|
||||
*/
|
||||
onDomLoad: function(callback) {
|
||||
$(document).onReady(callback);
|
||||
}
|
||||
};
|
||||
|
||||
// Try and Initialise History
|
||||
if ( typeof History.init !== 'undefined' ) {
|
||||
History.init();
|
||||
}
|
||||
|
||||
})(window);
|
74
js/libraries/balupton-history/scripts/uncompressed/history.adapter.zepto.js
Executable file
74
js/libraries/balupton-history/scripts/uncompressed/history.adapter.zepto.js
Executable file
@ -0,0 +1,74 @@
|
||||
/**
|
||||
* History.js Zepto Adapter
|
||||
* @author Benjamin Arthur Lupton <contact@balupton.com>
|
||||
* @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
||||
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
||||
*/
|
||||
|
||||
// Closure
|
||||
(function(window,undefined){
|
||||
"use strict";
|
||||
|
||||
// Localise Globals
|
||||
var
|
||||
History = window.History = window.History||{},
|
||||
Zepto = window.Zepto;
|
||||
|
||||
// Check Existence
|
||||
if ( typeof History.Adapter !== 'undefined' ) {
|
||||
throw new Error('History.js Adapter has already been loaded...');
|
||||
}
|
||||
|
||||
// Add the Adapter
|
||||
History.Adapter = {
|
||||
/**
|
||||
* History.Adapter.bind(el,event,callback)
|
||||
* @param {Element|string} el
|
||||
* @param {string} event - custom and standard events
|
||||
* @param {function} callback
|
||||
* @return {void}
|
||||
*/
|
||||
bind: function(el,event,callback){
|
||||
new Zepto(el).bind(event,callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* History.Adapter.trigger(el,event)
|
||||
* @param {Element|string} el
|
||||
* @param {string} event - custom and standard events
|
||||
* @return {void}
|
||||
*/
|
||||
trigger: function(el,event){
|
||||
new Zepto(el).trigger(event);
|
||||
},
|
||||
|
||||
/**
|
||||
* History.Adapter.extractEventData(key,event,extra)
|
||||
* @param {string} key - key for the event data to extract
|
||||
* @param {string} event - custom and standard events
|
||||
* @return {mixed}
|
||||
*/
|
||||
extractEventData: function(key,event){
|
||||
// Zepto Native
|
||||
var result = (event && event[key]) || undefined;
|
||||
|
||||
// Return
|
||||
return result;
|
||||
},
|
||||
|
||||
/**
|
||||
* History.Adapter.onDomLoad(callback)
|
||||
* @param {function} callback
|
||||
* @return {void}
|
||||
*/
|
||||
onDomLoad: function(callback) {
|
||||
new Zepto(callback);
|
||||
}
|
||||
};
|
||||
|
||||
// Try and Initialise History
|
||||
if ( typeof History.init !== 'undefined' ) {
|
||||
History.init();
|
||||
}
|
||||
|
||||
})(window);
|
621
js/libraries/balupton-history/scripts/uncompressed/history.html4.js
Executable file
621
js/libraries/balupton-history/scripts/uncompressed/history.html4.js
Executable file
@ -0,0 +1,621 @@
|
||||
/**
|
||||
* History.js HTML4 Support
|
||||
* Depends on the HTML5 Support
|
||||
* @author Benjamin Arthur Lupton <contact@balupton.com>
|
||||
* @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
||||
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
||||
*/
|
||||
|
||||
(function(window,undefined){
|
||||
"use strict";
|
||||
|
||||
// ========================================================================
|
||||
// Initialise
|
||||
|
||||
// Localise Globals
|
||||
var
|
||||
document = window.document, // Make sure we are using the correct document
|
||||
setTimeout = window.setTimeout||setTimeout,
|
||||
clearTimeout = window.clearTimeout||clearTimeout,
|
||||
setInterval = window.setInterval||setInterval,
|
||||
History = window.History = window.History||{}; // Public History Object
|
||||
|
||||
// Check Existence
|
||||
if ( typeof History.initHtml4 !== 'undefined' ) {
|
||||
throw new Error('History.js HTML4 Support has already been loaded...');
|
||||
}
|
||||
|
||||
|
||||
// ========================================================================
|
||||
// Initialise HTML4 Support
|
||||
|
||||
// Initialise HTML4 Support
|
||||
History.initHtml4 = function(){
|
||||
// Initialise
|
||||
if ( typeof History.initHtml4.initialized !== 'undefined' ) {
|
||||
// Already Loaded
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
History.initHtml4.initialized = true;
|
||||
}
|
||||
|
||||
|
||||
// ====================================================================
|
||||
// Properties
|
||||
|
||||
/**
|
||||
* History.enabled
|
||||
* Is History enabled?
|
||||
*/
|
||||
History.enabled = true;
|
||||
|
||||
|
||||
// ====================================================================
|
||||
// Hash Storage
|
||||
|
||||
/**
|
||||
* History.savedHashes
|
||||
* Store the hashes in an array
|
||||
*/
|
||||
History.savedHashes = [];
|
||||
|
||||
/**
|
||||
* History.isLastHash(newHash)
|
||||
* Checks if the hash is the last hash
|
||||
* @param {string} newHash
|
||||
* @return {boolean} true
|
||||
*/
|
||||
History.isLastHash = function(newHash){
|
||||
// Prepare
|
||||
var oldHash = History.getHashByIndex(),
|
||||
isLast;
|
||||
|
||||
// Check
|
||||
isLast = newHash === oldHash;
|
||||
|
||||
// Return isLast
|
||||
return isLast;
|
||||
};
|
||||
|
||||
/**
|
||||
* History.saveHash(newHash)
|
||||
* Push a Hash
|
||||
* @param {string} newHash
|
||||
* @return {boolean} true
|
||||
*/
|
||||
History.saveHash = function(newHash){
|
||||
// Check Hash
|
||||
if ( History.isLastHash(newHash) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Push the Hash
|
||||
History.savedHashes.push(newHash);
|
||||
|
||||
// Return true
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* History.getHashByIndex()
|
||||
* Gets a hash by the index
|
||||
* @param {integer} index
|
||||
* @return {string}
|
||||
*/
|
||||
History.getHashByIndex = function(index){
|
||||
// Prepare
|
||||
var hash = null;
|
||||
|
||||
// Handle
|
||||
if ( typeof index === 'undefined' ) {
|
||||
// Get the last inserted
|
||||
hash = History.savedHashes[History.savedHashes.length-1];
|
||||
}
|
||||
else if ( index < 0 ) {
|
||||
// Get from the end
|
||||
hash = History.savedHashes[History.savedHashes.length+index];
|
||||
}
|
||||
else {
|
||||
// Get from the beginning
|
||||
hash = History.savedHashes[index];
|
||||
}
|
||||
|
||||
// Return hash
|
||||
return hash;
|
||||
};
|
||||
|
||||
|
||||
// ====================================================================
|
||||
// Discarded States
|
||||
|
||||
/**
|
||||
* History.discardedHashes
|
||||
* A hashed array of discarded hashes
|
||||
*/
|
||||
History.discardedHashes = {};
|
||||
|
||||
/**
|
||||
* History.discardedStates
|
||||
* A hashed array of discarded states
|
||||
*/
|
||||
History.discardedStates = {};
|
||||
|
||||
/**
|
||||
* History.discardState(State)
|
||||
* Discards the state by ignoring it through History
|
||||
* @param {object} State
|
||||
* @return {true}
|
||||
*/
|
||||
History.discardState = function(discardedState,forwardState,backState){
|
||||
//History.debug('History.discardState', arguments);
|
||||
// Prepare
|
||||
var discardedStateHash = History.getHashByState(discardedState),
|
||||
discardObject;
|
||||
|
||||
// Create Discard Object
|
||||
discardObject = {
|
||||
'discardedState': discardedState,
|
||||
'backState': backState,
|
||||
'forwardState': forwardState
|
||||
};
|
||||
|
||||
// Add to DiscardedStates
|
||||
History.discardedStates[discardedStateHash] = discardObject;
|
||||
|
||||
// Return true
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* History.discardHash(hash)
|
||||
* Discards the hash by ignoring it through History
|
||||
* @param {string} hash
|
||||
* @return {true}
|
||||
*/
|
||||
History.discardHash = function(discardedHash,forwardState,backState){
|
||||
//History.debug('History.discardState', arguments);
|
||||
// Create Discard Object
|
||||
var discardObject = {
|
||||
'discardedHash': discardedHash,
|
||||
'backState': backState,
|
||||
'forwardState': forwardState
|
||||
};
|
||||
|
||||
// Add to discardedHash
|
||||
History.discardedHashes[discardedHash] = discardObject;
|
||||
|
||||
// Return true
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* History.discardState(State)
|
||||
* Checks to see if the state is discarded
|
||||
* @param {object} State
|
||||
* @return {bool}
|
||||
*/
|
||||
History.discardedState = function(State){
|
||||
// Prepare
|
||||
var StateHash = History.getHashByState(State),
|
||||
discarded;
|
||||
|
||||
// Check
|
||||
discarded = History.discardedStates[StateHash]||false;
|
||||
|
||||
// Return true
|
||||
return discarded;
|
||||
};
|
||||
|
||||
/**
|
||||
* History.discardedHash(hash)
|
||||
* Checks to see if the state is discarded
|
||||
* @param {string} State
|
||||
* @return {bool}
|
||||
*/
|
||||
History.discardedHash = function(hash){
|
||||
// Check
|
||||
var discarded = History.discardedHashes[hash]||false;
|
||||
|
||||
// Return true
|
||||
return discarded;
|
||||
};
|
||||
|
||||
/**
|
||||
* History.recycleState(State)
|
||||
* Allows a discarded state to be used again
|
||||
* @param {object} data
|
||||
* @param {string} title
|
||||
* @param {string} url
|
||||
* @return {true}
|
||||
*/
|
||||
History.recycleState = function(State){
|
||||
//History.debug('History.recycleState', arguments);
|
||||
// Prepare
|
||||
var StateHash = History.getHashByState(State);
|
||||
|
||||
// Remove from DiscardedStates
|
||||
if ( History.discardedState(State) ) {
|
||||
delete History.discardedStates[StateHash];
|
||||
}
|
||||
|
||||
// Return true
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
// ====================================================================
|
||||
// HTML4 HashChange Support
|
||||
|
||||
if ( History.emulated.hashChange ) {
|
||||
/*
|
||||
* We must emulate the HTML4 HashChange Support by manually checking for hash changes
|
||||
*/
|
||||
|
||||
/**
|
||||
* History.hashChangeInit()
|
||||
* Init the HashChange Emulation
|
||||
*/
|
||||
History.hashChangeInit = function(){
|
||||
// Define our Checker Function
|
||||
History.checkerFunction = null;
|
||||
|
||||
// Define some variables that will help in our checker function
|
||||
var lastDocumentHash = '',
|
||||
iframeId, iframe,
|
||||
lastIframeHash, checkerRunning;
|
||||
|
||||
// Handle depending on the browser
|
||||
if ( History.isInternetExplorer() ) {
|
||||
// IE6 and IE7
|
||||
// We need to use an iframe to emulate the back and forward buttons
|
||||
|
||||
// Create iFrame
|
||||
iframeId = 'historyjs-iframe';
|
||||
iframe = document.createElement('iframe');
|
||||
|
||||
// Adjust iFarme
|
||||
iframe.setAttribute('id', iframeId);
|
||||
iframe.style.display = 'none';
|
||||
|
||||
// Append iFrame
|
||||
document.body.appendChild(iframe);
|
||||
|
||||
// Create initial history entry
|
||||
iframe.contentWindow.document.open();
|
||||
iframe.contentWindow.document.close();
|
||||
|
||||
// Define some variables that will help in our checker function
|
||||
lastIframeHash = '';
|
||||
checkerRunning = false;
|
||||
|
||||
// Define the checker function
|
||||
History.checkerFunction = function(){
|
||||
// Check Running
|
||||
if ( checkerRunning ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update Running
|
||||
checkerRunning = true;
|
||||
|
||||
// Fetch
|
||||
var documentHash = History.getHash()||'',
|
||||
iframeHash = History.unescapeHash(iframe.contentWindow.document.location.hash)||'';
|
||||
|
||||
// The Document Hash has changed (application caused)
|
||||
if ( documentHash !== lastDocumentHash ) {
|
||||
// Equalise
|
||||
lastDocumentHash = documentHash;
|
||||
|
||||
// Create a history entry in the iframe
|
||||
if ( iframeHash !== documentHash ) {
|
||||
//History.debug('hashchange.checker: iframe hash change', 'documentHash (new):', documentHash, 'iframeHash (old):', iframeHash);
|
||||
|
||||
// Equalise
|
||||
lastIframeHash = iframeHash = documentHash;
|
||||
|
||||
// Create History Entry
|
||||
iframe.contentWindow.document.open();
|
||||
iframe.contentWindow.document.close();
|
||||
|
||||
// Update the iframe's hash
|
||||
iframe.contentWindow.document.location.hash = History.escapeHash(documentHash);
|
||||
}
|
||||
|
||||
// Trigger Hashchange Event
|
||||
History.Adapter.trigger(window,'hashchange');
|
||||
}
|
||||
|
||||
// The iFrame Hash has changed (back button caused)
|
||||
else if ( iframeHash !== lastIframeHash ) {
|
||||
//History.debug('hashchange.checker: iframe hash out of sync', 'iframeHash (new):', iframeHash, 'documentHash (old):', documentHash);
|
||||
|
||||
// Equalise
|
||||
lastIframeHash = iframeHash;
|
||||
|
||||
// Update the Hash
|
||||
History.setHash(iframeHash,false);
|
||||
}
|
||||
|
||||
// Reset Running
|
||||
checkerRunning = false;
|
||||
|
||||
// Return true
|
||||
return true;
|
||||
};
|
||||
}
|
||||
else {
|
||||
// We are not IE
|
||||
// Firefox 1 or 2, Opera
|
||||
|
||||
// Define the checker function
|
||||
History.checkerFunction = function(){
|
||||
// Prepare
|
||||
var documentHash = History.getHash();
|
||||
|
||||
// The Document Hash has changed (application caused)
|
||||
if ( documentHash !== lastDocumentHash ) {
|
||||
// Equalise
|
||||
lastDocumentHash = documentHash;
|
||||
|
||||
// Trigger Hashchange Event
|
||||
History.Adapter.trigger(window,'hashchange');
|
||||
}
|
||||
|
||||
// Return true
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
// Apply the checker function
|
||||
History.intervalList.push(setInterval(History.checkerFunction, History.options.hashChangeInterval));
|
||||
|
||||
// Done
|
||||
return true;
|
||||
}; // History.hashChangeInit
|
||||
|
||||
// Bind hashChangeInit
|
||||
History.Adapter.onDomLoad(History.hashChangeInit);
|
||||
|
||||
} // History.emulated.hashChange
|
||||
|
||||
|
||||
// ====================================================================
|
||||
// HTML5 State Support
|
||||
|
||||
// Non-Native pushState Implementation
|
||||
if ( History.emulated.pushState ) {
|
||||
/*
|
||||
* We must emulate the HTML5 State Management by using HTML4 HashChange
|
||||
*/
|
||||
|
||||
/**
|
||||
* History.onHashChange(event)
|
||||
* Trigger HTML5's window.onpopstate via HTML4 HashChange Support
|
||||
*/
|
||||
History.onHashChange = function(event){
|
||||
//History.debug('History.onHashChange', arguments);
|
||||
|
||||
// Prepare
|
||||
var currentUrl = ((event && event.newURL) || document.location.href),
|
||||
currentHash = History.getHashByUrl(currentUrl),
|
||||
currentState = null,
|
||||
currentStateHash = null,
|
||||
currentStateHashExits = null,
|
||||
discardObject;
|
||||
|
||||
// Check if we are the same state
|
||||
if ( History.isLastHash(currentHash) ) {
|
||||
// There has been no change (just the page's hash has finally propagated)
|
||||
//History.debug('History.onHashChange: no change');
|
||||
History.busy(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reset the double check
|
||||
History.doubleCheckComplete();
|
||||
|
||||
// Store our location for use in detecting back/forward direction
|
||||
History.saveHash(currentHash);
|
||||
|
||||
// Expand Hash
|
||||
if ( currentHash && History.isTraditionalAnchor(currentHash) ) {
|
||||
//History.debug('History.onHashChange: traditional anchor', currentHash);
|
||||
// Traditional Anchor Hash
|
||||
History.Adapter.trigger(window,'anchorchange');
|
||||
History.busy(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create State
|
||||
currentState = History.extractState(History.getFullUrl(currentHash||document.location.href,false),true);
|
||||
|
||||
// Check if we are the same state
|
||||
if ( History.isLastSavedState(currentState) ) {
|
||||
//History.debug('History.onHashChange: no change');
|
||||
// There has been no change (just the page's hash has finally propagated)
|
||||
History.busy(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the state Hash
|
||||
currentStateHash = History.getHashByState(currentState);
|
||||
|
||||
// Check if we are DiscardedState
|
||||
discardObject = History.discardedState(currentState);
|
||||
if ( discardObject ) {
|
||||
// Ignore this state as it has been discarded and go back to the state before it
|
||||
if ( History.getHashByIndex(-2) === History.getHashByState(discardObject.forwardState) ) {
|
||||
// We are going backwards
|
||||
//History.debug('History.onHashChange: go backwards');
|
||||
History.back(false);
|
||||
} else {
|
||||
// We are going forwards
|
||||
//History.debug('History.onHashChange: go forwards');
|
||||
History.forward(false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Push the new HTML5 State
|
||||
//History.debug('History.onHashChange: success hashchange');
|
||||
History.pushState(currentState.data,currentState.title,currentState.url,false);
|
||||
|
||||
// End onHashChange closure
|
||||
return true;
|
||||
};
|
||||
History.Adapter.bind(window,'hashchange',History.onHashChange);
|
||||
|
||||
/**
|
||||
* History.pushState(data,title,url)
|
||||
* Add a new State to the history object, become it, and trigger onpopstate
|
||||
* We have to trigger for HTML4 compatibility
|
||||
* @param {object} data
|
||||
* @param {string} title
|
||||
* @param {string} url
|
||||
* @return {true}
|
||||
*/
|
||||
History.pushState = function(data,title,url,queue){
|
||||
//History.debug('History.pushState: called', arguments);
|
||||
|
||||
// Check the State
|
||||
if ( History.getHashByUrl(url) ) {
|
||||
throw new Error('History.js does not support states with fragement-identifiers (hashes/anchors).');
|
||||
}
|
||||
|
||||
// Handle Queueing
|
||||
if ( queue !== false && History.busy() ) {
|
||||
// Wait + Push to Queue
|
||||
//History.debug('History.pushState: we must wait', arguments);
|
||||
History.pushQueue({
|
||||
scope: History,
|
||||
callback: History.pushState,
|
||||
args: arguments,
|
||||
queue: queue
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make Busy
|
||||
History.busy(true);
|
||||
|
||||
// Fetch the State Object
|
||||
var newState = History.createStateObject(data,title,url),
|
||||
newStateHash = History.getHashByState(newState),
|
||||
oldState = History.getState(false),
|
||||
oldStateHash = History.getHashByState(oldState),
|
||||
html4Hash = History.getHash();
|
||||
|
||||
// Store the newState
|
||||
History.storeState(newState);
|
||||
History.expectedStateId = newState.id;
|
||||
|
||||
// Recycle the State
|
||||
History.recycleState(newState);
|
||||
|
||||
// Force update of the title
|
||||
History.setTitle(newState);
|
||||
|
||||
// Check if we are the same State
|
||||
if ( newStateHash === oldStateHash ) {
|
||||
//History.debug('History.pushState: no change', newStateHash);
|
||||
History.busy(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update HTML4 Hash
|
||||
if ( newStateHash !== html4Hash && newStateHash !== History.getShortUrl(document.location.href) ) {
|
||||
//History.debug('History.pushState: update hash', newStateHash, html4Hash);
|
||||
History.setHash(newStateHash,false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update HTML5 State
|
||||
History.saveState(newState);
|
||||
|
||||
// Fire HTML5 Event
|
||||
//History.debug('History.pushState: trigger popstate');
|
||||
History.Adapter.trigger(window,'statechange');
|
||||
History.busy(false);
|
||||
|
||||
// End pushState closure
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* History.replaceState(data,title,url)
|
||||
* Replace the State and trigger onpopstate
|
||||
* We have to trigger for HTML4 compatibility
|
||||
* @param {object} data
|
||||
* @param {string} title
|
||||
* @param {string} url
|
||||
* @return {true}
|
||||
*/
|
||||
History.replaceState = function(data,title,url,queue){
|
||||
//History.debug('History.replaceState: called', arguments);
|
||||
|
||||
// Check the State
|
||||
if ( History.getHashByUrl(url) ) {
|
||||
throw new Error('History.js does not support states with fragement-identifiers (hashes/anchors).');
|
||||
}
|
||||
|
||||
// Handle Queueing
|
||||
if ( queue !== false && History.busy() ) {
|
||||
// Wait + Push to Queue
|
||||
//History.debug('History.replaceState: we must wait', arguments);
|
||||
History.pushQueue({
|
||||
scope: History,
|
||||
callback: History.replaceState,
|
||||
args: arguments,
|
||||
queue: queue
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make Busy
|
||||
History.busy(true);
|
||||
|
||||
// Fetch the State Objects
|
||||
var newState = History.createStateObject(data,title,url),
|
||||
oldState = History.getState(false),
|
||||
previousState = History.getStateByIndex(-2);
|
||||
|
||||
// Discard Old State
|
||||
History.discardState(oldState,newState,previousState);
|
||||
|
||||
// Alias to PushState
|
||||
History.pushState(newState.data,newState.title,newState.url,false);
|
||||
|
||||
// End replaceState closure
|
||||
return true;
|
||||
};
|
||||
|
||||
} // History.emulated.pushState
|
||||
|
||||
|
||||
|
||||
// ====================================================================
|
||||
// Initialise
|
||||
|
||||
// Non-Native pushState Implementation
|
||||
if ( History.emulated.pushState ) {
|
||||
/**
|
||||
* Ensure initial state is handled correctly
|
||||
*/
|
||||
if ( History.getHash() && !History.emulated.hashChange ) {
|
||||
History.Adapter.onDomLoad(function(){
|
||||
History.Adapter.trigger(window,'hashchange');
|
||||
});
|
||||
}
|
||||
|
||||
} // History.emulated.pushState
|
||||
|
||||
}; // History.initHtml4
|
||||
|
||||
// Try and Initialise History
|
||||
if ( typeof History.init !== 'undefined' ) {
|
||||
History.init();
|
||||
}
|
||||
|
||||
})(window);
|
1943
js/libraries/balupton-history/scripts/uncompressed/history.js
Executable file
1943
js/libraries/balupton-history/scripts/uncompressed/history.js
Executable file
File diff suppressed because it is too large
Load Diff
480
js/libraries/balupton-history/scripts/uncompressed/json2.js
Executable file
480
js/libraries/balupton-history/scripts/uncompressed/json2.js
Executable file
@ -0,0 +1,480 @@
|
||||
/*
|
||||
http://www.JSON.org/json2.js
|
||||
2011-01-18
|
||||
|
||||
Public Domain.
|
||||
|
||||
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
||||
|
||||
See http://www.JSON.org/js.html
|
||||
|
||||
|
||||
This code should be minified before deployment.
|
||||
See http://javascript.crockford.com/jsmin.html
|
||||
|
||||
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
||||
NOT CONTROL.
|
||||
|
||||
|
||||
This file creates a global JSON object containing two methods: stringify
|
||||
and parse.
|
||||
|
||||
JSON.stringify(value, replacer, space)
|
||||
value any JavaScript value, usually an object or array.
|
||||
|
||||
replacer an optional parameter that determines how object
|
||||
values are stringified for objects. It can be a
|
||||
function or an array of strings.
|
||||
|
||||
space an optional parameter that specifies the indentation
|
||||
of nested structures. If it is omitted, the text will
|
||||
be packed without extra whitespace. If it is a number,
|
||||
it will specify the number of spaces to indent at each
|
||||
level. If it is a string (such as '\t' or ' '),
|
||||
it contains the characters used to indent at each level.
|
||||
|
||||
This method produces a JSON text from a JavaScript value.
|
||||
|
||||
When an object value is found, if the object contains a toJSON
|
||||
method, its toJSON method will be called and the result will be
|
||||
stringified. A toJSON method does not serialize: it returns the
|
||||
value represented by the name/value pair that should be serialized,
|
||||
or undefined if nothing should be serialized. The toJSON method
|
||||
will be passed the key associated with the value, and this will be
|
||||
bound to the value
|
||||
|
||||
For example, this would serialize Dates as ISO strings.
|
||||
|
||||
Date.prototype.toJSON = function (key) {
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
|
||||
return this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z';
|
||||
};
|
||||
|
||||
You can provide an optional replacer method. It will be passed the
|
||||
key and value of each member, with this bound to the containing
|
||||
object. The value that is returned from your method will be
|
||||
serialized. If your method returns undefined, then the member will
|
||||
be excluded from the serialization.
|
||||
|
||||
If the replacer parameter is an array of strings, then it will be
|
||||
used to select the members to be serialized. It filters the results
|
||||
such that only members with keys listed in the replacer array are
|
||||
stringified.
|
||||
|
||||
Values that do not have JSON representations, such as undefined or
|
||||
functions, will not be serialized. Such values in objects will be
|
||||
dropped; in arrays they will be replaced with null. You can use
|
||||
a replacer function to replace those with JSON values.
|
||||
JSON.stringify(undefined) returns undefined.
|
||||
|
||||
The optional space parameter produces a stringification of the
|
||||
value that is filled with line breaks and indentation to make it
|
||||
easier to read.
|
||||
|
||||
If the space parameter is a non-empty string, then that string will
|
||||
be used for indentation. If the space parameter is a number, then
|
||||
the indentation will be that many spaces.
|
||||
|
||||
Example:
|
||||
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}]);
|
||||
// text is '["e",{"pluribus":"unum"}]'
|
||||
|
||||
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
||||
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
||||
|
||||
text = JSON.stringify([new Date()], function (key, value) {
|
||||
return this[key] instanceof Date ?
|
||||
'Date(' + this[key] + ')' : value;
|
||||
});
|
||||
// text is '["Date(---current time---)"]'
|
||||
|
||||
|
||||
JSON.parse(text, reviver)
|
||||
This method parses a JSON text to produce an object or array.
|
||||
It can throw a SyntaxError exception.
|
||||
|
||||
The optional reviver parameter is a function that can filter and
|
||||
transform the results. It receives each of the keys and values,
|
||||
and its return value is used instead of the original value.
|
||||
If it returns what it received, then the structure is not modified.
|
||||
If it returns undefined then the member is deleted.
|
||||
|
||||
Example:
|
||||
|
||||
// Parse the text. Values that look like ISO date strings will
|
||||
// be converted to Date objects.
|
||||
|
||||
myData = JSON.parse(text, function (key, value) {
|
||||
var a;
|
||||
if (typeof value === 'string') {
|
||||
a =
|
||||
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
||||
if (a) {
|
||||
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
||||
+a[5], +a[6]));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
||||
var d;
|
||||
if (typeof value === 'string' &&
|
||||
value.slice(0, 5) === 'Date(' &&
|
||||
value.slice(-1) === ')') {
|
||||
d = new Date(value.slice(5, -1));
|
||||
if (d) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
|
||||
This is a reference implementation. You are free to copy, modify, or
|
||||
redistribute.
|
||||
*/
|
||||
|
||||
/*jslint evil: true, strict: false, regexp: false */
|
||||
|
||||
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
||||
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
||||
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
|
||||
lastIndex, length, parse, prototype, push, replace, slice, stringify,
|
||||
test, toJSON, toString, valueOf
|
||||
*/
|
||||
|
||||
|
||||
// Create a JSON object only if one does not already exist. We create the
|
||||
// methods in a closure to avoid creating global variables.
|
||||
|
||||
if (!window.JSON) {
|
||||
window.JSON = {};
|
||||
}
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
|
||||
if (typeof Date.prototype.toJSON !== 'function') {
|
||||
|
||||
Date.prototype.toJSON = function (key) {
|
||||
|
||||
return isFinite(this.valueOf()) ?
|
||||
this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z' : null;
|
||||
};
|
||||
|
||||
String.prototype.toJSON =
|
||||
Number.prototype.toJSON =
|
||||
Boolean.prototype.toJSON = function (key) {
|
||||
return this.valueOf();
|
||||
};
|
||||
}
|
||||
|
||||
var JSON = window.JSON,
|
||||
cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
||||
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
||||
gap,
|
||||
indent,
|
||||
meta = { // table of character substitutions
|
||||
'\b': '\\b',
|
||||
'\t': '\\t',
|
||||
'\n': '\\n',
|
||||
'\f': '\\f',
|
||||
'\r': '\\r',
|
||||
'"' : '\\"',
|
||||
'\\': '\\\\'
|
||||
},
|
||||
rep;
|
||||
|
||||
|
||||
function quote(string) {
|
||||
|
||||
// If the string contains no control characters, no quote characters, and no
|
||||
// backslash characters, then we can safely slap some quotes around it.
|
||||
// Otherwise we must also replace the offending characters with safe escape
|
||||
// sequences.
|
||||
|
||||
escapable.lastIndex = 0;
|
||||
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
|
||||
var c = meta[a];
|
||||
return typeof c === 'string' ? c :
|
||||
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
}) + '"' : '"' + string + '"';
|
||||
}
|
||||
|
||||
|
||||
function str(key, holder) {
|
||||
|
||||
// Produce a string from holder[key].
|
||||
|
||||
var i, // The loop counter.
|
||||
k, // The member key.
|
||||
v, // The member value.
|
||||
length,
|
||||
mind = gap,
|
||||
partial,
|
||||
value = holder[key];
|
||||
|
||||
// If the value has a toJSON method, call it to obtain a replacement value.
|
||||
|
||||
if (value && typeof value === 'object' &&
|
||||
typeof value.toJSON === 'function') {
|
||||
value = value.toJSON(key);
|
||||
}
|
||||
|
||||
// If we were called with a replacer function, then call the replacer to
|
||||
// obtain a replacement value.
|
||||
|
||||
if (typeof rep === 'function') {
|
||||
value = rep.call(holder, key, value);
|
||||
}
|
||||
|
||||
// What happens next depends on the value's type.
|
||||
|
||||
switch (typeof value) {
|
||||
case 'string':
|
||||
return quote(value);
|
||||
|
||||
case 'number':
|
||||
|
||||
// JSON numbers must be finite. Encode non-finite numbers as null.
|
||||
|
||||
return isFinite(value) ? String(value) : 'null';
|
||||
|
||||
case 'boolean':
|
||||
case 'null':
|
||||
|
||||
// If the value is a boolean or null, convert it to a string. Note:
|
||||
// typeof null does not produce 'null'. The case is included here in
|
||||
// the remote chance that this gets fixed someday.
|
||||
|
||||
return String(value);
|
||||
|
||||
// If the type is 'object', we might be dealing with an object or an array or
|
||||
// null.
|
||||
|
||||
case 'object':
|
||||
|
||||
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
||||
// so watch out for that case.
|
||||
|
||||
if (!value) {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
// Make an array to hold the partial results of stringifying this object value.
|
||||
|
||||
gap += indent;
|
||||
partial = [];
|
||||
|
||||
// Is the value an array?
|
||||
|
||||
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
||||
|
||||
// The value is an array. Stringify every element. Use null as a placeholder
|
||||
// for non-JSON values.
|
||||
|
||||
length = value.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
partial[i] = str(i, value) || 'null';
|
||||
}
|
||||
|
||||
// Join all of the elements together, separated with commas, and wrap them in
|
||||
// brackets.
|
||||
|
||||
v = partial.length === 0 ? '[]' : gap ?
|
||||
'[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
|
||||
'[' + partial.join(',') + ']';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
|
||||
// If the replacer is an array, use it to select the members to be stringified.
|
||||
|
||||
if (rep && typeof rep === 'object') {
|
||||
length = rep.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
k = rep[i];
|
||||
if (typeof k === 'string') {
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
// Otherwise, iterate through all of the keys in the object.
|
||||
|
||||
for (k in value) {
|
||||
if (Object.hasOwnProperty.call(value, k)) {
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Join all of the member texts together, separated with commas,
|
||||
// and wrap them in braces.
|
||||
|
||||
v = partial.length === 0 ? '{}' : gap ?
|
||||
'{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
|
||||
'{' + partial.join(',') + '}';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
// If the JSON object does not yet have a stringify method, give it one.
|
||||
|
||||
if (typeof JSON.stringify !== 'function') {
|
||||
JSON.stringify = function (value, replacer, space) {
|
||||
|
||||
// The stringify method takes a value and an optional replacer, and an optional
|
||||
// space parameter, and returns a JSON text. The replacer can be a function
|
||||
// that can replace values, or an array of strings that will select the keys.
|
||||
// A default replacer method can be provided. Use of the space parameter can
|
||||
// produce text that is more easily readable.
|
||||
|
||||
var i;
|
||||
gap = '';
|
||||
indent = '';
|
||||
|
||||
// If the space parameter is a number, make an indent string containing that
|
||||
// many spaces.
|
||||
|
||||
if (typeof space === 'number') {
|
||||
for (i = 0; i < space; i += 1) {
|
||||
indent += ' ';
|
||||
}
|
||||
|
||||
// If the space parameter is a string, it will be used as the indent string.
|
||||
|
||||
} else if (typeof space === 'string') {
|
||||
indent = space;
|
||||
}
|
||||
|
||||
// If there is a replacer, it must be a function or an array.
|
||||
// Otherwise, throw an error.
|
||||
|
||||
rep = replacer;
|
||||
if (replacer && typeof replacer !== 'function' &&
|
||||
(typeof replacer !== 'object' ||
|
||||
typeof replacer.length !== 'number')) {
|
||||
throw new Error('JSON.stringify');
|
||||
}
|
||||
|
||||
// Make a fake root object containing our value under the key of ''.
|
||||
// Return the result of stringifying the value.
|
||||
|
||||
return str('', {'': value});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// If the JSON object does not yet have a parse method, give it one.
|
||||
|
||||
if (typeof JSON.parse !== 'function') {
|
||||
JSON.parse = function (text, reviver) {
|
||||
|
||||
// The parse method takes a text and an optional reviver function, and returns
|
||||
// a JavaScript value if the text is a valid JSON text.
|
||||
|
||||
var j;
|
||||
|
||||
function walk(holder, key) {
|
||||
|
||||
// The walk method is used to recursively walk the resulting structure so
|
||||
// that modifications can be made.
|
||||
|
||||
var k, v, value = holder[key];
|
||||
if (value && typeof value === 'object') {
|
||||
for (k in value) {
|
||||
if (Object.hasOwnProperty.call(value, k)) {
|
||||
v = walk(value, k);
|
||||
if (v !== undefined) {
|
||||
value[k] = v;
|
||||
} else {
|
||||
delete value[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return reviver.call(holder, key, value);
|
||||
}
|
||||
|
||||
|
||||
// Parsing happens in four stages. In the first stage, we replace certain
|
||||
// Unicode characters with escape sequences. JavaScript handles many characters
|
||||
// incorrectly, either silently deleting them, or treating them as line endings.
|
||||
|
||||
text = String(text);
|
||||
cx.lastIndex = 0;
|
||||
if (cx.test(text)) {
|
||||
text = text.replace(cx, function (a) {
|
||||
return '\\u' +
|
||||
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
}
|
||||
|
||||
// In the second stage, we run the text against regular expressions that look
|
||||
// for non-JSON patterns. We are especially concerned with '()' and 'new'
|
||||
// because they can cause invocation, and '=' because it can cause mutation.
|
||||
// But just to be safe, we want to reject all unexpected forms.
|
||||
|
||||
// We split the second stage into 4 regexp operations in order to work around
|
||||
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
||||
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
|
||||
// replace all simple value tokens with ']' characters. Third, we delete all
|
||||
// open brackets that follow a colon or comma or that begin the text. Finally,
|
||||
// we look to see that the remaining characters are only whitespace or ']' or
|
||||
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
||||
|
||||
if (/^[\],:{}\s]*$/
|
||||
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
||||
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
||||
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
||||
|
||||
// In the third stage we use the eval function to compile the text into a
|
||||
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
||||
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
||||
// in parens to eliminate the ambiguity.
|
||||
|
||||
j = eval('(' + text + ')');
|
||||
|
||||
// In the optional fourth stage, we recursively walk the new structure, passing
|
||||
// each name/value pair to a reviver function for possible transformation.
|
||||
|
||||
return typeof reviver === 'function' ?
|
||||
walk({'': j}, '') : j;
|
||||
}
|
||||
|
||||
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
||||
|
||||
throw new SyntaxError('JSON.parse');
|
||||
};
|
||||
}
|
||||
}());
|
22
js/libraries/balupton-history/tests.src/_header.php
Executable file
22
js/libraries/balupton-history/tests.src/_header.php
Executable file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
# Locations
|
||||
$dir = dirname(__FILE__);
|
||||
$out = "$dir/../tests";
|
||||
|
||||
# Base URL
|
||||
$base_url = '/';
|
||||
$tests_url = $base_url.'tests';
|
||||
|
||||
# Data
|
||||
$browsers = array(
|
||||
'html4+html5',
|
||||
'html5'
|
||||
);
|
||||
$adapters = array(
|
||||
'jquery',
|
||||
'mootools',
|
||||
'native',
|
||||
'right',
|
||||
'zepto'
|
||||
);
|
||||
|
45
js/libraries/balupton-history/tests.src/all.php
Executable file
45
js/libraries/balupton-history/tests.src/all.php
Executable file
@ -0,0 +1,45 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>History.js Test Suite</title>
|
||||
<style type="text/css">
|
||||
body,html,iframe {
|
||||
padding:0;
|
||||
margin:0;
|
||||
outline:none;
|
||||
border:none;
|
||||
}
|
||||
.browser {
|
||||
padding-top:1em;
|
||||
}
|
||||
.adapter {
|
||||
padding-top:1em;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>History.js Test Suite</h1>
|
||||
<p>HTML5 Browsers must pass the HTML4+HTML5 tests</p>
|
||||
<p>HTML4 Browsers must pass the HTML4 tests and should fail the HTML5 tests</p>
|
||||
<?php
|
||||
foreach ( $browsers as $browser ) :
|
||||
echo '<div class="browser">';
|
||||
foreach ( $adapters as $adapter ) :
|
||||
echo '<div class="adapter">';
|
||||
# Url
|
||||
$url = "${browser}.${adapter}.html";
|
||||
|
||||
# Title
|
||||
$Browser = ucwords($browser);
|
||||
$Adapter = ucwords($adapter);
|
||||
$title = "History.js ${Browser} ${Adapter} Test Suite";
|
||||
|
||||
# Render
|
||||
?><a href="<?=$url?>"><?=$title?></a><?php
|
||||
echo '</div>';
|
||||
endforeach;
|
||||
echo '</div>';
|
||||
endforeach;
|
||||
?>
|
||||
</body>
|
||||
</html>
|
51
js/libraries/balupton-history/tests.src/each.php
Executable file
51
js/libraries/balupton-history/tests.src/each.php
Executable file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
# Url
|
||||
$url = "${browser}.${adapter}.html";
|
||||
|
||||
# Titles
|
||||
$Browser = strtoupper($browser);
|
||||
$Adapter = ucwords($adapter);
|
||||
$title = "History.js ${Browser} ${Adapter} Test Suite";
|
||||
?><!DOCTYPE html>
|
||||
<html debug="true">
|
||||
<head>
|
||||
<meta http-equiv="Expires" CONTENT="Mon, 06 Jan 1990 00:00:01 GMT" />
|
||||
<meta http-equiv="PRAGMA" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="CACHE-CONTROL" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<title><?=$title?></title>
|
||||
|
||||
<!-- Check -->
|
||||
<script>
|
||||
var href = window.document.location.href,
|
||||
test_url = href.replace(/(history\.js\/tests\/[^\/\?\#]+).*/,'$1');
|
||||
if ( test_url !== href ) {
|
||||
window.document.location.href = test_url;
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Framework -->
|
||||
<script src="../vendor/<?=$adapter?>.js"></script>
|
||||
|
||||
<!-- QUnit -->
|
||||
<link rel="stylesheet" href="../vendor/qunit/qunit/qunit.css" type="text/css" media="screen">
|
||||
<script src="../vendor/qunit/qunit/qunit.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Elements -->
|
||||
<h1 id="qunit-header"><?=$title?></h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">test markup</div>
|
||||
<button onclick="history.back()">back</button><button onclick="history.forward()">forward</button>
|
||||
<textarea id="log" style="width:100%;height:400px"></textarea>
|
||||
|
||||
<!-- History.js -->
|
||||
<script src="../scripts/bundled/<?=$browser?>/<?=$adapter?>.history.js"></script>
|
||||
|
||||
<!-- Tests -->
|
||||
<script src="tests.js"></script>
|
||||
</body>
|
||||
</html>
|
23
js/libraries/balupton-history/tests.src/index.php
Executable file
23
js/libraries/balupton-history/tests.src/index.php
Executable file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
# Header
|
||||
require_once(dirname(__FILE__).'/_header.php');
|
||||
|
||||
# Index
|
||||
ob_start();
|
||||
require($dir.'/all.php');
|
||||
$contents = ob_get_contents();
|
||||
ob_end_clean();
|
||||
file_put_contents($out.'/index.html', $contents);
|
||||
|
||||
# Each
|
||||
foreach ( $browsers as $browser )
|
||||
foreach ( $adapters as $adapter ) {
|
||||
ob_start();
|
||||
require($dir.'/each.php');
|
||||
$contents = ob_get_contents();
|
||||
ob_end_clean();
|
||||
file_put_contents($out."/${url}", $contents);
|
||||
}
|
||||
|
||||
# Done
|
||||
?><html><body><a href="../tests">Tests</a></body></html>
|
13
js/libraries/balupton-history/tests/.htaccess
Executable file
13
js/libraries/balupton-history/tests/.htaccess
Executable file
@ -0,0 +1,13 @@
|
||||
Options +FollowSymlinks
|
||||
RewriteEngine On
|
||||
|
||||
# Clean Adapter
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ([^\.]+)$ $1.html [NC,L,QSA]
|
||||
|
||||
# Can someone smarter than me make it so:
|
||||
# http://localhost/history.js/tests/uncompressed-html5-persistant-jquery
|
||||
# Does not redirect to:
|
||||
# http://localhost/history.js/tests/uncompressed-html5-persistant-jquery.html
|
||||
# But still accesses that url
|
43
js/libraries/balupton-history/tests/html4+html5.jquery.html
Executable file
43
js/libraries/balupton-history/tests/html4+html5.jquery.html
Executable file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html debug="true">
|
||||
<head>
|
||||
<meta http-equiv="Expires" CONTENT="Mon, 06 Jan 1990 00:00:01 GMT" />
|
||||
<meta http-equiv="PRAGMA" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="CACHE-CONTROL" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<title>History.js HTML4+HTML5 Jquery Test Suite</title>
|
||||
|
||||
<!-- Check -->
|
||||
<script>
|
||||
var href = window.document.location.href,
|
||||
test_url = href.replace(/(history\.js\/tests\/[^\/\?\#]+).*/,'$1');
|
||||
if ( test_url !== href ) {
|
||||
window.document.location.href = test_url;
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Framework -->
|
||||
<script src="../vendor/jquery.js"></script>
|
||||
|
||||
<!-- QUnit -->
|
||||
<link rel="stylesheet" href="../vendor/qunit/qunit/qunit.css" type="text/css" media="screen">
|
||||
<script src="../vendor/qunit/qunit/qunit.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Elements -->
|
||||
<h1 id="qunit-header">History.js HTML4+HTML5 Jquery Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">test markup</div>
|
||||
<button onclick="history.back()">back</button><button onclick="history.forward()">forward</button>
|
||||
<textarea id="log" style="width:100%;height:400px"></textarea>
|
||||
|
||||
<!-- History.js -->
|
||||
<script src="../scripts/bundled/html4+html5/jquery.history.js"></script>
|
||||
|
||||
<!-- Tests -->
|
||||
<script src="tests.js"></script>
|
||||
</body>
|
||||
</html>
|
43
js/libraries/balupton-history/tests/html4+html5.mootools.html
Executable file
43
js/libraries/balupton-history/tests/html4+html5.mootools.html
Executable file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html debug="true">
|
||||
<head>
|
||||
<meta http-equiv="Expires" CONTENT="Mon, 06 Jan 1990 00:00:01 GMT" />
|
||||
<meta http-equiv="PRAGMA" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="CACHE-CONTROL" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<title>History.js HTML4+HTML5 Mootools Test Suite</title>
|
||||
|
||||
<!-- Check -->
|
||||
<script>
|
||||
var href = window.document.location.href,
|
||||
test_url = href.replace(/(history\.js\/tests\/[^\/\?\#]+).*/,'$1');
|
||||
if ( test_url !== href ) {
|
||||
window.document.location.href = test_url;
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Framework -->
|
||||
<script src="../vendor/mootools.js"></script>
|
||||
|
||||
<!-- QUnit -->
|
||||
<link rel="stylesheet" href="../vendor/qunit/qunit/qunit.css" type="text/css" media="screen">
|
||||
<script src="../vendor/qunit/qunit/qunit.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Elements -->
|
||||
<h1 id="qunit-header">History.js HTML4+HTML5 Mootools Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">test markup</div>
|
||||
<button onclick="history.back()">back</button><button onclick="history.forward()">forward</button>
|
||||
<textarea id="log" style="width:100%;height:400px"></textarea>
|
||||
|
||||
<!-- History.js -->
|
||||
<script src="../scripts/bundled/html4+html5/mootools.history.js"></script>
|
||||
|
||||
<!-- Tests -->
|
||||
<script src="tests.js"></script>
|
||||
</body>
|
||||
</html>
|
43
js/libraries/balupton-history/tests/html4+html5.native.html
Executable file
43
js/libraries/balupton-history/tests/html4+html5.native.html
Executable file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html debug="true">
|
||||
<head>
|
||||
<meta http-equiv="Expires" CONTENT="Mon, 06 Jan 1990 00:00:01 GMT" />
|
||||
<meta http-equiv="PRAGMA" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="CACHE-CONTROL" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<title>History.js HTML4+HTML5 Native Test Suite</title>
|
||||
|
||||
<!-- Check -->
|
||||
<script>
|
||||
var href = window.document.location.href,
|
||||
test_url = href.replace(/(history\.js\/tests\/[^\/\?\#]+).*/,'$1');
|
||||
if ( test_url !== href ) {
|
||||
window.document.location.href = test_url;
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Framework -->
|
||||
<script src="../vendor/native.js"></script>
|
||||
|
||||
<!-- QUnit -->
|
||||
<link rel="stylesheet" href="../vendor/qunit/qunit/qunit.css" type="text/css" media="screen">
|
||||
<script src="../vendor/qunit/qunit/qunit.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Elements -->
|
||||
<h1 id="qunit-header">History.js HTML4+HTML5 Native Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">test markup</div>
|
||||
<button onclick="history.back()">back</button><button onclick="history.forward()">forward</button>
|
||||
<textarea id="log" style="width:100%;height:400px"></textarea>
|
||||
|
||||
<!-- History.js -->
|
||||
<script src="../scripts/bundled/html4+html5/native.history.js"></script>
|
||||
|
||||
<!-- Tests -->
|
||||
<script src="tests.js"></script>
|
||||
</body>
|
||||
</html>
|
43
js/libraries/balupton-history/tests/html4+html5.right.html
Executable file
43
js/libraries/balupton-history/tests/html4+html5.right.html
Executable file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html debug="true">
|
||||
<head>
|
||||
<meta http-equiv="Expires" CONTENT="Mon, 06 Jan 1990 00:00:01 GMT" />
|
||||
<meta http-equiv="PRAGMA" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="CACHE-CONTROL" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<title>History.js HTML4+HTML5 Right Test Suite</title>
|
||||
|
||||
<!-- Check -->
|
||||
<script>
|
||||
var href = window.document.location.href,
|
||||
test_url = href.replace(/(history\.js\/tests\/[^\/\?\#]+).*/,'$1');
|
||||
if ( test_url !== href ) {
|
||||
window.document.location.href = test_url;
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Framework -->
|
||||
<script src="../vendor/right.js"></script>
|
||||
|
||||
<!-- QUnit -->
|
||||
<link rel="stylesheet" href="../vendor/qunit/qunit/qunit.css" type="text/css" media="screen">
|
||||
<script src="../vendor/qunit/qunit/qunit.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Elements -->
|
||||
<h1 id="qunit-header">History.js HTML4+HTML5 Right Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">test markup</div>
|
||||
<button onclick="history.back()">back</button><button onclick="history.forward()">forward</button>
|
||||
<textarea id="log" style="width:100%;height:400px"></textarea>
|
||||
|
||||
<!-- History.js -->
|
||||
<script src="../scripts/bundled/html4+html5/right.history.js"></script>
|
||||
|
||||
<!-- Tests -->
|
||||
<script src="tests.js"></script>
|
||||
</body>
|
||||
</html>
|
43
js/libraries/balupton-history/tests/html4+html5.zepto.html
Executable file
43
js/libraries/balupton-history/tests/html4+html5.zepto.html
Executable file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html debug="true">
|
||||
<head>
|
||||
<meta http-equiv="Expires" CONTENT="Mon, 06 Jan 1990 00:00:01 GMT" />
|
||||
<meta http-equiv="PRAGMA" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="CACHE-CONTROL" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<title>History.js HTML4+HTML5 Zepto Test Suite</title>
|
||||
|
||||
<!-- Check -->
|
||||
<script>
|
||||
var href = window.document.location.href,
|
||||
test_url = href.replace(/(history\.js\/tests\/[^\/\?\#]+).*/,'$1');
|
||||
if ( test_url !== href ) {
|
||||
window.document.location.href = test_url;
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Framework -->
|
||||
<script src="../vendor/zepto.js"></script>
|
||||
|
||||
<!-- QUnit -->
|
||||
<link rel="stylesheet" href="../vendor/qunit/qunit/qunit.css" type="text/css" media="screen">
|
||||
<script src="../vendor/qunit/qunit/qunit.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Elements -->
|
||||
<h1 id="qunit-header">History.js HTML4+HTML5 Zepto Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">test markup</div>
|
||||
<button onclick="history.back()">back</button><button onclick="history.forward()">forward</button>
|
||||
<textarea id="log" style="width:100%;height:400px"></textarea>
|
||||
|
||||
<!-- History.js -->
|
||||
<script src="../scripts/bundled/html4+html5/zepto.history.js"></script>
|
||||
|
||||
<!-- Tests -->
|
||||
<script src="tests.js"></script>
|
||||
</body>
|
||||
</html>
|
43
js/libraries/balupton-history/tests/html5.jquery.html
Executable file
43
js/libraries/balupton-history/tests/html5.jquery.html
Executable file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html debug="true">
|
||||
<head>
|
||||
<meta http-equiv="Expires" CONTENT="Mon, 06 Jan 1990 00:00:01 GMT" />
|
||||
<meta http-equiv="PRAGMA" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="CACHE-CONTROL" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<title>History.js HTML5 Jquery Test Suite</title>
|
||||
|
||||
<!-- Check -->
|
||||
<script>
|
||||
var href = window.document.location.href,
|
||||
test_url = href.replace(/(history\.js\/tests\/[^\/\?\#]+).*/,'$1');
|
||||
if ( test_url !== href ) {
|
||||
window.document.location.href = test_url;
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Framework -->
|
||||
<script src="../vendor/jquery.js"></script>
|
||||
|
||||
<!-- QUnit -->
|
||||
<link rel="stylesheet" href="../vendor/qunit/qunit/qunit.css" type="text/css" media="screen">
|
||||
<script src="../vendor/qunit/qunit/qunit.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Elements -->
|
||||
<h1 id="qunit-header">History.js HTML5 Jquery Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">test markup</div>
|
||||
<button onclick="history.back()">back</button><button onclick="history.forward()">forward</button>
|
||||
<textarea id="log" style="width:100%;height:400px"></textarea>
|
||||
|
||||
<!-- History.js -->
|
||||
<script src="../scripts/bundled/html5/jquery.history.js"></script>
|
||||
|
||||
<!-- Tests -->
|
||||
<script src="tests.js"></script>
|
||||
</body>
|
||||
</html>
|
43
js/libraries/balupton-history/tests/html5.mootools.html
Executable file
43
js/libraries/balupton-history/tests/html5.mootools.html
Executable file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html debug="true">
|
||||
<head>
|
||||
<meta http-equiv="Expires" CONTENT="Mon, 06 Jan 1990 00:00:01 GMT" />
|
||||
<meta http-equiv="PRAGMA" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="CACHE-CONTROL" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<title>History.js HTML5 Mootools Test Suite</title>
|
||||
|
||||
<!-- Check -->
|
||||
<script>
|
||||
var href = window.document.location.href,
|
||||
test_url = href.replace(/(history\.js\/tests\/[^\/\?\#]+).*/,'$1');
|
||||
if ( test_url !== href ) {
|
||||
window.document.location.href = test_url;
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Framework -->
|
||||
<script src="../vendor/mootools.js"></script>
|
||||
|
||||
<!-- QUnit -->
|
||||
<link rel="stylesheet" href="../vendor/qunit/qunit/qunit.css" type="text/css" media="screen">
|
||||
<script src="../vendor/qunit/qunit/qunit.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Elements -->
|
||||
<h1 id="qunit-header">History.js HTML5 Mootools Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">test markup</div>
|
||||
<button onclick="history.back()">back</button><button onclick="history.forward()">forward</button>
|
||||
<textarea id="log" style="width:100%;height:400px"></textarea>
|
||||
|
||||
<!-- History.js -->
|
||||
<script src="../scripts/bundled/html5/mootools.history.js"></script>
|
||||
|
||||
<!-- Tests -->
|
||||
<script src="tests.js"></script>
|
||||
</body>
|
||||
</html>
|
43
js/libraries/balupton-history/tests/html5.native.html
Executable file
43
js/libraries/balupton-history/tests/html5.native.html
Executable file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html debug="true">
|
||||
<head>
|
||||
<meta http-equiv="Expires" CONTENT="Mon, 06 Jan 1990 00:00:01 GMT" />
|
||||
<meta http-equiv="PRAGMA" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="CACHE-CONTROL" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<title>History.js HTML5 Native Test Suite</title>
|
||||
|
||||
<!-- Check -->
|
||||
<script>
|
||||
var href = window.document.location.href,
|
||||
test_url = href.replace(/(history\.js\/tests\/[^\/\?\#]+).*/,'$1');
|
||||
if ( test_url !== href ) {
|
||||
window.document.location.href = test_url;
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Framework -->
|
||||
<script src="../vendor/native.js"></script>
|
||||
|
||||
<!-- QUnit -->
|
||||
<link rel="stylesheet" href="../vendor/qunit/qunit/qunit.css" type="text/css" media="screen">
|
||||
<script src="../vendor/qunit/qunit/qunit.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Elements -->
|
||||
<h1 id="qunit-header">History.js HTML5 Native Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">test markup</div>
|
||||
<button onclick="history.back()">back</button><button onclick="history.forward()">forward</button>
|
||||
<textarea id="log" style="width:100%;height:400px"></textarea>
|
||||
|
||||
<!-- History.js -->
|
||||
<script src="../scripts/bundled/html5/native.history.js"></script>
|
||||
|
||||
<!-- Tests -->
|
||||
<script src="tests.js"></script>
|
||||
</body>
|
||||
</html>
|
43
js/libraries/balupton-history/tests/html5.right.html
Executable file
43
js/libraries/balupton-history/tests/html5.right.html
Executable file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html debug="true">
|
||||
<head>
|
||||
<meta http-equiv="Expires" CONTENT="Mon, 06 Jan 1990 00:00:01 GMT" />
|
||||
<meta http-equiv="PRAGMA" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="CACHE-CONTROL" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<title>History.js HTML5 Right Test Suite</title>
|
||||
|
||||
<!-- Check -->
|
||||
<script>
|
||||
var href = window.document.location.href,
|
||||
test_url = href.replace(/(history\.js\/tests\/[^\/\?\#]+).*/,'$1');
|
||||
if ( test_url !== href ) {
|
||||
window.document.location.href = test_url;
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Framework -->
|
||||
<script src="../vendor/right.js"></script>
|
||||
|
||||
<!-- QUnit -->
|
||||
<link rel="stylesheet" href="../vendor/qunit/qunit/qunit.css" type="text/css" media="screen">
|
||||
<script src="../vendor/qunit/qunit/qunit.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Elements -->
|
||||
<h1 id="qunit-header">History.js HTML5 Right Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">test markup</div>
|
||||
<button onclick="history.back()">back</button><button onclick="history.forward()">forward</button>
|
||||
<textarea id="log" style="width:100%;height:400px"></textarea>
|
||||
|
||||
<!-- History.js -->
|
||||
<script src="../scripts/bundled/html5/right.history.js"></script>
|
||||
|
||||
<!-- Tests -->
|
||||
<script src="tests.js"></script>
|
||||
</body>
|
||||
</html>
|
43
js/libraries/balupton-history/tests/html5.zepto.html
Executable file
43
js/libraries/balupton-history/tests/html5.zepto.html
Executable file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html debug="true">
|
||||
<head>
|
||||
<meta http-equiv="Expires" CONTENT="Mon, 06 Jan 1990 00:00:01 GMT" />
|
||||
<meta http-equiv="PRAGMA" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="CACHE-CONTROL" CONTENT="NO-CACHE" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<title>History.js HTML5 Zepto Test Suite</title>
|
||||
|
||||
<!-- Check -->
|
||||
<script>
|
||||
var href = window.document.location.href,
|
||||
test_url = href.replace(/(history\.js\/tests\/[^\/\?\#]+).*/,'$1');
|
||||
if ( test_url !== href ) {
|
||||
window.document.location.href = test_url;
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Framework -->
|
||||
<script src="../vendor/zepto.js"></script>
|
||||
|
||||
<!-- QUnit -->
|
||||
<link rel="stylesheet" href="../vendor/qunit/qunit/qunit.css" type="text/css" media="screen">
|
||||
<script src="../vendor/qunit/qunit/qunit.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Elements -->
|
||||
<h1 id="qunit-header">History.js HTML5 Zepto Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">test markup</div>
|
||||
<button onclick="history.back()">back</button><button onclick="history.forward()">forward</button>
|
||||
<textarea id="log" style="width:100%;height:400px"></textarea>
|
||||
|
||||
<!-- History.js -->
|
||||
<script src="../scripts/bundled/html5/zepto.history.js"></script>
|
||||
|
||||
<!-- Tests -->
|
||||
<script src="tests.js"></script>
|
||||
</body>
|
||||
</html>
|
3
js/libraries/balupton-history/tests/image.php
Executable file
3
js/libraries/balupton-history/tests/image.php
Executable file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
header('Content-type: image/jpeg');
|
||||
sleep(10);
|
25
js/libraries/balupton-history/tests/index.html
Executable file
25
js/libraries/balupton-history/tests/index.html
Executable file
@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>History.js Test Suite</title>
|
||||
<style type="text/css">
|
||||
body,html,iframe {
|
||||
padding:0;
|
||||
margin:0;
|
||||
outline:none;
|
||||
border:none;
|
||||
}
|
||||
.browser {
|
||||
padding-top:1em;
|
||||
}
|
||||
.adapter {
|
||||
padding-top:1em;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>History.js Test Suite</h1>
|
||||
<p>HTML5 Browsers must pass the HTML4+HTML5 tests</p>
|
||||
<p>HTML4 Browsers must pass the HTML4 tests and should fail the HTML5 tests</p>
|
||||
<div class="browser"><div class="adapter"><a href="html4+html5.jquery.html">History.js Html4+html5 Jquery Test Suite</a></div><div class="adapter"><a href="html4+html5.mootools.html">History.js Html4+html5 Mootools Test Suite</a></div><div class="adapter"><a href="html4+html5.native.html">History.js Html4+html5 Native Test Suite</a></div><div class="adapter"><a href="html4+html5.right.html">History.js Html4+html5 Right Test Suite</a></div><div class="adapter"><a href="html4+html5.zepto.html">History.js Html4+html5 Zepto Test Suite</a></div></div><div class="browser"><div class="adapter"><a href="html5.jquery.html">History.js Html5 Jquery Test Suite</a></div><div class="adapter"><a href="html5.mootools.html">History.js Html5 Mootools Test Suite</a></div><div class="adapter"><a href="html5.native.html">History.js Html5 Native Test Suite</a></div><div class="adapter"><a href="html5.right.html">History.js Html5 Right Test Suite</a></div><div class="adapter"><a href="html5.zepto.html">History.js Html5 Zepto Test Suite</a></div></div></body>
|
||||
</html>
|
254
js/libraries/balupton-history/tests/tests.js
Executable file
254
js/libraries/balupton-history/tests/tests.js
Executable file
@ -0,0 +1,254 @@
|
||||
(function(){
|
||||
|
||||
var
|
||||
History = window.History,
|
||||
document = window.document,
|
||||
test = window.test,
|
||||
same = window.same;
|
||||
|
||||
// Check
|
||||
if ( !History.enabled ) {
|
||||
throw new Error('History.js is disabled');
|
||||
}
|
||||
|
||||
// Prepare
|
||||
History.options.debug = false;
|
||||
|
||||
// Variables
|
||||
var
|
||||
States = {
|
||||
// Home
|
||||
0: {
|
||||
'url': document.location.href.replace(/#.*$/,''),
|
||||
'title': ''
|
||||
},
|
||||
// One
|
||||
1: {
|
||||
'data': {
|
||||
'state': 1,
|
||||
'rand': Math.random()
|
||||
},
|
||||
'title': 'State 1',
|
||||
'url': '?state=1'
|
||||
},
|
||||
// Two
|
||||
2: {
|
||||
'data': {
|
||||
'state': 2,
|
||||
'rand': Math.random()
|
||||
},
|
||||
'title': 'State 2',
|
||||
'url': '?state=2&asd=%20asd%2520asd'
|
||||
},
|
||||
// Three
|
||||
3: {
|
||||
'url': '?state=3'
|
||||
},
|
||||
// Four
|
||||
4: {
|
||||
'data': {
|
||||
'state': 4,
|
||||
'trick': true,
|
||||
'rand': Math.random()
|
||||
},
|
||||
'title': 'State 4',
|
||||
'url': '?state=3'
|
||||
},
|
||||
// Log
|
||||
5: {
|
||||
'url': '?state=1#log'
|
||||
},
|
||||
// Six
|
||||
6: {
|
||||
'data': {
|
||||
'state': 6,
|
||||
'rand': Math.random()
|
||||
},
|
||||
'url': 'six.html'
|
||||
},
|
||||
// Seven
|
||||
7: {
|
||||
'url': 'seven'
|
||||
},
|
||||
// Eight
|
||||
8: {
|
||||
'url': '/eight'
|
||||
}
|
||||
},
|
||||
stateOrder = [0,1,2,3,4,3,1,0,1,3,4,3,1,0,6,7,8,1,8,7,6,0],
|
||||
currentTest = 0;
|
||||
|
||||
// Original Title
|
||||
var title = document.title;
|
||||
|
||||
var banner;
|
||||
|
||||
var checkStatus = function(){
|
||||
banner = banner || document.getElementById('qunit-banner');
|
||||
var status = banner.className !== 'qunit-fail';
|
||||
return status;
|
||||
};
|
||||
|
||||
// Check State
|
||||
var checkState = function(){
|
||||
if ( !checkStatus() ) {
|
||||
throw new Error('A test has failed');
|
||||
}
|
||||
|
||||
var
|
||||
stateIndex = stateOrder[currentTest],
|
||||
expectedState = History.normalizeState(States[stateIndex]),
|
||||
actualState = History.getState(false);
|
||||
|
||||
++currentTest;
|
||||
|
||||
document.title = title+': '+actualState.url;
|
||||
|
||||
var
|
||||
testName = 'Test '+currentTest,
|
||||
stateName = 'State '+stateIndex;
|
||||
|
||||
test(testName,function(){
|
||||
History.log('Completed: '+testName +' / '+ stateName);
|
||||
same(actualState,expectedState,stateName);
|
||||
});
|
||||
|
||||
// Image Load to Stress Test Safari and Opera
|
||||
(new Image()).src = "image.php";
|
||||
};
|
||||
|
||||
// Check the Initial State
|
||||
checkState();
|
||||
|
||||
// State Change
|
||||
History.Adapter.bind(window,'statechange',checkState);
|
||||
|
||||
// Log
|
||||
var addLog = function(){
|
||||
var args = arguments;
|
||||
History.queue(function(){
|
||||
History.log.apply(History,args);
|
||||
});
|
||||
};
|
||||
|
||||
// Dom Load
|
||||
History.Adapter.onDomLoad(function(){
|
||||
setTimeout(function(){
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Test State Functionality: Adding
|
||||
|
||||
// Test 2 / State 1 (0 -> 1)
|
||||
// Tests HTML4 -> HTML5 Graceful Upgrade
|
||||
addLog('Test 2',History.queues.length,History.busy.flag);
|
||||
History.setHash(History.getHashByState(States[1]));
|
||||
|
||||
// Test 3 / State 2 (1 -> 2)
|
||||
addLog('Test 3',History.queues.length,History.busy.flag);
|
||||
History.pushState(States[2].data, States[2].title, States[2].url);
|
||||
|
||||
// Test 3-2 / State 2 (2 -> 2) / No Change
|
||||
addLog('Test 3-2',History.queues.length,History.busy.flag);
|
||||
History.pushState(States[2].data, States[2].title, States[2].url);
|
||||
|
||||
// Test 3-3 / State 2 (2 -> 2) / No Change
|
||||
addLog('Test 3-3',History.queues.length,History.busy.flag);
|
||||
History.replaceState(States[2].data, States[2].title, States[2].url);
|
||||
|
||||
// Test 4 / State 3 (2 -> 3)
|
||||
addLog('Test 4',History.queues.length,History.busy.flag);
|
||||
History.replaceState(States[3].data, States[3].title, States[3].url);
|
||||
|
||||
// Test 5 / State 4 (3 -> 4)
|
||||
addLog('Test 5',History.queues.length,History.busy.flag);
|
||||
History.pushState(States[4].data, States[4].title, States[4].url);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Test State Functionality: Traversing
|
||||
|
||||
// Test 6 / State 3 (4 -> 3)
|
||||
// Test 7 / State 1 (3 -> 2 -> 1)
|
||||
addLog('Test 6,7',History.queues.length,History.busy.flag);
|
||||
History.go(-2);
|
||||
|
||||
// Test 8 / State 0 (1 -> 0)
|
||||
// Tests Default State
|
||||
addLog('Test 8',History.queues.length,History.busy.flag);
|
||||
History.back();
|
||||
|
||||
// Test 9 / State 1 (0 -> 1)
|
||||
// Test 10 / State 3 (1 -> 2 -> 3)
|
||||
addLog('Test 9,10',History.queues.length,History.busy.flag);
|
||||
History.go(2);
|
||||
|
||||
// Test 11 / State 4 (3 -> 4)
|
||||
addLog('Test 11',History.queues.length,History.busy.flag);
|
||||
History.forward();
|
||||
|
||||
// Test 12 / State 3 (4 -> 3)
|
||||
addLog('Test 12',History.queues.length,History.busy.flag);
|
||||
History.back();
|
||||
|
||||
// Test 13 / State 1 (3 -> 2 -> 1)
|
||||
addLog('Test 13',History.queues.length,History.busy.flag);
|
||||
History.back();
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Test State Functionality: Traditional Anchors
|
||||
|
||||
// Test 13-2 / State 1 (1 -> #log) / No Change
|
||||
addLog('Test 13-2',History.queues.length,History.busy.flag);
|
||||
History.setHash('log');
|
||||
|
||||
// Test 13-3 / State 1 (#log -> 1) / No Change
|
||||
addLog('Test 13-3',History.queues.length,History.busy.flag);
|
||||
History.back();
|
||||
|
||||
// Test 14 / State 0 (1 -> 0)
|
||||
addLog('Test 14',History.queues.length,History.busy.flag);
|
||||
History.back();
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Test URL Handling: Adding
|
||||
|
||||
// Test 15 / State 6 (1 -> 6)
|
||||
// Also tests data with no title
|
||||
addLog('Test 15',History.queues.length,History.busy.flag);
|
||||
History.pushState(States[6].data, States[6].title, States[6].url);
|
||||
|
||||
// Test 16 / State 7 (6 -> 7)
|
||||
addLog('Test 16',History.queues.length,History.busy.flag);
|
||||
History.pushState(States[7].data, States[7].title, States[7].url);
|
||||
|
||||
// Test 17 / State 7 (7 -> 8)
|
||||
addLog('Test 17',History.queues.length,History.busy.flag);
|
||||
History.pushState(States[8].data, States[8].title, States[8].url);
|
||||
|
||||
// Test 18 / State 1 (8 -> 1)
|
||||
// Should be /eight?state=1
|
||||
addLog('Test 18',History.queues.length,History.busy.flag);
|
||||
History.pushState(States[1].data, States[1].title, States[1].url);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Test URL Handling: Traversing
|
||||
|
||||
// Test 19 / State 8 (1 -> 8)
|
||||
addLog('Test 19',History.queues.length,History.busy.flag);
|
||||
History.back();
|
||||
|
||||
// Test 20 / State 7 (8 -> 7)
|
||||
addLog('Test 20',History.queues.length,History.busy.flag);
|
||||
History.back();
|
||||
|
||||
// Test 21 / State 6 (7 -> 6)
|
||||
addLog('Test 21',History.queues.length,History.busy.flag);
|
||||
History.back();
|
||||
|
||||
// Test 22 / State 0 (6 -> 0)
|
||||
addLog('Test 22',History.queues.length,History.busy.flag);
|
||||
History.back();
|
||||
|
||||
},1000); // wait for test one to complete
|
||||
});
|
||||
|
||||
})();
|
9046
js/libraries/balupton-history/vendor/jquery.js
vendored
Executable file
9046
js/libraries/balupton-history/vendor/jquery.js
vendored
Executable file
File diff suppressed because it is too large
Load Diff
5815
js/libraries/balupton-history/vendor/mootools.js
vendored
Executable file
5815
js/libraries/balupton-history/vendor/mootools.js
vendored
Executable file
File diff suppressed because it is too large
Load Diff
6
js/libraries/balupton-history/vendor/qunit/.gitignore
vendored
Executable file
6
js/libraries/balupton-history/vendor/qunit/.gitignore
vendored
Executable file
@ -0,0 +1,6 @@
|
||||
.project
|
||||
*~
|
||||
*.diff
|
||||
*.patch
|
||||
.DS_Store
|
||||
|
27
js/libraries/balupton-history/vendor/qunit/README.md
vendored
Executable file
27
js/libraries/balupton-history/vendor/qunit/README.md
vendored
Executable file
@ -0,0 +1,27 @@
|
||||
[QUnit](http://docs.jquery.com/QUnit) - A JavaScript Unit Testing framework.
|
||||
================================
|
||||
|
||||
QUnit is a powerful, easy-to-use, JavaScript test suite. It's used by the jQuery
|
||||
project to test its code and plugins but is capable of testing any generic
|
||||
JavaScript code (and even capable of testing JavaScript code on the server-side).
|
||||
|
||||
QUnit is especially useful for regression testing: Whenever a bug is reported,
|
||||
write a test that asserts the existence of that particular bug. Then fix it and
|
||||
commit both. Every time you work on the code again, run the tests. If the bug
|
||||
comes up again - a regression - you'll spot it immediately and know how to fix
|
||||
it, because you know what code you just changed.
|
||||
|
||||
Having good unit test coverage makes safe refactoring easy and cheap. You can
|
||||
run the tests after each small refactoring step and always know what change
|
||||
broke something.
|
||||
|
||||
QUnit is similar to other unit testing frameworks like JUnit, but makes use of
|
||||
the features JavaScript provides and helps with testing code in the browser, eg.
|
||||
with it's stop/start facilities for testing asynchronous code.
|
||||
|
||||
If you are interested in helping developing QUnit, you are in the right place.
|
||||
For related discussions, visit the
|
||||
[QUnit and Testing forum](http://forum.jquery.com/qunit-and-testing).
|
||||
|
||||
Planning for a qunitjs.com site and other testing tools related work now happens
|
||||
on the [jQuery Testing Team planning wiki](http://jquerytesting.pbworks.com/w/page/41556026/FrontPage).
|
21
js/libraries/balupton-history/vendor/qunit/package.json
vendored
Executable file
21
js/libraries/balupton-history/vendor/qunit/package.json
vendored
Executable file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "qunit",
|
||||
"author": {
|
||||
"name": "John Resig",
|
||||
"email": "jeresig@gmail.com",
|
||||
"url": "http://ejohn.org/"
|
||||
},
|
||||
"maintainer": {
|
||||
"name": "Jörn Zaefferer",
|
||||
"email": "joern.zaefferer@googlemail.com",
|
||||
"url": "http://bassistance.de/"
|
||||
},
|
||||
"url": "http://docs.jquery.com/QUnit",
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "http://www.opensource.org/licenses/mit-license.php"
|
||||
},
|
||||
"description": "An easy-to-use JavaScript Unit Testing framework.",
|
||||
"keywords": [ "testing", "unit", "jquery" ],
|
||||
"lib": "qunit"
|
||||
}
|
225
js/libraries/balupton-history/vendor/qunit/qunit/qunit.css
vendored
Executable file
225
js/libraries/balupton-history/vendor/qunit/qunit/qunit.css
vendored
Executable file
@ -0,0 +1,225 @@
|
||||
/**
|
||||
* QUnit - A JavaScript Unit Testing Framework
|
||||
*
|
||||
* http://docs.jquery.com/QUnit
|
||||
*
|
||||
* Copyright (c) 2011 John Resig, Jörn Zaefferer
|
||||
* Dual licensed under the MIT (MIT-LICENSE.txt)
|
||||
* or GPL (GPL-LICENSE.txt) licenses.
|
||||
*/
|
||||
|
||||
/** Font Family and Sizes */
|
||||
|
||||
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
|
||||
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
|
||||
#qunit-tests { font-size: smaller; }
|
||||
|
||||
|
||||
/** Resets */
|
||||
|
||||
#qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
|
||||
/** Header */
|
||||
|
||||
#qunit-header {
|
||||
padding: 0.5em 0 0.5em 1em;
|
||||
|
||||
color: #8699a4;
|
||||
background-color: #0d3349;
|
||||
|
||||
font-size: 1.5em;
|
||||
line-height: 1em;
|
||||
font-weight: normal;
|
||||
|
||||
border-radius: 15px 15px 0 0;
|
||||
-moz-border-radius: 15px 15px 0 0;
|
||||
-webkit-border-top-right-radius: 15px;
|
||||
-webkit-border-top-left-radius: 15px;
|
||||
}
|
||||
|
||||
#qunit-header a {
|
||||
text-decoration: none;
|
||||
color: #c2ccd1;
|
||||
}
|
||||
|
||||
#qunit-header a:hover,
|
||||
#qunit-header a:focus {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
#qunit-banner {
|
||||
height: 5px;
|
||||
}
|
||||
|
||||
#qunit-testrunner-toolbar {
|
||||
padding: 0.5em 0 0.5em 2em;
|
||||
color: #5E740B;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
#qunit-userAgent {
|
||||
padding: 0.5em 0 0.5em 2.5em;
|
||||
background-color: #2b81af;
|
||||
color: #fff;
|
||||
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
|
||||
}
|
||||
|
||||
|
||||
/** Tests: Pass/Fail */
|
||||
|
||||
#qunit-tests {
|
||||
list-style-position: inside;
|
||||
}
|
||||
|
||||
#qunit-tests li {
|
||||
padding: 0.4em 0.5em 0.4em 2.5em;
|
||||
border-bottom: 1px solid #fff;
|
||||
list-style-position: inside;
|
||||
}
|
||||
|
||||
#qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#qunit-tests li strong {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#qunit-tests li a {
|
||||
padding: 0.5em;
|
||||
color: #c2ccd1;
|
||||
text-decoration: none;
|
||||
}
|
||||
#qunit-tests li a:hover,
|
||||
#qunit-tests li a:focus {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#qunit-tests ol {
|
||||
margin-top: 0.5em;
|
||||
padding: 0.5em;
|
||||
|
||||
background-color: #fff;
|
||||
|
||||
border-radius: 15px;
|
||||
-moz-border-radius: 15px;
|
||||
-webkit-border-radius: 15px;
|
||||
|
||||
box-shadow: inset 0px 2px 13px #999;
|
||||
-moz-box-shadow: inset 0px 2px 13px #999;
|
||||
-webkit-box-shadow: inset 0px 2px 13px #999;
|
||||
}
|
||||
|
||||
#qunit-tests table {
|
||||
border-collapse: collapse;
|
||||
margin-top: .2em;
|
||||
}
|
||||
|
||||
#qunit-tests th {
|
||||
text-align: right;
|
||||
vertical-align: top;
|
||||
padding: 0 .5em 0 0;
|
||||
}
|
||||
|
||||
#qunit-tests td {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
#qunit-tests pre {
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
#qunit-tests del {
|
||||
background-color: #e0f2be;
|
||||
color: #374e0c;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#qunit-tests ins {
|
||||
background-color: #ffcaca;
|
||||
color: #500;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/*** Test Counts */
|
||||
|
||||
#qunit-tests b.counts { color: black; }
|
||||
#qunit-tests b.passed { color: #5E740B; }
|
||||
#qunit-tests b.failed { color: #710909; }
|
||||
|
||||
#qunit-tests li li {
|
||||
margin: 0.5em;
|
||||
padding: 0.4em 0.5em 0.4em 0.5em;
|
||||
background-color: #fff;
|
||||
border-bottom: none;
|
||||
list-style-position: inside;
|
||||
}
|
||||
|
||||
/*** Passing Styles */
|
||||
|
||||
#qunit-tests li li.pass {
|
||||
color: #5E740B;
|
||||
background-color: #fff;
|
||||
border-left: 26px solid #C6E746;
|
||||
}
|
||||
|
||||
#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
|
||||
#qunit-tests .pass .test-name { color: #366097; }
|
||||
|
||||
#qunit-tests .pass .test-actual,
|
||||
#qunit-tests .pass .test-expected { color: #999999; }
|
||||
|
||||
#qunit-banner.qunit-pass { background-color: #C6E746; }
|
||||
|
||||
/*** Failing Styles */
|
||||
|
||||
#qunit-tests li li.fail {
|
||||
color: #710909;
|
||||
background-color: #fff;
|
||||
border-left: 26px solid #EE5757;
|
||||
}
|
||||
|
||||
#qunit-tests > li:last-child {
|
||||
border-radius: 0 0 15px 15px;
|
||||
-moz-border-radius: 0 0 15px 15px;
|
||||
-webkit-border-bottom-right-radius: 15px;
|
||||
-webkit-border-bottom-left-radius: 15px;
|
||||
}
|
||||
|
||||
#qunit-tests .fail { color: #000000; background-color: #EE5757; }
|
||||
#qunit-tests .fail .test-name,
|
||||
#qunit-tests .fail .module-name { color: #000000; }
|
||||
|
||||
#qunit-tests .fail .test-actual { color: #EE5757; }
|
||||
#qunit-tests .fail .test-expected { color: green; }
|
||||
|
||||
#qunit-banner.qunit-fail { background-color: #EE5757; }
|
||||
|
||||
|
||||
/** Result */
|
||||
|
||||
#qunit-testresult {
|
||||
padding: 0.5em 0.5em 0.5em 2.5em;
|
||||
|
||||
color: #2b81af;
|
||||
background-color: #D2E0E6;
|
||||
|
||||
border-bottom: 1px solid white;
|
||||
}
|
||||
|
||||
/** Fixture */
|
||||
|
||||
#qunit-fixture {
|
||||
position: absolute;
|
||||
top: -10000px;
|
||||
left: -10000px;
|
||||
}
|
1442
js/libraries/balupton-history/vendor/qunit/qunit/qunit.js
vendored
Executable file
1442
js/libraries/balupton-history/vendor/qunit/qunit/qunit.js
vendored
Executable file
File diff suppressed because it is too large
Load Diff
24
js/libraries/balupton-history/vendor/qunit/test/headless.html
vendored
Executable file
24
js/libraries/balupton-history/vendor/qunit/test/headless.html
vendored
Executable file
@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>QUnit Test Suite</title>
|
||||
<link rel="stylesheet" href="../qunit/qunit.css" type="text/css" media="screen">
|
||||
<script type="text/javascript" src="../qunit/qunit.js"></script>
|
||||
<script type="text/javascript" src="test.js"></script>
|
||||
<script type="text/javascript" src="same.js"></script>
|
||||
<script>
|
||||
var logs = ["begin", "testStart", "testDone", "log", "moduleStart", "moduleDone", "done"];
|
||||
for (var i = 0; i < logs.length; i++) {
|
||||
(function() {
|
||||
var log = logs[i];
|
||||
QUnit[log] = function() {
|
||||
console.log(log, arguments);
|
||||
};
|
||||
})();
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit-fixture">test markup</div>
|
||||
</body>
|
||||
</html>
|
19
js/libraries/balupton-history/vendor/qunit/test/index.html
vendored
Executable file
19
js/libraries/balupton-history/vendor/qunit/test/index.html
vendored
Executable file
@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>QUnit Test Suite</title>
|
||||
<link rel="stylesheet" href="../qunit/qunit.css" type="text/css" media="screen">
|
||||
<script type="text/javascript" src="../qunit/qunit.js"></script>
|
||||
<script type="text/javascript" src="test.js"></script>
|
||||
<script type="text/javascript" src="same.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">QUnit Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">test markup</div>
|
||||
</body>
|
||||
</html>
|
17
js/libraries/balupton-history/vendor/qunit/test/logs.html
vendored
Executable file
17
js/libraries/balupton-history/vendor/qunit/test/logs.html
vendored
Executable file
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>QUnit Test Suite</title>
|
||||
<link rel="stylesheet" href="../qunit/qunit.css" type="text/css" media="screen">
|
||||
<script type="text/javascript" src="../qunit/qunit.js"></script>
|
||||
<script type="text/javascript" src="logs.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">QUnit Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">test markup</div>
|
||||
</body>
|
||||
</html>
|
150
js/libraries/balupton-history/vendor/qunit/test/logs.js
vendored
Executable file
150
js/libraries/balupton-history/vendor/qunit/test/logs.js
vendored
Executable file
@ -0,0 +1,150 @@
|
||||
// TODO disable reordering for this suite!
|
||||
|
||||
|
||||
var begin = 0,
|
||||
moduleStart = 0,
|
||||
moduleDone = 0,
|
||||
testStart = 0,
|
||||
testDone = 0,
|
||||
log = 0,
|
||||
moduleContext,
|
||||
moduleDoneContext,
|
||||
testContext,
|
||||
testDoneContext,
|
||||
logContext;
|
||||
|
||||
QUnit.begin = function() {
|
||||
begin++;
|
||||
};
|
||||
QUnit.done = function() {
|
||||
};
|
||||
QUnit.moduleStart = function(context) {
|
||||
moduleStart++;
|
||||
moduleContext = context;
|
||||
};
|
||||
QUnit.moduleDone = function(context) {
|
||||
moduleDone++;
|
||||
moduleDoneContext = context;
|
||||
};
|
||||
QUnit.testStart = function(context) {
|
||||
testStart++;
|
||||
testContext = context;
|
||||
};
|
||||
QUnit.testDone = function(context) {
|
||||
testDone++;
|
||||
testDoneContext = context;
|
||||
};
|
||||
QUnit.log = function(context) {
|
||||
log++;
|
||||
logContext = context;
|
||||
};
|
||||
|
||||
var logs = ["begin", "testStart", "testDone", "log", "moduleStart", "moduleDone", "done"];
|
||||
for (var i = 0; i < logs.length; i++) {
|
||||
(function() {
|
||||
var log = logs[i],
|
||||
logger = QUnit[log];
|
||||
QUnit[log] = function() {
|
||||
console.log(log, arguments);
|
||||
logger.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
}
|
||||
|
||||
module("logs1");
|
||||
|
||||
test("test1", 13, function() {
|
||||
equal(begin, 1);
|
||||
equal(moduleStart, 1);
|
||||
equal(testStart, 1);
|
||||
equal(testDone, 0);
|
||||
equal(moduleDone, 0);
|
||||
|
||||
deepEqual(logContext, {
|
||||
result: true,
|
||||
message: undefined,
|
||||
actual: 0,
|
||||
expected: 0
|
||||
});
|
||||
equal("foo", "foo", "msg");
|
||||
deepEqual(logContext, {
|
||||
result: true,
|
||||
message: "msg",
|
||||
actual: "foo",
|
||||
expected: "foo"
|
||||
});
|
||||
strictEqual(testDoneContext, undefined);
|
||||
deepEqual(testContext, {
|
||||
name: "test1"
|
||||
});
|
||||
strictEqual(moduleDoneContext, undefined);
|
||||
deepEqual(moduleContext, {
|
||||
name: "logs1"
|
||||
});
|
||||
|
||||
equal(log, 12);
|
||||
});
|
||||
test("test2", 10, function() {
|
||||
equal(begin, 1);
|
||||
equal(moduleStart, 1);
|
||||
equal(testStart, 2);
|
||||
equal(testDone, 1);
|
||||
equal(moduleDone, 0);
|
||||
|
||||
deepEqual(testDoneContext, {
|
||||
name: "test1",
|
||||
failed: 0,
|
||||
passed: 13,
|
||||
total: 13
|
||||
});
|
||||
deepEqual(testContext, {
|
||||
name: "test2"
|
||||
});
|
||||
strictEqual(moduleDoneContext, undefined);
|
||||
deepEqual(moduleContext, {
|
||||
name: "logs1"
|
||||
});
|
||||
|
||||
equal(log, 22);
|
||||
});
|
||||
|
||||
module("logs2");
|
||||
|
||||
test("test1", 9, function() {
|
||||
equal(begin, 1);
|
||||
equal(moduleStart, 2);
|
||||
equal(testStart, 3);
|
||||
equal(testDone, 2);
|
||||
equal(moduleDone, 1);
|
||||
|
||||
deepEqual(testContext, {
|
||||
name: "test1"
|
||||
});
|
||||
deepEqual(moduleDoneContext, {
|
||||
name: "logs1",
|
||||
failed: 0,
|
||||
passed: 23,
|
||||
total: 23
|
||||
});
|
||||
deepEqual(moduleContext, {
|
||||
name: "logs2"
|
||||
});
|
||||
|
||||
equal(log, 31);
|
||||
});
|
||||
test("test2", 8, function() {
|
||||
equal(begin, 1);
|
||||
equal(moduleStart, 2);
|
||||
equal(testStart, 4);
|
||||
equal(testDone, 3);
|
||||
equal(moduleDone, 1);
|
||||
|
||||
deepEqual(testContext, {
|
||||
name: "test2"
|
||||
});
|
||||
deepEqual(moduleContext, {
|
||||
name: "logs2"
|
||||
});
|
||||
|
||||
equal(log, 39);
|
||||
});
|
1421
js/libraries/balupton-history/vendor/qunit/test/same.js
vendored
Executable file
1421
js/libraries/balupton-history/vendor/qunit/test/same.js
vendored
Executable file
File diff suppressed because it is too large
Load Diff
324
js/libraries/balupton-history/vendor/qunit/test/test.js
vendored
Executable file
324
js/libraries/balupton-history/vendor/qunit/test/test.js
vendored
Executable file
@ -0,0 +1,324 @@
|
||||
test("module without setup/teardown (default)", function() {
|
||||
expect(1);
|
||||
ok(true);
|
||||
});
|
||||
|
||||
test("expect in test", 3, function() {
|
||||
ok(true);
|
||||
ok(true);
|
||||
ok(true);
|
||||
});
|
||||
|
||||
test("expect in test", 1, function() {
|
||||
ok(true);
|
||||
});
|
||||
|
||||
module("setup test", {
|
||||
setup: function() {
|
||||
ok(true);
|
||||
}
|
||||
});
|
||||
|
||||
test("module with setup", function() {
|
||||
expect(2);
|
||||
ok(true);
|
||||
});
|
||||
|
||||
test("module with setup, expect in test call", 2, function() {
|
||||
ok(true);
|
||||
});
|
||||
|
||||
var state;
|
||||
|
||||
module("setup/teardown test", {
|
||||
setup: function() {
|
||||
state = true;
|
||||
ok(true);
|
||||
},
|
||||
teardown: function() {
|
||||
ok(true);
|
||||
}
|
||||
});
|
||||
|
||||
test("module with setup/teardown", function() {
|
||||
expect(3);
|
||||
ok(true);
|
||||
});
|
||||
|
||||
module("setup/teardown test 2");
|
||||
|
||||
test("module without setup/teardown", function() {
|
||||
expect(1);
|
||||
ok(true);
|
||||
});
|
||||
|
||||
if (typeof setTimeout !== 'undefined') {
|
||||
state = 'fail';
|
||||
|
||||
module("teardown and stop", {
|
||||
teardown: function() {
|
||||
equal(state, "done", "Test teardown.");
|
||||
}
|
||||
});
|
||||
|
||||
test("teardown must be called after test ended", function() {
|
||||
expect(1);
|
||||
stop();
|
||||
setTimeout(function() {
|
||||
state = "done";
|
||||
start();
|
||||
}, 13);
|
||||
});
|
||||
|
||||
module("async setup test", {
|
||||
setup: function() {
|
||||
stop();
|
||||
setTimeout(function(){
|
||||
ok(true);
|
||||
start();
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
|
||||
asyncTest("module with async setup", function() {
|
||||
expect(2);
|
||||
ok(true);
|
||||
start();
|
||||
});
|
||||
|
||||
module("async teardown test", {
|
||||
teardown: function() {
|
||||
stop();
|
||||
setTimeout(function(){
|
||||
ok(true);
|
||||
start();
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
|
||||
asyncTest("module with async teardown", function() {
|
||||
expect(2);
|
||||
ok(true);
|
||||
start();
|
||||
});
|
||||
|
||||
module("asyncTest");
|
||||
|
||||
asyncTest("asyncTest", function() {
|
||||
expect(2);
|
||||
ok(true);
|
||||
setTimeout(function() {
|
||||
state = "done";
|
||||
ok(true);
|
||||
start();
|
||||
}, 13);
|
||||
});
|
||||
|
||||
asyncTest("asyncTest", 2, function() {
|
||||
ok(true);
|
||||
setTimeout(function() {
|
||||
state = "done";
|
||||
ok(true);
|
||||
start();
|
||||
}, 13);
|
||||
});
|
||||
|
||||
test("sync", 2, function() {
|
||||
stop();
|
||||
setTimeout(function() {
|
||||
ok(true);
|
||||
start();
|
||||
}, 13);
|
||||
stop();
|
||||
setTimeout(function() {
|
||||
ok(true);
|
||||
start();
|
||||
}, 125);
|
||||
});
|
||||
}
|
||||
|
||||
module("save scope", {
|
||||
setup: function() {
|
||||
this.foo = "bar";
|
||||
},
|
||||
teardown: function() {
|
||||
deepEqual(this.foo, "bar");
|
||||
}
|
||||
});
|
||||
test("scope check", function() {
|
||||
expect(2);
|
||||
deepEqual(this.foo, "bar");
|
||||
});
|
||||
|
||||
module("simple testEnvironment setup", {
|
||||
foo: "bar",
|
||||
bugid: "#5311" // example of meta-data
|
||||
});
|
||||
test("scope check", function() {
|
||||
deepEqual(this.foo, "bar");
|
||||
});
|
||||
test("modify testEnvironment",function() {
|
||||
this.foo="hamster";
|
||||
});
|
||||
test("testEnvironment reset for next test",function() {
|
||||
deepEqual(this.foo, "bar");
|
||||
});
|
||||
|
||||
module("testEnvironment with object", {
|
||||
options:{
|
||||
recipe:"soup",
|
||||
ingredients:["hamster","onions"]
|
||||
}
|
||||
});
|
||||
test("scope check", function() {
|
||||
deepEqual(this.options, {recipe:"soup",ingredients:["hamster","onions"]}) ;
|
||||
});
|
||||
test("modify testEnvironment",function() {
|
||||
// since we do a shallow copy, the testEnvironment can be modified
|
||||
this.options.ingredients.push("carrots");
|
||||
});
|
||||
test("testEnvironment reset for next test",function() {
|
||||
deepEqual(this.options, {recipe:"soup",ingredients:["hamster","onions","carrots"]}, "Is this a bug or a feature? Could do a deep copy") ;
|
||||
});
|
||||
|
||||
|
||||
module("testEnvironment tests");
|
||||
|
||||
function makeurl() {
|
||||
var testEnv = QUnit.current_testEnvironment;
|
||||
var url = testEnv.url || 'http://example.com/search';
|
||||
var q = testEnv.q || 'a search test';
|
||||
return url + '?q='+encodeURIComponent(q);
|
||||
}
|
||||
|
||||
test("makeurl working",function() {
|
||||
equal( QUnit.current_testEnvironment, this, 'The current testEnvironment is global');
|
||||
equal( makeurl(), 'http://example.com/search?q=a%20search%20test', 'makeurl returns a default url if nothing specified in the testEnvironment');
|
||||
});
|
||||
|
||||
module("testEnvironment with makeurl settings", {
|
||||
url: 'http://google.com/',
|
||||
q: 'another_search_test'
|
||||
});
|
||||
test("makeurl working with settings from testEnvironment", function() {
|
||||
equal( makeurl(), 'http://google.com/?q=another_search_test', 'rather than passing arguments, we use test metadata to form the url');
|
||||
});
|
||||
test("each test can extend the module testEnvironment", {
|
||||
q:'hamstersoup'
|
||||
}, function() {
|
||||
equal( makeurl(), 'http://google.com/?q=hamstersoup', 'url from module, q from test');
|
||||
});
|
||||
|
||||
module("jsDump");
|
||||
test("jsDump output", function() {
|
||||
equals( QUnit.jsDump.parse([1, 2]), "[\n 1,\n 2\n]" );
|
||||
equals( QUnit.jsDump.parse({top: 5, left: 0}), "{\n \"top\": 5,\n \"left\": 0\n}" );
|
||||
if (typeof document !== 'undefined' && document.getElementById("qunit-header")) {
|
||||
equals( QUnit.jsDump.parse(document.getElementById("qunit-header")), "<h1 id=\"qunit-header\"></h1>" );
|
||||
equals( QUnit.jsDump.parse(document.getElementsByTagName("h1")), "[\n <h1 id=\"qunit-header\"></h1>\n]" );
|
||||
}
|
||||
});
|
||||
|
||||
module("assertions");
|
||||
test("raises",function() {
|
||||
function CustomError( message ) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
CustomError.prototype.toString = function() {
|
||||
return this.message;
|
||||
};
|
||||
|
||||
raises(
|
||||
function() {
|
||||
throw "error"
|
||||
}
|
||||
);
|
||||
|
||||
raises(
|
||||
function() {
|
||||
throw "error"
|
||||
},
|
||||
'raises with just a message, no expected'
|
||||
);
|
||||
|
||||
raises(
|
||||
function() {
|
||||
throw new CustomError();
|
||||
},
|
||||
CustomError,
|
||||
'raised error is an instance of CustomError'
|
||||
);
|
||||
|
||||
raises(
|
||||
function() {
|
||||
throw new CustomError("some error description");
|
||||
},
|
||||
/description/,
|
||||
"raised error message contains 'description'"
|
||||
);
|
||||
|
||||
raises(
|
||||
function() {
|
||||
throw new CustomError("some error description");
|
||||
},
|
||||
function( err ) {
|
||||
if ( (err instanceof CustomError) && /description/.test(err) ) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
"custom validation function"
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
if (typeof document !== "undefined") {
|
||||
|
||||
module("fixture");
|
||||
test("setup", function() {
|
||||
document.getElementById("qunit-fixture").innerHTML = "foobar";
|
||||
});
|
||||
test("basics", function() {
|
||||
equal( document.getElementById("qunit-fixture").innerHTML, "test markup", "automatically reset" );
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
module("custom assertions");
|
||||
(function() {
|
||||
function mod2(value, expected, message) {
|
||||
var actual = value % 2;
|
||||
QUnit.push(actual == expected, actual, expected, message);
|
||||
}
|
||||
test("mod2", function() {
|
||||
mod2(2, 0, "2 % 2 == 0");
|
||||
mod2(3, 1, "3 % 2 == 1");
|
||||
})
|
||||
})();
|
||||
|
||||
(function() {
|
||||
var reset = QUnit.reset;
|
||||
function afterTest() {
|
||||
ok( false, "reset should not modify test status" );
|
||||
}
|
||||
module("reset");
|
||||
test("reset runs assertions", function() {
|
||||
QUnit.reset = function() {
|
||||
afterTest();
|
||||
reset.apply( this, arguments );
|
||||
};
|
||||
});
|
||||
test("reset runs assertions2", function() {
|
||||
QUnit.reset = reset;
|
||||
});
|
||||
})();
|
||||
|
||||
module("noglobals", {
|
||||
teardown: function() {
|
||||
delete window.badGlobalVariableIntroducedInTest;
|
||||
}
|
||||
});
|
||||
test("let teardown clean up globals", function() {
|
||||
// this test will always pass if run without ?noglobals=true
|
||||
window.badGlobalVariableIntroducedInTest = true;
|
||||
});
|
6014
js/libraries/balupton-history/vendor/right.js
vendored
Executable file
6014
js/libraries/balupton-history/vendor/right.js
vendored
Executable file
File diff suppressed because it is too large
Load Diff
1193
js/libraries/balupton-history/vendor/zepto.js
vendored
Executable file
1193
js/libraries/balupton-history/vendor/zepto.js
vendored
Executable file
File diff suppressed because it is too large
Load Diff
1
js/libraries/jquery.history.js
Executable file
1
js/libraries/jquery.history.js
Executable file
File diff suppressed because one or more lines are too long
5
js/materio_search_api_ajax-ck.js
Normal file
5
js/materio_search_api_ajax-ck.js
Normal file
File diff suppressed because one or more lines are too long
206
js/materio_search_api_ajax.js
Normal file
206
js/materio_search_api_ajax.js
Normal file
@ -0,0 +1,206 @@
|
||||
// @codekit-prepend "gui.js"
|
||||
|
||||
(function($) {
|
||||
|
||||
MaterioBaseMod = function(){
|
||||
|
||||
var _History = window.History,
|
||||
_isloadingresults = false;
|
||||
_$content = $('#content');
|
||||
// TODO: define $content by module settings
|
||||
/**
|
||||
* init()
|
||||
*/
|
||||
function init(){
|
||||
trace('init module');
|
||||
|
||||
// $('#root').bind('resultsupdated', function(event) {
|
||||
// alert('HO');
|
||||
// });
|
||||
$(window).trigger('resultsupdated');
|
||||
initSearchAjax();
|
||||
initHistoryNav();
|
||||
initViewMode();
|
||||
};
|
||||
|
||||
/**
|
||||
* searchAjax
|
||||
*/
|
||||
function initSearchAjax(){
|
||||
// trace('initSearchAjax');
|
||||
$('#edit-searchfield').focus();
|
||||
|
||||
|
||||
$('#materio-search-api-search-form').bind('submit', function(event) {
|
||||
// trace('search submited', event);
|
||||
var $this = $(this);
|
||||
setTimeout(function(){
|
||||
// trace('submit load');
|
||||
loadResults(getSearchKeys());
|
||||
},10);
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
// /!\ AUTOCOMPLETE SELECT EVENT need a patch http://drupal.org/node/365241#comment-5374686
|
||||
$("#edit-searchfield").bind('autocompleteSelect', function(event) {
|
||||
// trace('autocompleteSelect - event', event);
|
||||
// trace('val', $(this).val());
|
||||
// var $form = $(this).parents('form');
|
||||
// setTimeout(function(){
|
||||
// $form.submit();
|
||||
// }, 10);
|
||||
loadResults($(this).val());
|
||||
});
|
||||
|
||||
|
||||
_$content
|
||||
.bind('jsp-initialised', function(event, isScrollable){
|
||||
// trace('isScrollable = '+isScrollable);
|
||||
// TODO: better to check scroll-y than isscrollable, load next page before the end of scroll
|
||||
if(!isScrollable)
|
||||
loadNextResultsPage();
|
||||
// TODO: what happend when there is no more page
|
||||
})
|
||||
.bind('jsp-scroll-y', function(event, scrollPositionY, isAtTop, isAtBottom){
|
||||
if(isAtBottom)
|
||||
loadNextResultsPage();
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
function loadResults(keys){
|
||||
// trace('keys', keys);
|
||||
if(keys !== undefined){
|
||||
keys = keys.replace('/', ' ');
|
||||
if(!_isloadingresults){
|
||||
_isloadingresults = true;
|
||||
// TODO: record ajax path in a variable from materio_search_api_ajax_init
|
||||
$.getJSON('/materio_search_api_ajax/search/'+keys, function(json){
|
||||
// trace('json', json);
|
||||
$(window).trigger('resultsloaded');
|
||||
_isloadingresults = false;
|
||||
updateContent(json);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function updateContent(json){
|
||||
if(json.return){
|
||||
// TODO: set jscrollpane to top
|
||||
|
||||
$('.inner-content',_$content).html(json.return);
|
||||
|
||||
// TODO: this a DIRTY sheet of what could be refresh results transitions
|
||||
// var $newContent = $(json.return);
|
||||
// trace('newContent', $newContent);
|
||||
// $('.node-materiau',$newContent).hide();
|
||||
// $('.node-materiau','#content').fadeOut(300);
|
||||
// setTimeout(function(){
|
||||
// $('#content').html($newContent);
|
||||
// $('.node-materiau','#content').fadeIn(500);
|
||||
// },300);
|
||||
|
||||
|
||||
var event = jQuery.Event('resultsupdated');
|
||||
event.container = $('.search-results', _$content);
|
||||
$(window).trigger(event);
|
||||
|
||||
_History.pushState({content:json.return}, json.keys, '/'+json.search_path + '/' +json.keys);
|
||||
// navigate({content:json.return}, '', '/'+json.page.path + '/' +json.keys);
|
||||
|
||||
|
||||
}else{
|
||||
alert('no results');
|
||||
}
|
||||
};
|
||||
|
||||
function getSearchKeys(){
|
||||
return $('#materio-search-api-search-form').find('input[name*="searchfield"]').val();
|
||||
};
|
||||
|
||||
/**
|
||||
* infinit scroll
|
||||
*/
|
||||
function loadNextResultsPage(){
|
||||
var $nextpage = $('ul.pager .pager-current', _$content).next(),
|
||||
href = $('a', $nextpage).attr('href');
|
||||
|
||||
if(href){
|
||||
var keys = href.match(/explore\/([^\/|\?]+)/);
|
||||
var page = href.match(/\?page=([0-9]+)/);
|
||||
|
||||
if(!_isloadingresults){
|
||||
_isloadingresults = true;
|
||||
$.getJSON('/materio_search_api_ajax/search/'+keys[1]+'/'+page[1], function(json){
|
||||
// trace('json', json);
|
||||
_isloadingresults = false;
|
||||
addNextpage(json);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
function addNextpage(json){
|
||||
var $newcontent = $(json.return),
|
||||
$newresults = $('.search-results article', $newcontent),
|
||||
$newpager = $('ul.pager', $newcontent);
|
||||
|
||||
$('.search-results', _$content).append($newresults);
|
||||
$('ul.pager', _$content).replaceWith($newpager);
|
||||
|
||||
var event = jQuery.Event('resultscompleted');
|
||||
event.container = $('.search-results', _$content);
|
||||
$(window).trigger(event);
|
||||
};
|
||||
|
||||
/**
|
||||
* history navigation
|
||||
*/
|
||||
function initHistoryNav(){
|
||||
var state = _History.getState();
|
||||
_History.log('initial:', state.data, state.title, state.url);
|
||||
|
||||
_History.Adapter.bind(window,'statechange',function(){
|
||||
var state = _History.getState();
|
||||
_History.log('statechange:', state.data, state.title, state.url);
|
||||
// TODO: History : empty content if we go back to the homepage
|
||||
$('.inner-content',_$content).html(state.data.content);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* viewmode
|
||||
*/
|
||||
function initViewMode(){
|
||||
$('.viewmode-link').click(function(event){
|
||||
changeViewMode($(this).attr('rel'), $(this));
|
||||
});
|
||||
};
|
||||
|
||||
function changeViewMode(vm, $btn){
|
||||
$.getJSON('/materiosearchapi/viewmode/change/'+vm, function(json){
|
||||
// trace('viewmode json', json);
|
||||
if (json.statut == "saved"){
|
||||
loadResults(getSearchKeys());
|
||||
$('.viewmode-link').removeClass('active');
|
||||
$btn.addClass('active');
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
init();
|
||||
|
||||
|
||||
};
|
||||
|
||||
var materiobasemod = new MaterioBaseMod();
|
||||
|
||||
})(jQuery);
|
49
materio_search_api.admin.inc
Normal file
49
materio_search_api.admin.inc
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
function materio_search_api_settings(){
|
||||
$indexes = search_api_index_load_multiple(false);
|
||||
// dsm($indexes, '$indexes');
|
||||
|
||||
foreach ($indexes as $machine_name => $index) {
|
||||
if($index->status == 1)
|
||||
$index_options[$index->machine_name] = $index->name;
|
||||
}
|
||||
|
||||
$form['mainsearchindex'] = array(
|
||||
'#type'=>'select',
|
||||
'#options'=>$index_options,
|
||||
'#default_value' => variable_get('mainsearchindex', -1),
|
||||
'#title' => t('Main search api index'),
|
||||
);
|
||||
|
||||
$form['autocompletesearchindex'] = array(
|
||||
'#type'=>'select',
|
||||
'#options'=>$index_options,
|
||||
'#default_value' => variable_get('autocompletesearchindex', -1),
|
||||
'#title' => t('Autocomplete search api index'),
|
||||
);
|
||||
|
||||
// TODO: select the activated viewmodes for change view mode and selected view mode
|
||||
$entity_infos = entity_get_info();
|
||||
// dsm($entity_infos, 'entity_infos');
|
||||
foreach ($entity_infos['node']['view modes'] as $viewmode => $value) {
|
||||
$viewmode_options[$viewmode] = $value['label'];
|
||||
}
|
||||
|
||||
$form['availableviewmodes'] = array(
|
||||
'#type'=>'select',
|
||||
'#options'=>$viewmode_options,
|
||||
'#default_value' => variable_get('availableviewmodes', -1),
|
||||
'#title' => t('Availble View modes'),
|
||||
'#multiple' => true,
|
||||
);
|
||||
|
||||
$form['defaultviewmode'] = array(
|
||||
'#type'=>'select',
|
||||
'#options'=>$viewmode_options,
|
||||
'#default_value' => variable_get('defaultviewmode', 'full'),
|
||||
'#title' => t('Defalut View mode'),
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
name = materiobasemod
|
||||
description = "Materio base module"
|
||||
name = materio_search_api
|
||||
description = "Materio Search Api module"
|
||||
|
||||
; Core version (required)
|
||||
core = 7.x
|
||||
@ -11,17 +11,19 @@ package = Materio
|
||||
; php = 5.2
|
||||
|
||||
; Loadable code files
|
||||
;files[] = materiobasemod.theme.inc
|
||||
;files[] = materiobasemod.forms.inc
|
||||
files[] = materiobasemod.pages.inc
|
||||
files[] = materiobasemod.module
|
||||
;files[] = materio_search_api.theme.inc
|
||||
;files[] = materio_search_api.forms.inc
|
||||
files[] = materio_search_api.pages.inc
|
||||
files[] = materio_search_api.admin.inc
|
||||
files[] = materio_search_api.module
|
||||
|
||||
; Module dependencies
|
||||
dependencies[] = taxonomy
|
||||
;dependencies[] = taxonomy
|
||||
dependencies[] = search_api
|
||||
dependencies[] = search_api_solr
|
||||
|
||||
; Configuration page
|
||||
; configure = admin/config/materiobasemod
|
||||
|
||||
|
||||
; For further information about configuration options, see
|
||||
; - http://drupal.org/node/542202
|
362
materio_search_api.module
Normal file
362
materio_search_api.module
Normal file
@ -0,0 +1,362 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* This is the file description for Materiobasemod module.
|
||||
*
|
||||
* In this more verbose, multi-line description, you can specify what this
|
||||
* file does exactly. Make sure to wrap your documentation in column 78 so
|
||||
* that the file can be displayed nicely in default-sized consoles.
|
||||
*/
|
||||
// define(MATERIO_SEARCH_API_RESULTS_PATH, 'explore');
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function materio_search_api_permission() {
|
||||
return array(
|
||||
'use materio search api' => array(
|
||||
'title' => t('Use materio search api'),
|
||||
'description' => t('Use materio search api.'),
|
||||
),
|
||||
'use materio search api autocomplete' => array(
|
||||
'title' => t('Use materio search api autocomplete'),
|
||||
'description' => t('Use materio search api autocomplete.'),
|
||||
),
|
||||
'use materio search api viewmode selection' => array(
|
||||
'title' => t('Use materio search api viewmode selection'),
|
||||
'description' => t('Use materio search api viewmode selection.'),
|
||||
),
|
||||
'administer materio_search_api' => array(
|
||||
'title' => t('administer Materio search api'),
|
||||
'description' => t('Administer materio search api.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function materio_search_api_menu() {
|
||||
$items = array();
|
||||
|
||||
$base = array(
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'materio_search_api.pages.inc',
|
||||
);
|
||||
|
||||
$items['admin/config/search/search_api/materiosearchapi'] = array(
|
||||
'title' => 'Materio Search Api',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('materio_search_api_settings'),
|
||||
'access arguments' => array('administer materio_search_api'),
|
||||
'file' => 'materio_search_api.admin.inc',
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
);
|
||||
|
||||
$items['materiosearchapi/autocomplete/dbselect'] = $base+array(
|
||||
'access arguments' => array('use materio search api autocomplete'),
|
||||
'page callback' => 'materio_search_api_autocomplete_dbselect',
|
||||
);
|
||||
|
||||
$items['materiosearchapi/autocomplete/searchapi'] = $base+array(
|
||||
'access arguments' => array('use materio search api autocomplete'),
|
||||
'page callback' => 'materio_search_api_autocomplete_searchapi',
|
||||
);
|
||||
|
||||
$items['explore'] = $base+array(
|
||||
'access arguments' => array('use materio search api'),
|
||||
'page callback' => 'materio_search_api_results_search',
|
||||
//'page argument' => array(1,2,3),
|
||||
);
|
||||
|
||||
$items['materiosearchapi/viewmode/change'] = $base+array(
|
||||
'access arguments' => array('use materio search api'),
|
||||
'page callback' => 'materio_search_api_viewmode_change',
|
||||
'page argument' => array(3),
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_block_info().
|
||||
*/
|
||||
function materio_search_api_block_info() {
|
||||
// This example comes from node.module.
|
||||
$blocks['materio_search_api_search'] = array(
|
||||
'info' => t('Materio search api search'),
|
||||
'cache' => DRUPAL_NO_CACHE
|
||||
);
|
||||
|
||||
$blocks['materio_search_api_viewmode'] = array(
|
||||
'info' => t('Materio search api view mode selection'),
|
||||
'cache' => DRUPAL_NO_CACHE
|
||||
);
|
||||
|
||||
return $blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_block_view().
|
||||
*/
|
||||
function materio_search_api_block_view($delta = '') {
|
||||
// This example comes from node.module. Note that you can also return a
|
||||
// renderable array rather than rendered HTML for 'content'.
|
||||
$block = array();
|
||||
|
||||
switch ($delta) {
|
||||
case 'materio_search_api_search':
|
||||
if (user_access('use materio search api')) {
|
||||
$block['subject'] = t('Search');
|
||||
$block['content'] = theme('materio_search_api_search_block', array());
|
||||
}
|
||||
break;
|
||||
case 'materio_search_api_viewmode':
|
||||
if (user_access('use materio search api viewmode selection')) {
|
||||
$block['subject'] = t('View mode');
|
||||
$block['content'] = theme('materio_search_api_select_viewmode_block', array());
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_info_alter().
|
||||
*/
|
||||
function materio_search_api_entity_info_alter(&$entity_info) {
|
||||
$entity_info['node']['view modes']['cardsmall'] = array(
|
||||
'label' => t('Small cards'),
|
||||
'custom settings' => TRUE,
|
||||
);
|
||||
|
||||
$entity_info['node']['view modes']['cardmedium'] = array(
|
||||
'label' => t('Medium cards'),
|
||||
'custom settings' => TRUE,
|
||||
);
|
||||
|
||||
$entity_info['node']['view modes']['cardbig'] = array(
|
||||
'label' => t('Big cards'),
|
||||
'custom settings' => TRUE,
|
||||
);
|
||||
|
||||
$entity_info['node']['view modes']['cardfull'] = array(
|
||||
'label' => t('Full cards'),
|
||||
'custom settings' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess_node().
|
||||
*/
|
||||
function materio_search_api_preprocess_node(&$vars) {
|
||||
// $vars['theme_hook_suggestions'][] = 'node__'.$vars['view_mode'];
|
||||
// $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode'];
|
||||
// dsm($vars, '$vars');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess_field().
|
||||
*/
|
||||
function materio_search_api_preprocess_field(&$vars) {
|
||||
//$vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#view_mode'];
|
||||
//$vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#field_type'] . '__' . $vars['element']['#view_mode'];
|
||||
//$vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#field_name'] . '__' . $vars['element']['#view_mode'];
|
||||
// dsm($vars, '$vars');
|
||||
}
|
||||
|
||||
/**
|
||||
* materiobase_search_form()
|
||||
*/
|
||||
function materio_search_api_search_form($form, &$form_state){
|
||||
$form = array();
|
||||
|
||||
$args = arg();
|
||||
$path = array_shift($args);
|
||||
$keys = implode('/', $args);
|
||||
|
||||
$form['searchfield'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $path == 'explore' ? $keys : "", // TODO: set the search page path global or a variable in settings
|
||||
// '#value' => $keys,
|
||||
'#autocomplete_path' => 'materiosearchapi/autocomplete/searchapi',
|
||||
//'#autocomplete_path' => 'materiosearchapi/autocomplete/dbselect',
|
||||
'#size' => 30,
|
||||
'#maxlength' => 1024,
|
||||
);
|
||||
|
||||
$form['create'] = array(
|
||||
'#type' => 'image_button',
|
||||
'#src' => drupal_get_path('module', 'materio_search_api') . '/images/search.png',
|
||||
'#value' => t('Search'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
function materio_search_api_search_form_validate($form, &$form_state){
|
||||
// dsm($form, '$form');
|
||||
// dsm($form_state, '$form_state');
|
||||
// dsm(strlen($form_state['values']['searchfield']));
|
||||
if (strlen(trim($form_state['values']['searchfield'])) <= 1) {
|
||||
form_set_error('searchfield', 'Please enter at least 2 characters keyword.');
|
||||
}
|
||||
}
|
||||
|
||||
function materio_search_api_search_form_submit($form, &$form_state){
|
||||
$keys = $form_state['values']['searchfield'];
|
||||
// drupal_go_to('base/explore/'.$keys);
|
||||
$form_state['redirect'] = 'explore/'.$keys;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*
|
||||
* Adds language fields to user forms.
|
||||
*/
|
||||
// TODO: user can choose preferred view mode
|
||||
// function materio_search_api_form_alter(&$form, &$form_state, $form_id) {
|
||||
// if (user_access('use materio search api viewmode selection')) {
|
||||
// if ($form_id == 'user_register_form' || ($form_id == 'user_profile_form' && $form['#user_category'] == 'account')) {
|
||||
// materio_search_api_viewmode_selector_form($form, $form_state, $form['#user']);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// function materio_search_api_viewmode_selector_form(&$form, &$form_state, $user) {
|
||||
|
||||
// }
|
||||
|
||||
/**
|
||||
* - - - - - - - - - - - - THEME - - - - - - - - - - - -
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function materio_search_api_theme($existing, $type, $theme, $path) {
|
||||
return array(
|
||||
'materio_search_api_search_block' => array(
|
||||
'arguments' => array(),
|
||||
'template' => 'materio-search-api-search-block',
|
||||
'path' => drupal_get_path('module', 'materio_search_api').'/templates',
|
||||
),
|
||||
'materio_search_api_select_viewmode_block' => array(
|
||||
'arguments' => array(),
|
||||
'template' => 'materio-search-api-select-viewmode-block',
|
||||
'path' => drupal_get_path('module', 'materio_search_api').'/templates',
|
||||
),
|
||||
'materio_search_api_results' => array(
|
||||
'arguments' => array(),
|
||||
'template' => 'materio-search-api-results',
|
||||
'path' => drupal_get_path('module', 'materio_search_api').'/templates',
|
||||
'variables' => array(
|
||||
'index' => NULL,
|
||||
'results' => array('result count' => 0),
|
||||
'items' => array(),
|
||||
'view_mode' => 'teaser',
|
||||
'keys' => '',
|
||||
// 'page_machine_name' => NULL,
|
||||
'spellcheck' => NULL,
|
||||
'pager' => NULL,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* template_preprocess_materiobase_search_block();
|
||||
*/
|
||||
function template_preprocess_materio_search_api_search_block(&$vars){
|
||||
// dsm($vars, '$vars');
|
||||
$vars['searchform'] = drupal_get_form("materio_search_api_search_form");
|
||||
}
|
||||
|
||||
function template_preprocess_materio_search_api_select_viewmode_block(&$vars){
|
||||
global $user;
|
||||
|
||||
$active = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
|
||||
|
||||
$availableviewmodes = variable_get('availableviewmodes', -1);
|
||||
// dsm($availableviewmodes);
|
||||
|
||||
$entity_infos = entity_get_info();
|
||||
// dsm($entity_infos, 'entity_infos');
|
||||
|
||||
$content = '<div class="btn-group btn-group-vertical">';
|
||||
foreach ($entity_infos['node']['view modes'] as $viewmode => $value) {
|
||||
if(in_array($viewmode, $availableviewmodes)){
|
||||
$content .= '<div class="viewmode-link viewmode-'.$viewmode.($active == $viewmode ? " active" : '').'" rel="'.$viewmode.'"><span class="inner">'.$value['label'].'</span></div>';
|
||||
}
|
||||
}
|
||||
$content .= '</div>';
|
||||
$vars['content'] = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for preprocessing the variables for the search_api_page_results
|
||||
* template.
|
||||
*
|
||||
* @param array $variables
|
||||
* An associative array containing:
|
||||
* - $index: The index this search was executed on.
|
||||
* - $results: An array of search results, as returned by
|
||||
* SearchApiQueryInterface::execute().
|
||||
* - $keys: The keywords of the executed search.
|
||||
*
|
||||
* @see materio-search-api-results.tpl.php
|
||||
*/
|
||||
function template_preprocess_materio_search_api_results(array &$variables) {
|
||||
// dsm($variables, '$variables');
|
||||
$results = $variables['results'];
|
||||
$keys = $variables['keys'];
|
||||
|
||||
$variables['items'] = $variables['index']->loadItems(array_keys($variables['results']['results']));
|
||||
$variables['result_count'] = $results['result count'];
|
||||
$variables['sec'] = round($results['performance']['complete'], 3);
|
||||
$variables['search_performance'] = array(
|
||||
'#theme' => 'search_performance',
|
||||
'#markup' => format_plural(
|
||||
$results['result count'],
|
||||
'The search found 1 result in @sec seconds.',
|
||||
'The search found @count results in @sec seconds.',
|
||||
array('@sec' => $variables['sec'])
|
||||
),
|
||||
'#prefix' => '<p class="search-performance">',
|
||||
'#suffix' => '</p>',
|
||||
);
|
||||
|
||||
// $variables['search_results'] = array(
|
||||
// '#theme' => 'search_results_list',
|
||||
// 'results' => $variables['results']['results'],
|
||||
// 'items' => $variables['items'],
|
||||
// 'index' => $variables['index'],
|
||||
// 'type' => 'ul',
|
||||
// );
|
||||
|
||||
// dsm($variables, 'variables');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* - - - - - - - - - - - - SEARCH API PAGE - - - - - - - - - - - -
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_block_view_alter().
|
||||
*/
|
||||
function materio_search_api_block_view_alter(&$data, $block) {
|
||||
// this alter prepopulate the search form provide by search_api_page
|
||||
if ($block->module == 'search_api_page') {
|
||||
$page = search_api_page_load($block->delta);
|
||||
$item = menu_get_item();
|
||||
|
||||
if (isset($page->path) && $page->path == $item['path']) {
|
||||
$keys = arg(count(arg(NULL, $page->path)));
|
||||
if ($keys) {
|
||||
$data['content']['keys_' . $page->id]['#default_value'] = $keys;
|
||||
$data['content']['keys_' . $page->id]['#value'] = $keys;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
252
materio_search_api.pages.inc
Normal file
252
materio_search_api.pages.inc
Normal file
@ -0,0 +1,252 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* materiobase_search_autocomplete_dbselect()
|
||||
*
|
||||
* inspired by taxonomy_autocomplete()
|
||||
*
|
||||
* OBSOLETE : this fonction use a direct dbselect request to provide results forautocomplete
|
||||
*
|
||||
*/
|
||||
function materio_search_api_autocomplete_dbselect($typed = ''){
|
||||
// If the request has a '/' in the search text, then the menu system will have
|
||||
// split it into multiple arguments, recover the intended $tags_typed.
|
||||
$args = func_get_args();
|
||||
$typed = implode('/', $args);
|
||||
|
||||
/*
|
||||
TODO riche serach engine + \\ etc gmail like
|
||||
*/
|
||||
|
||||
if ($typed != '') {
|
||||
|
||||
// Part of the criteria for the query come from the field's own settings.
|
||||
$vids = array();
|
||||
$vocabularies = taxonomy_vocabulary_get_names();
|
||||
foreach ($vocabularies as $voc) {
|
||||
$vids[] = $voc->vid;
|
||||
}
|
||||
|
||||
$query = db_select('taxonomy_term_data', 't');
|
||||
$query->addTag('translatable');
|
||||
$query->addTag('term_access');
|
||||
|
||||
// Select rows that match by term name.
|
||||
$tags_return = $query
|
||||
->fields('t', array('tid', 'name'))
|
||||
->condition('t.vid', $vids)
|
||||
->condition('t.name', '%' . db_like($typed) . '%', 'LIKE')
|
||||
->range(0, 10)
|
||||
->execute()
|
||||
->fetchAllKeyed();
|
||||
|
||||
$term_matches = array();
|
||||
foreach ($tags_return as $tid => $name) {
|
||||
$n = $name;
|
||||
// Term names containing commas or quotes must be wrapped in quotes.
|
||||
// if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) {
|
||||
// $n = '"' . str_replace('"', '""', $name) . '"';
|
||||
// }
|
||||
$term_matches[$n] = check_plain($name);
|
||||
}
|
||||
}
|
||||
|
||||
drupal_json_output($term_matches);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* materio_search_api_autocomplete_searchapi($typed = '')
|
||||
*
|
||||
* GOOD one using searchapi (SOLR)
|
||||
*/
|
||||
function materio_search_api_autocomplete_searchapi($typed = ''){
|
||||
// If the request has a '/' in the search text, then the menu system will have
|
||||
// split it into multiple arguments, recover the intended $tags_typed.
|
||||
$args = func_get_args();
|
||||
$typed = implode('/', $args);
|
||||
|
||||
// dsm($typed, 'typed');
|
||||
if ($typed != '') {
|
||||
|
||||
// search for patterns like key -another key +lastkey
|
||||
// and provide auto completion for the last key
|
||||
preg_match_all('/\s?[\+|-]?[^\s]+/', $typed, $adv_search_q);
|
||||
preg_match('/^(\+|-)?(.*)$/', trim(array_pop($adv_search_q[0])), $last);
|
||||
$tosearch = isset($last[2]) ? $last[2] : $typed;
|
||||
|
||||
// build the query
|
||||
$index_machine_name = variable_get('autocompletesearchindex', -1);
|
||||
$query = search_api_query($index_machine_name);
|
||||
$query_filter = $query->createFilter();
|
||||
$query_filter->condition('name', $tosearch);
|
||||
// $query_filter->condition('type', 'article');
|
||||
$query->filter($query_filter);
|
||||
$tags_return = $query->execute();
|
||||
// dsm($tags_return, '$tags_return');
|
||||
|
||||
if($tags_return['result count']){
|
||||
$term_matches = array();
|
||||
$index = search_api_index_load($index_machine_name);
|
||||
$delta = 0;
|
||||
foreach ($index->loadItems(array_keys($tags_return['results'])) as $item) {
|
||||
// dsm($item, '$item');
|
||||
//$term_matches[$item->tid] = check_plain($item->name);
|
||||
// $term_matches[check_plain($item->name)] = check_plain($item->name);
|
||||
// TODO: leave tags with nodes
|
||||
$term_matches[ trim(implode(' ', $adv_search_q[0]).' '.$last[1].$item->name)] = check_plain($item->name);
|
||||
|
||||
$delta++;
|
||||
if($delta > 7)
|
||||
break;
|
||||
}
|
||||
drupal_json_output($term_matches);
|
||||
}else{
|
||||
drupal_json_output(array());
|
||||
}
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// dsm($term_matches, 'term_matches');
|
||||
// return 'debug mode of materio_search_api_autocomplete_searchapi';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* materio_search_api_results_search()
|
||||
*
|
||||
*
|
||||
*/
|
||||
function materio_search_api_results_search(){//, $limit = 20, $page = 0
|
||||
global $user;
|
||||
|
||||
//dsm("materio_search_api_results_search");
|
||||
$args = func_get_args();
|
||||
$typed = implode('/', $args);
|
||||
|
||||
preg_match_all('/\?page=([0-9]+)/', $typed, $pages);
|
||||
//dsm($pages, '$pages');
|
||||
if($pages[0]){
|
||||
$typed = str_replace($pages[0][0], '', $typed);
|
||||
// $page = $pages[1][0];
|
||||
}
|
||||
// else{
|
||||
// $page = 0;
|
||||
// }
|
||||
|
||||
|
||||
preg_match_all('/\s?[^\s]+\s?/', $typed, $words);
|
||||
// dsm($words, "words");
|
||||
|
||||
// $escaper = array("+", "-", "&&", "||", "!", "(", ")", "{", "}", "[", "]", "^", '"', "~", "*", "?", ":", '\\');
|
||||
foreach ($words[0] as $word) {
|
||||
|
||||
// $word = preg_replace('/\b-/', '\-', trim($word));
|
||||
// dsm($word);
|
||||
|
||||
$keys[] = $word;
|
||||
}
|
||||
|
||||
if ($keys) {
|
||||
try {
|
||||
$limit = 15;
|
||||
$offset = pager_find_page() * $limit; //$page*$limit;//
|
||||
|
||||
$index_machine_name = variable_get('mainsearchindex', -1);
|
||||
$query = search_api_query($index_machine_name, array('parse mode'=>'direct'))
|
||||
->keys(implode(' ', $keys))
|
||||
->range($offset, $limit);
|
||||
|
||||
$results = $query->execute();
|
||||
}
|
||||
catch (SearchApiException $e) {
|
||||
$ret['message'] = t('An error occurred while executing the search. Please try again or contact the site administrator if the problem persists.');
|
||||
watchdog('materiobasemod', 'An error occurred while executing a search: !msg.', array('!msg' => $e->getMessage()), WATCHDOG_ERROR, l(t('search page'), $_GET['q']));
|
||||
}
|
||||
|
||||
// dsm($results, 'results');
|
||||
|
||||
# Load spellcheck.
|
||||
// if (isset($results['search_api_spellcheck'])) {
|
||||
// $ret['results']['#spellcheck'] = array(
|
||||
// '#theme' => 'search_api_spellcheck',
|
||||
// '#spellcheck' => $results['search_api_spellcheck'],
|
||||
// // Let the theme function know where the key is stored by passing its arg
|
||||
// // number. We can work this out from the number of args in the page path.
|
||||
// '#options' => array(
|
||||
// 'arg' => array(count(arg(NULL, $page->path))),
|
||||
// ),
|
||||
// '#prefix' => '<p class="search-api-spellcheck suggestion">',
|
||||
// '#suffix' => '</p>',
|
||||
// );
|
||||
|
||||
// }
|
||||
|
||||
|
||||
$ret['results']['#theme'] = 'materio_search_api_results';
|
||||
/*
|
||||
TODO choose index in module settings
|
||||
*/
|
||||
$ret['results']['#index'] = search_api_index_load('materiaux_breves');
|
||||
$ret['results']['#results'] = $results;
|
||||
/*
|
||||
TODO choose view mode from user data
|
||||
*/
|
||||
|
||||
$ret['results']['#view_mode'] = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
|
||||
$ret['results']['#keys'] = $keys;
|
||||
|
||||
|
||||
// Load pager.
|
||||
// if ($results['result count'] > $page->options['per_page']) {
|
||||
/*
|
||||
TODO set per page limit as module settings
|
||||
*/
|
||||
pager_default_initialize($results['result count'], $limit);
|
||||
$ret['results']['#pager'] = theme('pager');
|
||||
// }
|
||||
|
||||
if (!empty($results['ignored'])) {
|
||||
drupal_set_message(
|
||||
t('The following search keys are too short or too common and were therefore ignored: "@list".',
|
||||
array( '@list' => implode(t('", "'), $results['ignored']) ) ),
|
||||
'warning'
|
||||
);
|
||||
}
|
||||
if (!empty($results['warnings'])) {
|
||||
foreach ($results['warnings'] as $warning) {
|
||||
drupal_set_message($warning, 'warning');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function materio_search_api_viewmode_change($vm){
|
||||
// dsm($vm);
|
||||
|
||||
global $user;
|
||||
// dsm($user, 'user');
|
||||
|
||||
$entity_infos = entity_get_info();
|
||||
// dsm($entity_infos, 'entity_infos');
|
||||
|
||||
if (in_array($vm, variable_get('availableviewmodes', array()))) {
|
||||
user_save($user, array("data"=>array('materiosearchapi_viewmode' => $vm)));
|
||||
$rep = array('statut'=>'saved');
|
||||
}else{
|
||||
$rep = array('statut'=>'viewmode not allowed');
|
||||
}
|
||||
|
||||
//return 'debug mode for materio_search_api_viewmode_change';
|
||||
drupal_json_output($rep);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
name = Materiobaseajax
|
||||
name = Materio Search API Ajax
|
||||
description = "The description of this module"
|
||||
|
||||
; Core version (required)
|
||||
@ -11,18 +11,18 @@ package = Materio
|
||||
; php = 5.2
|
||||
|
||||
; Loadable code files
|
||||
files[] = materiobaseajax.module
|
||||
; files[] = materiobaseajax.admin.inc
|
||||
; files[] = materiobaseajax.class.inc
|
||||
files[] = materio_search_api_ajax.module
|
||||
; files[] = materio_search_api_ajax.admin.inc
|
||||
; files[] = materio_search_api_ajax.class.inc
|
||||
|
||||
; Module dependencies
|
||||
; dependencies[] = mymodule
|
||||
; dependencies[] = materio_search_api
|
||||
; dependencies[] = theirmodule (1.2)
|
||||
; dependencies[] = anothermodule (>=2.4)
|
||||
; dependencies[] = views (3.x)
|
||||
|
||||
; Configuration page
|
||||
; configure = admin/config/materiobaseajax
|
||||
; configure = admin/config/materio_search_api_ajax
|
||||
|
||||
|
||||
; For further information about configuration options, see
|
37
materio_search_api_ajax.module
Normal file
37
materio_search_api_ajax.module
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* This is the file description for materio_search_api_ajax module.
|
||||
*
|
||||
* In this more verbose, multi-line description, you can specify what this
|
||||
* file does exactly. Make sure to wrap your documentation in column 78 so
|
||||
* that the file can be displayed nicely in default-sized consoles.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_init().
|
||||
*/
|
||||
function materio_search_api_ajax_init() {
|
||||
drupal_add_js(drupal_get_path('module', 'materio_search_api_ajax').'/js/libraries/jquery.history.js');
|
||||
drupal_add_js(drupal_get_path('module', 'materio_search_api_ajax').'/js/materio_search_api_ajax-ck.js');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function materio_search_api_ajax_menu() {
|
||||
$items = array();
|
||||
|
||||
$items['materio_search_api_ajax/search/%'] = array(
|
||||
'title' => 'Matrio base ajax',
|
||||
'page callback' => 'materio_search_api_ajax_search',
|
||||
'page arguments' => array(2,3),
|
||||
'access callback' => TRUE,
|
||||
'access arguments' => array('use materio search api'),
|
||||
'file' => 'materio_search_api_ajax.pages.inc',
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
|
||||
|
||||
return $items;
|
||||
}
|
60
materio_search_api_ajax.pages.inc
Normal file
60
materio_search_api_ajax.pages.inc
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
|
||||
function materio_search_api_ajax_search($keys, $page = 0){
|
||||
// TODO: set research path configurable
|
||||
$debug = false;
|
||||
$search_path = "explore";
|
||||
|
||||
$_GET['page'] = $page;
|
||||
|
||||
$path = $search_path . '/' . $keys ;//. ($page ? '?page='.$page : '');
|
||||
// dsm($menuhandler, 'menuhandler');
|
||||
|
||||
// check if request is ajax, if not rediret to search_api_page page with right keys
|
||||
if (!$debug && (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest')) {
|
||||
drupal_goto($path, array(), 301);
|
||||
exit ;
|
||||
}
|
||||
|
||||
// get results
|
||||
menu_set_active_item($path);
|
||||
$return = menu_execute_active_handler($path, FALSE);
|
||||
|
||||
//dsm($return, '$return');
|
||||
|
||||
if (is_int($return)) {
|
||||
switch ($return) {
|
||||
case MENU_NOT_FOUND :
|
||||
drupal_add_http_header('Status', '404 Not Found');
|
||||
break;
|
||||
case MENU_ACCESS_DENIED :
|
||||
drupal_add_http_header('Status', '403 Forbidden');
|
||||
break;
|
||||
case MENU_SITE_OFFLINE :
|
||||
drupal_add_http_header('Status', '503 Service unavailable');
|
||||
break;
|
||||
}
|
||||
} elseif (isset($return)) {
|
||||
|
||||
if (is_array($return)) {
|
||||
$return = drupal_render($return);
|
||||
}
|
||||
|
||||
$rep = array(
|
||||
// 'id'=>$id,
|
||||
'keys'=>$keys,
|
||||
'search_path'=>$search_path,
|
||||
'return'=>$return,
|
||||
);
|
||||
|
||||
if ($debug) {
|
||||
dsm($rep, 'rep');
|
||||
return "debug display";
|
||||
}else{
|
||||
drupal_json_output($rep);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
// * date 2011/10/19 *
|
||||
/**
|
||||
* misc
|
||||
*/// ------ TRACE ------
|
||||
function trace(e,t){window.console&&window.console.debug&&(arguments.length===2?window.console.debug(e,t):window.console.debug(e))}function Timeout(e,t){var n=setTimeout(e,t);this.cleared=!1;this.clear=function(){this.cleared=!0;clearTimeout(n)}}function HexToRGB(e){if(e.charAt(0)=="#"){var t=e.substring(1,7),n=parseInt(t.substring(0,2),16),r=parseInt(t.substring(2,4),16),i=parseInt(t.substring(4,6),16);return"rgb("+n+", "+r+", "+i+")"}return null}function pair(e){return typeof e=="number"?e%2==0?!0:!1:null}function random(e,t){return arguments.length===1&&typeof e=="number"?Math.random()*e:arguments.length===2&&typeof e==typeof t&&typeof e=="number"?e+Math.random()*(t-e):NaN}function round(e,t){if(arguments.length==1)e=Math.round(e);else{t=t.toString();t=t.replace(/./gi,0);t=t.replace(/^./gi,1);t=parseInt(t);e=Math.round(e*t)/t}return e}function floor(e,t){if(arguments.length==1)e=Math.floor(e);else{t=t.toString();t=t.replace(/./gi,0);t=t.replace(/^./gi,1);t=parseInt(t);e=Math.floor(e*t)/t}return e}function ceil(e,t){if(arguments.length==1)e=Math.ceil(e);else{t=t.toString();t=t.replace(/./gi,0);t=t.replace(/^./gi,1);t=parseInt(t);e=Math.ceil(e*t)/t}return e}function ArraySubtract(e,t){var n=new Array;for(var r=e.length-1;r>=0;r--)t.contains(e[r])||n.push(e[r]);return n}function objectSize(e){var t=e.length?--e.length:0;for(var n in e)t++;return t}function objectGetKey(e,t){var n=0;for(var r in e){if(r==="length"||!e.hasOwnProperty(r))continue;if(n==t)return r;n++}}function objectSort(e,t){var n=new Array;for(var r=objectSize(e)-1;r>=0;r--){var i=objectGetKey(e,r);for(var s=objectSize(e[i].wit)-1;s>=0;s--){var o=objectGetKey(e[i].wit,s);if(o==t){var u=parseFloat(e[i].wit[o]);n.push({wit:u,nid:i})}}}n.sort(function(e,t){return t.wit-e.wit});var a={};for(var r=n.length-1;r>=0;r--)a[n[r].nid]=e[n[r].nid];return a}function getElementAngle(e,t,n,r){var i=n-e,s=r-t,o=Math.abs(Math.atan(s/i)*180/Math.PI);i>0&&s<0?o=90-o:i>=0&&s>=0?o+=90:i<0&&s>=0?o=180+(90-o):o+=270;return o}String.prototype.trim=function(){return this.replace(/(^\s*)|(\s*$)/gi,"").replace(/[ ]{2,}/gi," ").replace(/\n /,"\n")};Array.prototype.unique=function(){var e=new Array;e:for(var t=0,n=this.length;t<n;t++){for(var r=0,i=e.length;r<i;r++)if(e[r]==this[t])continue e;e[e.length]=this[t]}return e};Array.prototype.shuffle=function(){var e=this.length,t,n;if(e==0)return;while(--e){t=Math.floor(Math.random()*(e+1));n=this[e];this[e]=this[t];this[t]=n}};Array.prototype.contains=function(e){var t=this.length;while(t--)if(this[t]===e)return!0;return!1};Array.prototype.remove=function(){var e,t=arguments,n=t.length,r;while(n&&this.length){e=t[--n];while((r=this.indexOf(e))!=-1)this.splice(r,1)}return this};Array.prototype.indexOf||(Array.prototype.indexOf=function(e,t){t=t||0;var n=this.length;while(t<n){if(this[t]===e)return t;++t}return-1});(function(e){function t(){}e("#search-api-page-search-form-grid").bind("submit",function(t){trace("search submited",t);var n=e(this).find('input[name*="keys"]').val(),r=e(this).find('input[name="id"]').val();trace("keys",n);trace("form_id",r);e.getJSON("/materiobaseajax/search/"+r+"/"+n,function(t){trace("json",t);t.return&&e("#content").html(t.return)});return!1})})(jQuery);
|
@ -1,37 +0,0 @@
|
||||
// @codekit-prepend "gui.js"
|
||||
(function($) {
|
||||
|
||||
$('#search-api-page-search-form-grid').bind('submit', function(event) {
|
||||
trace('search submited', event);
|
||||
var keys = $(this).find('input[name*="keys"]').val(),
|
||||
id = $(this).find('input[name="id"]').val();
|
||||
trace('keys', keys);
|
||||
trace('form_id', id);
|
||||
|
||||
$.getJSON('/materiobaseajax/search/'+id+'/'+keys,
|
||||
// {form_id: "theform_id", keys: "thekeys"},
|
||||
function(json){
|
||||
trace('json', json);
|
||||
if(json.return){
|
||||
$('#content').html(json.return);
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// select event need a patch http://drupal.org/node/365241#comment-5374686
|
||||
|
||||
// $("input.form-text", '#search-api-page-search-form-grid').bind('autocomplete_select', function(event) {
|
||||
// trace('val', $(this).val());
|
||||
// var $form = $(this).parent('form');
|
||||
// // setTimeout(function(){
|
||||
// // $form.submit();
|
||||
// // }, 10);
|
||||
// });
|
||||
|
||||
function navigate(){
|
||||
|
||||
};
|
||||
|
||||
})(jQuery);
|
@ -1,74 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* This is the file description for Materiobaseajax module.
|
||||
*
|
||||
* In this more verbose, multi-line description, you can specify what this
|
||||
* file does exactly. Make sure to wrap your documentation in column 78 so
|
||||
* that the file can be displayed nicely in default-sized consoles.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_init().
|
||||
*/
|
||||
function materiobaseajax_init() {
|
||||
drupal_add_js(drupal_get_path('module', 'materiobaseajax').'/materiobaseajax-ck.js');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function materiobaseajax_menu() {
|
||||
$items = array();
|
||||
|
||||
$items['materiobaseajax/search'] = array(
|
||||
'title' => 'Matrio base ajax',
|
||||
'page callback' => 'materiobaseajax_search_ajax',
|
||||
'page arguments' => array(2, 3),
|
||||
// 'access callback' => TRUE,
|
||||
'access arguments' => array('access search_api_page'),
|
||||
'file' => 'materiobaseajax.pages.inc',
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_search_api_ajax_settings().
|
||||
*/
|
||||
function materiobaseajax_search_api_ajax_settings() {
|
||||
$settings = array(
|
||||
|
||||
// CSS id for main content (search results html)
|
||||
// format: content => CSS id
|
||||
'content' => '#content',
|
||||
|
||||
// CSS id's for regions containing search blocks
|
||||
// check your region names in mytheme.info
|
||||
// format: region_name => CSS id
|
||||
'regions' => array(
|
||||
'headerblock_left' => '#headerblock-left',
|
||||
// 'sidebar_second' => '#sidebar-second',
|
||||
),
|
||||
|
||||
// OPTIONAL: if you want to provide an AJAX spinner
|
||||
// this paht is for a default spinner path provided with this module
|
||||
// @note: see the search_api_ajax.css
|
||||
'spinner' => drupal_get_path('module', 'search_api_ajax') .'/spinner.gif',
|
||||
|
||||
// OPTIONAL: if you want to use scroll-to-top functionality when paging
|
||||
// scroll target div
|
||||
// 'scrolltarget' => '#main-content',
|
||||
// 'scrollspeed' => 1000,
|
||||
|
||||
// OPTIONAL: if you want to fade search results when Ajaxing
|
||||
// please set to 1 for TRUE
|
||||
'fade' => 1,
|
||||
'opacity' => 0.3,
|
||||
);
|
||||
|
||||
return $settings;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
function materiobaseajax_search_ajax($id, $keys){
|
||||
|
||||
$page = search_api_page_load($id);
|
||||
|
||||
$return = menu_execute_active_handler($page->path . '/' . $keys, FALSE);
|
||||
|
||||
if (is_array($return)) {
|
||||
$return = drupal_render($return);
|
||||
}
|
||||
|
||||
$rep = array(
|
||||
'id'=>$id,
|
||||
'keys'=>$keys,
|
||||
'page'=>$page,
|
||||
'return'=>$return,
|
||||
);
|
||||
|
||||
return drupal_json_output($rep);
|
||||
}
|
@ -1,176 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* This is the file description for Materiobasemod module.
|
||||
*
|
||||
* In this more verbose, multi-line description, you can specify what this
|
||||
* file does exactly. Make sure to wrap your documentation in column 78 so
|
||||
* that the file can be displayed nicely in default-sized consoles.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function materiobasemod_permission() {
|
||||
return array(
|
||||
'use materiobase search' => array(
|
||||
'title' => t('Materio base search'),
|
||||
'description' => t('Use materiobasemod search.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function materiobasemod_menu() {
|
||||
$items = array();
|
||||
$items['materiobase/search/autocomplete/dbselect'] = array(
|
||||
'title' => 'Autocomplete materiobase search',
|
||||
'page callback' => 'materiobase_search_autocomplete_dbselect',
|
||||
'access arguments' => array('access content'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'materiobasemod.pages.inc',
|
||||
);
|
||||
$items['materiobase/search/autocomplete/searchapi'] = array(
|
||||
'title' => 'Autocomplete materiobase search',
|
||||
'page callback' => 'materiobase_search_autocomplete_searchapi',
|
||||
'access arguments' => array('access content'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'materiobasemod.pages.inc',
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_block_info().
|
||||
*/
|
||||
function materiobasemod_block_info() {
|
||||
// This example comes from node.module.
|
||||
$blocks['base_search'] = array(
|
||||
'info' => t('Materio base search'),
|
||||
'cache' => DRUPAL_NO_CACHE
|
||||
);
|
||||
|
||||
return $blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function materiobasemod_theme($existing, $type, $theme, $path) {
|
||||
return array(
|
||||
'materiobase_search_block' => array(
|
||||
'arguments' => array(),
|
||||
'template' => 'materiobase-search-block',
|
||||
'path' => drupal_get_path('module', 'materiobasemod').'/templates',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_block_view().
|
||||
*/
|
||||
function materiobasemod_block_view($delta = '') {
|
||||
// This example comes from node.module. Note that you can also return a
|
||||
// renderable array rather than rendered HTML for 'content'.
|
||||
$block = array();
|
||||
|
||||
switch ($delta) {
|
||||
case 'base_search':
|
||||
if (user_access('use materiobase search')) {
|
||||
$block['subject'] = t('Search');
|
||||
$block['content'] = theme('materiobase_search_block', array());
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_block_view_alter().
|
||||
*/
|
||||
function materiobasemod_block_view_alter(&$data, $block) {
|
||||
if ($block->module == 'search_api_page') {
|
||||
$page = search_api_page_load($block->delta);
|
||||
$item = menu_get_item();
|
||||
|
||||
if (isset($page->path) && $page->path == $item['path']) {
|
||||
$keys = arg(count(arg(NULL, $page->path)));
|
||||
if ($keys) {
|
||||
$data['content']['keys_' . $page->id]['#default_value'] = $keys;
|
||||
$data['content']['keys_' . $page->id]['#value'] = $keys;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_info_alter().
|
||||
*/
|
||||
function materiobasemod_entity_info_alter(&$entity_info) {
|
||||
$entity_info['node']['view modes']['cardsmall'] = array(
|
||||
'label' => t('Small card for the grid'),
|
||||
'custom settings' => TRUE,
|
||||
);
|
||||
|
||||
$entity_info['node']['view modes']['cardmedium'] = array(
|
||||
'label' => t('Medium card for the grid'),
|
||||
'custom settings' => TRUE,
|
||||
);
|
||||
|
||||
$entity_info['node']['view modes']['cardbig'] = array(
|
||||
'label' => t('Big card for the grid'),
|
||||
'custom settings' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess_node().
|
||||
*/
|
||||
function materiobasemod_preprocess_node(&$vars) {
|
||||
$vars['theme_hook_suggestions'][] = 'node__'.$vars['view_mode'];
|
||||
$vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode'];
|
||||
// dsm($vars, '$vars');
|
||||
}
|
||||
|
||||
function materiobasemod_preprocess_field(&$vars) {
|
||||
$vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#view_mode'];
|
||||
$vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#field_type'] . '__' . $vars['element']['#view_mode'];
|
||||
$vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#field_name'] . '__' . $vars['element']['#view_mode'];
|
||||
// dsm($vars, '$vars');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* materiobase_search_form()
|
||||
*/
|
||||
function materiobase_search_form(){
|
||||
$form = array();
|
||||
$form['searchfield'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => '',
|
||||
// '#autocomplete_path' => 'materiobase/search/autocomplete/searchapi',
|
||||
'#autocomplete_path' => 'materiobase/search/autocomplete/dbselect',
|
||||
'#size' => 30,
|
||||
'#maxlength' => 1024,
|
||||
// '#element_validate' => array('taxonomy_autocomplete_validate'),
|
||||
);
|
||||
$form['create'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Search'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* template_preprocess_materiobase_search_block();
|
||||
*/
|
||||
function template_preprocess_materiobase_search_block(&$vars){
|
||||
|
||||
$vars['searchform'] = drupal_get_form("materiobase_search_form");
|
||||
|
||||
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* materiobase_search_autocomplete()
|
||||
*
|
||||
* inspired by taxonomy_autocomplete()
|
||||
*
|
||||
*/
|
||||
function materiobase_search_autocomplete_dbselect($typed = ''){
|
||||
// If the request has a '/' in the search text, then the menu system will have
|
||||
// split it into multiple arguments, recover the intended $tags_typed.
|
||||
$args = func_get_args();
|
||||
$typed = implode('/', $args);
|
||||
|
||||
/*
|
||||
TODO riche serach engine + \\ etc gmail like
|
||||
*/
|
||||
|
||||
if ($typed != '') {
|
||||
|
||||
// Part of the criteria for the query come from the field's own settings.
|
||||
$vids = array();
|
||||
$vocabularies = taxonomy_vocabulary_get_names();
|
||||
foreach ($vocabularies as $voc) {
|
||||
$vids[] = $voc->vid;
|
||||
}
|
||||
|
||||
$query = db_select('taxonomy_term_data', 't');
|
||||
$query->addTag('translatable');
|
||||
$query->addTag('term_access');
|
||||
|
||||
// Select rows that match by term name.
|
||||
$tags_return = $query
|
||||
->fields('t', array('tid', 'name'))
|
||||
->condition('t.vid', $vids)
|
||||
->condition('t.name', '%' . db_like($typed) . '%', 'LIKE')
|
||||
->range(0, 10)
|
||||
->execute()
|
||||
->fetchAllKeyed();
|
||||
|
||||
$term_matches = array();
|
||||
foreach ($tags_return as $tid => $name) {
|
||||
$n = $name;
|
||||
// Term names containing commas or quotes must be wrapped in quotes.
|
||||
// if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) {
|
||||
// $n = '"' . str_replace('"', '""', $name) . '"';
|
||||
// }
|
||||
$term_matches[$n] = check_plain($name);
|
||||
}
|
||||
}
|
||||
|
||||
drupal_json_output($term_matches);
|
||||
|
||||
}
|
||||
|
||||
function materiobase_search_autocomplete_searchapi($typed = ''){
|
||||
// If the request has a '/' in the search text, then the menu system will have
|
||||
// split it into multiple arguments, recover the intended $tags_typed.
|
||||
$args = func_get_args();
|
||||
$typed = implode('/', $args);
|
||||
|
||||
/*
|
||||
TODO riche serach engine + \\ etc gmail like
|
||||
*/
|
||||
|
||||
if ($typed != '') {
|
||||
|
||||
|
||||
$query = search_api_query('referencement');
|
||||
|
||||
$query_filter = $query->createFilter();
|
||||
$query_filter->condition('name', $typed);
|
||||
// $query_filter->condition('type', 'article');
|
||||
|
||||
$query->filter($query_filter);
|
||||
|
||||
$tags_return = $query->execute();
|
||||
|
||||
dsm($tags_return, '$tags_return');
|
||||
|
||||
$term_matches = array();
|
||||
$index = search_api_index_load('referencement');
|
||||
foreach ($index->loadItems(array_keys($tags_return['results'])) as $item) {
|
||||
dsm($item, '$item');
|
||||
}
|
||||
|
||||
//
|
||||
// foreach ($tags_return as $tid => $name) {
|
||||
// $n = $name;
|
||||
// // Term names containing commas or quotes must be wrapped in quotes.
|
||||
// // if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) {
|
||||
// // $n = '"' . str_replace('"', '""', $name) . '"';
|
||||
// // }
|
||||
// $term_matches[$n] = check_plain($name);
|
||||
// }
|
||||
}
|
||||
|
||||
drupal_json_output($term_matches);
|
||||
|
||||
}
|
57
templates/materio-search-api-results.tpl.php
Normal file
57
templates/materio-search-api-results.tpl.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Default theme implementation for displaying search results.
|
||||
*
|
||||
* This template collects each invocation of theme_search_result(). This and
|
||||
* the child template are dependent to one another sharing the markup for
|
||||
* definition lists.
|
||||
*
|
||||
* Note that modules and themes may implement their own search type and theme
|
||||
* function completely bypassing this template.
|
||||
*
|
||||
* Available variables:
|
||||
* - $result_count: Number of results.
|
||||
* - $spellcheck: Possible spelling suggestions from Search spellcheck module.
|
||||
* - $search_results: All results rendered as list items in a single HTML string.
|
||||
* - $items: All results as it is rendered through search-result.tpl.php.
|
||||
* - $search_performance: The number of results and how long the query took.
|
||||
* - $sec: The number of seconds it took to run the query.
|
||||
* - $pager: Row of control buttons for navigating between pages of results.
|
||||
* - $index:
|
||||
* - $keys: The keywords of the executed search.
|
||||
* - $page_machine_name: Machine name of the current Search API Page.
|
||||
*
|
||||
* View Mode is set in the Search page settings. If you select
|
||||
* "Themed as search results", then the child template will be used for
|
||||
* theming the individual result. Any other view mode will bypass the
|
||||
* child template.
|
||||
*
|
||||
* @see template_preprocess_search_api_page_results()
|
||||
*/
|
||||
|
||||
?>
|
||||
<?php if (!empty($result_count)) : ?>
|
||||
<div class="materiobase-results <?php print ' view-mode-' . $variables['view_mode'];?>">
|
||||
<?php if ($result_count) : ?>
|
||||
<?php //print render($search_performance); ?>
|
||||
<?php //print render($spellcheck); ?>
|
||||
<div class="search-results">
|
||||
<?php $eview = entity_view($index->item_type, $items, $variables['view_mode']); ?>
|
||||
<?php //dsm($eview, 'eview'); ?>
|
||||
<?php print render($eview); ?>
|
||||
<?php
|
||||
// foreach ($eview[$index->item_type] as $entity){
|
||||
// $renders[] = render($entity);
|
||||
// }
|
||||
// dsm($renders, 'renders');
|
||||
|
||||
// print implode('<!-- whitespace -->', $renders);
|
||||
?>
|
||||
</div>
|
||||
<?php print $pager; ?>
|
||||
<?php else : ?>
|
||||
<h2><?php print t('Your search yielded no results.');?></h2>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
3
templates/materio-search-api-search-block.tpl.php
Normal file
3
templates/materio-search-api-search-block.tpl.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
print render($searchform);
|
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
print $content;
|
@ -1,3 +0,0 @@
|
||||
<?php
|
||||
print "hello world !";
|
||||
print render($searchform);
|
Loading…
x
Reference in New Issue
Block a user