ajax_scaffold_plugin 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +3 -0
- data/MIT-LICENSE +20 -0
- data/README +13 -0
- data/app/views/ajax_scaffold/_column_headings.rhtml +20 -0
- data/app/views/ajax_scaffold/_column_totals.rhtml +10 -0
- data/app/views/ajax_scaffold/_form.rhtml +5 -0
- data/app/views/ajax_scaffold/_form_messages.rhtml +5 -0
- data/app/views/ajax_scaffold/_messages.rhtml +10 -0
- data/app/views/ajax_scaffold/_new_edit.rhtml +40 -0
- data/app/views/ajax_scaffold/_pagination_links.rhtml +26 -0
- data/app/views/ajax_scaffold/_row.rhtml +46 -0
- data/app/views/ajax_scaffold/cancel.rjs +12 -0
- data/app/views/ajax_scaffold/create.rjs +20 -0
- data/app/views/ajax_scaffold/destroy.rjs +11 -0
- data/app/views/ajax_scaffold/edit.rjs +16 -0
- data/app/views/ajax_scaffold/list.rhtml +1 -0
- data/app/views/ajax_scaffold/new.rjs +14 -0
- data/app/views/ajax_scaffold/table.rhtml +63 -0
- data/app/views/ajax_scaffold/update.rjs +19 -0
- data/init.rb +27 -0
- data/install.rb +1 -0
- data/lib/ajax_scaffold_plugin.rb +505 -0
- data/lib/base/ajax_scaffold.rb +180 -0
- data/public/blank.html +33 -0
- data/public/images/add.gif +0 -0
- data/public/images/arrow_down.gif +0 -0
- data/public/images/arrow_up.gif +0 -0
- data/public/images/indicator-small.gif +0 -0
- data/public/images/indicator.gif +0 -0
- data/public/javascripts/ajax_scaffold.js +126 -0
- data/public/javascripts/dhtml_history.js +961 -0
- data/public/javascripts/rico_corner.js +781 -0
- data/public/stylesheets/ajax_scaffold.css +482 -0
- data/tasks/ajax_scaffold_tasks.rake +4 -0
- data/test/ajax_scaffold_test.rb +8 -0
- metadata +90 -0
@@ -0,0 +1,180 @@
|
|
1
|
+
module AjaxScaffold # :nodoc:
|
2
|
+
class ScaffoldColumn
|
3
|
+
attr_reader :name, :eval, :sort_sql, :label, :class_name, :sanitize
|
4
|
+
|
5
|
+
# Only options[:name] is required. It will infer the eval and sort values
|
6
|
+
# based on the given class.
|
7
|
+
def initialize(klass, options)
|
8
|
+
@name = options[:name]
|
9
|
+
@eval = options[:eval].nil? ? "#{Inflector.underscore(klass.to_s)}.#{@name}" : options[:eval]
|
10
|
+
@label = options[:label].nil? ? Inflector.titleize(@name) : options[:label]
|
11
|
+
@sortable = options[:sortable].nil? ? true : options[:sortable]
|
12
|
+
@sort_sql = options[:sort_sql].nil? ? "#{klass.table_name}.#{@name}" : options[:sort_sql] unless !@sortable
|
13
|
+
@class_name = options[:class_name].nil? ? "" : options[:class_name]
|
14
|
+
@sanitize = options[:sanitize].nil? ? true : options[:sanitize]
|
15
|
+
end
|
16
|
+
|
17
|
+
def sanitize?
|
18
|
+
@sanitize
|
19
|
+
end
|
20
|
+
|
21
|
+
def sortable?
|
22
|
+
@sortable
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
module Common
|
28
|
+
def current_sort(params)
|
29
|
+
session[params[:scaffold_id]][:sort]
|
30
|
+
end
|
31
|
+
|
32
|
+
def current_sort_direction(params)
|
33
|
+
session[params[:scaffold_id]][:sort_direction]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module Controller
|
38
|
+
|
39
|
+
def clear_flashes
|
40
|
+
if request.xhr?
|
41
|
+
flash.keys.each do |flash_key|
|
42
|
+
flash[flash_key] = nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def default_per_page
|
48
|
+
25
|
49
|
+
end
|
50
|
+
|
51
|
+
def store_or_get_from_session(id_key, value_key)
|
52
|
+
session[id_key][value_key] = params[value_key] if !params[value_key].nil?
|
53
|
+
params[value_key] ||= session[id_key][value_key]
|
54
|
+
end
|
55
|
+
|
56
|
+
def update_params(options)
|
57
|
+
@scaffold_id = params[:scaffold_id] ||= options[:default_scaffold_id]
|
58
|
+
session[@scaffold_id] ||= {:sort => options[:default_sort], :sort_direction => options[:default_sort_direction], :page => 1}
|
59
|
+
|
60
|
+
store_or_get_from_session(@scaffold_id, :sort)
|
61
|
+
store_or_get_from_session(@scaffold_id, :sort_direction)
|
62
|
+
store_or_get_from_session(@scaffold_id, :page)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
module Helper
|
68
|
+
include AjaxScaffold::Common
|
69
|
+
|
70
|
+
def format_column(column_value, sanitize = true)
|
71
|
+
if column_empty?(column_value)
|
72
|
+
empty_column_text
|
73
|
+
elsif column_value.instance_of? Time
|
74
|
+
format_time(column_value)
|
75
|
+
elsif column_value.instance_of? Date
|
76
|
+
format_date(column_value)
|
77
|
+
else
|
78
|
+
sanitize ? h(column_value.to_s) : column_value.to_s
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def format_time(time)
|
83
|
+
time.strftime("%m/%d/%Y %I:%M %p")
|
84
|
+
end
|
85
|
+
|
86
|
+
def format_date(date)
|
87
|
+
date.strftime("%m/%d/%Y")
|
88
|
+
end
|
89
|
+
|
90
|
+
def column_empty?(column_value)
|
91
|
+
column_value.nil? || (column_value.empty? rescue false)
|
92
|
+
end
|
93
|
+
|
94
|
+
def empty_column_text
|
95
|
+
"-"
|
96
|
+
end
|
97
|
+
|
98
|
+
# Generates a temporary id for creating a new element
|
99
|
+
def generate_temporary_id
|
100
|
+
(Time.now.to_f*1000).to_i.to_s
|
101
|
+
end
|
102
|
+
|
103
|
+
def pagination_ajax_links(paginator, params)
|
104
|
+
pagination_links_each(paginator, {}) do |n|
|
105
|
+
link_to_remote n,
|
106
|
+
{ :url => params.merge(:page => n ),
|
107
|
+
:loading => "Element.show('#{loading_indicator_id(params.merge(:action => 'pagination'))}');",
|
108
|
+
:update => scaffold_content_id(params) },
|
109
|
+
{ :href => url_for(params.merge(:page => n )) }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def column_sort_direction(column_name, params)
|
114
|
+
if column_name && column_name == current_sort(params)
|
115
|
+
current_sort_direction(params) == "asc" ? "desc" : "asc"
|
116
|
+
else
|
117
|
+
"asc"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def column_class(column_name, column_value, sort_column, class_name = nil)
|
122
|
+
class_name = String.new
|
123
|
+
class_name += "empty " if column_empty?(column_value)
|
124
|
+
class_name += "sorted " if (!sort_column.nil? && column_name == sort_column)
|
125
|
+
class_name += "#{class_name} " unless class_name.nil?
|
126
|
+
class_name
|
127
|
+
end
|
128
|
+
|
129
|
+
def loading_indicator_tag(options)
|
130
|
+
image_tag "indicator.gif", :style => "display:none;", :id => loading_indicator_id(options), :alt => "loading indicator", :class => "loading-indicator"
|
131
|
+
end
|
132
|
+
|
133
|
+
# The following are a bunch of helper methods to produce the common scaffold view id's
|
134
|
+
|
135
|
+
def scaffold_content_id(options)
|
136
|
+
"#{options[:scaffold_id]}-content"
|
137
|
+
end
|
138
|
+
|
139
|
+
def scaffold_column_header_id(options)
|
140
|
+
"#{options[:scaffold_id]}-#{options[:column_name]}-column"
|
141
|
+
end
|
142
|
+
|
143
|
+
def scaffold_tbody_id(options)
|
144
|
+
"#{options[:scaffold_id]}-tbody"
|
145
|
+
end
|
146
|
+
|
147
|
+
def scaffold_messages_id(options)
|
148
|
+
"#{options[:scaffold_id]}-messages"
|
149
|
+
end
|
150
|
+
|
151
|
+
def empty_message_id(options)
|
152
|
+
"#{options[:scaffold_id]}-empty-message"
|
153
|
+
end
|
154
|
+
|
155
|
+
def element_row_id(options)
|
156
|
+
"#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-row"
|
157
|
+
end
|
158
|
+
|
159
|
+
def element_cell_id(options)
|
160
|
+
"#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-cell"
|
161
|
+
end
|
162
|
+
|
163
|
+
def element_form_id(options)
|
164
|
+
"#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-form"
|
165
|
+
end
|
166
|
+
|
167
|
+
def loading_indicator_id(options)
|
168
|
+
if options[:id].nil?
|
169
|
+
"#{options[:scaffold_id]}-#{options[:action]}-loading-indicator"
|
170
|
+
else
|
171
|
+
"#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-loading-indicator"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def element_messages_id(options)
|
176
|
+
"#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-messages"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
data/public/blank.html
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
<!--
|
2
|
+
Copyright (c) 2005, Brad Neuberg, bkn3@columbia.edu
|
3
|
+
http://codinginparadise.org
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the "Software"),
|
7
|
+
to deal in the Software without restriction, including without limitation
|
8
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
9
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
10
|
+
Software is furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
|
20
|
+
OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
21
|
+
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
-->
|
23
|
+
|
24
|
+
<html>
|
25
|
+
<script language="JavaScript">
|
26
|
+
function pageLoaded() {
|
27
|
+
window.parent.dhtmlHistory.iframeLoaded(window.location);
|
28
|
+
}
|
29
|
+
</script>
|
30
|
+
<body onload="pageLoaded()">
|
31
|
+
<h1>blank.html - Needed for Internet Explorer's hidden IFrame</h1>
|
32
|
+
</body>
|
33
|
+
</html>
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,126 @@
|
|
1
|
+
/*
|
2
|
+
AjaxScaffoldGenerator version 3.1.0
|
3
|
+
(c) 2006 Richard White <rrwhite@gmail.com>
|
4
|
+
|
5
|
+
AjaxScaffoldGenerator is freely distributable under the terms of an MIT-style license.
|
6
|
+
|
7
|
+
For details, see the AjaxScaffoldGenerator web site: http://www.ajaxscaffold.com/
|
8
|
+
*/
|
9
|
+
|
10
|
+
/*
|
11
|
+
* The following is a cross browser way to move around <tr> elements in a <table> or <tbody>
|
12
|
+
*/
|
13
|
+
|
14
|
+
var Abstract = new Object();
|
15
|
+
Abstract.Table = function() {};
|
16
|
+
Abstract.Table.prototype = {
|
17
|
+
tagTest: function(element, tagName) {
|
18
|
+
return $(element).tagName.toLowerCase() == tagName.toLowerCase();
|
19
|
+
}
|
20
|
+
};
|
21
|
+
|
22
|
+
Abstract.TableRow = function() {};
|
23
|
+
Abstract.TableRow.prototype = Object.extend(new Abstract.Table(), {
|
24
|
+
initialize: function(targetTableRow, sourceTableRow) {
|
25
|
+
try {
|
26
|
+
var sourceTableRow = $(sourceTableRow);
|
27
|
+
var targetTableRow = $(targetTableRow);
|
28
|
+
|
29
|
+
if (targetTableRow == null || !this.tagTest(targetTableRow,'tr')
|
30
|
+
|| sourceTableRow == null || !this.tagTest(sourceTableRow,'tr')) {
|
31
|
+
throw("TableRow: both parameters must be a <tr> tag.");
|
32
|
+
}
|
33
|
+
|
34
|
+
var tableOrTbody = this.findParentTableOrTbody(targetTableRow);
|
35
|
+
|
36
|
+
var newRow = tableOrTbody.insertRow(this.getNewRowIndex(targetTableRow) - this.getRowOffset(tableOrTbody));
|
37
|
+
newRow.parentNode.replaceChild(sourceTableRow, newRow);
|
38
|
+
|
39
|
+
} catch (e) {
|
40
|
+
alert(e);
|
41
|
+
}
|
42
|
+
},
|
43
|
+
getRowOffset: function(tableOrTbody) {
|
44
|
+
//If we are inserting into a tablebody we would need figure out the rowIndex of the first
|
45
|
+
// row in that tbody and subtract that offset from the new row index
|
46
|
+
var rowOffset = 0;
|
47
|
+
if (this.tagTest(tableOrTbody,'tbody')) {
|
48
|
+
rowOffset = tableOrTbody.rows[0].rowIndex;
|
49
|
+
}
|
50
|
+
return rowOffset;
|
51
|
+
},
|
52
|
+
findParentTableOrTbody: function(element) {
|
53
|
+
var element = $(element);
|
54
|
+
// Completely arbitrary value
|
55
|
+
var maxSearchDepth = 3;
|
56
|
+
var currentSearchDepth = 1;
|
57
|
+
var current = element;
|
58
|
+
while (currentSearchDepth <= maxSearchDepth) {
|
59
|
+
current = current.parentNode;
|
60
|
+
if (this.tagTest(current, 'tbody') || this.tagTest(current, 'table')) {
|
61
|
+
return current;
|
62
|
+
}
|
63
|
+
currentSearchDepth++;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
});
|
67
|
+
|
68
|
+
var TableRow = new Object();
|
69
|
+
|
70
|
+
TableRow.MoveBefore = Class.create();
|
71
|
+
TableRow.MoveBefore.prototype = Object.extend(new Abstract.TableRow(), {
|
72
|
+
getNewRowIndex: function(target) {
|
73
|
+
return target.rowIndex;
|
74
|
+
}
|
75
|
+
});
|
76
|
+
|
77
|
+
TableRow.MoveAfter = Class.create();
|
78
|
+
TableRow.MoveAfter.prototype = Object.extend(new Abstract.TableRow(), {
|
79
|
+
getNewRowIndex: function(target) {
|
80
|
+
return target.rowIndex+1;
|
81
|
+
}
|
82
|
+
});
|
83
|
+
|
84
|
+
/*
|
85
|
+
* The following are simple utility methods
|
86
|
+
*/
|
87
|
+
|
88
|
+
var AjaxScaffold = {
|
89
|
+
stripe: function(tableBody) {
|
90
|
+
var even = false;
|
91
|
+
var tableBody = $(tableBody);
|
92
|
+
var tableRows = tableBody.getElementsByTagName("tr");
|
93
|
+
var length = tableBody.rows.length;
|
94
|
+
|
95
|
+
for (var i = 0; i < length; i++) {
|
96
|
+
var tableRow = tableBody.rows[i];
|
97
|
+
//Make sure to skip rows that are create or edit rows or messages
|
98
|
+
if (!Element.hasClassName(tableRow, "create")
|
99
|
+
&& !Element.hasClassName(tableRow, "update")) {
|
100
|
+
|
101
|
+
if (even) {
|
102
|
+
Element.addClassName(tableRow, "even");
|
103
|
+
} else {
|
104
|
+
Element.removeClassName(tableRow, "even");
|
105
|
+
}
|
106
|
+
even = !even;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
},
|
110
|
+
displayMessageIfEmpty: function(tableBody, emptyMessageElement) {
|
111
|
+
// Check to see if this was the last element in the list
|
112
|
+
if ($(tableBody).rows.length == 0) {
|
113
|
+
Element.show($(emptyMessageElement));
|
114
|
+
}
|
115
|
+
},
|
116
|
+
removeSortClasses: function(scaffoldId) {
|
117
|
+
$$('#' + scaffoldId + ' td.sorted').each(function(element) {
|
118
|
+
Element.removeClassName(element, "sorted");
|
119
|
+
});
|
120
|
+
$$('#' + scaffoldId + ' th.sorted').each(function(element) {
|
121
|
+
Element.removeClassName(element, "sorted");
|
122
|
+
Element.removeClassName(element, "asc");
|
123
|
+
Element.removeClassName(element, "desc");
|
124
|
+
});
|
125
|
+
}
|
126
|
+
}
|
@@ -0,0 +1,961 @@
|
|
1
|
+
/**
|
2
|
+
Copyright (c) 2005, Brad Neuberg, bkn3@columbia.edu
|
3
|
+
http://codinginparadise.org
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the "Software"),
|
7
|
+
to deal in the Software without restriction, including without limitation
|
8
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
9
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
10
|
+
Software is furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
|
20
|
+
OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
21
|
+
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
The JSON class near the end of this file is
|
24
|
+
Copyright 2005, JSON.org
|
25
|
+
*/
|
26
|
+
|
27
|
+
/** An object that provides DHTML history, history data, and bookmarking
|
28
|
+
for AJAX applications. */
|
29
|
+
window.dhtmlHistory = {
|
30
|
+
/** Initializes our DHTML history. You should
|
31
|
+
call this after the page is finished loading. */
|
32
|
+
/** public */ initialize: function() {
|
33
|
+
// only Internet Explorer needs to be explicitly initialized;
|
34
|
+
// other browsers don't have its particular behaviors.
|
35
|
+
// Basicly, IE doesn't autofill form data until the page
|
36
|
+
// is finished loading, which means historyStorage won't
|
37
|
+
// work until onload has been fired.
|
38
|
+
if (this.isInternetExplorer() == false) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
|
42
|
+
// if this is the first time this page has loaded...
|
43
|
+
if (historyStorage.hasKey("DhtmlHistory_pageLoaded") == false) {
|
44
|
+
this.fireOnNewListener = false;
|
45
|
+
this.firstLoad = true;
|
46
|
+
historyStorage.put("DhtmlHistory_pageLoaded", true);
|
47
|
+
}
|
48
|
+
// else if this is a fake onload event
|
49
|
+
else {
|
50
|
+
this.fireOnNewListener = true;
|
51
|
+
this.firstLoad = false;
|
52
|
+
}
|
53
|
+
},
|
54
|
+
|
55
|
+
/** Adds a history change listener. Note that
|
56
|
+
only one listener is supported at this
|
57
|
+
time. */
|
58
|
+
/** public */ addListener: function(callback) {
|
59
|
+
this.listener = callback;
|
60
|
+
|
61
|
+
// if the page was just loaded and we
|
62
|
+
// should not ignore it, fire an event
|
63
|
+
// to our new listener now
|
64
|
+
if (this.fireOnNewListener == true) {
|
65
|
+
this.fireHistoryEvent(this.currentLocation);
|
66
|
+
this.fireOnNewListener = false;
|
67
|
+
}
|
68
|
+
},
|
69
|
+
|
70
|
+
/** public */ add: function(newLocation, historyData) {
|
71
|
+
// most browsers require that we wait a certain amount of time before changing the
|
72
|
+
// location, such as 200 milliseconds; rather than forcing external callers to use
|
73
|
+
// window.setTimeout to account for this to prevent bugs, we internally handle this
|
74
|
+
// detail by using a 'currentWaitTime' variable and have requests wait in line
|
75
|
+
var self = this;
|
76
|
+
var addImpl = function() {
|
77
|
+
// indicate that the current wait time is now less
|
78
|
+
if (self.currentWaitTime > 0)
|
79
|
+
self.currentWaitTime = self.currentWaitTime - self.WAIT_TIME;
|
80
|
+
|
81
|
+
// remove any leading hash symbols on newLocation
|
82
|
+
newLocation = self.removeHash(newLocation);
|
83
|
+
|
84
|
+
// IE has a strange bug; if the newLocation
|
85
|
+
// is the same as _any_ preexisting id in the
|
86
|
+
// document, then the history action gets recorded
|
87
|
+
// twice; throw a programmer exception if there is
|
88
|
+
// an element with this ID
|
89
|
+
var idCheck = $(newLocation);
|
90
|
+
if (idCheck != undefined || idCheck != null) {
|
91
|
+
var message =
|
92
|
+
"Exception: History locations can not have "
|
93
|
+
+ "the same value as _any_ id's "
|
94
|
+
+ "that might be in the document, "
|
95
|
+
+ "due to a bug in Internet "
|
96
|
+
+ "Explorer; please ask the "
|
97
|
+
+ "developer to choose a history "
|
98
|
+
+ "location that does not match "
|
99
|
+
+ "any HTML id's in this "
|
100
|
+
+ "document. The following ID "
|
101
|
+
+ "is already taken and can not "
|
102
|
+
+ "be a location: "
|
103
|
+
+ newLocation;
|
104
|
+
|
105
|
+
throw message;
|
106
|
+
}
|
107
|
+
|
108
|
+
// store the history data into history storage
|
109
|
+
historyStorage.put(newLocation, historyData);
|
110
|
+
|
111
|
+
// indicate to the browser to ignore this upcomming
|
112
|
+
// location change
|
113
|
+
self.ignoreLocationChange = true;
|
114
|
+
|
115
|
+
// indicate to IE that this is an atomic location change
|
116
|
+
// block
|
117
|
+
this.ieAtomicLocationChange = true;
|
118
|
+
|
119
|
+
// save this as our current location
|
120
|
+
self.currentLocation = newLocation;
|
121
|
+
|
122
|
+
// change the browser location
|
123
|
+
window.location.hash = newLocation;
|
124
|
+
|
125
|
+
// change the hidden iframe's location if on IE
|
126
|
+
if (self.isInternetExplorer())
|
127
|
+
self.iframe.src = "/blank.html?" + newLocation;
|
128
|
+
|
129
|
+
// end of atomic location change block
|
130
|
+
// for IE
|
131
|
+
this.ieAtomicLocationChange = false;
|
132
|
+
};
|
133
|
+
|
134
|
+
// now execute this add request after waiting a certain amount of time, so as to
|
135
|
+
// queue up requests
|
136
|
+
window.setTimeout(addImpl, this.currentWaitTime);
|
137
|
+
|
138
|
+
// indicate that the next request will have to wait for awhile
|
139
|
+
this.currentWaitTime = this.currentWaitTime + this.WAIT_TIME;
|
140
|
+
},
|
141
|
+
|
142
|
+
/** public */ isFirstLoad: function() {
|
143
|
+
if (this.firstLoad == true) {
|
144
|
+
return true;
|
145
|
+
}
|
146
|
+
else {
|
147
|
+
return false;
|
148
|
+
}
|
149
|
+
},
|
150
|
+
|
151
|
+
/** public */ isInternational: function() {
|
152
|
+
return false;
|
153
|
+
},
|
154
|
+
|
155
|
+
/** public */ getVersion: function() {
|
156
|
+
return "0.05";
|
157
|
+
},
|
158
|
+
|
159
|
+
/** Gets the current hash value that is in the browser's
|
160
|
+
location bar, removing leading # symbols if they are present. */
|
161
|
+
/** public */ getCurrentLocation: function() {
|
162
|
+
var currentLocation = this.removeHash(window.location.hash);
|
163
|
+
|
164
|
+
return currentLocation;
|
165
|
+
},
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
/** Our current hash location, without the "#" symbol. */
|
172
|
+
/** private */ currentLocation: null,
|
173
|
+
|
174
|
+
/** Our history change listener. */
|
175
|
+
/** private */ listener: null,
|
176
|
+
|
177
|
+
/** A hidden IFrame we use in Internet Explorer to detect history
|
178
|
+
changes. */
|
179
|
+
/** private */ iframe: null,
|
180
|
+
|
181
|
+
/** Indicates to the browser whether to ignore location changes. */
|
182
|
+
/** private */ ignoreLocationChange: null,
|
183
|
+
|
184
|
+
/** The amount of time in milliseconds that we should wait between add requests.
|
185
|
+
Firefox is okay with 200 ms, but Internet Explorer needs 400. */
|
186
|
+
/** private */ WAIT_TIME: 200,
|
187
|
+
|
188
|
+
/** The amount of time in milliseconds an add request has to wait in line before being
|
189
|
+
run on a window.setTimeout. */
|
190
|
+
/** private */ currentWaitTime: 0,
|
191
|
+
|
192
|
+
/** A flag that indicates that we should fire a history change event
|
193
|
+
when we are ready, i.e. after we are initialized and
|
194
|
+
we have a history change listener. This is needed due to
|
195
|
+
an edge case in browsers other than Internet Explorer; if
|
196
|
+
you leave a page entirely then return, we must fire this
|
197
|
+
as a history change event. Unfortunately, we have lost
|
198
|
+
all references to listeners from earlier, because JavaScript
|
199
|
+
clears out. */
|
200
|
+
/** private */ fireOnNewListener: null,
|
201
|
+
|
202
|
+
/** A variable that indicates whether this is the first time
|
203
|
+
this page has been loaded. If you go to a web page, leave
|
204
|
+
it for another one, and then return, the page's onload
|
205
|
+
listener fires again. We need a way to differentiate
|
206
|
+
between the first page load and subsequent ones.
|
207
|
+
This variable works hand in hand with the pageLoaded
|
208
|
+
variable we store into historyStorage.*/
|
209
|
+
/** private */ firstLoad: null,
|
210
|
+
|
211
|
+
/** A variable to handle an important edge case in Internet
|
212
|
+
Explorer. In IE, if a user manually types an address into
|
213
|
+
their browser's location bar, we must intercept this by
|
214
|
+
continiously checking the location bar with an timer
|
215
|
+
interval. However, if we manually change the location
|
216
|
+
bar ourselves programmatically, when using our hidden
|
217
|
+
iframe, we need to ignore these changes. Unfortunately,
|
218
|
+
these changes are not atomic, so we surround them with
|
219
|
+
the variable 'ieAtomicLocationChange', that if true,
|
220
|
+
means we are programmatically setting the location and
|
221
|
+
should ignore this atomic chunked change. */
|
222
|
+
/** private */ ieAtomicLocationChange: null,
|
223
|
+
|
224
|
+
/** Creates the DHTML history infrastructure. */
|
225
|
+
/** private */ create: function() {
|
226
|
+
// get our initial location
|
227
|
+
var initialHash = this.getCurrentLocation();
|
228
|
+
|
229
|
+
// save this as our current location
|
230
|
+
this.currentLocation = initialHash;
|
231
|
+
|
232
|
+
// write out a hidden iframe for IE and
|
233
|
+
// set the amount of time to wait between add() requests
|
234
|
+
if (this.isInternetExplorer()) {
|
235
|
+
document.write("<iframe style='border: 0px; width: 1px; "
|
236
|
+
+ "height: 1px; position: absolute; bottom: 0px; "
|
237
|
+
+ "right: 0px; visibility: visible;' "
|
238
|
+
+ "name='DhtmlHistoryFrame' id='DhtmlHistoryFrame' "
|
239
|
+
+ "src='/blank.html?" + initialHash + "'>"
|
240
|
+
+ "</iframe>");
|
241
|
+
// wait 400 milliseconds between history
|
242
|
+
// updates on IE, versus 200 on Firefox
|
243
|
+
this.WAIT_TIME = 400;
|
244
|
+
}
|
245
|
+
|
246
|
+
// add an unload listener for the page; this is
|
247
|
+
// needed for Firefox 1.5+ because this browser caches all
|
248
|
+
// dynamic updates to the page, which can break some of our
|
249
|
+
// logic related to testing whether this is the first instance
|
250
|
+
// a page has loaded or whether it is being pulled from the cache
|
251
|
+
var self = this;
|
252
|
+
window.onunload = function() {
|
253
|
+
self.firstLoad = null;
|
254
|
+
};
|
255
|
+
|
256
|
+
// determine if this is our first page load;
|
257
|
+
// for Internet Explorer, we do this in
|
258
|
+
// this.iframeLoaded(), which is fired on
|
259
|
+
// page load. We do it there because
|
260
|
+
// we have no historyStorage at this point
|
261
|
+
// in IE, which only exists after the page
|
262
|
+
// is finished loading for that browser
|
263
|
+
if (this.isInternetExplorer() == false) {
|
264
|
+
if (historyStorage.hasKey("DhtmlHistory_pageLoaded") == false) {
|
265
|
+
this.ignoreLocationChange = true;
|
266
|
+
this.firstLoad = true;
|
267
|
+
historyStorage.put("DhtmlHistory_pageLoaded", true);
|
268
|
+
}
|
269
|
+
else {
|
270
|
+
// indicate that we want to pay attention
|
271
|
+
// to this location change
|
272
|
+
this.ignoreLocationChange = false;
|
273
|
+
// For browser's other than IE, fire
|
274
|
+
// a history change event; on IE,
|
275
|
+
// the event will be thrown automatically
|
276
|
+
// when it's hidden iframe reloads
|
277
|
+
// on page load.
|
278
|
+
// Unfortunately, we don't have any
|
279
|
+
// listeners yet; indicate that we want
|
280
|
+
// to fire an event when a listener
|
281
|
+
// is added.
|
282
|
+
this.fireOnNewListener = true;
|
283
|
+
}
|
284
|
+
}
|
285
|
+
else { // Internet Explorer
|
286
|
+
// the iframe will get loaded on page
|
287
|
+
// load, and we want to ignore this fact
|
288
|
+
this.ignoreLocationChange = true;
|
289
|
+
}
|
290
|
+
|
291
|
+
if (this.isInternetExplorer()) {
|
292
|
+
this.iframe = $("DhtmlHistoryFrame");
|
293
|
+
}
|
294
|
+
|
295
|
+
// other browsers can use a location handler that checks
|
296
|
+
// at regular intervals as their primary mechanism;
|
297
|
+
// we use it for Internet Explorer as well to handle
|
298
|
+
// an important edge case; see checkLocation() for
|
299
|
+
// details
|
300
|
+
var self = this;
|
301
|
+
var locationHandler = function() {
|
302
|
+
self.checkLocation();
|
303
|
+
};
|
304
|
+
setInterval(locationHandler, 100);
|
305
|
+
},
|
306
|
+
|
307
|
+
/** Notify the listener of new history changes. */
|
308
|
+
/** private */ fireHistoryEvent: function(newHash) {
|
309
|
+
// extract the value from our history storage for
|
310
|
+
// this hash
|
311
|
+
var historyData = historyStorage.get(newHash);
|
312
|
+
|
313
|
+
// call our listener
|
314
|
+
this.listener.call(null, newHash, historyData);
|
315
|
+
},
|
316
|
+
|
317
|
+
/** Sees if the browsers has changed location. This is the primary history mechanism
|
318
|
+
for Firefox. For Internet Explorer, we use this to handle an important edge case:
|
319
|
+
if a user manually types in a new hash value into their Internet Explorer location
|
320
|
+
bar and press enter, we want to intercept this and notify any history listener. */
|
321
|
+
/** private */ checkLocation: function() {
|
322
|
+
// ignore any location changes that we made ourselves
|
323
|
+
// for browsers other than Internet Explorer
|
324
|
+
if (this.isInternetExplorer() == false
|
325
|
+
&& this.ignoreLocationChange == true) {
|
326
|
+
this.ignoreLocationChange = false;
|
327
|
+
return;
|
328
|
+
}
|
329
|
+
|
330
|
+
// if we are dealing with Internet Explorer
|
331
|
+
// and we are in the middle of making a location
|
332
|
+
// change from an iframe, ignore it
|
333
|
+
if (this.isInternetExplorer() == false
|
334
|
+
&& this.ieAtomicLocationChange == true) {
|
335
|
+
return;
|
336
|
+
}
|
337
|
+
|
338
|
+
// get hash location
|
339
|
+
var hash = this.getCurrentLocation();
|
340
|
+
|
341
|
+
// see if there has been a change
|
342
|
+
if (hash == this.currentLocation)
|
343
|
+
return;
|
344
|
+
|
345
|
+
// on Internet Explorer, we need to intercept users manually
|
346
|
+
// entering locations into the browser; we do this by comparing
|
347
|
+
// the browsers location against the iframes location; if they
|
348
|
+
// differ, we are dealing with a manual event and need to
|
349
|
+
// place it inside our history, otherwise we can return
|
350
|
+
this.ieAtomicLocationChange = true;
|
351
|
+
|
352
|
+
if (this.isInternetExplorer()
|
353
|
+
&& this.getIFrameHash() != hash) {
|
354
|
+
this.iframe.src = "/blank.html?" + hash;
|
355
|
+
}
|
356
|
+
else if (this.isInternetExplorer()) {
|
357
|
+
// the iframe is unchanged
|
358
|
+
return;
|
359
|
+
}
|
360
|
+
|
361
|
+
// save this new location
|
362
|
+
this.currentLocation = hash;
|
363
|
+
|
364
|
+
this.ieAtomicLocationChange = false;
|
365
|
+
|
366
|
+
// notify listeners of the change
|
367
|
+
this.fireHistoryEvent(hash);
|
368
|
+
},
|
369
|
+
|
370
|
+
/** Gets the current location of the hidden IFrames
|
371
|
+
that is stored as history. For Internet Explorer. */
|
372
|
+
/** private */ getIFrameHash: function() {
|
373
|
+
// get the new location
|
374
|
+
var historyFrame = $("DhtmlHistoryFrame");
|
375
|
+
var doc = historyFrame.contentWindow.document;
|
376
|
+
var hash = new String(doc.location.search);
|
377
|
+
|
378
|
+
if (hash.length == 1 && hash.charAt(0) == "?")
|
379
|
+
hash = "";
|
380
|
+
else if (hash.length >= 2 && hash.charAt(0) == "?")
|
381
|
+
hash = hash.substring(1);
|
382
|
+
|
383
|
+
|
384
|
+
return hash;
|
385
|
+
},
|
386
|
+
|
387
|
+
/** Removes any leading hash that might be on a location. */
|
388
|
+
/** private */ removeHash: function(hashValue) {
|
389
|
+
if (hashValue == null || hashValue == undefined)
|
390
|
+
return null;
|
391
|
+
else if (hashValue == "")
|
392
|
+
return "";
|
393
|
+
else if (hashValue.length == 1 && hashValue.charAt(0) == "#")
|
394
|
+
return "";
|
395
|
+
else if (hashValue.length > 1 && hashValue.charAt(0) == "#")
|
396
|
+
return hashValue.substring(1);
|
397
|
+
else
|
398
|
+
return hashValue;
|
399
|
+
},
|
400
|
+
|
401
|
+
/** For IE, says when the hidden iframe has finished loading. */
|
402
|
+
/** private */ iframeLoaded: function(newLocation) {
|
403
|
+
// ignore any location changes that we made ourselves
|
404
|
+
if (this.ignoreLocationChange == true) {
|
405
|
+
this.ignoreLocationChange = false;
|
406
|
+
return;
|
407
|
+
}
|
408
|
+
|
409
|
+
// get the new location
|
410
|
+
var hash = new String(newLocation.search);
|
411
|
+
if (hash.length == 1 && hash.charAt(0) == "?")
|
412
|
+
hash = "";
|
413
|
+
else if (hash.length >= 2 && hash.charAt(0) == "?")
|
414
|
+
hash = hash.substring(1);
|
415
|
+
|
416
|
+
// move to this location in the browser location bar
|
417
|
+
// if we are not dealing with a page load event
|
418
|
+
if (this.pageLoadEvent != true) {
|
419
|
+
window.location.hash = hash;
|
420
|
+
}
|
421
|
+
|
422
|
+
// notify listeners of the change
|
423
|
+
this.fireHistoryEvent(hash);
|
424
|
+
},
|
425
|
+
|
426
|
+
/** Determines if this is Internet Explorer. */
|
427
|
+
/** private */ isInternetExplorer: function() {
|
428
|
+
var userAgent = navigator.userAgent.toLowerCase();
|
429
|
+
if (document.all && userAgent.indexOf('msie')!=-1) {
|
430
|
+
return true;
|
431
|
+
}
|
432
|
+
else {
|
433
|
+
return false;
|
434
|
+
}
|
435
|
+
}
|
436
|
+
};
|
437
|
+
|
438
|
+
/** An object that uses a hidden form to store history state
|
439
|
+
across page loads. The chief mechanism for doing so is using
|
440
|
+
the fact that browser's save the text in form data for the
|
441
|
+
life of the browser and cache, which means the text is still
|
442
|
+
there when the user navigates back to the page. See
|
443
|
+
http://codinginparadise.org/weblog/2005/08/ajax-tutorial-saving-session-across.html
|
444
|
+
for full details. */
|
445
|
+
window.historyStorage = {
|
446
|
+
/** If true, we are debugging and show the storage textfield. */
|
447
|
+
/** public */ debugging: false,
|
448
|
+
|
449
|
+
/** Our hash of key name/values. */
|
450
|
+
/** private */ storageHash: new Object(),
|
451
|
+
|
452
|
+
/** If true, we have loaded our hash table out of the storage form. */
|
453
|
+
/** private */ hashLoaded: false,
|
454
|
+
|
455
|
+
/** public */ put: function(key, value) {
|
456
|
+
this.assertValidKey(key);
|
457
|
+
|
458
|
+
// if we already have a value for this,
|
459
|
+
// remove the value before adding the
|
460
|
+
// new one
|
461
|
+
if (this.hasKey(key)) {
|
462
|
+
this.remove(key);
|
463
|
+
}
|
464
|
+
|
465
|
+
// store this new key
|
466
|
+
this.storageHash[key] = value;
|
467
|
+
|
468
|
+
// save and serialize the hashtable into the form
|
469
|
+
this.saveHashTable();
|
470
|
+
},
|
471
|
+
|
472
|
+
/** public */ get: function(key) {
|
473
|
+
this.assertValidKey(key);
|
474
|
+
|
475
|
+
// make sure the hash table has been loaded
|
476
|
+
// from the form
|
477
|
+
this.loadHashTable();
|
478
|
+
|
479
|
+
var value = this.storageHash[key];
|
480
|
+
|
481
|
+
if (value == undefined)
|
482
|
+
return null;
|
483
|
+
else
|
484
|
+
return value;
|
485
|
+
},
|
486
|
+
|
487
|
+
/** public */ remove: function(key) {
|
488
|
+
this.assertValidKey(key);
|
489
|
+
|
490
|
+
// make sure the hash table has been loaded
|
491
|
+
// from the form
|
492
|
+
this.loadHashTable();
|
493
|
+
|
494
|
+
// delete the value
|
495
|
+
delete this.storageHash[key];
|
496
|
+
|
497
|
+
// serialize and save the hash table into the
|
498
|
+
// form
|
499
|
+
this.saveHashTable();
|
500
|
+
},
|
501
|
+
|
502
|
+
/** Clears out all saved data. */
|
503
|
+
/** public */ reset: function() {
|
504
|
+
this.storageField.value = "";
|
505
|
+
this.storageHash = new Object();
|
506
|
+
},
|
507
|
+
|
508
|
+
/** public */ hasKey: function(key) {
|
509
|
+
this.assertValidKey(key);
|
510
|
+
|
511
|
+
// make sure the hash table has been loaded
|
512
|
+
// from the form
|
513
|
+
this.loadHashTable();
|
514
|
+
|
515
|
+
if (typeof this.storageHash[key] == "undefined")
|
516
|
+
return false;
|
517
|
+
else
|
518
|
+
return true;
|
519
|
+
},
|
520
|
+
|
521
|
+
/** public */ isValidKey: function(key) {
|
522
|
+
// allow all strings, since we don't use XML serialization
|
523
|
+
// format anymore
|
524
|
+
return (typeof key == "string");
|
525
|
+
},
|
526
|
+
|
527
|
+
/** A reference to our textarea field. */
|
528
|
+
/** private */ storageField: null,
|
529
|
+
|
530
|
+
/** private */ init: function() {
|
531
|
+
// write a hidden form into the page
|
532
|
+
var newContent = "<div id='historyStorageFieldFormDiv' style='display:none;'><form id='historyStorageFieldForm'>"+
|
533
|
+
"<input type='textarea' id='historyStorageField' name='historyStorageField'/></form></div>";
|
534
|
+
document.write(newContent);
|
535
|
+
|
536
|
+
this.storageField = $("historyStorageField");
|
537
|
+
},
|
538
|
+
|
539
|
+
/** Asserts that a key is valid, throwing
|
540
|
+
an exception if it is not. */
|
541
|
+
/** private */ assertValidKey: function(key) {
|
542
|
+
if (this.isValidKey(key) == false) {
|
543
|
+
throw "Please provide a valid key for "
|
544
|
+
+ "window.historyStorage, key= "
|
545
|
+
+ key;
|
546
|
+
}
|
547
|
+
},
|
548
|
+
|
549
|
+
/** Loads the hash table up from the form. */
|
550
|
+
/** private */ loadHashTable: function() {
|
551
|
+
if (this.hashLoaded == false) {
|
552
|
+
// get the hash table as a serialized
|
553
|
+
// string
|
554
|
+
var serializedHashTable = this.storageField.value;
|
555
|
+
|
556
|
+
if (serializedHashTable != "" &&
|
557
|
+
serializedHashTable != null) {
|
558
|
+
// destringify the content back into a
|
559
|
+
// real JavaScript object
|
560
|
+
this.storageHash = eval('(' + serializedHashTable + ')');
|
561
|
+
}
|
562
|
+
|
563
|
+
this.hashLoaded = true;
|
564
|
+
}
|
565
|
+
},
|
566
|
+
|
567
|
+
/** Saves the hash table into the form. */
|
568
|
+
/** private */ saveHashTable: function() {
|
569
|
+
this.loadHashTable();
|
570
|
+
|
571
|
+
// serialized the hash table
|
572
|
+
var serializedHashTable = JSON.stringify(this.storageHash);
|
573
|
+
|
574
|
+
// save this value
|
575
|
+
this.storageField.value = serializedHashTable;
|
576
|
+
}
|
577
|
+
};
|
578
|
+
|
579
|
+
/** The JSON class is copyright 2005 JSON.org. */
|
580
|
+
Array.prototype.______array = '______array';
|
581
|
+
|
582
|
+
var JSON = {
|
583
|
+
org: 'http://www.JSON.org',
|
584
|
+
copyright: '(c)2005 JSON.org',
|
585
|
+
license: 'http://www.crockford.com/JSON/license.html',
|
586
|
+
|
587
|
+
stringify: function (arg) {
|
588
|
+
var c, i, l, s = '', v;
|
589
|
+
|
590
|
+
switch (typeof arg) {
|
591
|
+
case 'object':
|
592
|
+
if (arg) {
|
593
|
+
if (arg.______array == '______array') {
|
594
|
+
for (i = 0; i < arg.length; ++i) {
|
595
|
+
v = this.stringify(arg[i]);
|
596
|
+
if (s) {
|
597
|
+
s += ',';
|
598
|
+
}
|
599
|
+
s += v;
|
600
|
+
}
|
601
|
+
return '[' + s + ']';
|
602
|
+
} else if (typeof arg.toString != 'undefined') {
|
603
|
+
for (i in arg) {
|
604
|
+
v = arg[i];
|
605
|
+
if (typeof v != 'undefined' && typeof v != 'function') {
|
606
|
+
v = this.stringify(v);
|
607
|
+
if (s) {
|
608
|
+
s += ',';
|
609
|
+
}
|
610
|
+
s += this.stringify(i) + ':' + v;
|
611
|
+
}
|
612
|
+
}
|
613
|
+
return '{' + s + '}';
|
614
|
+
}
|
615
|
+
}
|
616
|
+
return 'null';
|
617
|
+
case 'number':
|
618
|
+
return isFinite(arg) ? String(arg) : 'null';
|
619
|
+
case 'string':
|
620
|
+
l = arg.length;
|
621
|
+
s = '"';
|
622
|
+
for (i = 0; i < l; i += 1) {
|
623
|
+
c = arg.charAt(i);
|
624
|
+
if (c >= ' ') {
|
625
|
+
if (c == '\\' || c == '"') {
|
626
|
+
s += '\\';
|
627
|
+
}
|
628
|
+
s += c;
|
629
|
+
} else {
|
630
|
+
switch (c) {
|
631
|
+
case '\b':
|
632
|
+
s += '\\b';
|
633
|
+
break;
|
634
|
+
case '\f':
|
635
|
+
s += '\\f';
|
636
|
+
break;
|
637
|
+
case '\n':
|
638
|
+
s += '\\n';
|
639
|
+
break;
|
640
|
+
case '\r':
|
641
|
+
s += '\\r';
|
642
|
+
break;
|
643
|
+
case '\t':
|
644
|
+
s += '\\t';
|
645
|
+
break;
|
646
|
+
default:
|
647
|
+
c = c.charCodeAt();
|
648
|
+
s += '\\u00' + Math.floor(c / 16).toString(16) +
|
649
|
+
(c % 16).toString(16);
|
650
|
+
}
|
651
|
+
}
|
652
|
+
}
|
653
|
+
return s + '"';
|
654
|
+
case 'boolean':
|
655
|
+
return String(arg);
|
656
|
+
default:
|
657
|
+
return 'null';
|
658
|
+
}
|
659
|
+
},
|
660
|
+
parse: function (text) {
|
661
|
+
var at = 0;
|
662
|
+
var ch = ' ';
|
663
|
+
|
664
|
+
function error(m) {
|
665
|
+
throw {
|
666
|
+
name: 'JSONError',
|
667
|
+
message: m,
|
668
|
+
at: at - 1,
|
669
|
+
text: text
|
670
|
+
};
|
671
|
+
}
|
672
|
+
|
673
|
+
function next() {
|
674
|
+
ch = text.charAt(at);
|
675
|
+
at += 1;
|
676
|
+
return ch;
|
677
|
+
}
|
678
|
+
|
679
|
+
function white() {
|
680
|
+
while (ch != '' && ch <= ' ') {
|
681
|
+
next();
|
682
|
+
}
|
683
|
+
}
|
684
|
+
|
685
|
+
function str() {
|
686
|
+
var i, s = '', t, u;
|
687
|
+
|
688
|
+
if (ch == '"') {
|
689
|
+
outer: while (next()) {
|
690
|
+
if (ch == '"') {
|
691
|
+
next();
|
692
|
+
return s;
|
693
|
+
} else if (ch == '\\') {
|
694
|
+
switch (next()) {
|
695
|
+
case 'b':
|
696
|
+
s += '\b';
|
697
|
+
break;
|
698
|
+
case 'f':
|
699
|
+
s += '\f';
|
700
|
+
break;
|
701
|
+
case 'n':
|
702
|
+
s += '\n';
|
703
|
+
break;
|
704
|
+
case 'r':
|
705
|
+
s += '\r';
|
706
|
+
break;
|
707
|
+
case 't':
|
708
|
+
s += '\t';
|
709
|
+
break;
|
710
|
+
case 'u':
|
711
|
+
u = 0;
|
712
|
+
for (i = 0; i < 4; i += 1) {
|
713
|
+
t = parseInt(next(), 16);
|
714
|
+
if (!isFinite(t)) {
|
715
|
+
break outer;
|
716
|
+
}
|
717
|
+
u = u * 16 + t;
|
718
|
+
}
|
719
|
+
s += String.fromCharCode(u);
|
720
|
+
break;
|
721
|
+
default:
|
722
|
+
s += ch;
|
723
|
+
}
|
724
|
+
} else {
|
725
|
+
s += ch;
|
726
|
+
}
|
727
|
+
}
|
728
|
+
}
|
729
|
+
error("Bad string");
|
730
|
+
}
|
731
|
+
|
732
|
+
function arr() {
|
733
|
+
var a = [];
|
734
|
+
|
735
|
+
if (ch == '[') {
|
736
|
+
next();
|
737
|
+
white();
|
738
|
+
if (ch == ']') {
|
739
|
+
next();
|
740
|
+
return a;
|
741
|
+
}
|
742
|
+
while (ch) {
|
743
|
+
a.push(val());
|
744
|
+
white();
|
745
|
+
if (ch == ']') {
|
746
|
+
next();
|
747
|
+
return a;
|
748
|
+
} else if (ch != ',') {
|
749
|
+
break;
|
750
|
+
}
|
751
|
+
next();
|
752
|
+
white();
|
753
|
+
}
|
754
|
+
}
|
755
|
+
error("Bad array");
|
756
|
+
}
|
757
|
+
|
758
|
+
function obj() {
|
759
|
+
var k, o = {};
|
760
|
+
|
761
|
+
if (ch == '{') {
|
762
|
+
next();
|
763
|
+
white();
|
764
|
+
if (ch == '}') {
|
765
|
+
next();
|
766
|
+
return o;
|
767
|
+
}
|
768
|
+
while (ch) {
|
769
|
+
k = str();
|
770
|
+
white();
|
771
|
+
if (ch != ':') {
|
772
|
+
break;
|
773
|
+
}
|
774
|
+
next();
|
775
|
+
o[k] = val();
|
776
|
+
white();
|
777
|
+
if (ch == '}') {
|
778
|
+
next();
|
779
|
+
return o;
|
780
|
+
} else if (ch != ',') {
|
781
|
+
break;
|
782
|
+
}
|
783
|
+
next();
|
784
|
+
white();
|
785
|
+
}
|
786
|
+
}
|
787
|
+
error("Bad object");
|
788
|
+
}
|
789
|
+
|
790
|
+
function num() {
|
791
|
+
var n = '', v;
|
792
|
+
if (ch == '-') {
|
793
|
+
n = '-';
|
794
|
+
next();
|
795
|
+
}
|
796
|
+
while (ch >= '0' && ch <= '9') {
|
797
|
+
n += ch;
|
798
|
+
next();
|
799
|
+
}
|
800
|
+
if (ch == '.') {
|
801
|
+
n += '.';
|
802
|
+
while (next() && ch >= '0' && ch <= '9') {
|
803
|
+
n += ch;
|
804
|
+
}
|
805
|
+
}
|
806
|
+
if (ch == 'e' || ch == 'E') {
|
807
|
+
n += 'e';
|
808
|
+
next();
|
809
|
+
if (ch == '-' || ch == '+') {
|
810
|
+
n += ch;
|
811
|
+
next();
|
812
|
+
}
|
813
|
+
while (ch >= '0' && ch <= '9') {
|
814
|
+
n += ch;
|
815
|
+
next();
|
816
|
+
}
|
817
|
+
}
|
818
|
+
v = +n;
|
819
|
+
if (!isFinite(v)) {
|
820
|
+
error("Bad number");
|
821
|
+
} else {
|
822
|
+
return v;
|
823
|
+
}
|
824
|
+
}
|
825
|
+
|
826
|
+
function word() {
|
827
|
+
switch (ch) {
|
828
|
+
case 't':
|
829
|
+
if (next() == 'r' && next() == 'u' && next() == 'e') {
|
830
|
+
next();
|
831
|
+
return true;
|
832
|
+
}
|
833
|
+
break;
|
834
|
+
case 'f':
|
835
|
+
if (next() == 'a' && next() == 'l' && next() == 's' &&
|
836
|
+
next() == 'e') {
|
837
|
+
next();
|
838
|
+
return false;
|
839
|
+
}
|
840
|
+
break;
|
841
|
+
case 'n':
|
842
|
+
if (next() == 'u' && next() == 'l' && next() == 'l') {
|
843
|
+
next();
|
844
|
+
return null;
|
845
|
+
}
|
846
|
+
break;
|
847
|
+
}
|
848
|
+
error("Syntax error");
|
849
|
+
}
|
850
|
+
|
851
|
+
function val() {
|
852
|
+
white();
|
853
|
+
switch (ch) {
|
854
|
+
case '{':
|
855
|
+
return obj();
|
856
|
+
case '[':
|
857
|
+
return arr();
|
858
|
+
case '"':
|
859
|
+
return str();
|
860
|
+
case '-':
|
861
|
+
return num();
|
862
|
+
default:
|
863
|
+
return ch >= '0' && ch <= '9' ? num() : word();
|
864
|
+
}
|
865
|
+
}
|
866
|
+
|
867
|
+
return val();
|
868
|
+
}
|
869
|
+
};
|
870
|
+
|
871
|
+
/** QueryString Object from http://adamv.com/dev/javascript/querystring */
|
872
|
+
/* Client-side access to querystring name=value pairs
|
873
|
+
Version 1.2.3
|
874
|
+
22 Jun 2005
|
875
|
+
Adam Vandenberg
|
876
|
+
*/
|
877
|
+
function Querystring(qs) { // optionally pass a querystring to parse
|
878
|
+
this.params = new Object()
|
879
|
+
this.get=Querystring_get
|
880
|
+
|
881
|
+
if (qs == null)
|
882
|
+
qs=location.search.substring(1,location.search.length)
|
883
|
+
|
884
|
+
if (qs.length == 0) return
|
885
|
+
|
886
|
+
// Turn <plus> back to <space>
|
887
|
+
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
|
888
|
+
qs = qs.replace(/\+/g, ' ')
|
889
|
+
// added by Scott Rutherford, change all & to &
|
890
|
+
qs = qs.replace(/&/g, '&')
|
891
|
+
var args = qs.split('&') // parse out name/value pairs separated via &
|
892
|
+
|
893
|
+
// split out each name=value pair
|
894
|
+
for (var i=0;i<args.length;i++) {
|
895
|
+
var value;
|
896
|
+
var pair = args[i].split('=')
|
897
|
+
var name = unescape(pair[0])
|
898
|
+
|
899
|
+
if (pair.length == 2)
|
900
|
+
value = unescape(pair[1])
|
901
|
+
else
|
902
|
+
value = name
|
903
|
+
|
904
|
+
this.params[name] = value
|
905
|
+
}
|
906
|
+
}
|
907
|
+
|
908
|
+
function Querystring_get(key, default_) {
|
909
|
+
// This silly looking line changes UNDEFINED to NULL
|
910
|
+
if (default_ == null) default_ = null;
|
911
|
+
|
912
|
+
var value=this.params[key]
|
913
|
+
if (value==null) value=default_;
|
914
|
+
|
915
|
+
return value
|
916
|
+
}
|
917
|
+
|
918
|
+
/** ADDED BY SCOTT RUTHERFORD, COMINDED July 2006 scott@cominded */
|
919
|
+
/** Initialize all of our objects now. */
|
920
|
+
window.historyStorage.init();
|
921
|
+
window.dhtmlHistory.create();
|
922
|
+
|
923
|
+
/** Create init methods for ajax_table */
|
924
|
+
function initialize() {
|
925
|
+
// initialize our DHTML history
|
926
|
+
dhtmlHistory.initialize();
|
927
|
+
// subscribe to DHTML history change
|
928
|
+
// events
|
929
|
+
dhtmlHistory.addListener(handleHistoryChange);
|
930
|
+
}
|
931
|
+
|
932
|
+
/** Our callback to receive history
|
933
|
+
change events. */
|
934
|
+
function handleHistoryChange(pageId, pageData) {
|
935
|
+
//alert(pageData)
|
936
|
+
var info = pageId.split(':');
|
937
|
+
var id = info[0];
|
938
|
+
new Ajax.Updater(id+'-content', pageData, {asynchronous:true, evalScripts:true, onLoading:function(request){Element.show(id+'-pagination-loading-indicator');}});
|
939
|
+
}
|
940
|
+
|
941
|
+
function debugMsg(msg) {
|
942
|
+
var debugMsg = $("debugMsg");
|
943
|
+
debugMsg.innerHTML = msg;
|
944
|
+
}
|
945
|
+
|
946
|
+
function addAjaxTableUrlToHistory(url) {
|
947
|
+
var array = url.split('?');
|
948
|
+
var qs = new Querystring(array[1]);
|
949
|
+
var sort = qs.get('sort')
|
950
|
+
var dir = qs.get('sort_direction')
|
951
|
+
dhtmlHistory.add(qs.get('scaffold_id')+":"+qs.get('page')+":"+sort+":"+dir, url);
|
952
|
+
}
|
953
|
+
|
954
|
+
/** set onload handler */
|
955
|
+
Event.observe(window, 'load', initialize, false);
|
956
|
+
|
957
|
+
|
958
|
+
|
959
|
+
|
960
|
+
|
961
|
+
|