riojs 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +24 -0
- data/VERSION +1 -0
- data/bin/rio +5 -0
- data/generators/rio_app/USAGE +19 -0
- data/generators/rio_app/rio_app_generator.rb +40 -0
- data/generators/rio_app/templates/app.build +10 -0
- data/generators/rio_app/templates/app.css +0 -0
- data/generators/rio_app/templates/app.js +20 -0
- data/generators/rio_app/templates/app_view.html.erb +19 -0
- data/generators/rio_app/templates/fixture.js +4 -0
- data/generators/rio_app/templates/rio.html.erb +18 -0
- data/generators/rio_app/templates/rio_controller.rb +2 -0
- data/generators/rio_app/templates/spec.js +7 -0
- data/generators/rio_component/USAGE +13 -0
- data/generators/rio_component/rio_component_generator.rb +16 -0
- data/generators/rio_component/templates/component.css +0 -0
- data/generators/rio_component/templates/component.js +11 -0
- data/generators/rio_component/templates/fixture.js +3 -0
- data/generators/rio_component/templates/spec.js +6 -0
- data/generators/rio_model/USAGE +12 -0
- data/generators/rio_model/rio_model_generator.rb +21 -0
- data/generators/rio_model/templates/fixture.js +3 -0
- data/generators/rio_model/templates/model.js +9 -0
- data/generators/rio_model/templates/spec.js +6 -0
- data/generators/rio_page/USAGE +14 -0
- data/generators/rio_page/rio_page_generator.rb +16 -0
- data/generators/rio_page/templates/fixture.js +3 -0
- data/generators/rio_page/templates/page.css +12 -0
- data/generators/rio_page/templates/page.js +12 -0
- data/generators/rio_page/templates/page.jst +64 -0
- data/generators/rio_page/templates/spec.js +6 -0
- data/generators/rio_resource/USAGE +20 -0
- data/generators/rio_resource/rio_resource_generator.rb +10 -0
- data/generators/rio_resource/templates/controller.rb +3 -0
- data/init.rb +4 -0
- data/install/config/juggernaut_hosts.yml +18 -0
- data/install/lib/tasks/rio.rake +1 -0
- data/install/script/rio_server +37 -0
- data/lib/rio/autospec.rb +86 -0
- data/lib/rio/install.rb +90 -0
- data/lib/rio/juggernaut.rb +212 -0
- data/lib/rio/path.rb +3 -0
- data/lib/rio/rio_compressor.rb +219 -0
- data/lib/rio/rio_file_controller.rb +16 -0
- data/lib/rio/rio_on_rails.rb +586 -0
- data/lib/rio/rio_proxy_controller.rb +60 -0
- data/lib/rio/rio_push_controller.rb +48 -0
- data/lib/rio/rio_routes.rb +24 -0
- data/lib/rio/rio_spec_controller.rb +70 -0
- data/lib/riojs.rb +14 -0
- data/lib/tasks/rio.rb +63 -0
- data/public/images/background-chiffon.png +0 -0
- data/public/images/button-gradient-overlay-down.png +0 -0
- data/public/images/button-gradient-overlay.png +0 -0
- data/public/images/icons/add.png +0 -0
- data/public/images/icons/error-big.png +0 -0
- data/public/images/icons/warning-big.png +0 -0
- data/public/images/rio-logo-big.png +0 -0
- data/public/images/rio-logo.png +0 -0
- data/public/images/splitter-handle-horizontal.png +0 -0
- data/public/images/splitter-handle-vertical.png +0 -0
- data/public/images/tab-bar-gradient-overlay.png +0 -0
- data/public/images/title-gradient-overlay.png +0 -0
- data/public/images/trash.gif +0 -0
- data/public/javascripts/components/accordion.js +144 -0
- data/public/javascripts/components/alert_box.js +59 -0
- data/public/javascripts/components/base.js +47 -0
- data/public/javascripts/components/box.js +63 -0
- data/public/javascripts/components/button.js +98 -0
- data/public/javascripts/components/checkbox.js +44 -0
- data/public/javascripts/components/container.js +265 -0
- data/public/javascripts/components/grid_view.js +107 -0
- data/public/javascripts/components/image.js +19 -0
- data/public/javascripts/components/input.js +171 -0
- data/public/javascripts/components/label.js +15 -0
- data/public/javascripts/components/lightbox.js +160 -0
- data/public/javascripts/components/link.js +43 -0
- data/public/javascripts/components/list_item.js +44 -0
- data/public/javascripts/components/list_view.js +192 -0
- data/public/javascripts/components/marquee.js +131 -0
- data/public/javascripts/components/menu.js +89 -0
- data/public/javascripts/components/notification.js +75 -0
- data/public/javascripts/components/overlay.js +134 -0
- data/public/javascripts/components/panel.js +146 -0
- data/public/javascripts/components/radio.js +46 -0
- data/public/javascripts/components/splitter.js +65 -0
- data/public/javascripts/components/tab_bar.js +64 -0
- data/public/javascripts/components/tab_panel.js +57 -0
- data/public/javascripts/components/textarea.js +223 -0
- data/public/javascripts/components/toggle_button.js +22 -0
- data/public/javascripts/components/tooltip.js +80 -0
- data/public/javascripts/lib/application.js +482 -0
- data/public/javascripts/lib/attr.js +760 -0
- data/public/javascripts/lib/benchmark.js +235 -0
- data/public/javascripts/lib/blank.html +39 -0
- data/public/javascripts/lib/boot.js +300 -0
- data/public/javascripts/lib/clipboard.js +96 -0
- data/public/javascripts/lib/collection_entity.js +46 -0
- data/public/javascripts/lib/component.js +129 -0
- data/public/javascripts/lib/console.js +75 -0
- data/public/javascripts/lib/console/apps/console.build +43 -0
- data/public/javascripts/lib/console/apps/console.js +28 -0
- data/public/javascripts/lib/console/blank.html +39 -0
- data/public/javascripts/lib/console/components/benchmark.js +196 -0
- data/public/javascripts/lib/console/components/console.js +352 -0
- data/public/javascripts/lib/console/components/dependencies_list.js +17 -0
- data/public/javascripts/lib/console/components/docs.js +66 -0
- data/public/javascripts/lib/console/components/playground.js +30 -0
- data/public/javascripts/lib/console/console.html +27 -0
- data/public/javascripts/lib/console/console_commands.js +287 -0
- data/public/javascripts/lib/console/console_commands.js.rej +21 -0
- data/public/javascripts/lib/console/console_mixin.js +22 -0
- data/public/javascripts/lib/console/docs/files.html +579 -0
- data/public/javascripts/lib/console/docs/index.html +323 -0
- data/public/javascripts/lib/console/docs/symbols/Object.html +291 -0
- data/public/javascripts/lib/console/docs/symbols/_global_.html +413 -0
- data/public/javascripts/lib/console/docs/symbols/rio.AIM.html +490 -0
- data/public/javascripts/lib/console/docs/symbols/rio.Application.html +841 -0
- data/public/javascripts/lib/console/docs/symbols/rio.Attr.html +1075 -0
- data/public/javascripts/lib/console/docs/symbols/rio.Binding.html +272 -0
- data/public/javascripts/lib/console/docs/symbols/rio.Component.html +419 -0
- data/public/javascripts/lib/console/docs/symbols/rio.Cookie.html +543 -0
- data/public/javascripts/lib/console/docs/symbols/rio.DelayedTask#initialize.html +270 -0
- data/public/javascripts/lib/console/docs/symbols/rio.DelayedTask.html +391 -0
- data/public/javascripts/lib/console/docs/symbols/rio.JsTemplate.html +271 -0
- data/public/javascripts/lib/console/docs/symbols/rio.Juggernaut.html +329 -0
- data/public/javascripts/lib/console/docs/symbols/rio.Model.html +822 -0
- data/public/javascripts/lib/console/docs/symbols/rio.Page.html +383 -0
- data/public/javascripts/lib/console/docs/symbols/rio.Template.html +328 -0
- data/public/javascripts/lib/console/docs/symbols/rio.Utils.html +617 -0
- data/public/javascripts/lib/console/docs/symbols/rio.html +506 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_components_base.js.html +54 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_application.js.html +490 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_attr.js.html +768 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_boot.js.html +308 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_clipboard.js.html +103 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_collection_entity.js.html +53 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_component.js.html +137 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_cookie.js.html +81 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_delayed_task.js.html +68 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_file.js.html +80 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_flash_detect.js.html +129 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_form.js.html +95 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_id.js.html +50 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_inflector.js.html +167 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_js_template.js.html +283 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_juggernaut.js.html +303 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_key_map.js.html +68 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_layout_manager.js.html +175 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_log.js.html +17 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_model.js.html +1074 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_page.js.html +246 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_parameters.js.html +66 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_protohack.js.html +305 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_push.js.html +12 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_rsh.js.html +659 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_swfobject.js.html +12 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_tag.js.html +60 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_template.js.html +64 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_theme.js.html +105 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_undo.js.html +142 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_utils.js.html +87 -0
- data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_yaml.js.html +88 -0
- data/public/javascripts/lib/console/file-small.png +0 -0
- data/public/javascripts/lib/console/green-circle.png +0 -0
- data/public/javascripts/lib/console/loading.gif +0 -0
- data/public/javascripts/lib/console/pages/console_page.js +149 -0
- data/public/javascripts/lib/console/pages/console_page.jst +27 -0
- data/public/javascripts/lib/console/red-circle.png +0 -0
- data/public/javascripts/lib/cookie.js +74 -0
- data/public/javascripts/lib/delayed_task.js +61 -0
- data/public/javascripts/lib/dependencies.js +76 -0
- data/public/javascripts/lib/environment.js +30 -0
- data/public/javascripts/lib/event.simulate.js +137 -0
- data/public/javascripts/lib/expressinstall.swf +0 -0
- data/public/javascripts/lib/file.js +72 -0
- data/public/javascripts/lib/flash_detect.js +122 -0
- data/public/javascripts/lib/flashembed.min.js +16 -0
- data/public/javascripts/lib/form.js +88 -0
- data/public/javascripts/lib/id.js +43 -0
- data/public/javascripts/lib/inflector.js +160 -0
- data/public/javascripts/lib/instrumenter.js +106 -0
- data/public/javascripts/lib/js_template.js +275 -0
- data/public/javascripts/lib/jslint.js +4950 -0
- data/public/javascripts/lib/juggernaut.js +295 -0
- data/public/javascripts/lib/juggernaut.swf +0 -0
- data/public/javascripts/lib/key_map.js +60 -0
- data/public/javascripts/lib/layout_manager.js +167 -0
- data/public/javascripts/lib/model.js +1067 -0
- data/public/javascripts/lib/page.js +238 -0
- data/public/javascripts/lib/parameters.js +59 -0
- data/public/javascripts/lib/png_fix.js +75 -0
- data/public/javascripts/lib/protohack.js +297 -0
- data/public/javascripts/lib/push.js +5 -0
- data/public/javascripts/lib/rio.build +28 -0
- data/public/javascripts/lib/rio_development.build +5 -0
- data/public/javascripts/lib/rio_lint.js +66 -0
- data/public/javascripts/lib/rsh.js +651 -0
- data/public/javascripts/lib/spec.js +545 -0
- data/public/javascripts/lib/spec_runner.js +242 -0
- data/public/javascripts/lib/swfobject.js +5 -0
- data/public/javascripts/lib/tag.js +52 -0
- data/public/javascripts/lib/undo.js +134 -0
- data/public/javascripts/lib/utils.js +80 -0
- data/public/javascripts/lib/yaml.js +80 -0
- data/public/javascripts/pages/playground_page.js +15 -0
- data/public/javascripts/prototype/builder.js +146 -0
- data/public/javascripts/prototype/controls.js +1004 -0
- data/public/javascripts/prototype/dragdrop.js +1030 -0
- data/public/javascripts/prototype/effects.js +1137 -0
- data/public/javascripts/prototype/prototype.js +4320 -0
- data/public/javascripts/prototype/slider.js +283 -0
- data/public/javascripts/prototype/sound.js +67 -0
- data/public/javascripts/specs/components/box_spec.js +6 -0
- data/public/javascripts/specs/components/checkbox_spec.js +26 -0
- data/public/javascripts/specs/components/container_spec.js +6 -0
- data/public/javascripts/specs/components/input_spec.js +71 -0
- data/public/javascripts/specs/components/panel_spec.js +6 -0
- data/public/javascripts/specs/components/radio_spec.js +40 -0
- data/public/javascripts/specs/fixtures/components/box.js +3 -0
- data/public/javascripts/specs/fixtures/components/checkbox.js +9 -0
- data/public/javascripts/specs/fixtures/components/container.js +3 -0
- data/public/javascripts/specs/fixtures/components/input.js +12 -0
- data/public/javascripts/specs/fixtures/components/menu.js +19 -0
- data/public/javascripts/specs/fixtures/components/menu_item.js +18 -0
- data/public/javascripts/specs/fixtures/components/radio.js +11 -0
- data/public/javascripts/specs/lib/application_spec.js +281 -0
- data/public/javascripts/specs/lib/attr_spec.js +1514 -0
- data/public/javascripts/specs/lib/benchmark_spec.js +361 -0
- data/public/javascripts/specs/lib/collection_entity_spec.js +131 -0
- data/public/javascripts/specs/lib/component_spec.js +86 -0
- data/public/javascripts/specs/lib/form_spec.js +171 -0
- data/public/javascripts/specs/lib/id_spec.js +21 -0
- data/public/javascripts/specs/lib/instrumenter_spec.js +5 -0
- data/public/javascripts/specs/lib/js_template_spec.js +131 -0
- data/public/javascripts/specs/lib/key_map_spec.js +227 -0
- data/public/javascripts/specs/lib/model_spec.js +2268 -0
- data/public/javascripts/specs/lib/parameters_spec.js +94 -0
- data/public/javascripts/specs/lib/spec_spec.js +943 -0
- data/public/javascripts/specs/lib/undo_spec.js +105 -0
- data/public/javascripts/specs/lib/yaml_spec.js +127 -0
- data/public/sounds/basso.wav +0 -0
- data/public/sounds/purr.wav +0 -0
- data/public/stylesheets/components/accordion.css +24 -0
- data/public/stylesheets/components/alert_box.css +35 -0
- data/public/stylesheets/components/box.css +0 -0
- data/public/stylesheets/components/button.css +39 -0
- data/public/stylesheets/components/checkbox.css +9 -0
- data/public/stylesheets/components/container.css +3 -0
- data/public/stylesheets/components/grid_view.css +52 -0
- data/public/stylesheets/components/input.css +10 -0
- data/public/stylesheets/components/label.css +3 -0
- data/public/stylesheets/components/lightbox.css +31 -0
- data/public/stylesheets/components/link.css +4 -0
- data/public/stylesheets/components/list_view.css +23 -0
- data/public/stylesheets/components/marquee.css +29 -0
- data/public/stylesheets/components/menu.css +34 -0
- data/public/stylesheets/components/notification.css +52 -0
- data/public/stylesheets/components/overlay.css +8 -0
- data/public/stylesheets/components/panel.css +36 -0
- data/public/stylesheets/components/radio.css +9 -0
- data/public/stylesheets/components/splitter.css +35 -0
- data/public/stylesheets/components/tab_bar.css +59 -0
- data/public/stylesheets/components/tab_panel.css +15 -0
- data/public/stylesheets/components/textarea.css +11 -0
- data/public/stylesheets/components/tooltip.css +10 -0
- data/public/stylesheets/console.css +151 -0
- data/public/stylesheets/css_reset.css +55 -0
- metadata +343 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
lib/flash_detect
|
2
|
+
lib/protohack
|
3
|
+
lib/cookie
|
4
|
+
lib/file
|
5
|
+
lib/yaml
|
6
|
+
lib/tag
|
7
|
+
lib/key_map
|
8
|
+
lib/clipboard
|
9
|
+
lib/utils
|
10
|
+
lib/rsh
|
11
|
+
lib/swfobject
|
12
|
+
lib/delayed_task
|
13
|
+
lib/push
|
14
|
+
lib/juggernaut
|
15
|
+
lib/layout_manager
|
16
|
+
lib/inflector
|
17
|
+
lib/attr
|
18
|
+
lib/parameters
|
19
|
+
lib/collection_entity
|
20
|
+
lib/form
|
21
|
+
lib/id
|
22
|
+
lib/undo
|
23
|
+
lib/model
|
24
|
+
lib/component
|
25
|
+
components/base
|
26
|
+
lib/js_template
|
27
|
+
lib/page
|
28
|
+
lib/application
|
@@ -0,0 +1,66 @@
|
|
1
|
+
rio.require("lib/jslint");
|
2
|
+
rio.require("lib/file");
|
3
|
+
|
4
|
+
rio.RioLint = {
|
5
|
+
checkFileSyntax: function(file, options) {
|
6
|
+
options = Object.extend({
|
7
|
+
onComplete: Prototype.emptyFunction
|
8
|
+
}, options);
|
9
|
+
var path = "/javascripts/" + file + ".js";
|
10
|
+
rio.File.open(path, {
|
11
|
+
onSuccess: function(content) {
|
12
|
+
var errors = this.checkSyntax(content, file);
|
13
|
+
options.onComplete(errors);
|
14
|
+
}.bind(this),
|
15
|
+
onFailure: function() {
|
16
|
+
rio.error("This file might not exist.", "RioLint failed to load: " + file);
|
17
|
+
}
|
18
|
+
});
|
19
|
+
},
|
20
|
+
|
21
|
+
checkSyntax: function(content, fileName) {
|
22
|
+
try {
|
23
|
+
var errors = rio.JSLINT.process(content, {
|
24
|
+
browser: true,
|
25
|
+
eqeqeq: false,
|
26
|
+
evil: true,
|
27
|
+
newcap: false,
|
28
|
+
passfail: false
|
29
|
+
}).compact().reject(function(error) {
|
30
|
+
return this.ignoreError(error);
|
31
|
+
}.bind(this));
|
32
|
+
|
33
|
+
return this.formatErrors(errors, fileName);
|
34
|
+
} catch(e) {
|
35
|
+
rio.log(e + "(" + e.fileName + ": " + e.lineNumber + ")", "errorLogItem", "> ");
|
36
|
+
rio.log("Syntax check failed for: " + file, "errorLogItem");
|
37
|
+
}
|
38
|
+
},
|
39
|
+
|
40
|
+
formatErrors: function(errors, fileName) {
|
41
|
+
return errors.map(function(error) {
|
42
|
+
// lines are 0 indexed in lint
|
43
|
+
return {
|
44
|
+
toString: function() {
|
45
|
+
return fileName + ".js (line " + (error.line + 1) + ", char " + (error.character + 1) + ")" + " " + error.reason;
|
46
|
+
},
|
47
|
+
toHtml: function(){
|
48
|
+
return '<span class="errorLine">' + fileName + '.js</span> (line <span class="errorLine">' + (error.line + 1) + "</span>, char " + (error.character + 1) + ")" + " " + error.reason;
|
49
|
+
}
|
50
|
+
|
51
|
+
};
|
52
|
+
});
|
53
|
+
},
|
54
|
+
|
55
|
+
ignoreError: function(error) {
|
56
|
+
return [
|
57
|
+
/Use '[!=]==' to compare with .*/,
|
58
|
+
"'new' should not be used as a statement.",
|
59
|
+
"document.write can be a form of eval.",
|
60
|
+
"The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.",
|
61
|
+
"Expected an identifier and instead saw 'eval' (a reserved word)."
|
62
|
+
].any(function(allowable) {
|
63
|
+
return (error.reason == allowable) || error.reason.match(allowable);
|
64
|
+
});
|
65
|
+
}
|
66
|
+
};
|
@@ -0,0 +1,651 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2007 Brian Dillard and Brad Neuberg:
|
3
|
+
Brian Dillard | Project Lead | bdillard@pathf.com | http://blogs.pathf.com/agileajax/
|
4
|
+
Brad Neuberg | Original Project Creator | http://codinginparadise.org
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
|
7
|
+
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
|
8
|
+
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do
|
9
|
+
so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
14
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
15
|
+
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
16
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
17
|
+
*/
|
18
|
+
|
19
|
+
/*
|
20
|
+
dhtmlHistory: An object that provides history, history data, and bookmarking for DHTML and Ajax applications.
|
21
|
+
|
22
|
+
dependencies:
|
23
|
+
* the historyStorage object included in this file.
|
24
|
+
|
25
|
+
*/
|
26
|
+
dhtmlHistory = {
|
27
|
+
|
28
|
+
/*Public: User-agent booleans*/
|
29
|
+
isIE: false,
|
30
|
+
isOpera: false,
|
31
|
+
isSafari: false,
|
32
|
+
isKonquerer: false,
|
33
|
+
isGecko: false,
|
34
|
+
isSupported: false,
|
35
|
+
|
36
|
+
/*Public: Create the DHTML history infrastructure*/
|
37
|
+
create: function(options) {
|
38
|
+
/*
|
39
|
+
options - object to store initialization parameters
|
40
|
+
options.debugMode - boolean that causes hidden form fields to be shown for development purposes.
|
41
|
+
options.toJSON - function to override default JSON stringifier
|
42
|
+
options.fromJSON - function to override default JSON parser
|
43
|
+
*/
|
44
|
+
|
45
|
+
var that = this;
|
46
|
+
|
47
|
+
/*set user-agent flags*/
|
48
|
+
var UA = navigator.userAgent.toLowerCase();
|
49
|
+
var platform = navigator.platform.toLowerCase();
|
50
|
+
var vendor = navigator.vendor || "";
|
51
|
+
if (vendor === "KDE") {
|
52
|
+
this.isKonqueror = true;
|
53
|
+
this.isSupported = false;
|
54
|
+
} else if (typeof window.opera !== "undefined") {
|
55
|
+
this.isOpera = true;
|
56
|
+
this.isSupported = true;
|
57
|
+
} else if (typeof document.all !== "undefined") {
|
58
|
+
this.isIE = true;
|
59
|
+
this.isSupported = true;
|
60
|
+
} else if (vendor.indexOf("Apple Computer, Inc.") > -1) {
|
61
|
+
versionString = UA.substring(UA.toLowerCase().indexOf("version")+8,UA.toLowerCase().indexOf("safari"));
|
62
|
+
versionNumber = parseFloat(versionString);
|
63
|
+
if( 2 <= versionNumber && versionNumber < 3){
|
64
|
+
this.isSafari = true;
|
65
|
+
this.isSupported = (platform.indexOf("mac") > -1);
|
66
|
+
} else if( 3 <= versionNumber && versionNumber < 4 ){
|
67
|
+
this.isGecko = true;
|
68
|
+
this.isSupported = true;
|
69
|
+
}
|
70
|
+
} else if (UA.indexOf("gecko") != -1) {
|
71
|
+
this.isGecko = true;
|
72
|
+
this.isSupported = true;
|
73
|
+
}
|
74
|
+
|
75
|
+
/*Set up the historyStorage object; pass in init parameters*/
|
76
|
+
window.historyStorage.setup(options);
|
77
|
+
|
78
|
+
/*Execute browser-specific setup methods*/
|
79
|
+
if (this.isSafari) {
|
80
|
+
this.createSafari();
|
81
|
+
} else if (this.isOpera) {
|
82
|
+
this.createOpera();
|
83
|
+
}
|
84
|
+
|
85
|
+
/*Get our initial location*/
|
86
|
+
var initialHash = this.getCurrentLocation();
|
87
|
+
|
88
|
+
/*Save it as our current location*/
|
89
|
+
this.currentLocation = initialHash;
|
90
|
+
|
91
|
+
/*Now that we have a hash, create IE-specific code*/
|
92
|
+
if (this.isIE) {
|
93
|
+
this.createIE(initialHash);
|
94
|
+
}
|
95
|
+
|
96
|
+
/*Add an unload listener for the page; this is needed for FF 1.5+ because this browser caches all dynamic updates to the
|
97
|
+
page, which can break some of our logic related to testing whether this is the first instance a page has loaded or whether
|
98
|
+
it is being pulled from the cache*/
|
99
|
+
|
100
|
+
var unloadHandler = function() {
|
101
|
+
that.firstLoad = null;
|
102
|
+
};
|
103
|
+
|
104
|
+
this.addEventListener(window,'unload',unloadHandler);
|
105
|
+
|
106
|
+
/*Determine if this is our first page load; for IE, we do this in this.iframeLoaded(), which is fired on pageload. We do it
|
107
|
+
there because we have no historyStorage at this point, which only exists after the page is finished loading in IE*/
|
108
|
+
if (this.isIE) {
|
109
|
+
/*The iframe will get loaded on page load, and we want to ignore this fact*/
|
110
|
+
this.ignoreLocationChange = true;
|
111
|
+
} else {
|
112
|
+
if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) {
|
113
|
+
/*This is our first page load, so ignore the location change and add our special history entry*/
|
114
|
+
this.ignoreLocationChange = true;
|
115
|
+
this.firstLoad = true;
|
116
|
+
historyStorage.put(this.PAGELOADEDSTRING, true);
|
117
|
+
} else {
|
118
|
+
/*This isn't our first page load, so indicate that we want to pay attention to this location change*/
|
119
|
+
this.ignoreLocationChange = false;
|
120
|
+
/*For browsers other than IE, fire a history change event; on IE, the event will be thrown automatically when its
|
121
|
+
hidden iframe reloads on page load. Unfortunately, we don't have any listeners yet; indicate that we want to fire
|
122
|
+
an event when a listener is added.*/
|
123
|
+
this.fireOnNewListener = true;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
/*Other browsers can use a location handler that checks at regular intervals as their primary mechanism; we use it for IE as
|
128
|
+
well to handle an important edge case; see checkLocation() for details*/
|
129
|
+
var locationHandler = function() {
|
130
|
+
that.checkLocation();
|
131
|
+
};
|
132
|
+
setInterval(locationHandler, 100);
|
133
|
+
},
|
134
|
+
|
135
|
+
/*Public: Initialize our DHTML history. You must call this after the page is finished loading.*/
|
136
|
+
initialize: function() {
|
137
|
+
/*IE needs to be explicitly initialized. IE doesn't autofill form data until the page is finished loading, so we have to wait*/
|
138
|
+
if (this.isIE) {
|
139
|
+
/*If this is the first time this page has loaded*/
|
140
|
+
if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) {
|
141
|
+
/*For IE, we do this in initialize(); for other browsers, we do it in create()*/
|
142
|
+
this.fireOnNewListener = false;
|
143
|
+
this.firstLoad = true;
|
144
|
+
historyStorage.put(this.PAGELOADEDSTRING, true);
|
145
|
+
}
|
146
|
+
/*Else if this is a fake onload event*/
|
147
|
+
else {
|
148
|
+
this.fireOnNewListener = true;
|
149
|
+
this.firstLoad = false;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
},
|
153
|
+
|
154
|
+
/*Public: Adds a history change listener. Note that only one listener is supported at this time.*/
|
155
|
+
addListener: function(listener) {
|
156
|
+
this.listener = listener;
|
157
|
+
/*If the page was just loaded and we should not ignore it, fire an event to our new listener now*/
|
158
|
+
if (this.fireOnNewListener) {
|
159
|
+
this.fireHistoryEvent(this.currentLocation);
|
160
|
+
this.fireOnNewListener = false;
|
161
|
+
}
|
162
|
+
},
|
163
|
+
|
164
|
+
/*Public: Generic utility function for attaching events*/
|
165
|
+
addEventListener: function(o,e,l) {
|
166
|
+
if (o.addEventListener) {
|
167
|
+
o.addEventListener(e,l,false);
|
168
|
+
} else if (o.attachEvent) {
|
169
|
+
o.attachEvent('on'+e,function() {
|
170
|
+
l(window.event);
|
171
|
+
});
|
172
|
+
}
|
173
|
+
},
|
174
|
+
|
175
|
+
/*Public: Add a history point.*/
|
176
|
+
add: function(newLocation, historyData) {
|
177
|
+
if (this.isSafari) {
|
178
|
+
|
179
|
+
/*Remove any leading hash symbols on newLocation*/
|
180
|
+
newLocation = this.removeHash(newLocation);
|
181
|
+
|
182
|
+
/*Store the history data into history storage*/
|
183
|
+
historyStorage.put(newLocation, historyData);
|
184
|
+
|
185
|
+
/*Save this as our current location*/
|
186
|
+
this.currentLocation = newLocation;
|
187
|
+
|
188
|
+
/*Change the browser location*/
|
189
|
+
window.location.hash = newLocation;
|
190
|
+
|
191
|
+
/*Save this to the Safari form field*/
|
192
|
+
this.putSafariState(newLocation);
|
193
|
+
} else {
|
194
|
+
|
195
|
+
/*Most browsers require that we wait a certain amount of time before changing the location, such
|
196
|
+
as 200 MS; rather than forcing external callers to use window.setTimeout to account for this,
|
197
|
+
we internally handle it by putting requests in a queue.*/
|
198
|
+
var that = this;
|
199
|
+
var addImpl = function() {
|
200
|
+
|
201
|
+
/*Indicate that the current wait time is now less*/
|
202
|
+
if (that.currentWaitTime > 0) {
|
203
|
+
that.currentWaitTime = that.currentWaitTime - that.waitTime;
|
204
|
+
}
|
205
|
+
|
206
|
+
/*Remove any leading hash symbols on newLocation*/
|
207
|
+
newLocation = that.removeHash(newLocation);
|
208
|
+
|
209
|
+
/*IE has a strange bug; if the newLocation is the same as _any_ preexisting id in the
|
210
|
+
document, then the history action gets recorded twice; throw a programmer exception if
|
211
|
+
there is an element with this ID*/
|
212
|
+
if (document.getElementById(newLocation) && that.debugMode) {
|
213
|
+
var e = "Exception: History locations can not have the same value as _any_ IDs that might be in the document," +
|
214
|
+
" due to a bug in IE; please ask the developer to choose a history location that does not match any HTML" +
|
215
|
+
" IDs in this document. The following ID is already taken and cannot be a location: " + newLocation;
|
216
|
+
throw new Error(e);
|
217
|
+
}
|
218
|
+
|
219
|
+
/*Store the history data into history storage*/
|
220
|
+
historyStorage.put(newLocation, historyData);
|
221
|
+
|
222
|
+
/*Indicate to the browser to ignore this upcomming location change since we're making it programmatically*/
|
223
|
+
that.ignoreLocationChange = true;
|
224
|
+
|
225
|
+
/*Indicate to IE that this is an atomic location change block*/
|
226
|
+
that.ieAtomicLocationChange = true;
|
227
|
+
|
228
|
+
/*Save this as our current location*/
|
229
|
+
that.currentLocation = newLocation;
|
230
|
+
|
231
|
+
/*Change the browser location*/
|
232
|
+
window.location.hash = newLocation;
|
233
|
+
|
234
|
+
/*Change the hidden iframe's location if on IE*/
|
235
|
+
if (that.isIE) {
|
236
|
+
that.iframe.src = "/javascripts/lib/blank.html?" + newLocation;
|
237
|
+
}
|
238
|
+
|
239
|
+
/*End of atomic location change block for IE*/
|
240
|
+
that.ieAtomicLocationChange = false;
|
241
|
+
};
|
242
|
+
|
243
|
+
/*Now queue up this add request*/
|
244
|
+
window.setTimeout(addImpl, this.currentWaitTime);
|
245
|
+
|
246
|
+
/*Indicate that the next request will have to wait for awhile*/
|
247
|
+
this.currentWaitTime = this.currentWaitTime + this.waitTime;
|
248
|
+
}
|
249
|
+
},
|
250
|
+
|
251
|
+
/*Public*/
|
252
|
+
isFirstLoad: function() {
|
253
|
+
return this.firstLoad;
|
254
|
+
},
|
255
|
+
|
256
|
+
/*Public*/
|
257
|
+
getVersion: function() {
|
258
|
+
return "0.6";
|
259
|
+
},
|
260
|
+
|
261
|
+
/*Get browser's current hash location; for Safari, read value from a hidden form field*/
|
262
|
+
|
263
|
+
/*Public*/
|
264
|
+
getCurrentLocation: function() {
|
265
|
+
var r = (this.isSafari ? this.getSafariState() : this.getCurrentHash());
|
266
|
+
return r;
|
267
|
+
},
|
268
|
+
|
269
|
+
/*Public: Manually parse the current url for a hash; tip of the hat to YUI*/
|
270
|
+
getCurrentHash: function() {
|
271
|
+
var r = window.location.href;
|
272
|
+
var i = r.indexOf("#");
|
273
|
+
return (i >= 0 ? r.substr(i+1) : "");
|
274
|
+
},
|
275
|
+
|
276
|
+
/*- - - - - - - - - - - -*/
|
277
|
+
|
278
|
+
/*Private: Constant for our own internal history event called when the page is loaded*/
|
279
|
+
PAGELOADEDSTRING: "DhtmlHistory_pageLoaded",
|
280
|
+
|
281
|
+
/*Private: Our history change listener.*/
|
282
|
+
listener: null,
|
283
|
+
|
284
|
+
/*Private: MS to wait between add requests - will be reset for certain browsers*/
|
285
|
+
waitTime: 200,
|
286
|
+
|
287
|
+
/*Private: MS before an add request can execute*/
|
288
|
+
currentWaitTime: 0,
|
289
|
+
|
290
|
+
/*Private: Our current hash location, without the "#" symbol.*/
|
291
|
+
currentLocation: null,
|
292
|
+
|
293
|
+
/*Private: Hidden iframe used to IE to detect history changes*/
|
294
|
+
iframe: null,
|
295
|
+
|
296
|
+
/*Private: Flags and DOM references used only by Safari*/
|
297
|
+
safariHistoryStartPoint: null,
|
298
|
+
safariStack: null,
|
299
|
+
safariLength: null,
|
300
|
+
|
301
|
+
/*Private: Flag used to keep checkLocation() from doing anything when it discovers location changes we've made ourselves
|
302
|
+
programmatically with the add() method. Basically, add() sets this to true. When checkLocation() discovers it's true,
|
303
|
+
it refrains from firing our listener, then resets the flag to false for next cycle. That way, our listener only gets fired on
|
304
|
+
history change events triggered by the user via back/forward buttons and manual hash changes. This flag also helps us set up
|
305
|
+
IE's special iframe-based method of handling history changes.*/
|
306
|
+
ignoreLocationChange: null,
|
307
|
+
|
308
|
+
/*Private: A flag that indicates that we should fire a history change event when we are ready, i.e. after we are initialized and
|
309
|
+
we have a history change listener. This is needed due to an edge case in browsers other than IE; if you leave a page entirely
|
310
|
+
then return, we must fire this as a history change event. Unfortunately, we have lost all references to listeners from earlier,
|
311
|
+
because JavaScript clears out.*/
|
312
|
+
fireOnNewListener: null,
|
313
|
+
|
314
|
+
/*Private: A variable that indicates whether this is the first time this page has been loaded. If you go to a web page, leave it
|
315
|
+
for another one, and then return, the page's onload listener fires again. We need a way to differentiate between the first page
|
316
|
+
load and subsequent ones. This variable works hand in hand with the pageLoaded variable we store into historyStorage.*/
|
317
|
+
firstLoad: null,
|
318
|
+
|
319
|
+
/*Private: A variable to handle an important edge case in IE. In IE, if a user manually types an address into their browser's
|
320
|
+
location bar, we must intercept this by calling checkLocation() at regular intervals. However, if we are programmatically
|
321
|
+
changing the location bar ourselves using the add() method, we need to ignore these changes in checkLocation(). Unfortunately,
|
322
|
+
these changes take several lines of code to complete, so for the duration of those lines of code, we set this variable to true.
|
323
|
+
That signals to checkLocation() to ignore the change-in-progress. Once we're done with our chunk of location-change code in
|
324
|
+
add(), we set this back to false. We'll do the same thing when capturing user-entered address changes in checkLocation itself.*/
|
325
|
+
ieAtomicLocationChange: null,
|
326
|
+
|
327
|
+
/*Private: Create IE-specific DOM nodes and overrides*/
|
328
|
+
createIE: function(initialHash) {
|
329
|
+
/*write out a hidden iframe for IE and set the amount of time to wait between add() requests*/
|
330
|
+
this.waitTime = 400;/*IE needs longer between history updates*/
|
331
|
+
var styles = (historyStorage.debugMode ? 'width: 800px;height:80px;border:1px solid black;' : historyStorage.hideStyles);
|
332
|
+
var iframeID = "rshHistoryFrame";
|
333
|
+
var iframeHTML = '<iframe frameborder="0" id="' + iframeID + '" style="' + styles + '" src="/javascripts/lib/blank.html?' + initialHash + '"></iframe>';
|
334
|
+
document.write(iframeHTML);
|
335
|
+
this.iframe = document.getElementById(iframeID);
|
336
|
+
},
|
337
|
+
|
338
|
+
/*Private: Create Opera-specific DOM nodes and overrides*/
|
339
|
+
createOpera: function() {
|
340
|
+
this.waitTime = 400;/*Opera needs longer between history updates*/
|
341
|
+
var imgHTML = '<img src="javascript:location.href=\'javascript:dhtmlHistory.checkLocation();\';" style="' + historyStorage.hideStyles + '" />';
|
342
|
+
document.write(imgHTML);
|
343
|
+
},
|
344
|
+
|
345
|
+
/*Private: Create Safari-specific DOM nodes and overrides*/
|
346
|
+
createSafari: function() {
|
347
|
+
var formID = "rshSafariForm";
|
348
|
+
var stackID = "rshSafariStack";
|
349
|
+
var lengthID = "rshSafariLength";
|
350
|
+
var formStyles = historyStorage.debugMode ? historyStorage.showStyles : historyStorage.hideStyles;
|
351
|
+
var inputStyles = (historyStorage.debugMode ? 'width:800px;height:20px;border:1px solid black;margin:0;padding:0;' : historyStorage.hideStyles);
|
352
|
+
var safariHTML = '<form id="' + formID + '" style="' + formStyles + '">' +
|
353
|
+
'<input type="text" style="' + inputStyles + '" id="' + stackID + '" value="[]"/>' +
|
354
|
+
'<input type="text" style="' + inputStyles + '" id="' + lengthID + '" value=""/>' +
|
355
|
+
'</form>';
|
356
|
+
document.write(safariHTML);
|
357
|
+
this.safariStack = document.getElementById(stackID);
|
358
|
+
this.safariLength = document.getElementById(lengthID);
|
359
|
+
if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) {
|
360
|
+
this.safariHistoryStartPoint = history.length;
|
361
|
+
this.safariLength.value = this.safariHistoryStartPoint;
|
362
|
+
} else {
|
363
|
+
this.safariHistoryStartPoint = this.safariLength.value;
|
364
|
+
}
|
365
|
+
},
|
366
|
+
|
367
|
+
/*Private: Safari method to read the history stack from a hidden form field*/
|
368
|
+
getSafariStack: function() {
|
369
|
+
var r = this.safariStack.value;
|
370
|
+
return historyStorage.fromJSON(r);
|
371
|
+
},
|
372
|
+
|
373
|
+
/*Private: Safari method to read from the history stack*/
|
374
|
+
getSafariState: function() {
|
375
|
+
var stack = this.getSafariStack();
|
376
|
+
var state = stack[history.length - this.safariHistoryStartPoint - 1];
|
377
|
+
return state;
|
378
|
+
},
|
379
|
+
/*Private: Safari method to write the history stack to a hidden form field*/
|
380
|
+
putSafariState: function(newLocation) {
|
381
|
+
var stack = this.getSafariStack();
|
382
|
+
stack[history.length - this.safariHistoryStartPoint] = newLocation;
|
383
|
+
this.safariStack.value = historyStorage.toJSON(stack);
|
384
|
+
},
|
385
|
+
|
386
|
+
/*Private: Notify the listener of new history changes.*/
|
387
|
+
fireHistoryEvent: function(newHash) {
|
388
|
+
/*extract the value from our history storage for this hash*/
|
389
|
+
var historyData = historyStorage.get(newHash);
|
390
|
+
/*call our listener*/
|
391
|
+
this.listener.call(null, newHash, historyData);
|
392
|
+
},
|
393
|
+
|
394
|
+
/*Private: See if the browser has changed location. This is the primary history mechanism for Firefox. For IE, we use this to
|
395
|
+
handle an important edge case: if a user manually types in a new hash value into their IE location bar and press enter, we want to
|
396
|
+
to intercept this and notify any history listener.*/
|
397
|
+
checkLocation: function() {
|
398
|
+
|
399
|
+
/*Ignore any location changes that we made ourselves for browsers other than IE*/
|
400
|
+
if (!this.isIE && this.ignoreLocationChange) {
|
401
|
+
this.ignoreLocationChange = false;
|
402
|
+
return;
|
403
|
+
}
|
404
|
+
|
405
|
+
/*If we are dealing with IE and we are in the middle of making a location change from an iframe, ignore it*/
|
406
|
+
if (!this.isIE && this.ieAtomicLocationChange) {
|
407
|
+
return;
|
408
|
+
}
|
409
|
+
|
410
|
+
/*Get hash location*/
|
411
|
+
var hash = this.getCurrentLocation();
|
412
|
+
|
413
|
+
/*Do nothing if there's been no change*/
|
414
|
+
if (hash == this.currentLocation) {
|
415
|
+
return;
|
416
|
+
}
|
417
|
+
|
418
|
+
/*In IE, users manually entering locations into the browser; we do this by comparing the browser's location against the
|
419
|
+
iframe's location; if they differ, we are dealing with a manual event and need to place it inside our history, otherwise
|
420
|
+
we can return*/
|
421
|
+
this.ieAtomicLocationChange = true;
|
422
|
+
|
423
|
+
if (this.isIE && this.getIframeHash() != hash) {
|
424
|
+
this.iframe.src = "/javascripts/lib/blank.html?" + hash;
|
425
|
+
}
|
426
|
+
else if (this.isIE) {
|
427
|
+
/*the iframe is unchanged*/
|
428
|
+
return;
|
429
|
+
}
|
430
|
+
|
431
|
+
/*Save this new location*/
|
432
|
+
this.currentLocation = hash;
|
433
|
+
|
434
|
+
this.ieAtomicLocationChange = false;
|
435
|
+
|
436
|
+
/*Notify listeners of the change*/
|
437
|
+
this.fireHistoryEvent(hash);
|
438
|
+
},
|
439
|
+
|
440
|
+
/*Private: Get the current location of IE's hidden iframe.*/
|
441
|
+
getIframeHash: function() {
|
442
|
+
var doc = this.iframe.contentWindow.document;
|
443
|
+
var hash = String(doc.location.search);
|
444
|
+
if (hash.length == 1 && hash.charAt(0) == "?") {
|
445
|
+
hash = "";
|
446
|
+
}
|
447
|
+
else if (hash.length >= 2 && hash.charAt(0) == "?") {
|
448
|
+
hash = hash.substring(1);
|
449
|
+
}
|
450
|
+
return hash;
|
451
|
+
},
|
452
|
+
|
453
|
+
/*Private: Remove any leading hash that might be on a location.*/
|
454
|
+
removeHash: function(hashValue) {
|
455
|
+
var r;
|
456
|
+
if (hashValue === null || hashValue === undefined) {
|
457
|
+
r = null;
|
458
|
+
}
|
459
|
+
else if (hashValue === "") {
|
460
|
+
r = "";
|
461
|
+
}
|
462
|
+
else if (hashValue.length == 1 && hashValue.charAt(0) == "#") {
|
463
|
+
r = "";
|
464
|
+
}
|
465
|
+
else if (hashValue.length > 1 && hashValue.charAt(0) == "#") {
|
466
|
+
r = hashValue.substring(1);
|
467
|
+
}
|
468
|
+
else {
|
469
|
+
r = hashValue;
|
470
|
+
}
|
471
|
+
return r;
|
472
|
+
},
|
473
|
+
|
474
|
+
/*Private: For IE, tell when the hidden iframe has finished loading.*/
|
475
|
+
iframeLoaded: function(newLocation) {
|
476
|
+
/*ignore any location changes that we made ourselves*/
|
477
|
+
if (this.ignoreLocationChange) {
|
478
|
+
this.ignoreLocationChange = false;
|
479
|
+
return;
|
480
|
+
}
|
481
|
+
|
482
|
+
/*Get the new location*/
|
483
|
+
var hash = String(newLocation.search);
|
484
|
+
if (hash.length == 1 && hash.charAt(0) == "?") {
|
485
|
+
hash = "";
|
486
|
+
}
|
487
|
+
else if (hash.length >= 2 && hash.charAt(0) == "?") {
|
488
|
+
hash = hash.substring(1);
|
489
|
+
}
|
490
|
+
/*Keep the browser location bar in sync with the iframe hash*/
|
491
|
+
window.location.hash = hash;
|
492
|
+
|
493
|
+
/*Notify listeners of the change*/
|
494
|
+
this.fireHistoryEvent(hash);
|
495
|
+
}
|
496
|
+
|
497
|
+
};
|
498
|
+
|
499
|
+
/*
|
500
|
+
historyStorage: An object that uses a hidden form to store history state across page loads. The mechanism for doing so relies on
|
501
|
+
the fact that browsers save the text in form data for the life of the browser session, which means the text is still there when
|
502
|
+
the user navigates back to the page. This object can be used independently of the dhtmlHistory object for caching of Ajax
|
503
|
+
session information.
|
504
|
+
|
505
|
+
dependencies:
|
506
|
+
* json2007.js (included in a separate file) or alternate JSON methods passed in through an options bundle.
|
507
|
+
*/
|
508
|
+
historyStorage = {
|
509
|
+
|
510
|
+
/*Public: Set up our historyStorage object for use by dhtmlHistory or other objects*/
|
511
|
+
setup: function(options) {
|
512
|
+
|
513
|
+
/*
|
514
|
+
options - object to store initialization parameters - passed in from dhtmlHistory or directly into historyStorage
|
515
|
+
options.debugMode - boolean that causes hidden form fields to be shown for development purposes.
|
516
|
+
options.toJSON - function to override default JSON stringifier
|
517
|
+
options.fromJSON - function to override default JSON parser
|
518
|
+
*/
|
519
|
+
|
520
|
+
/*process init parameters*/
|
521
|
+
if (typeof options !== "undefined") {
|
522
|
+
if (options.debugMode) {
|
523
|
+
this.debugMode = options.debugMode;
|
524
|
+
}
|
525
|
+
if (options.toJSON) {
|
526
|
+
this.toJSON = options.toJSON;
|
527
|
+
}
|
528
|
+
if (options.fromJSON) {
|
529
|
+
this.fromJSON = options.fromJSON;
|
530
|
+
}
|
531
|
+
}
|
532
|
+
|
533
|
+
/*write a hidden form and textarea into the page; we'll stow our history stack here*/
|
534
|
+
var formID = "rshStorageForm";
|
535
|
+
var textareaID = "rshStorageField";
|
536
|
+
var formStyles = this.debugMode ? historyStorage.showStyles : historyStorage.hideStyles;
|
537
|
+
var textareaStyles = (historyStorage.debugMode ? 'width: 800px;height:80px;border:1px solid black;' : historyStorage.hideStyles);
|
538
|
+
var textareaHTML = '<textarea id="' + textareaID + '" style="' + textareaStyles + '"></textarea>';
|
539
|
+
document.write(textareaHTML);
|
540
|
+
|
541
|
+
this.storageField = document.getElementById(textareaID);
|
542
|
+
if (typeof window.opera !== "undefined") {
|
543
|
+
this.storageField.focus();/*Opera needs to focus this element before persisting values in it*/
|
544
|
+
}
|
545
|
+
},
|
546
|
+
|
547
|
+
/*Public*/
|
548
|
+
put: function(key, value) {
|
549
|
+
this.assertValidKey(key);
|
550
|
+
/*if we already have a value for this, remove the value before adding the new one*/
|
551
|
+
if (this.hasKey(key)) {
|
552
|
+
this.remove(key);
|
553
|
+
}
|
554
|
+
/*store this new key*/
|
555
|
+
this.storageHash[key] = value;
|
556
|
+
/*save and serialize the hashtable into the form*/
|
557
|
+
this.saveHashTable();
|
558
|
+
},
|
559
|
+
|
560
|
+
/*Public*/
|
561
|
+
get: function(key) {
|
562
|
+
this.assertValidKey(key);
|
563
|
+
/*make sure the hash table has been loaded from the form*/
|
564
|
+
this.loadHashTable();
|
565
|
+
var value = this.storageHash[key];
|
566
|
+
if (value === undefined) {
|
567
|
+
value = null;
|
568
|
+
}
|
569
|
+
return value;
|
570
|
+
},
|
571
|
+
|
572
|
+
/*Public*/
|
573
|
+
remove: function(key) {
|
574
|
+
this.assertValidKey(key);
|
575
|
+
/*make sure the hash table has been loaded from the form*/
|
576
|
+
this.loadHashTable();
|
577
|
+
/*delete the value*/
|
578
|
+
delete this.storageHash[key];
|
579
|
+
/*serialize and save the hash table into the form*/
|
580
|
+
this.saveHashTable();
|
581
|
+
},
|
582
|
+
|
583
|
+
/*Public: Clears out all saved data.*/
|
584
|
+
reset: function() {
|
585
|
+
this.storageField.value = "";
|
586
|
+
this.storageHash = {};
|
587
|
+
},
|
588
|
+
|
589
|
+
/*Public*/
|
590
|
+
hasKey: function(key) {
|
591
|
+
this.assertValidKey(key);
|
592
|
+
/*make sure the hash table has been loaded from the form*/
|
593
|
+
this.loadHashTable();
|
594
|
+
return (typeof this.storageHash[key] !== "undefined");
|
595
|
+
},
|
596
|
+
|
597
|
+
/*Public*/
|
598
|
+
isValidKey: function(key) {
|
599
|
+
return (typeof key === "string");
|
600
|
+
},
|
601
|
+
|
602
|
+
/*Public - CSS strings utilized by both objects to hide or show behind-the-scenes DOM elements*/
|
603
|
+
showStyles: 'border:0;margin:0;padding:0;',
|
604
|
+
hideStyles: 'left:-1000px;top:-1000px;width:1px;height:1px;border:0;position:absolute;',
|
605
|
+
|
606
|
+
/*Public - debug mode flag*/
|
607
|
+
debugMode: false,
|
608
|
+
|
609
|
+
/*- - - - - - - - - - - -*/
|
610
|
+
|
611
|
+
/*Private: Our hash of key name/values.*/
|
612
|
+
storageHash: {},
|
613
|
+
|
614
|
+
/*Private: If true, we have loaded our hash table out of the storage form.*/
|
615
|
+
hashLoaded: false,
|
616
|
+
|
617
|
+
/*Private: DOM reference to our history field*/
|
618
|
+
storageField: null,
|
619
|
+
|
620
|
+
/*Private: Assert that a key is valid; throw an exception if it not.*/
|
621
|
+
assertValidKey: function(key) {
|
622
|
+
var isValid = this.isValidKey(key);
|
623
|
+
if (!isValid && this.debugMode) {
|
624
|
+
throw new Error("Please provide a valid key for window.historyStorage. Invalid key = " + key + ".");
|
625
|
+
}
|
626
|
+
},
|
627
|
+
|
628
|
+
/*Private: Load the hash table up from the form.*/
|
629
|
+
loadHashTable: function() {
|
630
|
+
if (!this.hashLoaded) {
|
631
|
+
var serializedHashTable = this.storageField.value;
|
632
|
+
if (serializedHashTable !== "" && serializedHashTable !== null) {
|
633
|
+
this.storageHash = this.fromJSON(serializedHashTable);
|
634
|
+
this.hashLoaded = true;
|
635
|
+
}
|
636
|
+
}
|
637
|
+
},
|
638
|
+
/*Private: Save the hash table into the form.*/
|
639
|
+
saveHashTable: function() {
|
640
|
+
this.loadHashTable();
|
641
|
+
var serializedHashTable = this.toJSON(this.storageHash);
|
642
|
+
this.storageField.value = serializedHashTable;
|
643
|
+
},
|
644
|
+
/*Private: Bridges for our JSON implementations - both rely on 2007 JSON.org library - can be overridden by options bundle*/
|
645
|
+
toJSON: function(o) {
|
646
|
+
return o.toJSONString();
|
647
|
+
},
|
648
|
+
fromJSON: function(s) {
|
649
|
+
return s.parseJSON();
|
650
|
+
}
|
651
|
+
};
|