Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

better fireEvent implementation

  • Loading branch information...
commit be6d8602a7f49234450121956252b9e73ea376e6 1 parent 057bae3
Arieh Glazer authored
12 Demo/blank.html
... ... @@ -1,6 +1,6 @@
1   -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2   -<html xmlns="http://www.w3.org/1999/xhtml">
3   -<head><title>blank</title></head>
4   -<body>
5   -</body>
6   -</html>
  1 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2 +<html xmlns="http://www.w3.org/1999/xhtml">
  3 +<head><title>blank</title></head>
  4 +<body>
  5 +</body>
  6 +</html>
480 Demo/mootools-1-1.2.4.4-more.js
... ... @@ -1,241 +1,241 @@
1   -//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2009 Aaron Newton <http://clientcide.com/>, Valerio Proietti <http://mad4milk.net> & the MooTools team <http://mootools.net/developers>, MIT Style License.
2   -
3   -/*
4   ----
5   -
6   -script: More.js
7   -
8   -description: MooTools More
9   -
10   -license: MIT-style license
11   -
12   -authors:
13   -- Guillermo Rauch
14   -- Thomas Aylott
15   -- Scott Kyle
16   -
17   -requires:
18   -- core:1.2.4/MooTools
19   -
20   -provides: [MooTools.More]
21   -
22   -...
23   -*/
24   -
25   -MooTools.More = {
26   - 'version': '1.2.4.4',
27   - 'build': '6f6057dc645fdb7547689183b2311063bd653ddf'
28   -};
29   -
30   -/*
31   ----
32   -
33   -script: String.QueryString.js
34   -
35   -description: Methods for dealing with URI query strings.
36   -
37   -license: MIT-style license
38   -
39   -authors:
40   -- Sebastian Markbåge, Aaron Newton, Lennart Pilon, Valerio Proietti
41   -
42   -requires:
43   -- core:1.2.4/Array
44   -- core:1.2.4/String
45   -- /MooTools.More
46   -
47   -provides: [String.QueryString]
48   -
49   -...
50   -*/
51   -
52   -String.implement({
53   -
54   - parseQueryString: function(){
55   - var vars = this.split(/[&;]/), res = {};
56   - if (vars.length) vars.each(function(val){
57   - var index = val.indexOf('='),
58   - keys = index < 0 ? [''] : val.substr(0, index).match(/[^\]\[]+/g),
59   - value = decodeURIComponent(val.substr(index + 1)),
60   - obj = res;
61   - keys.each(function(key, i){
62   - var current = obj[key];
63   - if(i < keys.length - 1)
64   - obj = obj[key] = current || {};
65   - else if($type(current) == 'array')
66   - current.push(value);
67   - else
68   - obj[key] = $defined(current) ? [current, value] : value;
69   - });
70   - });
71   - return res;
72   - },
73   -
74   - cleanQueryString: function(method){
75   - return this.split('&').filter(function(val){
76   - var index = val.indexOf('='),
77   - key = index < 0 ? '' : val.substr(0, index),
78   - value = val.substr(index + 1);
79   - return method ? method.run([key, value]) : $chk(value);
80   - }).join('&');
81   - }
82   -
83   -});
84   -
85   -/*
86   ----
87   -
88   -script: URI.js
89   -
90   -description: Provides methods useful in managing the window location and uris.
91   -
92   -license: MIT-style license
93   -
94   -authors:
95   -- Sebastian Markb�ge
96   -- Aaron Newton
97   -
98   -requires:
99   -- core:1.2.4/Selectors
100   -- /String.QueryString
101   -
102   -provides: URI
103   -
104   -...
105   -*/
106   -
107   -var URI = new Class({
108   -
109   - Implements: Options,
110   -
111   - options: {
112   - /*base: false*/
113   - },
114   -
115   - regex: /^(?:(\w+):)?(?:\/\/(?:(?:([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?)?(\.\.?$|(?:[^?#\/]*\/)*)([^?#]*)(?:\?([^#]*))?(?:#(.*))?/,
116   - parts: ['scheme', 'user', 'password', 'host', 'port', 'directory', 'file', 'query', 'fragment'],
117   - schemes: {http: 80, https: 443, ftp: 21, rtsp: 554, mms: 1755, file: 0},
118   -
119   - initialize: function(uri, options){
120   - this.setOptions(options);
121   - var base = this.options.base || URI.base;
122   - if(!uri) uri = base;
123   -
124   - if (uri && uri.parsed) this.parsed = $unlink(uri.parsed);
125   - else this.set('value', uri.href || uri.toString(), base ? new URI(base) : false);
126   - },
127   -
128   - parse: function(value, base){
129   - var bits = value.match(this.regex);
130   - if (!bits) return false;
131   - bits.shift();
132   - return this.merge(bits.associate(this.parts), base);
133   - },
134   -
135   - merge: function(bits, base){
136   - if ((!bits || !bits.scheme) && (!base || !base.scheme)) return false;
137   - if (base){
138   - this.parts.every(function(part){
139   - if (bits[part]) return false;
140   - bits[part] = base[part] || '';
141   - return true;
142   - });
143   - }
144   - bits.port = bits.port || this.schemes[bits.scheme.toLowerCase()];
145   - bits.directory = bits.directory ? this.parseDirectory(bits.directory, base ? base.directory : '') : '/';
146   - return bits;
147   - },
148   -
149   - parseDirectory: function(directory, baseDirectory) {
150   - directory = (directory.substr(0, 1) == '/' ? '' : (baseDirectory || '/')) + directory;
151   - if (!directory.test(URI.regs.directoryDot)) return directory;
152   - var result = [];
153   - directory.replace(URI.regs.endSlash, '').split('/').each(function(dir){
154   - if (dir == '..' && result.length > 0) result.pop();
155   - else if (dir != '.') result.push(dir);
156   - });
157   - return result.join('/') + '/';
158   - },
159   -
160   - combine: function(bits){
161   - return bits.value || bits.scheme + '://' +
162   - (bits.user ? bits.user + (bits.password ? ':' + bits.password : '') + '@' : '') +
163   - (bits.host || '') + (bits.port && bits.port != this.schemes[bits.scheme] ? ':' + bits.port : '') +
164   - (bits.directory || '/') + (bits.file || '') +
165   - (bits.query ? '?' + bits.query : '') +
166   - (bits.fragment ? '#' + bits.fragment : '');
167   - },
168   -
169   - set: function(part, value, base){
170   - if (part == 'value'){
171   - var scheme = value.match(URI.regs.scheme);
172   - if (scheme) scheme = scheme[1];
173   - if (scheme && !$defined(this.schemes[scheme.toLowerCase()])) this.parsed = { scheme: scheme, value: value };
174   - else this.parsed = this.parse(value, (base || this).parsed) || (scheme ? { scheme: scheme, value: value } : { value: value });
175   - } else if (part == 'data') {
176   - this.setData(value);
177   - } else {
178   - this.parsed[part] = value;
179   - }
180   - return this;
181   - },
182   -
183   - get: function(part, base){
184   - switch(part){
185   - case 'value': return this.combine(this.parsed, base ? base.parsed : false);
186   - case 'data' : return this.getData();
187   - }
188   - return this.parsed[part] || '';
189   - },
190   -
191   - go: function(){
192   - document.location.href = this.toString();
193   - },
194   -
195   - toURI: function(){
196   - return this;
197   - },
198   -
199   - getData: function(key, part){
200   - var qs = this.get(part || 'query');
201   - if (!$chk(qs)) return key ? null : {};
202   - var obj = qs.parseQueryString();
203   - return key ? obj[key] : obj;
204   - },
205   -
206   - setData: function(values, merge, part){
207   - if (typeof values == 'string'){
208   - data = this.getData();
209   - data[arguments[0]] = arguments[1];
210   - values = data;
211   - } else if (merge) {
212   - values = $merge(this.getData(), values);
213   - }
214   - return this.set(part || 'query', Hash.toQueryString(values));
215   - },
216   -
217   - clearData: function(part){
218   - return this.set(part || 'query', '');
219   - }
220   -
221   -});
222   -
223   -URI.prototype.toString = URI.prototype.valueOf = function(){
224   - return this.get('value');
225   -};
226   -
227   -URI.regs = {
228   - endSlash: /\/$/,
229   - scheme: /^(\w+):/,
230   - directoryDot: /\.\/|\.$/
231   -};
232   -
233   -URI.base = new URI(document.getElements('base[href]', true).getLast(), {base: document.location});
234   -
235   -String.implement({
236   -
237   - toURI: function(options){
238   - return new URI(this, options);
239   - }
240   -
  1 +//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2009 Aaron Newton <http://clientcide.com/>, Valerio Proietti <http://mad4milk.net> & the MooTools team <http://mootools.net/developers>, MIT Style License.
  2 +
  3 +/*
  4 +---
  5 +
  6 +script: More.js
  7 +
  8 +description: MooTools More
  9 +
  10 +license: MIT-style license
  11 +
  12 +authors:
  13 +- Guillermo Rauch
  14 +- Thomas Aylott
  15 +- Scott Kyle
  16 +
  17 +requires:
  18 +- core:1.2.4/MooTools
  19 +
  20 +provides: [MooTools.More]
  21 +
  22 +...
  23 +*/
  24 +
  25 +MooTools.More = {
  26 + 'version': '1.2.4.4',
  27 + 'build': '6f6057dc645fdb7547689183b2311063bd653ddf'
  28 +};
  29 +
  30 +/*
  31 +---
  32 +
  33 +script: String.QueryString.js
  34 +
  35 +description: Methods for dealing with URI query strings.
  36 +
  37 +license: MIT-style license
  38 +
  39 +authors:
  40 +- Sebastian Markbåge, Aaron Newton, Lennart Pilon, Valerio Proietti
  41 +
  42 +requires:
  43 +- core:1.2.4/Array
  44 +- core:1.2.4/String
  45 +- /MooTools.More
  46 +
  47 +provides: [String.QueryString]
  48 +
  49 +...
  50 +*/
  51 +
  52 +String.implement({
  53 +
  54 + parseQueryString: function(){
  55 + var vars = this.split(/[&;]/), res = {};
  56 + if (vars.length) vars.each(function(val){
  57 + var index = val.indexOf('='),
  58 + keys = index < 0 ? [''] : val.substr(0, index).match(/[^\]\[]+/g),
  59 + value = decodeURIComponent(val.substr(index + 1)),
  60 + obj = res;
  61 + keys.each(function(key, i){
  62 + var current = obj[key];
  63 + if(i < keys.length - 1)
  64 + obj = obj[key] = current || {};
  65 + else if($type(current) == 'array')
  66 + current.push(value);
  67 + else
  68 + obj[key] = $defined(current) ? [current, value] : value;
  69 + });
  70 + });
  71 + return res;
  72 + },
  73 +
  74 + cleanQueryString: function(method){
  75 + return this.split('&').filter(function(val){
  76 + var index = val.indexOf('='),
  77 + key = index < 0 ? '' : val.substr(0, index),
  78 + value = val.substr(index + 1);
  79 + return method ? method.run([key, value]) : $chk(value);
  80 + }).join('&');
  81 + }
  82 +
  83 +});
  84 +
  85 +/*
  86 +---
  87 +
  88 +script: URI.js
  89 +
  90 +description: Provides methods useful in managing the window location and uris.
  91 +
  92 +license: MIT-style license
  93 +
  94 +authors:
  95 +- Sebastian Markb�ge
  96 +- Aaron Newton
  97 +
  98 +requires:
  99 +- core:1.2.4/Selectors
  100 +- /String.QueryString
  101 +
  102 +provides: URI
  103 +
  104 +...
  105 +*/
  106 +
  107 +var URI = new Class({
  108 +
  109 + Implements: Options,
  110 +
  111 + options: {
  112 + /*base: false*/
  113 + },
  114 +
  115 + regex: /^(?:(\w+):)?(?:\/\/(?:(?:([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?)?(\.\.?$|(?:[^?#\/]*\/)*)([^?#]*)(?:\?([^#]*))?(?:#(.*))?/,
  116 + parts: ['scheme', 'user', 'password', 'host', 'port', 'directory', 'file', 'query', 'fragment'],
  117 + schemes: {http: 80, https: 443, ftp: 21, rtsp: 554, mms: 1755, file: 0},
  118 +
  119 + initialize: function(uri, options){
  120 + this.setOptions(options);
  121 + var base = this.options.base || URI.base;
  122 + if(!uri) uri = base;
  123 +
  124 + if (uri && uri.parsed) this.parsed = $unlink(uri.parsed);
  125 + else this.set('value', uri.href || uri.toString(), base ? new URI(base) : false);
  126 + },
  127 +
  128 + parse: function(value, base){
  129 + var bits = value.match(this.regex);
  130 + if (!bits) return false;
  131 + bits.shift();
  132 + return this.merge(bits.associate(this.parts), base);
  133 + },
  134 +
  135 + merge: function(bits, base){
  136 + if ((!bits || !bits.scheme) && (!base || !base.scheme)) return false;
  137 + if (base){
  138 + this.parts.every(function(part){
  139 + if (bits[part]) return false;
  140 + bits[part] = base[part] || '';
  141 + return true;
  142 + });
  143 + }
  144 + bits.port = bits.port || this.schemes[bits.scheme.toLowerCase()];
  145 + bits.directory = bits.directory ? this.parseDirectory(bits.directory, base ? base.directory : '') : '/';
  146 + return bits;
  147 + },
  148 +
  149 + parseDirectory: function(directory, baseDirectory) {
  150 + directory = (directory.substr(0, 1) == '/' ? '' : (baseDirectory || '/')) + directory;
  151 + if (!directory.test(URI.regs.directoryDot)) return directory;
  152 + var result = [];
  153 + directory.replace(URI.regs.endSlash, '').split('/').each(function(dir){
  154 + if (dir == '..' && result.length > 0) result.pop();
  155 + else if (dir != '.') result.push(dir);
  156 + });
  157 + return result.join('/') + '/';
  158 + },
  159 +
  160 + combine: function(bits){
  161 + return bits.value || bits.scheme + '://' +
  162 + (bits.user ? bits.user + (bits.password ? ':' + bits.password : '') + '@' : '') +
  163 + (bits.host || '') + (bits.port && bits.port != this.schemes[bits.scheme] ? ':' + bits.port : '') +
  164 + (bits.directory || '/') + (bits.file || '') +
  165 + (bits.query ? '?' + bits.query : '') +
  166 + (bits.fragment ? '#' + bits.fragment : '');
  167 + },
  168 +
  169 + set: function(part, value, base){
  170 + if (part == 'value'){
  171 + var scheme = value.match(URI.regs.scheme);
  172 + if (scheme) scheme = scheme[1];
  173 + if (scheme && !$defined(this.schemes[scheme.toLowerCase()])) this.parsed = { scheme: scheme, value: value };
  174 + else this.parsed = this.parse(value, (base || this).parsed) || (scheme ? { scheme: scheme, value: value } : { value: value });
  175 + } else if (part == 'data') {
  176 + this.setData(value);
  177 + } else {
  178 + this.parsed[part] = value;
  179 + }
  180 + return this;
  181 + },
  182 +
  183 + get: function(part, base){
  184 + switch(part){
  185 + case 'value': return this.combine(this.parsed, base ? base.parsed : false);
  186 + case 'data' : return this.getData();
  187 + }
  188 + return this.parsed[part] || '';
  189 + },
  190 +
  191 + go: function(){
  192 + document.location.href = this.toString();
  193 + },
  194 +
  195 + toURI: function(){
  196 + return this;
  197 + },
  198 +
  199 + getData: function(key, part){
  200 + var qs = this.get(part || 'query');
  201 + if (!$chk(qs)) return key ? null : {};
  202 + var obj = qs.parseQueryString();
  203 + return key ? obj[key] : obj;
  204 + },
  205 +
  206 + setData: function(values, merge, part){
  207 + if (typeof values == 'string'){
  208 + data = this.getData();
  209 + data[arguments[0]] = arguments[1];
  210 + values = data;
  211 + } else if (merge) {
  212 + values = $merge(this.getData(), values);
  213 + }
  214 + return this.set(part || 'query', Hash.toQueryString(values));
  215 + },
  216 +
  217 + clearData: function(part){
  218 + return this.set(part || 'query', '');
  219 + }
  220 +
  221 +});
  222 +
  223 +URI.prototype.toString = URI.prototype.valueOf = function(){
  224 + return this.get('value');
  225 +};
  226 +
  227 +URI.regs = {
  228 + endSlash: /\/$/,
  229 + scheme: /^(\w+):/,
  230 + directoryDot: /\.\/|\.$/
  231 +};
  232 +
  233 +URI.base = new URI(document.getElements('base[href]', true).getLast(), {base: document.location});
  234 +
  235 +String.implement({
  236 +
  237 + toURI: function(options){
  238 + return new URI(this, options);
  239 + }
  240 +
241 241 });
126 Demo/serialize-test.html
... ... @@ -1,63 +1,63 @@
1   -<!DOCTYPE html
2   - PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3   - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4   -
5   -<html>
6   -<head>
7   - <title>History-Manager Demo</title>
8   - <meta http-equiv="Content-Type" content="text/html; charset='UTF-8'" />
9   -</head>
10   -<body>
11   -<ul>
12   - <li><a href='javascript:;' id='step'>Click To Step</a></li>
13   -</ul>
14   -<ul id='result'></ul>
15   -<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js'></script>
16   -<script type="text/javascript" src="mootools-1.2.4.4-more.js"></script>
17   -<script type='text/javascript' src='../Source/HashListener.js'></script>
18   -<script type='text/javascript' src='../Source/HistoryManager.js'></script>
19   -<script type='text/javascript'>
20   - var i=0,
21   - HM = new HistoryManager({
22   - 'delimiter':'!'
23   - , serialize:function(obj){
24   - return obj.toQueryString();
25   - }
26   - , desserialize:function(hash){
27   - return new Hash(hash.parseQueryString());
28   - }
29   - }),
30   - res = $('result')
31   - , testValues = [
32   - ['select','L1']
33   - ,['b','hide']
34   - ,['select','L1;L2']
35   - ,['b','hide']
36   - ];
37   -
38   - $('step').addEvent('click',function(){
39   - var value = testValues[i++];
40   - HM.set(value[0],value[1]);
41   - if (i==4) i=0;
42   - });
43   -
44   - function updateSelect(value){
45   - res.adopt(new Element('li',{'html':'select: '+value}));
46   - }
47   -
48   - function updateB(value){
49   - res.adopt(new Element('li',{'html':'b: '+value}));
50   - }
51   -
52   - HM.addEvents({
53   - 'select-changed' :updateSelect
54   - , 'b-changed' :updateB
55   - ,'select-added' :updateSelect
56   - , 'b-added' :updateB
57   - });
58   -
59   - HM.start();
60   -
61   -</script>
62   -</body>
63   -</html>
  1 +<!DOCTYPE html
  2 + PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4 +
  5 +<html>
  6 +<head>
  7 + <title>History-Manager Demo</title>
  8 + <meta http-equiv="Content-Type" content="text/html; charset='UTF-8'" />
  9 +</head>
  10 +<body>
  11 +<ul>
  12 + <li><a href='javascript:;' id='step'>Click To Step</a></li>
  13 +</ul>
  14 +<ul id='result'></ul>
  15 +<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js'></script>
  16 +<script type="text/javascript" src="mootools-1.2.4.4-more.js"></script>
  17 +<script type='text/javascript' src='../Source/HashListener.js'></script>
  18 +<script type='text/javascript' src='../Source/HistoryManager.js'></script>
  19 +<script type='text/javascript'>
  20 + var i=0,
  21 + HM = new HistoryManager({
  22 + 'delimiter':'!'
  23 + , serialize:function(obj){
  24 + return obj.toQueryString();
  25 + }
  26 + , desserialize:function(hash){
  27 + return new Hash(hash.parseQueryString());
  28 + }
  29 + }),
  30 + res = $('result')
  31 + , testValues = [
  32 + ['select','L1']
  33 + ,['b','hide']
  34 + ,['select','L1;L2']
  35 + ,['b','hide']
  36 + ];
  37 +
  38 + $('step').addEvent('click',function(){
  39 + var value = testValues[i++];
  40 + HM.set(value[0],value[1]);
  41 + if (i==4) i=0;
  42 + });
  43 +
  44 + function updateSelect(value){
  45 + res.adopt(new Element('li',{'html':'select: '+value}));
  46 + }
  47 +
  48 + function updateB(value){
  49 + res.adopt(new Element('li',{'html':'b: '+value}));
  50 + }
  51 +
  52 + HM.addEvents({
  53 + 'select-changed' :updateSelect
  54 + , 'b-changed' :updateB
  55 + ,'select-added' :updateSelect
  56 + , 'b-added' :updateB
  57 + });
  58 +
  59 + HM.start();
  60 +
  61 +</script>
  62 +</body>
  63 +</html>
108 Demo/test1.html
... ... @@ -1,54 +1,54 @@
1   -<!DOCTYPE html
2   - PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3   - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4   -
5   -<html>
6   -<head>
7   - <title>History-Manager Demo</title>
8   - <meta http-equiv="Content-Type" content="text/html; charset='UTF-8'" />
9   -</head>
10   -<body>
11   -<ul>
12   - <li><a href='javascript:;' id='step'>Click To Step</a></li>
13   -</ul>
14   -<ul id='result'></ul>
15   -<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js'></script>
16   -<script type='text/javascript' src='../Source/HashListener.js'></script>
17   -<script type='text/javascript' src='../Source/HistoryManager.js'></script>
18   -<script type='text/javascript'>
19   - var i=0,
20   - HM = new HistoryManager({'delimiter':'!'}),
21   - res = $('result')
22   - , testValues = [
23   - ['select','L1']
24   - ,['b','hide']
25   - ,['select','L1;L2']
26   - ,['b','hide']
27   - ];
28   -
29   - $('step').addEvent('click',function(){
30   - var value = testValues[i++];
31   - HM.set(value[0],value[1]);
32   - if (i==4) i=0;
33   - });
34   -
35   - function updateSelect(value){
36   - res.adopt(new Element('li',{'html':'select: '+value}));
37   - }
38   -
39   - function updateB(value){
40   - res.adopt(new Element('li',{'html':'b: '+value}));
41   - }
42   -
43   - HM.addEvents({
44   - 'select-changed' :updateSelect
45   - , 'b-changed' :updateB
46   - ,'select-added' :updateSelect
47   - , 'b-added' :updateB
48   - });
49   -
50   - HM.start();
51   -
52   -</script>
53   -</body>
54   -</html>
  1 +<!DOCTYPE html
  2 + PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4 +
  5 +<html>
  6 +<head>
  7 + <title>History-Manager Demo</title>
  8 + <meta http-equiv="Content-Type" content="text/html; charset='UTF-8'" />
  9 +</head>
  10 +<body>
  11 +<ul>
  12 + <li><a href='javascript:;' id='step'>Click To Step</a></li>
  13 +</ul>
  14 +<ul id='result'></ul>
  15 +<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js'></script>
  16 +<script type='text/javascript' src='../Source/HashListener.js'></script>
  17 +<script type='text/javascript' src='../Source/HistoryManager.js'></script>
  18 +<script type='text/javascript'>
  19 + var i=0,
  20 + HM = new HistoryManager({'delimiter':'!'}),
  21 + res = $('result')
  22 + , testValues = [
  23 + ['select','L1']
  24 + ,['b','hide']
  25 + ,['select','L1;L2']
  26 + ,['b','hide']
  27 + ];
  28 +
  29 + $('step').addEvent('click',function(){
  30 + var value = testValues[i++];
  31 + HM.set(value[0],value[1]);
  32 + if (i==4) i=0;
  33 + });
  34 +
  35 + function updateSelect(value){
  36 + res.adopt(new Element('li',{'html':'select: '+value}));
  37 + }
  38 +
  39 + function updateB(value){
  40 + res.adopt(new Element('li',{'html':'b: '+value}));
  41 + }
  42 +
  43 + HM.addEvents({
  44 + 'select-changed' :updateSelect
  45 + , 'b-changed' :updateB
  46 + ,'select-added' :updateSelect
  47 + , 'b-added' :updateB
  48 + });
  49 +
  50 + HM.start();
  51 +
  52 +</script>
  53 +</body>
  54 +</html>
130 Demo/test2.html
... ... @@ -1,65 +1,65 @@
1   -<!DOCTYPE html
2   - PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3   - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4   -
5   -<html>
6   -<head>
7   - <title>History-Manager Demo</title>
8   - <meta http-equiv="Content-Type" content="text/html; charset='UTF-8'" />
9   -</head>
10   -<body>
11   -<ul>
12   - <li><a href='javascript:;' id='step'>Click To Step</a></li>
13   -</ul>
14   -<ul id='result'></ul>
15   -<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js'></script>
16   -<script src="mootools-1-1.2.4.4-more.js" type="text/javascript" charset="utf-8"></script>
17   -
18   -<script type='text/javascript' src='../Source/HashListener.js'></script>
19   -<script type='text/javascript' src='../Source/HistoryManager.js'></script>
20   -<script type='text/javascript'>
21   - var i=0;
22   - var HM = new HistoryManager({
23   - 'delimiter':'!',
24   - serializeHash: function (h) {
25   - return h.toQueryString().substr(1);
26   - },
27   - deserializeHash: function (s) {
28   - return new Hash(s.parseQueryString());
29   - }
30   - });
31   - var res = $('result');
32   - var testValues = [
33   - ['select','L1']
34   - ,['b','hide']
35   - ,['select','L1;L2']
36   - ,['select', ['L1','L2']]
37   - ,['b','hide']
38   - ];
39   -
40   - $('step').addEvent('click',function(){
41   - var value = testValues[i++];
42   - HM.set(value[0],value[1]);
43   - if (i==4) i=0;
44   - });
45   -
46   - function updateSelect(value){
47   - res.adopt(new Element('li',{'html':'select: '+value}));
48   - }
49   -
50   - function updateB(value){
51   - res.adopt(new Element('li',{'html':'b: '+value}));
52   - }
53   -
54   - HM.addEvents({
55   - 'select-changed' :updateSelect
56   - , 'b-changed' :updateB
57   - ,'select-added' :updateSelect
58   - , 'b-added' :updateB
59   - });
60   -
61   - HM.start();
62   -
63   -</script>
64   -</body>
65   -</html>
  1 +<!DOCTYPE html
  2 + PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4 +
  5 +<html>
  6 +<head>
  7 + <title>History-Manager Demo</title>
  8 + <meta http-equiv="Content-Type" content="text/html; charset='UTF-8'" />
  9 +</head>
  10 +<body>
  11 +<ul>
  12 + <li><a href='javascript:;' id='step'>Click To Step</a></li>
  13 +</ul>
  14 +<ul id='result'></ul>
  15 +<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js'></script>
  16 +<script src="mootools-1-1.2.4.4-more.js" type="text/javascript" charset="utf-8"></script>
  17 +
  18 +<script type='text/javascript' src='../Source/HashListener.js'></script>
  19 +<script type='text/javascript' src='../Source/HistoryManager.js'></script>
  20 +<script type='text/javascript'>
  21 + var i=0;
  22 + var HM = new HistoryManager({
  23 + 'delimiter':'!',
  24 + serializeHash: function (h) {
  25 + return h.toQueryString().substr(1);
  26 + },
  27 + deserializeHash: function (s) {
  28 + return new Hash(s.parseQueryString());
  29 + }
  30 + });
  31 + var res = $('result');
  32 + var testValues = [
  33 + ['select','L1']
  34 + ,['b','hide']
  35 + ,['select','L1;L2']
  36 + ,['select', ['L1','L2']]
  37 + ,['b','hide']
  38 + ];
  39 +
  40 + $('step').addEvent('click',function(){
  41 + var value = testValues[i++];
  42 + HM.set(value[0],value[1]);
  43 + if (i==4) i=0;
  44 + });
  45 +
  46 + function updateSelect(value){
  47 + res.adopt(new Element('li',{'html':'select: '+value}));
  48 + }
  49 +
  50 + function updateB(value){
  51 + res.adopt(new Element('li',{'html':'b: '+value}));
  52 + }
  53 +
  54 + HM.addEvents({
  55 + 'select-changed' :updateSelect
  56 + , 'b-changed' :updateB
  57 + ,'select-added' :updateSelect
  58 + , 'b-added' :updateB
  59 + });
  60 +
  61 + HM.start();
  62 +
  63 +</script>
  64 +</body>
  65 +</html>
64 Docs/HashListener.mdown
Source Rendered
... ... @@ -1,32 +1,32 @@
1   -Class: HashListener {#HashListener}
2   -==========================================
3   -A Class that provides a cross-browser history-management functionality, using the browser hash to store the application's state
4   -
5   -HashListener Method: constructor {#HashListener:constructor}
6   ----------------------------------
7   -### Example:
8   -
9   - var HL = new HashListener(options);
10   -
11   -### Arguments:
12   -
13   -1. options - (`object`: optional) See below:
14   -
15   -### Options:
16   -
17   -* blank_page - (`string`: defaults to `blank.html`) an alternative path to the blank.html file.
18   -* start - (`bool`: defaults to `false`) whether to start the listener on construction
19   -
20   -HashListener Method: updateHash {#HashListener:updateHash}
21   ---------------------------------
22   -### Example:
23   -
24   - HL.updateHash(value);
25   -
26   -### Arguments:
27   -
28   -1. value - (`string`) a new value for the browser hash
29   -
30   -HashListener: Events {#HashListener:Events}
31   ---------
32   - * `hashChanged` - will be fired whenever the hash was changed - whether by method or by browser behaviour. will pass the new hash value as parameter
  1 +Class: HashListener {#HashListener}
  2 +==========================================
  3 +A Class that provides a cross-browser history-management functionality, using the browser hash to store the application's state
  4 +
  5 +HashListener Method: constructor {#HashListener:constructor}
  6 +---------------------------------
  7 +### Example:
  8 +
  9 + var HL = new HashListener(options);
  10 +
  11 +### Arguments:
  12 +
  13 +1. options - (`object`: optional) See below:
  14 +
  15 +### Options:
  16 +
  17 +* blank_page - (`string`: defaults to `blank.html`) an alternative path to the blank.html file.
  18 +* start - (`bool`: defaults to `false`) whether to start the listener on construction
  19 +
  20 +HashListener Method: updateHash {#HashListener:updateHash}
  21 +--------------------------------
  22 +### Example:
  23 +
  24 + HL.updateHash(value);
  25 +
  26 +### Arguments:
  27 +
  28 +1. value - (`string`) a new value for the browser hash
  29 +
  30 +HashListener: Events {#HashListener:Events}
  31 +--------
  32 + * `hashChanged` - will be fired whenever the hash was changed - whether by method or by browser behaviour. will pass the new hash value as parameter
256 Docs/HistoryManager.mdown
Source Rendered
... ... @@ -1,128 +1,128 @@
1   -Class: HistoryManager {#HistoryManager}
2   -==========================================
3   -<big>This class is meant to function as a domain observer. It uses the browser-hash (via HashListener) to monitor and save the domain-state (enabling bookmarks and back/forward button functionality).
4   -The class acts as a parameter stack, to monitor and modify the state of an application. Whenever a parameter withing the stack changes state, the class notifies its followers of the change.</big>
5   -
6   -HistoryManager Method: constructor {#HistoryManager:constructor}
7   -----------------------------------
8   -### Example:
9   -
10   - var HM = new HistoryManager(options);
11   -
12   -### Arguments:
13   -
14   -1. options - (`object`: optional) See below:
15   -
16   -### Options:
17   -
18   -* blank_page - (`string`: defaults to `blank.html`) an alternative path to the blank.html file.
19   -* start - (`bool`: defaults to `false`) whether to start the listener on construction
20   -* delimiter - (`string`: defaults no '') a beginning delimiter to add to the hash, to support the new Google AJAX syntax (#!)
21   -* serializeHash - `string function (aHash)` (_Optional_, use with `deserializeHash`) A callback function which serializes a Hash
22   -* deserializeHash - `Hash function (aString)` (_Optional_, use with `serializeHash`) A callback function which deserializes a String to a Hash
23   -* compat - (`boolean` : defaults to `false`) whether to file deprecated event style as well (`key-added` aongside `key:added`)
24   -
25   -### Delimiter Usage:
26   - var HM = new HistoryManager({delimiter:'!'}); //will add support for the google syntax
27   -
28   -### Custom (de)serializer Usage:
29   - // using URI query syntax for data instead of JSON
30   - var HM = new HistoryManager({
31   - serializeHash: function (h) {
32   - return h.toQueryString();
33   - },
34   - deserializeHash: function (s) {
35   - return new Hash(s.parseQueryString());
36   - }
37   - });
38   -
39   -HistoryManager Method: Set {#HistoryManager:set}
40   ----------------------------
41   -<big>Used to set a state for the domain. Will set a key's value in the state.</big>
42   -
43   -### Example:
44   -
45   - HM.set(key,value);
46   -
47   -### Arguments:
48   -
49   -1. key - (`string`) A key identifier
50   -2. elements - (`mixed`) whatever value you want to set to that key (must be JSON encodable)
51   -
52   -A note about set. Because of the way the hash is analyzed, changing the order of the inner members of a value will cuase a state-change event.
53   -This is because i'm convering the objects to JSON instead of parsing them to save speed.
54   -If you do not controll the order of the values in your objects, make sure you check this manuly.
55   -An Example for this:
56   -
57   - HM.set('someValue',{a:'a',b:'b'});
58   - HM.set('someValue',{b:'b',a:'a'}); //will fire someValue-changed although values aren't actualy modified.
59   -
60   -HistoryManager Method: Remove {#HistoryManager:remove}
61   ------------------------------
62   -<big>Used to remove a state from the domain. Will remove `key` and its value from the state.</big>
63   -
64   -### Example:
65   -
66   - HM.remove('my-key');
67   -
68   -### Arguments:
69   -
70   -1. key - (`string`) A key identifier
71   -
72   -HistoryManager Method: Start {#HistoryManager:start}
73   -----------------------------
74   -<big>Will start the listener. This will enable the various events attached to the class.</big>
75   -
76   -### Example:
77   -
78   - HM.start();
79   -
80   -HistoryManager Method: Stop {#HistoryManager:stop}
81   ----------------------------
82   -<big>Will stop the event listener. When down, no events will be fired</big>
83   -
84   -### JavaScript:
85   -
86   - HM.stop();
87   -
88   -HistoryManaget: Events {#HistoryManager:Events}
89   --------
90   -<big>The class is event-based, but doesn't have prefixed events. The events change according to the key being observed.
91   -The names point to one of 3 states a value might be in: Added, Changed and Removed.</big>
92   -For every change that goes on on a specific key, an event with that key's name will be fired, passing it's value as parameter.
93   -
94   -
95   -<small>As of v1.1, all event names will be using colon seperation. For dash seperation, use the compat options.</small>
96   -
97   - * `key`':added' : will be fired when an unset key is given a value. will pass the new value as parameter.
98   - * `key`':updated' : will be fired when a current key's value was changed. will pass the new value as parameter.
99   - * `key`':removed' : will be fired when a key has been removed from the state. will pas the key's last value as parameter.
100   - * `key`':changed' : will fire when any a key is added/updated. will pass the new value as parameter. *NOTE: this will fire alongside the add/updated events*
101   -
102   -HistoryManager: Example {#HistoryManager:Example}
103   ---------
104   -
105   - var HM = new HistoryManager();
106   -
107   - HM.addEvent( 'MyVar:added' , function(myvar){console.log('added '+myvar)} );
108   - HM.addEvent( 'MyVar:updated' , function(myvar){console.log('changed '+myvar)} );
109   - HM.addEvent( 'MyVar:removed' , function(myvar){console.log('removed '+myvar)} );
110   -
111   - /*
112   - * it is strongly recommended to set the events before starting the object.
113   - * this is because we want the hash to be analyzed when we enter the site through a bookmark/history.
114   - */
115   - HM.start();
116   -
117   - HM.set('MyVar',1); //will log 'added 1'
118   - HM.set('MyVar',2); //will log 'changed 2'
119   - HM.set('MyVar',3); //will log 'changed 3'
120   - HM.remove('MyVar');//will log 'removed 3'
121   -
122   - /*
123   - * pressing back button will log the following:
124   - * 1. added 3
125   - * 2. changed 2
126   - * 3. changed 1
127   - * 4. removed 1
128   - */
  1 +Class: HistoryManager {#HistoryManager}
  2 +==========================================
  3 +<big>This class is meant to function as a domain observer. It uses the browser-hash (via HashListener) to monitor and save the domain-state (enabling bookmarks and back/forward button functionality).
  4 +The class acts as a parameter stack, to monitor and modify the state of an application. Whenever a parameter withing the stack changes state, the class notifies its followers of the change.</big>
  5 +
  6 +HistoryManager Method: constructor {#HistoryManager:constructor}
  7 +----------------------------------
  8 +### Example:
  9 +
  10 + var HM = new HistoryManager(options);
  11 +
  12 +### Arguments:
  13 +
  14 +1. options - (`object`: optional) See below:
  15 +
  16 +### Options:
  17 +
  18 +* blank_page - (`string`: defaults to `blank.html`) an alternative path to the blank.html file.
  19 +* start - (`bool`: defaults to `false`) whether to start the listener on construction
  20 +* delimiter - (`string`: defaults no '') a beginning delimiter to add to the hash, to support the new Google AJAX syntax (#!)
  21 +* serializeHash - `string function (aHash)` (_Optional_, use with `deserializeHash`) A callback function which serializes a Hash
  22 +* deserializeHash - `Hash function (aString)` (_Optional_, use with `serializeHash`) A callback function which deserializes a String to a Hash
  23 +* compat - (`boolean` : defaults to `false`) whether to file deprecated event style as well (`key-added` aongside `key:added`)
  24 +
  25 +### Delimiter Usage:
  26 + var HM = new HistoryManager({delimiter:'!'}); //will add support for the google syntax
  27 +
  28 +### Custom (de)serializer Usage:
  29 + // using URI query syntax for data instead of JSON
  30 + var HM = new HistoryManager({
  31 + serializeHash: function (h) {
  32 + return h.toQueryString();
  33 + },
  34 + deserializeHash: function (s) {
  35 + return new Hash(s.parseQueryString());
  36 + }
  37 + });
  38 +
  39 +HistoryManager Method: Set {#HistoryManager:set}
  40 +---------------------------
  41 +<big>Used to set a state for the domain. Will set a key's value in the state.</big>
  42 +
  43 +### Example:
  44 +
  45 + HM.set(key,value);
  46 +
  47 +### Arguments:
  48 +
  49 +1. key - (`string`) A key identifier
  50 +2. elements - (`mixed`) whatever value you want to set to that key (must be JSON encodable)
  51 +
  52 +A note about set. Because of the way the hash is analyzed, changing the order of the inner members of a value will cuase a state-change event.
  53 +This is because i'm convering the objects to JSON instead of parsing them to save speed.
  54 +If you do not controll the order of the values in your objects, make sure you check this manuly.
  55 +An Example for this:
  56 +
  57 + HM.set('someValue',{a:'a',b:'b'});
  58 + HM.set('someValue',{b:'b',a:'a'}); //will fire someValue-changed although values aren't actualy modified.
  59 +
  60 +HistoryManager Method: Remove {#HistoryManager:remove}
  61 +-----------------------------
  62 +<big>Used to remove a state from the domain. Will remove `key` and its value from the state.</big>
  63 +
  64 +### Example:
  65 +
  66 + HM.remove('my-key');
  67 +
  68 +### Arguments:
  69 +
  70 +1. key - (`string`) A key identifier
  71 +
  72 +HistoryManager Method: Start {#HistoryManager:start}
  73 +----------------------------
  74 +<big>Will start the listener. This will enable the various events attached to the class.</big>
  75 +
  76 +### Example:
  77 +
  78 + HM.start();
  79 +
  80 +HistoryManager Method: Stop {#HistoryManager:stop}
  81 +---------------------------
  82 +<big>Will stop the event listener. When down, no events will be fired</big>
  83 +
  84 +### JavaScript:
  85 +
  86 + HM.stop();
  87 +
  88 +HistoryManaget: Events {#HistoryManager:Events}
  89 +-------
  90 +<big>The class is event-based, but doesn't have prefixed events. The events change according to the key being observed.
  91 +The names point to one of 3 states a value might be in: Added, Changed and Removed.</big>
  92 +For every change that goes on on a specific key, an event with that key's name will be fired, passing it's value as parameter.
  93 +
  94 +
  95 +<small>As of v1.1, all event names will be using colon seperation. For dash seperation, use the compat options.</small>
  96 +
  97 + * `key`':added' : will be fired when an unset key is given a value. will pass the new value as parameter.
  98 + * `key`':updated' : will be fired when a current key's value was changed. will pass the new value as parameter.
  99 + * `key`':removed' : will be fired when a key has been removed from the state. will pas the key's last value as parameter.
  100 + * `key`':changed' : will fire when any a key is added/updated. will pass the new value as parameter. *NOTE: this will fire alongside the add/updated events*
  101 +
  102 +HistoryManager: Example {#HistoryManager:Example}
  103 +--------
  104 +
  105 + var HM = new HistoryManager();
  106 +
  107 + HM.addEvent( 'MyVar:added' , function(myvar){console.log('added '+myvar)} );
  108 + HM.addEvent( 'MyVar:updated' , function(myvar){console.log('changed '+myvar)} );
  109 + HM.addEvent( 'MyVar:removed' , function(myvar){console.log('removed '+myvar)} );
  110 +
  111 + /*
  112 + * it is strongly recommended to set the events before starting the object.
  113 + * this is because we want the hash to be analyzed when we enter the site through a bookmark/history.
  114 + */
  115 + HM.start();
  116 +
  117 + HM.set('MyVar',1); //will log 'added 1'
  118 + HM.set('MyVar',2); //will log 'changed 2'
  119 + HM.set('MyVar',3); //will log 'changed 3'
  120 + HM.remove('MyVar');//will log 'removed 3'
  121 +
  122 + /*
  123 + * pressing back button will log the following:
  124 + * 1. added 3
  125 + * 2. changed 2
  126 + * 3. changed 1
  127 + * 4. removed 1
  128 + */
284 README.md
Source Rendered
... ... @@ -1,142 +1,142 @@
1   -HistoryManager
2   -================
3   -This library consists of 2 Classes:
4   -