mofo 0.2.10 → 0.2.11
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/Manifest.txt +11 -0
- data/Rakefile +12 -1
- data/lib/microformat.rb +5 -3
- data/lib/microformat/object.rb +5 -0
- data/lib/mofo/hentry.rb +51 -2
- data/site/favicon.ico +0 -0
- data/site/p.js +181 -0
- data/site/spinner.gif +0 -0
- data/site/try.html +6 -0
- data/site/try/index.html +6 -0
- data/site/try/p.js +181 -0
- data/site/try/spinner.gif +0 -0
- data/site/try/template.html +86 -0
- data/site/try/trymofo.rb +66 -0
- data/test/fixtures/hatom.html +9 -4
- data/test/hatom_test.rb +69 -2
- metadata +14 -3
data/Manifest.txt
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
./CHANGELOG
|
2
2
|
./init.rb
|
3
3
|
./lib/microformat/array.rb
|
4
|
+
./lib/microformat/object.rb
|
4
5
|
./lib/microformat/simple.rb
|
5
6
|
./lib/microformat/string.rb
|
6
7
|
./lib/microformat/time.rb
|
@@ -22,10 +23,19 @@
|
|
22
23
|
./Manifest.txt
|
23
24
|
./Rakefile
|
24
25
|
./README
|
26
|
+
./site/favicon.ico
|
25
27
|
./site/index.html
|
26
28
|
./site/mofo-logo.png
|
27
29
|
./site/mootools.v1.00.js
|
30
|
+
./site/p.js
|
31
|
+
./site/spinner.gif
|
28
32
|
./site/style.css
|
33
|
+
./site/try/index.html
|
34
|
+
./site/try/p.js
|
35
|
+
./site/try/spinner.gif
|
36
|
+
./site/try/template.html
|
37
|
+
./site/try/trymofo.rb
|
38
|
+
./site/try.html
|
29
39
|
./test/base_url_test.rb
|
30
40
|
./test/ext_test.rb
|
31
41
|
./test/fixtures/bob.html
|
@@ -50,6 +60,7 @@
|
|
50
60
|
./test/hreview_test.rb
|
51
61
|
./test/include_pattern_test.rb
|
52
62
|
./test/reltag_test.rb
|
63
|
+
./test/subclass_test.rb
|
53
64
|
./test/test_helper.rb
|
54
65
|
./test/xfn_test.rb
|
55
66
|
./test/xoxo_test.rb
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
gem 'echoe', '=1.3'
|
4
4
|
|
5
|
-
version = '0.2.
|
5
|
+
version = '0.2.11'
|
6
6
|
|
7
7
|
ENV['RUBY_FLAGS'] = ""
|
8
8
|
|
@@ -24,3 +24,14 @@ rescue LoadError => boom
|
|
24
24
|
puts "You are missing a dependency required for meta-operations on this gem."
|
25
25
|
puts "#{boom.to_s.capitalize}."
|
26
26
|
end
|
27
|
+
|
28
|
+
desc 'Generate RDoc documentation for mofo.'
|
29
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
30
|
+
files = ['README', 'LICENSE', 'lib/**/*.rb']
|
31
|
+
rdoc.rdoc_files.add(files)
|
32
|
+
rdoc.main = "README" # page to start on
|
33
|
+
rdoc.title = "mofo"
|
34
|
+
rdoc.template = File.exists?(t="/Users/chris/ruby/projects/err/rock/template.rb") ? t : "/var/www/rock/template.rb"
|
35
|
+
rdoc.rdoc_dir = 'doc' # rdoc output folder
|
36
|
+
rdoc.options << '--inline-source'
|
37
|
+
end
|
data/lib/microformat.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
%w(rubygems set hpricot microformat/string microformat/array open-uri ostruct timeout).each { |f| require f }
|
1
|
+
%w(rubygems set hpricot microformat/object microformat/string microformat/array open-uri ostruct timeout).each { |f| require f }
|
2
2
|
gem 'hpricot', '>=0.4.59'
|
3
3
|
|
4
4
|
class Microformat
|
@@ -153,10 +153,11 @@ class Microformat
|
|
153
153
|
|
154
154
|
def build_class(microformat)
|
155
155
|
hash = build_hash(microformat)
|
156
|
-
class_eval { attr_reader *(hash.keys << :properties) }
|
156
|
+
class_eval { attr_reader *(hash.keys << :properties); attr_reader :base_url }
|
157
157
|
|
158
158
|
klass = new
|
159
159
|
klass.instance_variable_set(:@properties, hash.keys.map { |i| i.to_s } )
|
160
|
+
klass.instance_variable_set(:@base_url, @options[:base_url])
|
160
161
|
|
161
162
|
hash.each do |key, value|
|
162
163
|
klass.instance_variable_set("@#{key}", prepare_value(value) )
|
@@ -285,7 +286,8 @@ class Microformat
|
|
285
286
|
when 'img' then element['alt']
|
286
287
|
end || ''
|
287
288
|
|
288
|
-
(value.empty? ? element.innerHTML : value).strip
|
289
|
+
ret = (value.empty? ? element.innerHTML : value).strip
|
290
|
+
target == :html ? ret : ret.strip_html.coerce
|
289
291
|
end
|
290
292
|
end
|
291
293
|
|
data/lib/mofo/hentry.rb
CHANGED
@@ -2,14 +2,63 @@
|
|
2
2
|
require 'microformat'
|
3
3
|
require 'mofo/hcard'
|
4
4
|
require 'mofo/rel_tag'
|
5
|
+
require 'mofo/rel_bookmark'
|
6
|
+
require 'digest/md5'
|
5
7
|
|
6
8
|
class HEntry < Microformat
|
7
9
|
one :entry_title, :entry_summary, :updated, :published,
|
8
10
|
:author => HCard
|
9
11
|
|
10
|
-
many :entry_content, :tags => RelTag
|
12
|
+
many :entry_content => :html, :tags => RelTag
|
11
13
|
|
12
14
|
after_find do
|
13
|
-
@updated
|
15
|
+
@updated ||= @published if @published
|
16
|
+
end
|
17
|
+
|
18
|
+
def atom_id
|
19
|
+
"<id>tag:#{@base_url.sub('http://','')},#{Date.today.year}:#{Digest::MD5.hexdigest(entry_content)}</id>"
|
20
|
+
end
|
21
|
+
|
22
|
+
def atom_link
|
23
|
+
%(<link type="text/html" href="#{@base_url}#{@bookmark}" rel="alternate"/>)
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_atom(property = nil, value = nil)
|
27
|
+
if property
|
28
|
+
value ||= instance_variable_get("@#{property}")
|
29
|
+
return value ? ("<#{property}>%s</#{property}>" % value) : nil
|
30
|
+
end
|
31
|
+
|
32
|
+
entity = <<-atom_entity
|
33
|
+
<entry>
|
34
|
+
#{atom_id}
|
35
|
+
#{atom_link}
|
36
|
+
#{to_atom :title, @entry_title}
|
37
|
+
<content type="html">#{@entry_content}</content>
|
38
|
+
#{to_atom :updated}
|
39
|
+
#{to_atom :published}
|
40
|
+
<author>
|
41
|
+
#{to_atom :name, @author.try(:fn)}
|
42
|
+
#{to_atom :email, @author.try(:email)}
|
43
|
+
</author>
|
44
|
+
</entry>
|
45
|
+
atom_entity
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Array
|
50
|
+
def to_atom(options = {})
|
51
|
+
entries = map { |entry| entry.try(:to_atom) }.compact.join("\n")
|
52
|
+
<<-end_atom
|
53
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
54
|
+
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
|
55
|
+
<id>#{first.atom_id}</id>
|
56
|
+
<link type="text/html" href="#{first.base_url}" rel="alternate"/>
|
57
|
+
<link type="application/atom+xml" href="" rel="self"/>
|
58
|
+
<title>#{options[:title]}</title>
|
59
|
+
<updated>#{first.updated || first.published}</updated>
|
60
|
+
#{entries}
|
61
|
+
</feed>
|
62
|
+
end_atom
|
14
63
|
end
|
15
64
|
end
|
data/site/favicon.ico
ADDED
Binary file
|
data/site/p.js
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
|
2
|
+
var Prototype={Version:'1.5.0_rc2',BrowserFeatures:{XPath:!!document.evaluate},ScriptFragment:'(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)',emptyFunction:function(){},K:function(x){return x}}
|
3
|
+
var Class={create:function(){return function(){this.initialize.apply(this,arguments);}}}
|
4
|
+
var Abstract=new Object();Object.extend=function(destination,source){for(var property in source){destination[property]=source[property];}
|
5
|
+
return destination;}
|
6
|
+
Object.extend(Object,{inspect:function(object){try{if(object===undefined)return'undefined';if(object===null)return'null';return object.inspect?object.inspect():object.toString();}catch(e){if(e instanceof RangeError)return'...';throw e;}},keys:function(object){var keys=[];for(var property in object)
|
7
|
+
keys.push(property);return keys;},values:function(object){var values=[];for(var property in object)
|
8
|
+
values.push(object[property]);return values;},clone:function(object){return Object.extend({},object);}});Function.prototype.bind=function(){var __method=this,args=$A(arguments),object=args.shift();return function(){return __method.apply(object,args.concat($A(arguments)));}}
|
9
|
+
Function.prototype.bindAsEventListener=function(object){var __method=this,args=$A(arguments),object=args.shift();return function(event){return __method.apply(object,[(event||window.event)].concat(args).concat($A(arguments)));}}
|
10
|
+
Object.extend(Number.prototype,{toColorPart:function(){var digits=this.toString(16);if(this<16)return'0'+digits;return digits;},succ:function(){return this+1;},times:function(iterator){$R(0,this,true).each(iterator);return this;}});var Try={these:function(){var returnValue;for(var i=0,length=arguments.length;i<length;i++){var lambda=arguments[i];try{returnValue=lambda();break;}catch(e){}}
|
11
|
+
return returnValue;}}
|
12
|
+
var PeriodicalExecuter=Class.create();PeriodicalExecuter.prototype={initialize:function(callback,frequency){this.callback=callback;this.frequency=frequency;this.currentlyExecuting=false;this.registerCallback();},registerCallback:function(){this.timer=setInterval(this.onTimerEvent.bind(this),this.frequency*1000);},stop:function(){if(!this.timer)return;clearInterval(this.timer);this.timer=null;},onTimerEvent:function(){if(!this.currentlyExecuting){try{this.currentlyExecuting=true;this.callback(this);}finally{this.currentlyExecuting=false;}}}}
|
13
|
+
Object.extend(String.prototype,{gsub:function(pattern,replacement){var result='',source=this,match;replacement=arguments.callee.prepareReplacement(replacement);while(source.length>0){if(match=source.match(pattern)){result+=source.slice(0,match.index);result+=(replacement(match)||'').toString();source=source.slice(match.index+match[0].length);}else{result+=source,source='';}}
|
14
|
+
return result;},sub:function(pattern,replacement,count){replacement=this.gsub.prepareReplacement(replacement);count=count===undefined?1:count;return this.gsub(pattern,function(match){if(--count<0)return match[0];return replacement(match);});},scan:function(pattern,iterator){this.gsub(pattern,iterator);return this;},truncate:function(length,truncation){length=length||30;truncation=truncation===undefined?'...':truncation;return this.length>length?this.slice(0,length-truncation.length)+truncation:this;},strip:function(){return this.replace(/^\s+/,'').replace(/\s+$/,'');},stripTags:function(){return this.replace(/<\/?[^>]+>/gi,'');},stripScripts:function(){return this.replace(new RegExp(Prototype.ScriptFragment,'img'),'');},extractScripts:function(){var matchAll=new RegExp(Prototype.ScriptFragment,'img');var matchOne=new RegExp(Prototype.ScriptFragment,'im');return(this.match(matchAll)||[]).map(function(scriptTag){return(scriptTag.match(matchOne)||['',''])[1];});},evalScripts:function(){return this.extractScripts().map(function(script){return eval(script)});},escapeHTML:function(){var div=document.createElement('div');var text=document.createTextNode(this);div.appendChild(text);return div.innerHTML;},unescapeHTML:function(){var div=document.createElement('div');div.innerHTML=this.stripTags();return div.childNodes[0]?(div.childNodes.length>1?$A(div.childNodes).inject('',function(memo,node){return memo+node.nodeValue}):div.childNodes[0].nodeValue):'';},toQueryParams:function(separator){var match=this.strip().match(/([^?#]*)(#.*)?$/);if(!match)return{};return match[1].split(separator||'&').inject({},function(hash,pair){if((pair=pair.split('='))[0]){var name=decodeURIComponent(pair[0]);var value=pair[1]?decodeURIComponent(pair[1]):undefined;if(hash[name]!==undefined){if(hash[name].constructor!=Array)
|
15
|
+
hash[name]=[hash[name]];if(value)hash[name].push(value);}
|
16
|
+
else hash[name]=value;}
|
17
|
+
return hash;});},toArray:function(){return this.split('');},camelize:function(){var oStringList=this.split('-');if(oStringList.length==1)return oStringList[0];var camelizedString=this.indexOf('-')==0?oStringList[0].charAt(0).toUpperCase()+oStringList[0].substring(1):oStringList[0];for(var i=1,length=oStringList.length;i<length;i++){var s=oStringList[i];camelizedString+=s.charAt(0).toUpperCase()+s.substring(1);}
|
18
|
+
return camelizedString;},underscore:function(){return this.gsub(/::/,'/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'-').toLowerCase();},dasherize:function(){return this.gsub(/_/,'-');},inspect:function(useDoubleQuotes){var escapedString=this.replace(/\\/g,'\\\\');if(useDoubleQuotes)
|
19
|
+
return'"'+escapedString.replace(/"/g,'\\"')+'"';else
|
20
|
+
return"'"+escapedString.replace(/'/g,'\\\'')+"'";}});String.prototype.gsub.prepareReplacement=function(replacement){if(typeof replacement=='function')return replacement;var template=new Template(replacement);return function(match){return template.evaluate(match)};}
|
21
|
+
String.prototype.parseQuery=String.prototype.toQueryParams;var Template=Class.create();Template.Pattern=/(^|.|\r|\n)(#\{(.*?)\})/;Template.prototype={initialize:function(template,pattern){this.template=template.toString();this.pattern=pattern||Template.Pattern;},evaluate:function(object){return this.template.gsub(this.pattern,function(match){var before=match[1];if(before=='\\')return match[2];return before+(object[match[3]]||'').toString();});}}
|
22
|
+
var $break=new Object();var $continue=new Object();var Enumerable={each:function(iterator){var index=0;try{this._each(function(value){try{iterator(value,index++);}catch(e){if(e!=$continue)throw e;}});}catch(e){if(e!=$break)throw e;}
|
23
|
+
return this;},eachSlice:function(number,iterator){var index=-number,slices=[],array=this.toArray();while((index+=number)<array.length)
|
24
|
+
slices.push(array.slice(index,index+number));return slices.collect(iterator||Prototype.K);},all:function(iterator){var result=true;this.each(function(value,index){result=result&&!!(iterator||Prototype.K)(value,index);if(!result)throw $break;});return result;},any:function(iterator){var result=false;this.each(function(value,index){if(result=!!(iterator||Prototype.K)(value,index))
|
25
|
+
throw $break;});return result;},collect:function(iterator){var results=[];this.each(function(value,index){results.push(iterator(value,index));});return results;},detect:function(iterator){var result;this.each(function(value,index){if(iterator(value,index)){result=value;throw $break;}});return result;},findAll:function(iterator){var results=[];this.each(function(value,index){if(iterator(value,index))
|
26
|
+
results.push(value);});return results;},grep:function(pattern,iterator){var results=[];this.each(function(value,index){var stringValue=value.toString();if(stringValue.match(pattern))
|
27
|
+
results.push((iterator||Prototype.K)(value,index));})
|
28
|
+
return results;},include:function(object){var found=false;this.each(function(value){if(value==object){found=true;throw $break;}});return found;},inGroupsOf:function(number,fillWith){fillWith=fillWith||null;var results=this.eachSlice(number);if(results.length>0)(number-results.last().length).times(function(){results.last().push(fillWith)});return results;},inject:function(memo,iterator){this.each(function(value,index){memo=iterator(memo,value,index);});return memo;},invoke:function(method){var args=$A(arguments).slice(1);return this.collect(function(value){return value[method].apply(value,args);});},max:function(iterator){var result;this.each(function(value,index){value=(iterator||Prototype.K)(value,index);if(result==undefined||value>=result)
|
29
|
+
result=value;});return result;},min:function(iterator){var result;this.each(function(value,index){value=(iterator||Prototype.K)(value,index);if(result==undefined||value<result)
|
30
|
+
result=value;});return result;},partition:function(iterator){var trues=[],falses=[];this.each(function(value,index){((iterator||Prototype.K)(value,index)?trues:falses).push(value);});return[trues,falses];},pluck:function(property){var results=[];this.each(function(value,index){results.push(value[property]);});return results;},reject:function(iterator){var results=[];this.each(function(value,index){if(!iterator(value,index))
|
31
|
+
results.push(value);});return results;},sortBy:function(iterator){return this.collect(function(value,index){return{value:value,criteria:iterator(value,index)};}).sort(function(left,right){var a=left.criteria,b=right.criteria;return a<b?-1:a>b?1:0;}).pluck('value');},toArray:function(){return this.collect(Prototype.K);},zip:function(){var iterator=Prototype.K,args=$A(arguments);if(typeof args.last()=='function')
|
32
|
+
iterator=args.pop();var collections=[this].concat(args).map($A);return this.map(function(value,index){return iterator(collections.pluck(index));});},inspect:function(){return'#<Enumerable:'+this.toArray().inspect()+'>';}}
|
33
|
+
Object.extend(Enumerable,{map:Enumerable.collect,find:Enumerable.detect,select:Enumerable.findAll,member:Enumerable.include,entries:Enumerable.toArray});var $A=Array.from=function(iterable){if(!iterable)return[];if(iterable.toArray){return iterable.toArray();}else{var results=[];for(var i=0,length=iterable.length;i<length;i++)
|
34
|
+
results.push(iterable[i]);return results;}}
|
35
|
+
Object.extend(Array.prototype,Enumerable);if(!Array.prototype._reverse)
|
36
|
+
Array.prototype._reverse=Array.prototype.reverse;Object.extend(Array.prototype,{_each:function(iterator){for(var i=0,length=this.length;i<length;i++)
|
37
|
+
iterator(this[i]);},clear:function(){this.length=0;return this;},first:function(){return this[0];},last:function(){return this[this.length-1];},compact:function(){return this.select(function(value){return value!=undefined||value!=null;});},flatten:function(){return this.inject([],function(array,value){return array.concat(value&&value.constructor==Array?value.flatten():[value]);});},without:function(){var values=$A(arguments);return this.select(function(value){return!values.include(value);});},indexOf:function(object){for(var i=0,length=this.length;i<length;i++)
|
38
|
+
if(this[i]==object)return i;return-1;},reverse:function(inline){return(inline!==false?this:this.toArray())._reverse();},reduce:function(){return this.length>1?this:this[0];},uniq:function(){return this.inject([],function(array,value){return array.include(value)?array:array.concat([value]);});},clone:function(){return[].concat(this);},inspect:function(){return'['+this.map(Object.inspect).join(', ')+']';}});Array.prototype.toArray=Array.prototype.clone;if(window.opera){Array.prototype.concat=function(){var array=[];for(var i=0,length=this.length;i<length;i++)array.push(this[i]);for(var i=0,length=arguments.length;i<length;i++){if(arguments[i].constructor==Array){for(var j=0,arrayLength=arguments[i].length;j<arrayLength;j++)
|
39
|
+
array.push(arguments[i][j]);}else{array.push(arguments[i]);}}
|
40
|
+
return array;}}
|
41
|
+
var Hash={_each:function(iterator){for(var key in this){var value=this[key];if(typeof value=='function')continue;var pair=[key,value];pair.key=key;pair.value=value;iterator(pair);}},keys:function(){return this.pluck('key');},values:function(){return this.pluck('value');},merge:function(hash){return $H(hash).inject(this,function(mergedHash,pair){mergedHash[pair.key]=pair.value;return mergedHash;});},toQueryString:function(){return this.map(function(pair){if(!pair.key)return null;if(pair.value&&pair.value.constructor==Array){pair.value=pair.value.compact();if(pair.value.length<2){pair.value=pair.value.reduce();}else{var key=encodeURIComponent(pair.key);return pair.value.map(function(value){return key+'='+encodeURIComponent(value);}).join('&');}}
|
42
|
+
if(pair.value==undefined)pair[1]='';return pair.map(encodeURIComponent).join('=');}).join('&');},inspect:function(){return'#<Hash:{'+this.map(function(pair){return pair.map(Object.inspect).join(': ');}).join(', ')+'}>';}}
|
43
|
+
function $H(object){var hash=Object.extend({},object||{});Object.extend(hash,Enumerable);Object.extend(hash,Hash);return hash;}
|
44
|
+
ObjectRange=Class.create();Object.extend(ObjectRange.prototype,Enumerable);Object.extend(ObjectRange.prototype,{initialize:function(start,end,exclusive){this.start=start;this.end=end;this.exclusive=exclusive;},_each:function(iterator){var value=this.start;while(this.include(value)){iterator(value);value=value.succ();}},include:function(value){if(value<this.start)
|
45
|
+
return false;if(this.exclusive)
|
46
|
+
return value<this.end;return value<=this.end;}});var $R=function(start,end,exclusive){return new ObjectRange(start,end,exclusive);}
|
47
|
+
var Ajax={getTransport:function(){return Try.these(function(){return new XMLHttpRequest()},function(){return new ActiveXObject('Msxml2.XMLHTTP')},function(){return new ActiveXObject('Microsoft.XMLHTTP')})||false;},activeRequestCount:0}
|
48
|
+
Ajax.Responders={responders:[],_each:function(iterator){this.responders._each(iterator);},register:function(responder){if(!this.include(responder))
|
49
|
+
this.responders.push(responder);},unregister:function(responder){this.responders=this.responders.without(responder);},dispatch:function(callback,request,transport,json){this.each(function(responder){if(typeof responder[callback]=='function'){try{responder[callback].apply(responder,[request,transport,json]);}catch(e){}}});}};Object.extend(Ajax.Responders,Enumerable);Ajax.Responders.register({onCreate:function(){Ajax.activeRequestCount++;},onComplete:function(){Ajax.activeRequestCount--;}});Ajax.Base=function(){};Ajax.Base.prototype={setOptions:function(options){this.options={method:'post',asynchronous:true,contentType:'application/x-www-form-urlencoded',encoding:'UTF-8',parameters:''}
|
50
|
+
Object.extend(this.options,options||{});this.options.method=this.options.method.toLowerCase();this.options.parameters=$H(typeof this.options.parameters=='string'?this.options.parameters.toQueryParams():this.options.parameters);}}
|
51
|
+
Ajax.Request=Class.create();Ajax.Request.Events=['Uninitialized','Loading','Loaded','Interactive','Complete'];Ajax.Request.prototype=Object.extend(new Ajax.Base(),{_complete:false,initialize:function(url,options){this.transport=Ajax.getTransport();this.setOptions(options);this.request(url);},request:function(url){var params=this.options.parameters;if(params.any())params['_']='';if(!['get','post'].include(this.options.method)){params['_method']=this.options.method;this.options.method='post';}
|
52
|
+
this.url=url;if(this.options.method=='get'&¶ms.any())
|
53
|
+
this.url+=(this.url.indexOf('?')>=0?'&':'?')+
|
54
|
+
params.toQueryString();try{Ajax.Responders.dispatch('onCreate',this,this.transport);this.transport.open(this.options.method.toUpperCase(),this.url,this.options.asynchronous,this.options.username,this.options.password);if(this.options.asynchronous)
|
55
|
+
setTimeout(function(){this.respondToReadyState(1)}.bind(this),10);this.transport.onreadystatechange=this.onStateChange.bind(this);this.setRequestHeaders();var body=this.options.method=='post'?(this.options.postBody||params.toQueryString()):null;this.transport.send(body);if(!this.options.asynchronous&&this.transport.overrideMimeType)
|
56
|
+
this.onStateChange();}
|
57
|
+
catch(e){this.dispatchException(e);}},onStateChange:function(){var readyState=this.transport.readyState;if(readyState>1&&!((readyState==4)&&this._complete))
|
58
|
+
this.respondToReadyState(this.transport.readyState);},setRequestHeaders:function(){var headers={'X-Requested-With':'XMLHttpRequest','X-Prototype-Version':Prototype.Version,'Accept':'text/javascript, text/html, application/xml, text/xml, */*'};if(this.options.method=='post'){headers['Content-type']=this.options.contentType+
|
59
|
+
(this.options.encoding?'; charset='+this.options.encoding:'');if(this.transport.overrideMimeType&&(navigator.userAgent.match(/Gecko\/(\d{4})/)||[0,2005])[1]<2005)
|
60
|
+
headers['Connection']='close';}
|
61
|
+
if(typeof this.options.requestHeaders=='object'){var extras=this.options.requestHeaders;if(typeof extras.push=='function')
|
62
|
+
for(var i=0,length=extras.length;i<length;i+=2)
|
63
|
+
headers[extras[i]]=extras[i+1];else
|
64
|
+
$H(extras).each(function(pair){headers[pair.key]=pair.value});}
|
65
|
+
for(var name in headers)
|
66
|
+
this.transport.setRequestHeader(name,headers[name]);},success:function(){return!this.transport.status||(this.transport.status>=200&&this.transport.status<300);},respondToReadyState:function(readyState){var state=Ajax.Request.Events[readyState];var transport=this.transport,json=this.evalJSON();if(state=='Complete'){try{this._complete=true;(this.options['on'+this.transport.status]||this.options['on'+(this.success()?'Success':'Failure')]||Prototype.emptyFunction)(transport,json);}catch(e){this.dispatchException(e);}}
|
67
|
+
try{(this.options['on'+state]||Prototype.emptyFunction)(transport,json);Ajax.Responders.dispatch('on'+state,this,transport,json);}catch(e){this.dispatchException(e);}
|
68
|
+
if(state=='Complete'){if((this.getHeader('Content-type')||'').strip().match(/^(text|application)\/(x-)?(java|ecma)script(;.*)?$/i))
|
69
|
+
this.evalResponse();this.transport.onreadystatechange=Prototype.emptyFunction;}},getHeader:function(name){try{return this.transport.getResponseHeader(name);}catch(e){return null}},evalJSON:function(){try{var json=this.getHeader('X-JSON');return json?eval('('+json+')'):null;}catch(e){return null}},evalResponse:function(){try{return eval(this.transport.responseText);}catch(e){this.dispatchException(e);}},dispatchException:function(exception){(this.options.onException||Prototype.emptyFunction)(this,exception);Ajax.Responders.dispatch('onException',this,exception);}});Ajax.Updater=Class.create();Object.extend(Object.extend(Ajax.Updater.prototype,Ajax.Request.prototype),{initialize:function(container,url,options){this.container={success:(container.success||container),failure:(container.failure||(container.success?null:container))}
|
70
|
+
this.transport=Ajax.getTransport();this.setOptions(options);var onComplete=this.options.onComplete||Prototype.emptyFunction;this.options.onComplete=(function(transport,param){this.updateContent();onComplete(transport,param);}).bind(this);this.request(url);},updateContent:function(){var receiver=this.container[this.success()?'success':'failure'];var response=this.transport.responseText;if(!this.options.evalScripts)response=response.stripScripts();if(receiver=$(receiver)){if(this.options.insertion)
|
71
|
+
new this.options.insertion(receiver,response);else
|
72
|
+
receiver.update(response);}
|
73
|
+
if(this.success()){if(this.onComplete)
|
74
|
+
setTimeout(this.onComplete.bind(this),10);}}});Ajax.PeriodicalUpdater=Class.create();Ajax.PeriodicalUpdater.prototype=Object.extend(new Ajax.Base(),{initialize:function(container,url,options){this.setOptions(options);this.onComplete=this.options.onComplete;this.frequency=(this.options.frequency||2);this.decay=(this.options.decay||1);this.updater={};this.container=container;this.url=url;this.start();},start:function(){this.options.onComplete=this.updateComplete.bind(this);this.onTimerEvent();},stop:function(){this.updater.options.onComplete=undefined;clearTimeout(this.timer);(this.onComplete||Prototype.emptyFunction).apply(this,arguments);},updateComplete:function(request){if(this.options.decay){this.decay=(request.responseText==this.lastText?this.decay*this.options.decay:1);this.lastText=request.responseText;}
|
75
|
+
this.timer=setTimeout(this.onTimerEvent.bind(this),this.decay*this.frequency*1000);},onTimerEvent:function(){this.updater=new Ajax.Updater(this.container,this.url,this.options);}});function $(element){if(arguments.length>1){for(var i=0,elements=[],length=arguments.length;i<length;i++)
|
76
|
+
elements.push($(arguments[i]));return elements;}
|
77
|
+
if(typeof element=='string')
|
78
|
+
element=document.getElementById(element);return Element.extend(element);}
|
79
|
+
if(Prototype.BrowserFeatures.XPath){document._getElementsByXPath=function(expression,parentElement){var results=[];var query=document.evaluate(expression,$(parentElement)||document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);for(var i=0,length=query.snapshotLength;i<length;i++)
|
80
|
+
results.push(query.snapshotItem(i));return results;}}
|
81
|
+
document.getElementsByClassName=function(className,parentElement){if(Prototype.BrowserFeatures.XPath){var q=".//*[contains(concat(' ', @class, ' '), ' "+className+" ')]";return document._getElementsByXPath(q,parentElement);}else{var children=($(parentElement)||document.body).getElementsByTagName('*');var elements=[],child;for(var i=0,length=children.length;i<length;i++){child=children[i];if(Element.hasClassName(child,className))
|
82
|
+
elements.push(Element.extend(child));}
|
83
|
+
return elements;}}
|
84
|
+
if(!window.Element)
|
85
|
+
var Element=new Object();Element.extend=function(element){if(!element)return;if(_nativeExtensions||element.nodeType==3)return element;if(!element._extended&&element.tagName&&element!=window){var methods=Object.clone(Element.Methods),cache=Element.extend.cache;if(element.tagName=='FORM')
|
86
|
+
Object.extend(methods,Form.Methods);if(['INPUT','TEXTAREA','SELECT'].include(element.tagName))
|
87
|
+
Object.extend(methods,Form.Element.Methods);Object.extend(methods,Element.Methods.Simulated);for(var property in methods){var value=methods[property];if(typeof value=='function'&&!(property in element))
|
88
|
+
element[property]=cache.findOrStore(value);}}
|
89
|
+
element._extended=true;return element;}
|
90
|
+
Element.extend.cache={findOrStore:function(value){return this[value]=this[value]||function(){return value.apply(null,[this].concat($A(arguments)));}}}
|
91
|
+
Element.Methods={visible:function(element){return $(element).style.display!='none';},toggle:function(element){element=$(element);Element[Element.visible(element)?'hide':'show'](element);return element;},hide:function(element){$(element).style.display='none';return element;},show:function(element){$(element).style.display='';return element;},remove:function(element){element=$(element);element.parentNode.removeChild(element);return element;},update:function(element,html){html=typeof html=='undefined'?'':html.toString();$(element).innerHTML=html.stripScripts();setTimeout(function(){html.evalScripts()},10);return element;},replace:function(element,html){element=$(element);if(element.outerHTML){element.outerHTML=html.stripScripts();}else{var range=element.ownerDocument.createRange();range.selectNodeContents(element);element.parentNode.replaceChild(range.createContextualFragment(html.stripScripts()),element);}
|
92
|
+
setTimeout(function(){html.evalScripts()},10);return element;},inspect:function(element){element=$(element);var result='<'+element.tagName.toLowerCase();$H({'id':'id','className':'class'}).each(function(pair){var property=pair.first(),attribute=pair.last();var value=(element[property]||'').toString();if(value)result+=' '+attribute+'='+value.inspect(true);});return result+'>';},recursivelyCollect:function(element,property){element=$(element);var elements=[];while(element=element[property])
|
93
|
+
if(element.nodeType==1)
|
94
|
+
elements.push(Element.extend(element));return elements;},ancestors:function(element){return $(element).recursivelyCollect('parentNode');},descendants:function(element){element=$(element);return $A(element.getElementsByTagName('*'));},immediateDescendants:function(element){if(!(element=$(element).firstChild))return[];while(element&&element.nodeType!=1)element=element.nextSibling;if(element)return[element].concat($(element).nextSiblings());return[];},previousSiblings:function(element){return $(element).recursivelyCollect('previousSibling');},nextSiblings:function(element){return $(element).recursivelyCollect('nextSibling');},siblings:function(element){element=$(element);return element.previousSiblings().reverse().concat(element.nextSiblings());},match:function(element,selector){element=$(element);if(typeof selector=='string')
|
95
|
+
selector=new Selector(selector);return selector.match(element);},up:function(element,expression,index){return Selector.findElement($(element).ancestors(),expression,index);},down:function(element,expression,index){return Selector.findElement($(element).descendants(),expression,index);},previous:function(element,expression,index){return Selector.findElement($(element).previousSiblings(),expression,index);},next:function(element,expression,index){return Selector.findElement($(element).nextSiblings(),expression,index);},getElementsBySelector:function(){var args=$A(arguments),element=$(args.shift());return Selector.findChildElements(element,args);},getElementsByClassName:function(element,className){element=$(element);return document.getElementsByClassName(className,element);},readAttribute:function(element,name){return $(element).getAttribute(name);},getHeight:function(element){element=$(element);return element.offsetHeight;},classNames:function(element){return new Element.ClassNames(element);},hasClassName:function(element,className){if(!(element=$(element)))return;var elementClassName=element.className;if(elementClassName.length==0)return false;if(elementClassName==className||elementClassName.match(new RegExp("(^|\\s)"+className+"(\\s|$)")))
|
96
|
+
return true;return false;},addClassName:function(element,className){if(!(element=$(element)))return;Element.classNames(element).add(className);return element;},removeClassName:function(element,className){if(!(element=$(element)))return;Element.classNames(element).remove(className);return element;},observe:function(){Event.observe.apply(Event,arguments);return $A(arguments).first();},stopObserving:function(){Event.stopObserving.apply(Event,arguments);return $A(arguments).first();},cleanWhitespace:function(element){element=$(element);var node=element.firstChild;while(node){var nextNode=node.nextSibling;if(node.nodeType==3&&!/\S/.test(node.nodeValue))
|
97
|
+
element.removeChild(node);node=nextNode;}
|
98
|
+
return element;},empty:function(element){return $(element).innerHTML.match(/^\s*$/);},childOf:function(element,ancestor){element=$(element),ancestor=$(ancestor);while(element=element.parentNode)
|
99
|
+
if(element==ancestor)return true;return false;},scrollTo:function(element){element=$(element);var x=element.x?element.x:element.offsetLeft,y=element.y?element.y:element.offsetTop;window.scrollTo(x,y);return element;},getStyle:function(element,style){element=$(element);var inline=(style=='float'?(typeof element.style.styleFloat!='undefined'?'styleFloat':'cssFloat'):style);var value=element.style[inline.camelize()];if(!value){if(document.defaultView&&document.defaultView.getComputedStyle){var css=document.defaultView.getComputedStyle(element,null);value=css?css.getPropertyValue(style):null;}else if(element.currentStyle){value=element.currentStyle[inline.camelize()];}}
|
100
|
+
if((value=='auto')&&['width','height'].include(style)&&(element.getStyle('display')!='none'))
|
101
|
+
value=element['offset'+style.charAt(0).toUpperCase()+style.substring(1)]+'px';if(window.opera&&['left','top','right','bottom'].include(style))
|
102
|
+
if(Element.getStyle(element,'position')=='static')value='auto';return value=='auto'?null:value;},setStyle:function(element,style){element=$(element);for(var name in style)
|
103
|
+
element.style[(name=='float'?((typeof element.style.styleFloat!='undefined')?'styleFloat':'cssFloat'):name).camelize()]=style[name];return element;},getDimensions:function(element){element=$(element);if(Element.getStyle(element,'display')!='none')
|
104
|
+
return{width:element.offsetWidth,height:element.offsetHeight};var els=element.style;var originalVisibility=els.visibility;var originalPosition=els.position;els.visibility='hidden';els.position='absolute';els.display='';var originalWidth=element.clientWidth;var originalHeight=element.clientHeight;els.display='none';els.position=originalPosition;els.visibility=originalVisibility;return{width:originalWidth,height:originalHeight};},makePositioned:function(element){element=$(element);var pos=Element.getStyle(element,'position');if(pos=='static'||!pos){element._madePositioned=true;element.style.position='relative';if(window.opera){element.style.top=0;element.style.left=0;}}
|
105
|
+
return element;},undoPositioned:function(element){element=$(element);if(element._madePositioned){element._madePositioned=undefined;element.style.position=element.style.top=element.style.left=element.style.bottom=element.style.right='';}
|
106
|
+
return element;},makeClipping:function(element){element=$(element);if(element._overflow)return element;element._overflow=element.style.overflow||'auto';if((Element.getStyle(element,'overflow')||'visible')!='hidden')
|
107
|
+
element.style.overflow='hidden';return element;},undoClipping:function(element){element=$(element);if(!element._overflow)return element;element.style.overflow=element._overflow=='auto'?'':element._overflow;element._overflow=null;return element;}}
|
108
|
+
Element.Methods.Simulated={hasAttribute:function(element,attribute){return $(element).getAttributeNode(attribute).specified;}}
|
109
|
+
if(document.all){Element.Methods.update=function(element,html){element=$(element);html=typeof html=='undefined'?'':html.toString();var tagName=element.tagName.toUpperCase();if(['THEAD','TBODY','TR','TD'].include(tagName)){var div=document.createElement('div');switch(tagName){case'THEAD':case'TBODY':div.innerHTML='<table><tbody>'+html.stripScripts()+'</tbody></table>';depth=2;break;case'TR':div.innerHTML='<table><tbody><tr>'+html.stripScripts()+'</tr></tbody></table>';depth=3;break;case'TD':div.innerHTML='<table><tbody><tr><td>'+html.stripScripts()+'</td></tr></tbody></table>';depth=4;}
|
110
|
+
$A(element.childNodes).each(function(node){element.removeChild(node)});depth.times(function(){div=div.firstChild});$A(div.childNodes).each(function(node){element.appendChild(node)});}else{element.innerHTML=html.stripScripts();}
|
111
|
+
setTimeout(function(){html.evalScripts()},10);return element;}}
|
112
|
+
Object.extend(Element,Element.Methods);var _nativeExtensions=false;if(/Konqueror|Safari|KHTML/.test(navigator.userAgent))
|
113
|
+
['','Form','Input','TextArea','Select'].each(function(tag){var className='HTML'+tag+'Element';if(window[className])return;var klass=window[className]={};klass.prototype=document.createElement(tag?tag.toLowerCase():'div').__proto__;});Element.addMethods=function(methods){Object.extend(Element.Methods,methods||{});function copy(methods,destination,onlyIfAbsent){onlyIfAbsent=onlyIfAbsent||false;var cache=Element.extend.cache;for(var property in methods){var value=methods[property];if(!onlyIfAbsent||!(property in destination))
|
114
|
+
destination[property]=cache.findOrStore(value);}}
|
115
|
+
if(typeof HTMLElement!='undefined'){copy(Element.Methods,HTMLElement.prototype);copy(Element.Methods.Simulated,HTMLElement.prototype,true);copy(Form.Methods,HTMLFormElement.prototype);[HTMLInputElement,HTMLTextAreaElement,HTMLSelectElement].each(function(klass){copy(Form.Element.Methods,klass.prototype);});_nativeExtensions=true;}}
|
116
|
+
var Toggle=new Object();Toggle.display=Element.toggle;Abstract.Insertion=function(adjacency){this.adjacency=adjacency;}
|
117
|
+
Abstract.Insertion.prototype={initialize:function(element,content){this.element=$(element);this.content=content.stripScripts();if(this.adjacency&&this.element.insertAdjacentHTML){try{this.element.insertAdjacentHTML(this.adjacency,this.content);}catch(e){var tagName=this.element.tagName.toUpperCase();if(['TBODY','TR'].include(tagName)){this.insertContent(this.contentFromAnonymousTable());}else{throw e;}}}else{this.range=this.element.ownerDocument.createRange();if(this.initializeRange)this.initializeRange();this.insertContent([this.range.createContextualFragment(this.content)]);}
|
118
|
+
setTimeout(function(){content.evalScripts()},10);},contentFromAnonymousTable:function(){var div=document.createElement('div');div.innerHTML='<table><tbody>'+this.content+'</tbody></table>';return $A(div.childNodes[0].childNodes[0].childNodes);}}
|
119
|
+
var Insertion=new Object();Insertion.Before=Class.create();Insertion.Before.prototype=Object.extend(new Abstract.Insertion('beforeBegin'),{initializeRange:function(){this.range.setStartBefore(this.element);},insertContent:function(fragments){fragments.each((function(fragment){this.element.parentNode.insertBefore(fragment,this.element);}).bind(this));}});Insertion.Top=Class.create();Insertion.Top.prototype=Object.extend(new Abstract.Insertion('afterBegin'),{initializeRange:function(){this.range.selectNodeContents(this.element);this.range.collapse(true);},insertContent:function(fragments){fragments.reverse(false).each((function(fragment){this.element.insertBefore(fragment,this.element.firstChild);}).bind(this));}});Insertion.Bottom=Class.create();Insertion.Bottom.prototype=Object.extend(new Abstract.Insertion('beforeEnd'),{initializeRange:function(){this.range.selectNodeContents(this.element);this.range.collapse(this.element);},insertContent:function(fragments){fragments.each((function(fragment){this.element.appendChild(fragment);}).bind(this));}});Insertion.After=Class.create();Insertion.After.prototype=Object.extend(new Abstract.Insertion('afterEnd'),{initializeRange:function(){this.range.setStartAfter(this.element);},insertContent:function(fragments){fragments.each((function(fragment){this.element.parentNode.insertBefore(fragment,this.element.nextSibling);}).bind(this));}});Element.ClassNames=Class.create();Element.ClassNames.prototype={initialize:function(element){this.element=$(element);},_each:function(iterator){this.element.className.split(/\s+/).select(function(name){return name.length>0;})._each(iterator);},set:function(className){this.element.className=className;},add:function(classNameToAdd){if(this.include(classNameToAdd))return;this.set($A(this).concat(classNameToAdd).join(' '));},remove:function(classNameToRemove){if(!this.include(classNameToRemove))return;this.set($A(this).without(classNameToRemove).join(' '));},toString:function(){return $A(this).join(' ');}}
|
120
|
+
Object.extend(Element.ClassNames.prototype,Enumerable);var Selector=Class.create();Selector.prototype={initialize:function(expression){this.params={classNames:[]};this.expression=expression.toString().strip();this.parseExpression();this.compileMatcher();},parseExpression:function(){function abort(message){throw'Parse error in selector: '+message;}
|
121
|
+
if(this.expression=='')abort('empty expression');var params=this.params,expr=this.expression,match,modifier,clause,rest;while(match=expr.match(/^(.*)\[([a-z0-9_:-]+?)(?:([~\|!]?=)(?:"([^"]*)"|([^\]\s]*)))?\]$/i)){params.attributes=params.attributes||[];params.attributes.push({name:match[2],operator:match[3],value:match[4]||match[5]||''});expr=match[1];}
|
122
|
+
if(expr=='*')return this.params.wildcard=true;while(match=expr.match(/^([^a-z0-9_-])?([a-z0-9_-]+)(.*)/i)){modifier=match[1],clause=match[2],rest=match[3];switch(modifier){case'#':params.id=clause;break;case'.':params.classNames.push(clause);break;case'':case undefined:params.tagName=clause.toUpperCase();break;default:abort(expr.inspect());}
|
123
|
+
expr=rest;}
|
124
|
+
if(expr.length>0)abort(expr.inspect());},buildMatchExpression:function(){var params=this.params,conditions=[],clause;if(params.wildcard)
|
125
|
+
conditions.push('true');if(clause=params.id)
|
126
|
+
conditions.push('element.id == '+clause.inspect());if(clause=params.tagName)
|
127
|
+
conditions.push('element.tagName.toUpperCase() == '+clause.inspect());if((clause=params.classNames).length>0)
|
128
|
+
for(var i=0,length=clause.length;i<length;i++)
|
129
|
+
conditions.push('Element.hasClassName(element, '+clause[i].inspect()+')');if(clause=params.attributes){clause.each(function(attribute){var value='element.getAttribute('+attribute.name.inspect()+')';var splitValueBy=function(delimiter){return value+' && '+value+'.split('+delimiter.inspect()+')';}
|
130
|
+
switch(attribute.operator){case'=':conditions.push(value+' == '+attribute.value.inspect());break;case'~=':conditions.push(splitValueBy(' ')+'.include('+attribute.value.inspect()+')');break;case'|=':conditions.push(splitValueBy('-')+'.first().toUpperCase() == '+attribute.value.toUpperCase().inspect());break;case'!=':conditions.push(value+' != '+attribute.value.inspect());break;case'':case undefined:conditions.push(value+' != null');break;default:throw'Unknown operator '+attribute.operator+' in selector';}});}
|
131
|
+
return conditions.join(' && ');},compileMatcher:function(){this.match=new Function('element','if (!element.tagName) return false; \
|
132
|
+
return '+this.buildMatchExpression());},findElements:function(scope){var element;if(element=$(this.params.id))
|
133
|
+
if(this.match(element))
|
134
|
+
if(!scope||Element.childOf(element,scope))
|
135
|
+
return[element];scope=(scope||document).getElementsByTagName(this.params.tagName||'*');var results=[];for(var i=0,length=scope.length;i<length;i++)
|
136
|
+
if(this.match(element=scope[i]))
|
137
|
+
results.push(Element.extend(element));return results;},toString:function(){return this.expression;}}
|
138
|
+
Object.extend(Selector,{matchElements:function(elements,expression){var selector=new Selector(expression);return elements.select(selector.match.bind(selector)).collect(Element.extend);},findElement:function(elements,expression,index){if(typeof expression=='number')index=expression,expression=false;return Selector.matchElements(elements,expression||'*')[index||0];},findChildElements:function(element,expressions){return expressions.map(function(expression){return expression.strip().split(/\s+/).inject([null],function(results,expr){var selector=new Selector(expr);return results.inject([],function(elements,result){return elements.concat(selector.findElements(result||element));});});}).flatten();}});function $$(){return Selector.findChildElements(document,$A(arguments));}
|
139
|
+
var Form={reset:function(form){$(form).reset();return form;},serializeElements:function(elements){return elements.inject([],function(queryComponents,element){var queryComponent=Form.Element.serialize(element);if(queryComponent)queryComponents.push(queryComponent);return queryComponents;}).join('&');}};Form.Methods={serialize:function(form){return Form.serializeElements($(form).getElements());},getElements:function(form){return $A($(form).getElementsByTagName('*')).inject([],function(elements,child){if(Form.Element.Serializers[child.tagName.toLowerCase()])
|
140
|
+
elements.push(Element.extend(child));return elements;});},getInputs:function(form,typeName,name){form=$(form);var inputs=form.getElementsByTagName('input');if(!typeName&&!name)
|
141
|
+
return inputs;var matchingInputs=new Array();for(var i=0,length=inputs.length;i<length;i++){var input=inputs[i];if((typeName&&input.type!=typeName)||(name&&input.name!=name))
|
142
|
+
continue;matchingInputs.push(Element.extend(input));}
|
143
|
+
return matchingInputs;},disable:function(form){form=$(form);form.getElements().each(function(element){element.blur();element.disabled='true';});return form;},enable:function(form){form=$(form);form.getElements().each(function(element){element.disabled='';});return form;},findFirstElement:function(form){return $(form).getElements().find(function(element){return element.type!='hidden'&&!element.disabled&&['input','select','textarea'].include(element.tagName.toLowerCase());});},focusFirstElement:function(form){form=$(form);form.findFirstElement().activate();return form;}}
|
144
|
+
Object.extend(Form,Form.Methods);Form.Element={focus:function(element){$(element).focus();return element;},select:function(element){$(element).select();return element;}}
|
145
|
+
Form.Element.Methods={serialize:function(element){element=$(element);if(element.disabled)return'';var method=element.tagName.toLowerCase();var parameter=Form.Element.Serializers[method](element);if(parameter){var key=encodeURIComponent(parameter[0]);if(key.length==0)return;if(parameter[1].constructor!=Array)
|
146
|
+
parameter[1]=[parameter[1]];return parameter[1].map(function(value){return key+'='+encodeURIComponent(value);}).join('&');}},getValue:function(element){element=$(element);var method=element.tagName.toLowerCase();var parameter=Form.Element.Serializers[method](element);if(parameter)
|
147
|
+
return parameter[1];},clear:function(element){$(element).value='';return element;},present:function(element){return $(element).value!='';},activate:function(element){element=$(element);element.focus();if(element.select&&(element.tagName.toLowerCase()!='input'||!['button','reset','submit'].include(element.type)))
|
148
|
+
element.select();return element;},disable:function(element){element=$(element);element.disabled=true;return element;},enable:function(element){element=$(element);element.blur();element.disabled=false;return element;}}
|
149
|
+
Object.extend(Form.Element,Form.Element.Methods);var Field=Form.Element;Form.Element.Serializers={input:function(element){switch(element.type.toLowerCase()){case'checkbox':case'radio':return Form.Element.Serializers.inputSelector(element);default:return Form.Element.Serializers.textarea(element);}
|
150
|
+
return false;},inputSelector:function(element){if(element.checked)
|
151
|
+
return[element.name,element.value];},textarea:function(element){return[element.name,element.value];},select:function(element){return Form.Element.Serializers[element.type=='select-one'?'selectOne':'selectMany'](element);},selectOne:function(element){var value='',opt,index=element.selectedIndex;if(index>=0){opt=Element.extend(element.options[index]);value=opt.hasAttribute('value')?opt.value:opt.text;}
|
152
|
+
return[element.name,value];},selectMany:function(element){var value=[];for(var i=0,length=element.length;i<length;i++){var opt=Element.extend(element.options[i]);if(opt.selected)
|
153
|
+
value.push(opt.hasAttribute('value')?opt.value:opt.text);}
|
154
|
+
return[element.name,value];}}
|
155
|
+
var $F=Form.Element.getValue;Abstract.TimedObserver=function(){}
|
156
|
+
Abstract.TimedObserver.prototype={initialize:function(element,frequency,callback){this.frequency=frequency;this.element=$(element);this.callback=callback;this.lastValue=this.getValue();this.registerCallback();},registerCallback:function(){setInterval(this.onTimerEvent.bind(this),this.frequency*1000);},onTimerEvent:function(){var value=this.getValue();if(this.lastValue!=value){this.callback(this.element,value);this.lastValue=value;}}}
|
157
|
+
Form.Element.Observer=Class.create();Form.Element.Observer.prototype=Object.extend(new Abstract.TimedObserver(),{getValue:function(){return Form.Element.getValue(this.element);}});Form.Observer=Class.create();Form.Observer.prototype=Object.extend(new Abstract.TimedObserver(),{getValue:function(){return Form.serialize(this.element);}});Abstract.EventObserver=function(){}
|
158
|
+
Abstract.EventObserver.prototype={initialize:function(element,callback){this.element=$(element);this.callback=callback;this.lastValue=this.getValue();if(this.element.tagName.toLowerCase()=='form')
|
159
|
+
this.registerFormCallbacks();else
|
160
|
+
this.registerCallback(this.element);},onElementEvent:function(){var value=this.getValue();if(this.lastValue!=value){this.callback(this.element,value);this.lastValue=value;}},registerFormCallbacks:function(){Form.getElements(this.element).each(this.registerCallback.bind(this));},registerCallback:function(element){if(element.type){switch(element.type.toLowerCase()){case'checkbox':case'radio':Event.observe(element,'click',this.onElementEvent.bind(this));break;default:Event.observe(element,'change',this.onElementEvent.bind(this));break;}}}}
|
161
|
+
Form.Element.EventObserver=Class.create();Form.Element.EventObserver.prototype=Object.extend(new Abstract.EventObserver(),{getValue:function(){return Form.Element.getValue(this.element);}});Form.EventObserver=Class.create();Form.EventObserver.prototype=Object.extend(new Abstract.EventObserver(),{getValue:function(){return Form.serialize(this.element);}});if(!window.Event){var Event=new Object();}
|
162
|
+
Object.extend(Event,{KEY_BACKSPACE:8,KEY_TAB:9,KEY_RETURN:13,KEY_ESC:27,KEY_LEFT:37,KEY_UP:38,KEY_RIGHT:39,KEY_DOWN:40,KEY_DELETE:46,KEY_HOME:36,KEY_END:35,KEY_PAGEUP:33,KEY_PAGEDOWN:34,element:function(event){return event.target||event.srcElement;},isLeftClick:function(event){return(((event.which)&&(event.which==1))||((event.button)&&(event.button==1)));},pointerX:function(event){return event.pageX||(event.clientX+
|
163
|
+
(document.documentElement.scrollLeft||document.body.scrollLeft));},pointerY:function(event){return event.pageY||(event.clientY+
|
164
|
+
(document.documentElement.scrollTop||document.body.scrollTop));},stop:function(event){if(event.preventDefault){event.preventDefault();event.stopPropagation();}else{event.returnValue=false;event.cancelBubble=true;}},findElement:function(event,tagName){var element=Event.element(event);while(element.parentNode&&(!element.tagName||(element.tagName.toUpperCase()!=tagName.toUpperCase())))
|
165
|
+
element=element.parentNode;return element;},observers:false,_observeAndCache:function(element,name,observer,useCapture){if(!this.observers)this.observers=[];if(element.addEventListener){this.observers.push([element,name,observer,useCapture]);element.addEventListener(name,observer,useCapture);}else if(element.attachEvent){this.observers.push([element,name,observer,useCapture]);element.attachEvent('on'+name,observer);}},unloadCache:function(){if(!Event.observers)return;for(var i=0,length=Event.observers.length;i<length;i++){Event.stopObserving.apply(this,Event.observers[i]);Event.observers[i][0]=null;}
|
166
|
+
Event.observers=false;},observe:function(element,name,observer,useCapture){element=$(element);useCapture=useCapture||false;if(name=='keypress'&&(navigator.appVersion.match(/Konqueror|Safari|KHTML/)||element.attachEvent))
|
167
|
+
name='keydown';Event._observeAndCache(element,name,observer,useCapture);},stopObserving:function(element,name,observer,useCapture){element=$(element);useCapture=useCapture||false;if(name=='keypress'&&(navigator.appVersion.match(/Konqueror|Safari|KHTML/)||element.detachEvent))
|
168
|
+
name='keydown';if(element.removeEventListener){element.removeEventListener(name,observer,useCapture);}else if(element.detachEvent){try{element.detachEvent('on'+name,observer);}catch(e){}}}});if(navigator.appVersion.match(/\bMSIE\b/))
|
169
|
+
Event.observe(window,'unload',Event.unloadCache,false);var Position={includeScrollOffsets:false,prepare:function(){this.deltaX=window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft||0;this.deltaY=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0;},realOffset:function(element){var valueT=0,valueL=0;do{valueT+=element.scrollTop||0;valueL+=element.scrollLeft||0;element=element.parentNode;}while(element);return[valueL,valueT];},cumulativeOffset:function(element){var valueT=0,valueL=0;do{valueT+=element.offsetTop||0;valueL+=element.offsetLeft||0;element=element.offsetParent;}while(element);return[valueL,valueT];},positionedOffset:function(element){var valueT=0,valueL=0;do{valueT+=element.offsetTop||0;valueL+=element.offsetLeft||0;element=element.offsetParent;if(element){if(element.tagName=='BODY')break;var p=Element.getStyle(element,'position');if(p=='relative'||p=='absolute')break;}}while(element);return[valueL,valueT];},offsetParent:function(element){if(element.offsetParent)return element.offsetParent;if(element==document.body)return element;while((element=element.parentNode)&&element!=document.body)
|
170
|
+
if(Element.getStyle(element,'position')!='static')
|
171
|
+
return element;return document.body;},within:function(element,x,y){if(this.includeScrollOffsets)
|
172
|
+
return this.withinIncludingScrolloffsets(element,x,y);this.xcomp=x;this.ycomp=y;this.offset=this.cumulativeOffset(element);return(y>=this.offset[1]&&y<this.offset[1]+element.offsetHeight&&x>=this.offset[0]&&x<this.offset[0]+element.offsetWidth);},withinIncludingScrolloffsets:function(element,x,y){var offsetcache=this.realOffset(element);this.xcomp=x+offsetcache[0]-this.deltaX;this.ycomp=y+offsetcache[1]-this.deltaY;this.offset=this.cumulativeOffset(element);return(this.ycomp>=this.offset[1]&&this.ycomp<this.offset[1]+element.offsetHeight&&this.xcomp>=this.offset[0]&&this.xcomp<this.offset[0]+element.offsetWidth);},overlap:function(mode,element){if(!mode)return 0;if(mode=='vertical')
|
173
|
+
return((this.offset[1]+element.offsetHeight)-this.ycomp)/element.offsetHeight;if(mode=='horizontal')
|
174
|
+
return((this.offset[0]+element.offsetWidth)-this.xcomp)/element.offsetWidth;},page:function(forElement){var valueT=0,valueL=0;var element=forElement;do{valueT+=element.offsetTop||0;valueL+=element.offsetLeft||0;if(element.offsetParent==document.body)
|
175
|
+
if(Element.getStyle(element,'position')=='absolute')break;}while(element=element.offsetParent);element=forElement;do{if(!window.opera||element.tagName=='BODY'){valueT-=element.scrollTop||0;valueL-=element.scrollLeft||0;}}while(element=element.parentNode);return[valueL,valueT];},clone:function(source,target){var options=Object.extend({setLeft:true,setTop:true,setWidth:true,setHeight:true,offsetTop:0,offsetLeft:0},arguments[2]||{})
|
176
|
+
source=$(source);var p=Position.page(source);target=$(target);var delta=[0,0];var parent=null;if(Element.getStyle(target,'position')=='absolute'){parent=Position.offsetParent(target);delta=Position.page(parent);}
|
177
|
+
if(parent==document.body){delta[0]-=document.body.offsetLeft;delta[1]-=document.body.offsetTop;}
|
178
|
+
if(options.setLeft)target.style.left=(p[0]-delta[0]+options.offsetLeft)+'px';if(options.setTop)target.style.top=(p[1]-delta[1]+options.offsetTop)+'px';if(options.setWidth)target.style.width=source.offsetWidth+'px';if(options.setHeight)target.style.height=source.offsetHeight+'px';},absolutize:function(element){element=$(element);if(element.style.position=='absolute')return;Position.prepare();var offsets=Position.positionedOffset(element);var top=offsets[1];var left=offsets[0];var width=element.clientWidth;var height=element.clientHeight;element._originalLeft=left-parseFloat(element.style.left||0);element._originalTop=top-parseFloat(element.style.top||0);element._originalWidth=element.style.width;element._originalHeight=element.style.height;element.style.position='absolute';element.style.top=top+'px';;element.style.left=left+'px';;element.style.width=width+'px';;element.style.height=height+'px';;},relativize:function(element){element=$(element);if(element.style.position=='relative')return;Position.prepare();element.style.position='relative';var top=parseFloat(element.style.top||0)-(element._originalTop||0);var left=parseFloat(element.style.left||0)-(element._originalLeft||0);element.style.top=top+'px';element.style.left=left+'px';element.style.height=element._originalHeight;element.style.width=element._originalWidth;}}
|
179
|
+
if(/Konqueror|Safari|KHTML/.test(navigator.userAgent)){Position.cumulativeOffset=function(element){var valueT=0,valueL=0;do{valueT+=element.offsetTop||0;valueL+=element.offsetLeft||0;if(element.offsetParent==document.body)
|
180
|
+
if(Element.getStyle(element,'position')=='absolute')break;element=element.offsetParent;}while(element);return[valueL,valueT];}}
|
181
|
+
Element.addMethods();
|
data/site/spinner.gif
ADDED
Binary file
|
data/site/try.html
ADDED
data/site/try/index.html
ADDED
data/site/try/p.js
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
|
2
|
+
var Prototype={Version:'1.5.0_rc2',BrowserFeatures:{XPath:!!document.evaluate},ScriptFragment:'(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)',emptyFunction:function(){},K:function(x){return x}}
|
3
|
+
var Class={create:function(){return function(){this.initialize.apply(this,arguments);}}}
|
4
|
+
var Abstract=new Object();Object.extend=function(destination,source){for(var property in source){destination[property]=source[property];}
|
5
|
+
return destination;}
|
6
|
+
Object.extend(Object,{inspect:function(object){try{if(object===undefined)return'undefined';if(object===null)return'null';return object.inspect?object.inspect():object.toString();}catch(e){if(e instanceof RangeError)return'...';throw e;}},keys:function(object){var keys=[];for(var property in object)
|
7
|
+
keys.push(property);return keys;},values:function(object){var values=[];for(var property in object)
|
8
|
+
values.push(object[property]);return values;},clone:function(object){return Object.extend({},object);}});Function.prototype.bind=function(){var __method=this,args=$A(arguments),object=args.shift();return function(){return __method.apply(object,args.concat($A(arguments)));}}
|
9
|
+
Function.prototype.bindAsEventListener=function(object){var __method=this,args=$A(arguments),object=args.shift();return function(event){return __method.apply(object,[(event||window.event)].concat(args).concat($A(arguments)));}}
|
10
|
+
Object.extend(Number.prototype,{toColorPart:function(){var digits=this.toString(16);if(this<16)return'0'+digits;return digits;},succ:function(){return this+1;},times:function(iterator){$R(0,this,true).each(iterator);return this;}});var Try={these:function(){var returnValue;for(var i=0,length=arguments.length;i<length;i++){var lambda=arguments[i];try{returnValue=lambda();break;}catch(e){}}
|
11
|
+
return returnValue;}}
|
12
|
+
var PeriodicalExecuter=Class.create();PeriodicalExecuter.prototype={initialize:function(callback,frequency){this.callback=callback;this.frequency=frequency;this.currentlyExecuting=false;this.registerCallback();},registerCallback:function(){this.timer=setInterval(this.onTimerEvent.bind(this),this.frequency*1000);},stop:function(){if(!this.timer)return;clearInterval(this.timer);this.timer=null;},onTimerEvent:function(){if(!this.currentlyExecuting){try{this.currentlyExecuting=true;this.callback(this);}finally{this.currentlyExecuting=false;}}}}
|
13
|
+
Object.extend(String.prototype,{gsub:function(pattern,replacement){var result='',source=this,match;replacement=arguments.callee.prepareReplacement(replacement);while(source.length>0){if(match=source.match(pattern)){result+=source.slice(0,match.index);result+=(replacement(match)||'').toString();source=source.slice(match.index+match[0].length);}else{result+=source,source='';}}
|
14
|
+
return result;},sub:function(pattern,replacement,count){replacement=this.gsub.prepareReplacement(replacement);count=count===undefined?1:count;return this.gsub(pattern,function(match){if(--count<0)return match[0];return replacement(match);});},scan:function(pattern,iterator){this.gsub(pattern,iterator);return this;},truncate:function(length,truncation){length=length||30;truncation=truncation===undefined?'...':truncation;return this.length>length?this.slice(0,length-truncation.length)+truncation:this;},strip:function(){return this.replace(/^\s+/,'').replace(/\s+$/,'');},stripTags:function(){return this.replace(/<\/?[^>]+>/gi,'');},stripScripts:function(){return this.replace(new RegExp(Prototype.ScriptFragment,'img'),'');},extractScripts:function(){var matchAll=new RegExp(Prototype.ScriptFragment,'img');var matchOne=new RegExp(Prototype.ScriptFragment,'im');return(this.match(matchAll)||[]).map(function(scriptTag){return(scriptTag.match(matchOne)||['',''])[1];});},evalScripts:function(){return this.extractScripts().map(function(script){return eval(script)});},escapeHTML:function(){var div=document.createElement('div');var text=document.createTextNode(this);div.appendChild(text);return div.innerHTML;},unescapeHTML:function(){var div=document.createElement('div');div.innerHTML=this.stripTags();return div.childNodes[0]?(div.childNodes.length>1?$A(div.childNodes).inject('',function(memo,node){return memo+node.nodeValue}):div.childNodes[0].nodeValue):'';},toQueryParams:function(separator){var match=this.strip().match(/([^?#]*)(#.*)?$/);if(!match)return{};return match[1].split(separator||'&').inject({},function(hash,pair){if((pair=pair.split('='))[0]){var name=decodeURIComponent(pair[0]);var value=pair[1]?decodeURIComponent(pair[1]):undefined;if(hash[name]!==undefined){if(hash[name].constructor!=Array)
|
15
|
+
hash[name]=[hash[name]];if(value)hash[name].push(value);}
|
16
|
+
else hash[name]=value;}
|
17
|
+
return hash;});},toArray:function(){return this.split('');},camelize:function(){var oStringList=this.split('-');if(oStringList.length==1)return oStringList[0];var camelizedString=this.indexOf('-')==0?oStringList[0].charAt(0).toUpperCase()+oStringList[0].substring(1):oStringList[0];for(var i=1,length=oStringList.length;i<length;i++){var s=oStringList[i];camelizedString+=s.charAt(0).toUpperCase()+s.substring(1);}
|
18
|
+
return camelizedString;},underscore:function(){return this.gsub(/::/,'/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'-').toLowerCase();},dasherize:function(){return this.gsub(/_/,'-');},inspect:function(useDoubleQuotes){var escapedString=this.replace(/\\/g,'\\\\');if(useDoubleQuotes)
|
19
|
+
return'"'+escapedString.replace(/"/g,'\\"')+'"';else
|
20
|
+
return"'"+escapedString.replace(/'/g,'\\\'')+"'";}});String.prototype.gsub.prepareReplacement=function(replacement){if(typeof replacement=='function')return replacement;var template=new Template(replacement);return function(match){return template.evaluate(match)};}
|
21
|
+
String.prototype.parseQuery=String.prototype.toQueryParams;var Template=Class.create();Template.Pattern=/(^|.|\r|\n)(#\{(.*?)\})/;Template.prototype={initialize:function(template,pattern){this.template=template.toString();this.pattern=pattern||Template.Pattern;},evaluate:function(object){return this.template.gsub(this.pattern,function(match){var before=match[1];if(before=='\\')return match[2];return before+(object[match[3]]||'').toString();});}}
|
22
|
+
var $break=new Object();var $continue=new Object();var Enumerable={each:function(iterator){var index=0;try{this._each(function(value){try{iterator(value,index++);}catch(e){if(e!=$continue)throw e;}});}catch(e){if(e!=$break)throw e;}
|
23
|
+
return this;},eachSlice:function(number,iterator){var index=-number,slices=[],array=this.toArray();while((index+=number)<array.length)
|
24
|
+
slices.push(array.slice(index,index+number));return slices.collect(iterator||Prototype.K);},all:function(iterator){var result=true;this.each(function(value,index){result=result&&!!(iterator||Prototype.K)(value,index);if(!result)throw $break;});return result;},any:function(iterator){var result=false;this.each(function(value,index){if(result=!!(iterator||Prototype.K)(value,index))
|
25
|
+
throw $break;});return result;},collect:function(iterator){var results=[];this.each(function(value,index){results.push(iterator(value,index));});return results;},detect:function(iterator){var result;this.each(function(value,index){if(iterator(value,index)){result=value;throw $break;}});return result;},findAll:function(iterator){var results=[];this.each(function(value,index){if(iterator(value,index))
|
26
|
+
results.push(value);});return results;},grep:function(pattern,iterator){var results=[];this.each(function(value,index){var stringValue=value.toString();if(stringValue.match(pattern))
|
27
|
+
results.push((iterator||Prototype.K)(value,index));})
|
28
|
+
return results;},include:function(object){var found=false;this.each(function(value){if(value==object){found=true;throw $break;}});return found;},inGroupsOf:function(number,fillWith){fillWith=fillWith||null;var results=this.eachSlice(number);if(results.length>0)(number-results.last().length).times(function(){results.last().push(fillWith)});return results;},inject:function(memo,iterator){this.each(function(value,index){memo=iterator(memo,value,index);});return memo;},invoke:function(method){var args=$A(arguments).slice(1);return this.collect(function(value){return value[method].apply(value,args);});},max:function(iterator){var result;this.each(function(value,index){value=(iterator||Prototype.K)(value,index);if(result==undefined||value>=result)
|
29
|
+
result=value;});return result;},min:function(iterator){var result;this.each(function(value,index){value=(iterator||Prototype.K)(value,index);if(result==undefined||value<result)
|
30
|
+
result=value;});return result;},partition:function(iterator){var trues=[],falses=[];this.each(function(value,index){((iterator||Prototype.K)(value,index)?trues:falses).push(value);});return[trues,falses];},pluck:function(property){var results=[];this.each(function(value,index){results.push(value[property]);});return results;},reject:function(iterator){var results=[];this.each(function(value,index){if(!iterator(value,index))
|
31
|
+
results.push(value);});return results;},sortBy:function(iterator){return this.collect(function(value,index){return{value:value,criteria:iterator(value,index)};}).sort(function(left,right){var a=left.criteria,b=right.criteria;return a<b?-1:a>b?1:0;}).pluck('value');},toArray:function(){return this.collect(Prototype.K);},zip:function(){var iterator=Prototype.K,args=$A(arguments);if(typeof args.last()=='function')
|
32
|
+
iterator=args.pop();var collections=[this].concat(args).map($A);return this.map(function(value,index){return iterator(collections.pluck(index));});},inspect:function(){return'#<Enumerable:'+this.toArray().inspect()+'>';}}
|
33
|
+
Object.extend(Enumerable,{map:Enumerable.collect,find:Enumerable.detect,select:Enumerable.findAll,member:Enumerable.include,entries:Enumerable.toArray});var $A=Array.from=function(iterable){if(!iterable)return[];if(iterable.toArray){return iterable.toArray();}else{var results=[];for(var i=0,length=iterable.length;i<length;i++)
|
34
|
+
results.push(iterable[i]);return results;}}
|
35
|
+
Object.extend(Array.prototype,Enumerable);if(!Array.prototype._reverse)
|
36
|
+
Array.prototype._reverse=Array.prototype.reverse;Object.extend(Array.prototype,{_each:function(iterator){for(var i=0,length=this.length;i<length;i++)
|
37
|
+
iterator(this[i]);},clear:function(){this.length=0;return this;},first:function(){return this[0];},last:function(){return this[this.length-1];},compact:function(){return this.select(function(value){return value!=undefined||value!=null;});},flatten:function(){return this.inject([],function(array,value){return array.concat(value&&value.constructor==Array?value.flatten():[value]);});},without:function(){var values=$A(arguments);return this.select(function(value){return!values.include(value);});},indexOf:function(object){for(var i=0,length=this.length;i<length;i++)
|
38
|
+
if(this[i]==object)return i;return-1;},reverse:function(inline){return(inline!==false?this:this.toArray())._reverse();},reduce:function(){return this.length>1?this:this[0];},uniq:function(){return this.inject([],function(array,value){return array.include(value)?array:array.concat([value]);});},clone:function(){return[].concat(this);},inspect:function(){return'['+this.map(Object.inspect).join(', ')+']';}});Array.prototype.toArray=Array.prototype.clone;if(window.opera){Array.prototype.concat=function(){var array=[];for(var i=0,length=this.length;i<length;i++)array.push(this[i]);for(var i=0,length=arguments.length;i<length;i++){if(arguments[i].constructor==Array){for(var j=0,arrayLength=arguments[i].length;j<arrayLength;j++)
|
39
|
+
array.push(arguments[i][j]);}else{array.push(arguments[i]);}}
|
40
|
+
return array;}}
|
41
|
+
var Hash={_each:function(iterator){for(var key in this){var value=this[key];if(typeof value=='function')continue;var pair=[key,value];pair.key=key;pair.value=value;iterator(pair);}},keys:function(){return this.pluck('key');},values:function(){return this.pluck('value');},merge:function(hash){return $H(hash).inject(this,function(mergedHash,pair){mergedHash[pair.key]=pair.value;return mergedHash;});},toQueryString:function(){return this.map(function(pair){if(!pair.key)return null;if(pair.value&&pair.value.constructor==Array){pair.value=pair.value.compact();if(pair.value.length<2){pair.value=pair.value.reduce();}else{var key=encodeURIComponent(pair.key);return pair.value.map(function(value){return key+'='+encodeURIComponent(value);}).join('&');}}
|
42
|
+
if(pair.value==undefined)pair[1]='';return pair.map(encodeURIComponent).join('=');}).join('&');},inspect:function(){return'#<Hash:{'+this.map(function(pair){return pair.map(Object.inspect).join(': ');}).join(', ')+'}>';}}
|
43
|
+
function $H(object){var hash=Object.extend({},object||{});Object.extend(hash,Enumerable);Object.extend(hash,Hash);return hash;}
|
44
|
+
ObjectRange=Class.create();Object.extend(ObjectRange.prototype,Enumerable);Object.extend(ObjectRange.prototype,{initialize:function(start,end,exclusive){this.start=start;this.end=end;this.exclusive=exclusive;},_each:function(iterator){var value=this.start;while(this.include(value)){iterator(value);value=value.succ();}},include:function(value){if(value<this.start)
|
45
|
+
return false;if(this.exclusive)
|
46
|
+
return value<this.end;return value<=this.end;}});var $R=function(start,end,exclusive){return new ObjectRange(start,end,exclusive);}
|
47
|
+
var Ajax={getTransport:function(){return Try.these(function(){return new XMLHttpRequest()},function(){return new ActiveXObject('Msxml2.XMLHTTP')},function(){return new ActiveXObject('Microsoft.XMLHTTP')})||false;},activeRequestCount:0}
|
48
|
+
Ajax.Responders={responders:[],_each:function(iterator){this.responders._each(iterator);},register:function(responder){if(!this.include(responder))
|
49
|
+
this.responders.push(responder);},unregister:function(responder){this.responders=this.responders.without(responder);},dispatch:function(callback,request,transport,json){this.each(function(responder){if(typeof responder[callback]=='function'){try{responder[callback].apply(responder,[request,transport,json]);}catch(e){}}});}};Object.extend(Ajax.Responders,Enumerable);Ajax.Responders.register({onCreate:function(){Ajax.activeRequestCount++;},onComplete:function(){Ajax.activeRequestCount--;}});Ajax.Base=function(){};Ajax.Base.prototype={setOptions:function(options){this.options={method:'post',asynchronous:true,contentType:'application/x-www-form-urlencoded',encoding:'UTF-8',parameters:''}
|
50
|
+
Object.extend(this.options,options||{});this.options.method=this.options.method.toLowerCase();this.options.parameters=$H(typeof this.options.parameters=='string'?this.options.parameters.toQueryParams():this.options.parameters);}}
|
51
|
+
Ajax.Request=Class.create();Ajax.Request.Events=['Uninitialized','Loading','Loaded','Interactive','Complete'];Ajax.Request.prototype=Object.extend(new Ajax.Base(),{_complete:false,initialize:function(url,options){this.transport=Ajax.getTransport();this.setOptions(options);this.request(url);},request:function(url){var params=this.options.parameters;if(params.any())params['_']='';if(!['get','post'].include(this.options.method)){params['_method']=this.options.method;this.options.method='post';}
|
52
|
+
this.url=url;if(this.options.method=='get'&¶ms.any())
|
53
|
+
this.url+=(this.url.indexOf('?')>=0?'&':'?')+
|
54
|
+
params.toQueryString();try{Ajax.Responders.dispatch('onCreate',this,this.transport);this.transport.open(this.options.method.toUpperCase(),this.url,this.options.asynchronous,this.options.username,this.options.password);if(this.options.asynchronous)
|
55
|
+
setTimeout(function(){this.respondToReadyState(1)}.bind(this),10);this.transport.onreadystatechange=this.onStateChange.bind(this);this.setRequestHeaders();var body=this.options.method=='post'?(this.options.postBody||params.toQueryString()):null;this.transport.send(body);if(!this.options.asynchronous&&this.transport.overrideMimeType)
|
56
|
+
this.onStateChange();}
|
57
|
+
catch(e){this.dispatchException(e);}},onStateChange:function(){var readyState=this.transport.readyState;if(readyState>1&&!((readyState==4)&&this._complete))
|
58
|
+
this.respondToReadyState(this.transport.readyState);},setRequestHeaders:function(){var headers={'X-Requested-With':'XMLHttpRequest','X-Prototype-Version':Prototype.Version,'Accept':'text/javascript, text/html, application/xml, text/xml, */*'};if(this.options.method=='post'){headers['Content-type']=this.options.contentType+
|
59
|
+
(this.options.encoding?'; charset='+this.options.encoding:'');if(this.transport.overrideMimeType&&(navigator.userAgent.match(/Gecko\/(\d{4})/)||[0,2005])[1]<2005)
|
60
|
+
headers['Connection']='close';}
|
61
|
+
if(typeof this.options.requestHeaders=='object'){var extras=this.options.requestHeaders;if(typeof extras.push=='function')
|
62
|
+
for(var i=0,length=extras.length;i<length;i+=2)
|
63
|
+
headers[extras[i]]=extras[i+1];else
|
64
|
+
$H(extras).each(function(pair){headers[pair.key]=pair.value});}
|
65
|
+
for(var name in headers)
|
66
|
+
this.transport.setRequestHeader(name,headers[name]);},success:function(){return!this.transport.status||(this.transport.status>=200&&this.transport.status<300);},respondToReadyState:function(readyState){var state=Ajax.Request.Events[readyState];var transport=this.transport,json=this.evalJSON();if(state=='Complete'){try{this._complete=true;(this.options['on'+this.transport.status]||this.options['on'+(this.success()?'Success':'Failure')]||Prototype.emptyFunction)(transport,json);}catch(e){this.dispatchException(e);}}
|
67
|
+
try{(this.options['on'+state]||Prototype.emptyFunction)(transport,json);Ajax.Responders.dispatch('on'+state,this,transport,json);}catch(e){this.dispatchException(e);}
|
68
|
+
if(state=='Complete'){if((this.getHeader('Content-type')||'').strip().match(/^(text|application)\/(x-)?(java|ecma)script(;.*)?$/i))
|
69
|
+
this.evalResponse();this.transport.onreadystatechange=Prototype.emptyFunction;}},getHeader:function(name){try{return this.transport.getResponseHeader(name);}catch(e){return null}},evalJSON:function(){try{var json=this.getHeader('X-JSON');return json?eval('('+json+')'):null;}catch(e){return null}},evalResponse:function(){try{return eval(this.transport.responseText);}catch(e){this.dispatchException(e);}},dispatchException:function(exception){(this.options.onException||Prototype.emptyFunction)(this,exception);Ajax.Responders.dispatch('onException',this,exception);}});Ajax.Updater=Class.create();Object.extend(Object.extend(Ajax.Updater.prototype,Ajax.Request.prototype),{initialize:function(container,url,options){this.container={success:(container.success||container),failure:(container.failure||(container.success?null:container))}
|
70
|
+
this.transport=Ajax.getTransport();this.setOptions(options);var onComplete=this.options.onComplete||Prototype.emptyFunction;this.options.onComplete=(function(transport,param){this.updateContent();onComplete(transport,param);}).bind(this);this.request(url);},updateContent:function(){var receiver=this.container[this.success()?'success':'failure'];var response=this.transport.responseText;if(!this.options.evalScripts)response=response.stripScripts();if(receiver=$(receiver)){if(this.options.insertion)
|
71
|
+
new this.options.insertion(receiver,response);else
|
72
|
+
receiver.update(response);}
|
73
|
+
if(this.success()){if(this.onComplete)
|
74
|
+
setTimeout(this.onComplete.bind(this),10);}}});Ajax.PeriodicalUpdater=Class.create();Ajax.PeriodicalUpdater.prototype=Object.extend(new Ajax.Base(),{initialize:function(container,url,options){this.setOptions(options);this.onComplete=this.options.onComplete;this.frequency=(this.options.frequency||2);this.decay=(this.options.decay||1);this.updater={};this.container=container;this.url=url;this.start();},start:function(){this.options.onComplete=this.updateComplete.bind(this);this.onTimerEvent();},stop:function(){this.updater.options.onComplete=undefined;clearTimeout(this.timer);(this.onComplete||Prototype.emptyFunction).apply(this,arguments);},updateComplete:function(request){if(this.options.decay){this.decay=(request.responseText==this.lastText?this.decay*this.options.decay:1);this.lastText=request.responseText;}
|
75
|
+
this.timer=setTimeout(this.onTimerEvent.bind(this),this.decay*this.frequency*1000);},onTimerEvent:function(){this.updater=new Ajax.Updater(this.container,this.url,this.options);}});function $(element){if(arguments.length>1){for(var i=0,elements=[],length=arguments.length;i<length;i++)
|
76
|
+
elements.push($(arguments[i]));return elements;}
|
77
|
+
if(typeof element=='string')
|
78
|
+
element=document.getElementById(element);return Element.extend(element);}
|
79
|
+
if(Prototype.BrowserFeatures.XPath){document._getElementsByXPath=function(expression,parentElement){var results=[];var query=document.evaluate(expression,$(parentElement)||document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);for(var i=0,length=query.snapshotLength;i<length;i++)
|
80
|
+
results.push(query.snapshotItem(i));return results;}}
|
81
|
+
document.getElementsByClassName=function(className,parentElement){if(Prototype.BrowserFeatures.XPath){var q=".//*[contains(concat(' ', @class, ' '), ' "+className+" ')]";return document._getElementsByXPath(q,parentElement);}else{var children=($(parentElement)||document.body).getElementsByTagName('*');var elements=[],child;for(var i=0,length=children.length;i<length;i++){child=children[i];if(Element.hasClassName(child,className))
|
82
|
+
elements.push(Element.extend(child));}
|
83
|
+
return elements;}}
|
84
|
+
if(!window.Element)
|
85
|
+
var Element=new Object();Element.extend=function(element){if(!element)return;if(_nativeExtensions||element.nodeType==3)return element;if(!element._extended&&element.tagName&&element!=window){var methods=Object.clone(Element.Methods),cache=Element.extend.cache;if(element.tagName=='FORM')
|
86
|
+
Object.extend(methods,Form.Methods);if(['INPUT','TEXTAREA','SELECT'].include(element.tagName))
|
87
|
+
Object.extend(methods,Form.Element.Methods);Object.extend(methods,Element.Methods.Simulated);for(var property in methods){var value=methods[property];if(typeof value=='function'&&!(property in element))
|
88
|
+
element[property]=cache.findOrStore(value);}}
|
89
|
+
element._extended=true;return element;}
|
90
|
+
Element.extend.cache={findOrStore:function(value){return this[value]=this[value]||function(){return value.apply(null,[this].concat($A(arguments)));}}}
|
91
|
+
Element.Methods={visible:function(element){return $(element).style.display!='none';},toggle:function(element){element=$(element);Element[Element.visible(element)?'hide':'show'](element);return element;},hide:function(element){$(element).style.display='none';return element;},show:function(element){$(element).style.display='';return element;},remove:function(element){element=$(element);element.parentNode.removeChild(element);return element;},update:function(element,html){html=typeof html=='undefined'?'':html.toString();$(element).innerHTML=html.stripScripts();setTimeout(function(){html.evalScripts()},10);return element;},replace:function(element,html){element=$(element);if(element.outerHTML){element.outerHTML=html.stripScripts();}else{var range=element.ownerDocument.createRange();range.selectNodeContents(element);element.parentNode.replaceChild(range.createContextualFragment(html.stripScripts()),element);}
|
92
|
+
setTimeout(function(){html.evalScripts()},10);return element;},inspect:function(element){element=$(element);var result='<'+element.tagName.toLowerCase();$H({'id':'id','className':'class'}).each(function(pair){var property=pair.first(),attribute=pair.last();var value=(element[property]||'').toString();if(value)result+=' '+attribute+'='+value.inspect(true);});return result+'>';},recursivelyCollect:function(element,property){element=$(element);var elements=[];while(element=element[property])
|
93
|
+
if(element.nodeType==1)
|
94
|
+
elements.push(Element.extend(element));return elements;},ancestors:function(element){return $(element).recursivelyCollect('parentNode');},descendants:function(element){element=$(element);return $A(element.getElementsByTagName('*'));},immediateDescendants:function(element){if(!(element=$(element).firstChild))return[];while(element&&element.nodeType!=1)element=element.nextSibling;if(element)return[element].concat($(element).nextSiblings());return[];},previousSiblings:function(element){return $(element).recursivelyCollect('previousSibling');},nextSiblings:function(element){return $(element).recursivelyCollect('nextSibling');},siblings:function(element){element=$(element);return element.previousSiblings().reverse().concat(element.nextSiblings());},match:function(element,selector){element=$(element);if(typeof selector=='string')
|
95
|
+
selector=new Selector(selector);return selector.match(element);},up:function(element,expression,index){return Selector.findElement($(element).ancestors(),expression,index);},down:function(element,expression,index){return Selector.findElement($(element).descendants(),expression,index);},previous:function(element,expression,index){return Selector.findElement($(element).previousSiblings(),expression,index);},next:function(element,expression,index){return Selector.findElement($(element).nextSiblings(),expression,index);},getElementsBySelector:function(){var args=$A(arguments),element=$(args.shift());return Selector.findChildElements(element,args);},getElementsByClassName:function(element,className){element=$(element);return document.getElementsByClassName(className,element);},readAttribute:function(element,name){return $(element).getAttribute(name);},getHeight:function(element){element=$(element);return element.offsetHeight;},classNames:function(element){return new Element.ClassNames(element);},hasClassName:function(element,className){if(!(element=$(element)))return;var elementClassName=element.className;if(elementClassName.length==0)return false;if(elementClassName==className||elementClassName.match(new RegExp("(^|\\s)"+className+"(\\s|$)")))
|
96
|
+
return true;return false;},addClassName:function(element,className){if(!(element=$(element)))return;Element.classNames(element).add(className);return element;},removeClassName:function(element,className){if(!(element=$(element)))return;Element.classNames(element).remove(className);return element;},observe:function(){Event.observe.apply(Event,arguments);return $A(arguments).first();},stopObserving:function(){Event.stopObserving.apply(Event,arguments);return $A(arguments).first();},cleanWhitespace:function(element){element=$(element);var node=element.firstChild;while(node){var nextNode=node.nextSibling;if(node.nodeType==3&&!/\S/.test(node.nodeValue))
|
97
|
+
element.removeChild(node);node=nextNode;}
|
98
|
+
return element;},empty:function(element){return $(element).innerHTML.match(/^\s*$/);},childOf:function(element,ancestor){element=$(element),ancestor=$(ancestor);while(element=element.parentNode)
|
99
|
+
if(element==ancestor)return true;return false;},scrollTo:function(element){element=$(element);var x=element.x?element.x:element.offsetLeft,y=element.y?element.y:element.offsetTop;window.scrollTo(x,y);return element;},getStyle:function(element,style){element=$(element);var inline=(style=='float'?(typeof element.style.styleFloat!='undefined'?'styleFloat':'cssFloat'):style);var value=element.style[inline.camelize()];if(!value){if(document.defaultView&&document.defaultView.getComputedStyle){var css=document.defaultView.getComputedStyle(element,null);value=css?css.getPropertyValue(style):null;}else if(element.currentStyle){value=element.currentStyle[inline.camelize()];}}
|
100
|
+
if((value=='auto')&&['width','height'].include(style)&&(element.getStyle('display')!='none'))
|
101
|
+
value=element['offset'+style.charAt(0).toUpperCase()+style.substring(1)]+'px';if(window.opera&&['left','top','right','bottom'].include(style))
|
102
|
+
if(Element.getStyle(element,'position')=='static')value='auto';return value=='auto'?null:value;},setStyle:function(element,style){element=$(element);for(var name in style)
|
103
|
+
element.style[(name=='float'?((typeof element.style.styleFloat!='undefined')?'styleFloat':'cssFloat'):name).camelize()]=style[name];return element;},getDimensions:function(element){element=$(element);if(Element.getStyle(element,'display')!='none')
|
104
|
+
return{width:element.offsetWidth,height:element.offsetHeight};var els=element.style;var originalVisibility=els.visibility;var originalPosition=els.position;els.visibility='hidden';els.position='absolute';els.display='';var originalWidth=element.clientWidth;var originalHeight=element.clientHeight;els.display='none';els.position=originalPosition;els.visibility=originalVisibility;return{width:originalWidth,height:originalHeight};},makePositioned:function(element){element=$(element);var pos=Element.getStyle(element,'position');if(pos=='static'||!pos){element._madePositioned=true;element.style.position='relative';if(window.opera){element.style.top=0;element.style.left=0;}}
|
105
|
+
return element;},undoPositioned:function(element){element=$(element);if(element._madePositioned){element._madePositioned=undefined;element.style.position=element.style.top=element.style.left=element.style.bottom=element.style.right='';}
|
106
|
+
return element;},makeClipping:function(element){element=$(element);if(element._overflow)return element;element._overflow=element.style.overflow||'auto';if((Element.getStyle(element,'overflow')||'visible')!='hidden')
|
107
|
+
element.style.overflow='hidden';return element;},undoClipping:function(element){element=$(element);if(!element._overflow)return element;element.style.overflow=element._overflow=='auto'?'':element._overflow;element._overflow=null;return element;}}
|
108
|
+
Element.Methods.Simulated={hasAttribute:function(element,attribute){return $(element).getAttributeNode(attribute).specified;}}
|
109
|
+
if(document.all){Element.Methods.update=function(element,html){element=$(element);html=typeof html=='undefined'?'':html.toString();var tagName=element.tagName.toUpperCase();if(['THEAD','TBODY','TR','TD'].include(tagName)){var div=document.createElement('div');switch(tagName){case'THEAD':case'TBODY':div.innerHTML='<table><tbody>'+html.stripScripts()+'</tbody></table>';depth=2;break;case'TR':div.innerHTML='<table><tbody><tr>'+html.stripScripts()+'</tr></tbody></table>';depth=3;break;case'TD':div.innerHTML='<table><tbody><tr><td>'+html.stripScripts()+'</td></tr></tbody></table>';depth=4;}
|
110
|
+
$A(element.childNodes).each(function(node){element.removeChild(node)});depth.times(function(){div=div.firstChild});$A(div.childNodes).each(function(node){element.appendChild(node)});}else{element.innerHTML=html.stripScripts();}
|
111
|
+
setTimeout(function(){html.evalScripts()},10);return element;}}
|
112
|
+
Object.extend(Element,Element.Methods);var _nativeExtensions=false;if(/Konqueror|Safari|KHTML/.test(navigator.userAgent))
|
113
|
+
['','Form','Input','TextArea','Select'].each(function(tag){var className='HTML'+tag+'Element';if(window[className])return;var klass=window[className]={};klass.prototype=document.createElement(tag?tag.toLowerCase():'div').__proto__;});Element.addMethods=function(methods){Object.extend(Element.Methods,methods||{});function copy(methods,destination,onlyIfAbsent){onlyIfAbsent=onlyIfAbsent||false;var cache=Element.extend.cache;for(var property in methods){var value=methods[property];if(!onlyIfAbsent||!(property in destination))
|
114
|
+
destination[property]=cache.findOrStore(value);}}
|
115
|
+
if(typeof HTMLElement!='undefined'){copy(Element.Methods,HTMLElement.prototype);copy(Element.Methods.Simulated,HTMLElement.prototype,true);copy(Form.Methods,HTMLFormElement.prototype);[HTMLInputElement,HTMLTextAreaElement,HTMLSelectElement].each(function(klass){copy(Form.Element.Methods,klass.prototype);});_nativeExtensions=true;}}
|
116
|
+
var Toggle=new Object();Toggle.display=Element.toggle;Abstract.Insertion=function(adjacency){this.adjacency=adjacency;}
|
117
|
+
Abstract.Insertion.prototype={initialize:function(element,content){this.element=$(element);this.content=content.stripScripts();if(this.adjacency&&this.element.insertAdjacentHTML){try{this.element.insertAdjacentHTML(this.adjacency,this.content);}catch(e){var tagName=this.element.tagName.toUpperCase();if(['TBODY','TR'].include(tagName)){this.insertContent(this.contentFromAnonymousTable());}else{throw e;}}}else{this.range=this.element.ownerDocument.createRange();if(this.initializeRange)this.initializeRange();this.insertContent([this.range.createContextualFragment(this.content)]);}
|
118
|
+
setTimeout(function(){content.evalScripts()},10);},contentFromAnonymousTable:function(){var div=document.createElement('div');div.innerHTML='<table><tbody>'+this.content+'</tbody></table>';return $A(div.childNodes[0].childNodes[0].childNodes);}}
|
119
|
+
var Insertion=new Object();Insertion.Before=Class.create();Insertion.Before.prototype=Object.extend(new Abstract.Insertion('beforeBegin'),{initializeRange:function(){this.range.setStartBefore(this.element);},insertContent:function(fragments){fragments.each((function(fragment){this.element.parentNode.insertBefore(fragment,this.element);}).bind(this));}});Insertion.Top=Class.create();Insertion.Top.prototype=Object.extend(new Abstract.Insertion('afterBegin'),{initializeRange:function(){this.range.selectNodeContents(this.element);this.range.collapse(true);},insertContent:function(fragments){fragments.reverse(false).each((function(fragment){this.element.insertBefore(fragment,this.element.firstChild);}).bind(this));}});Insertion.Bottom=Class.create();Insertion.Bottom.prototype=Object.extend(new Abstract.Insertion('beforeEnd'),{initializeRange:function(){this.range.selectNodeContents(this.element);this.range.collapse(this.element);},insertContent:function(fragments){fragments.each((function(fragment){this.element.appendChild(fragment);}).bind(this));}});Insertion.After=Class.create();Insertion.After.prototype=Object.extend(new Abstract.Insertion('afterEnd'),{initializeRange:function(){this.range.setStartAfter(this.element);},insertContent:function(fragments){fragments.each((function(fragment){this.element.parentNode.insertBefore(fragment,this.element.nextSibling);}).bind(this));}});Element.ClassNames=Class.create();Element.ClassNames.prototype={initialize:function(element){this.element=$(element);},_each:function(iterator){this.element.className.split(/\s+/).select(function(name){return name.length>0;})._each(iterator);},set:function(className){this.element.className=className;},add:function(classNameToAdd){if(this.include(classNameToAdd))return;this.set($A(this).concat(classNameToAdd).join(' '));},remove:function(classNameToRemove){if(!this.include(classNameToRemove))return;this.set($A(this).without(classNameToRemove).join(' '));},toString:function(){return $A(this).join(' ');}}
|
120
|
+
Object.extend(Element.ClassNames.prototype,Enumerable);var Selector=Class.create();Selector.prototype={initialize:function(expression){this.params={classNames:[]};this.expression=expression.toString().strip();this.parseExpression();this.compileMatcher();},parseExpression:function(){function abort(message){throw'Parse error in selector: '+message;}
|
121
|
+
if(this.expression=='')abort('empty expression');var params=this.params,expr=this.expression,match,modifier,clause,rest;while(match=expr.match(/^(.*)\[([a-z0-9_:-]+?)(?:([~\|!]?=)(?:"([^"]*)"|([^\]\s]*)))?\]$/i)){params.attributes=params.attributes||[];params.attributes.push({name:match[2],operator:match[3],value:match[4]||match[5]||''});expr=match[1];}
|
122
|
+
if(expr=='*')return this.params.wildcard=true;while(match=expr.match(/^([^a-z0-9_-])?([a-z0-9_-]+)(.*)/i)){modifier=match[1],clause=match[2],rest=match[3];switch(modifier){case'#':params.id=clause;break;case'.':params.classNames.push(clause);break;case'':case undefined:params.tagName=clause.toUpperCase();break;default:abort(expr.inspect());}
|
123
|
+
expr=rest;}
|
124
|
+
if(expr.length>0)abort(expr.inspect());},buildMatchExpression:function(){var params=this.params,conditions=[],clause;if(params.wildcard)
|
125
|
+
conditions.push('true');if(clause=params.id)
|
126
|
+
conditions.push('element.id == '+clause.inspect());if(clause=params.tagName)
|
127
|
+
conditions.push('element.tagName.toUpperCase() == '+clause.inspect());if((clause=params.classNames).length>0)
|
128
|
+
for(var i=0,length=clause.length;i<length;i++)
|
129
|
+
conditions.push('Element.hasClassName(element, '+clause[i].inspect()+')');if(clause=params.attributes){clause.each(function(attribute){var value='element.getAttribute('+attribute.name.inspect()+')';var splitValueBy=function(delimiter){return value+' && '+value+'.split('+delimiter.inspect()+')';}
|
130
|
+
switch(attribute.operator){case'=':conditions.push(value+' == '+attribute.value.inspect());break;case'~=':conditions.push(splitValueBy(' ')+'.include('+attribute.value.inspect()+')');break;case'|=':conditions.push(splitValueBy('-')+'.first().toUpperCase() == '+attribute.value.toUpperCase().inspect());break;case'!=':conditions.push(value+' != '+attribute.value.inspect());break;case'':case undefined:conditions.push(value+' != null');break;default:throw'Unknown operator '+attribute.operator+' in selector';}});}
|
131
|
+
return conditions.join(' && ');},compileMatcher:function(){this.match=new Function('element','if (!element.tagName) return false; \
|
132
|
+
return '+this.buildMatchExpression());},findElements:function(scope){var element;if(element=$(this.params.id))
|
133
|
+
if(this.match(element))
|
134
|
+
if(!scope||Element.childOf(element,scope))
|
135
|
+
return[element];scope=(scope||document).getElementsByTagName(this.params.tagName||'*');var results=[];for(var i=0,length=scope.length;i<length;i++)
|
136
|
+
if(this.match(element=scope[i]))
|
137
|
+
results.push(Element.extend(element));return results;},toString:function(){return this.expression;}}
|
138
|
+
Object.extend(Selector,{matchElements:function(elements,expression){var selector=new Selector(expression);return elements.select(selector.match.bind(selector)).collect(Element.extend);},findElement:function(elements,expression,index){if(typeof expression=='number')index=expression,expression=false;return Selector.matchElements(elements,expression||'*')[index||0];},findChildElements:function(element,expressions){return expressions.map(function(expression){return expression.strip().split(/\s+/).inject([null],function(results,expr){var selector=new Selector(expr);return results.inject([],function(elements,result){return elements.concat(selector.findElements(result||element));});});}).flatten();}});function $$(){return Selector.findChildElements(document,$A(arguments));}
|
139
|
+
var Form={reset:function(form){$(form).reset();return form;},serializeElements:function(elements){return elements.inject([],function(queryComponents,element){var queryComponent=Form.Element.serialize(element);if(queryComponent)queryComponents.push(queryComponent);return queryComponents;}).join('&');}};Form.Methods={serialize:function(form){return Form.serializeElements($(form).getElements());},getElements:function(form){return $A($(form).getElementsByTagName('*')).inject([],function(elements,child){if(Form.Element.Serializers[child.tagName.toLowerCase()])
|
140
|
+
elements.push(Element.extend(child));return elements;});},getInputs:function(form,typeName,name){form=$(form);var inputs=form.getElementsByTagName('input');if(!typeName&&!name)
|
141
|
+
return inputs;var matchingInputs=new Array();for(var i=0,length=inputs.length;i<length;i++){var input=inputs[i];if((typeName&&input.type!=typeName)||(name&&input.name!=name))
|
142
|
+
continue;matchingInputs.push(Element.extend(input));}
|
143
|
+
return matchingInputs;},disable:function(form){form=$(form);form.getElements().each(function(element){element.blur();element.disabled='true';});return form;},enable:function(form){form=$(form);form.getElements().each(function(element){element.disabled='';});return form;},findFirstElement:function(form){return $(form).getElements().find(function(element){return element.type!='hidden'&&!element.disabled&&['input','select','textarea'].include(element.tagName.toLowerCase());});},focusFirstElement:function(form){form=$(form);form.findFirstElement().activate();return form;}}
|
144
|
+
Object.extend(Form,Form.Methods);Form.Element={focus:function(element){$(element).focus();return element;},select:function(element){$(element).select();return element;}}
|
145
|
+
Form.Element.Methods={serialize:function(element){element=$(element);if(element.disabled)return'';var method=element.tagName.toLowerCase();var parameter=Form.Element.Serializers[method](element);if(parameter){var key=encodeURIComponent(parameter[0]);if(key.length==0)return;if(parameter[1].constructor!=Array)
|
146
|
+
parameter[1]=[parameter[1]];return parameter[1].map(function(value){return key+'='+encodeURIComponent(value);}).join('&');}},getValue:function(element){element=$(element);var method=element.tagName.toLowerCase();var parameter=Form.Element.Serializers[method](element);if(parameter)
|
147
|
+
return parameter[1];},clear:function(element){$(element).value='';return element;},present:function(element){return $(element).value!='';},activate:function(element){element=$(element);element.focus();if(element.select&&(element.tagName.toLowerCase()!='input'||!['button','reset','submit'].include(element.type)))
|
148
|
+
element.select();return element;},disable:function(element){element=$(element);element.disabled=true;return element;},enable:function(element){element=$(element);element.blur();element.disabled=false;return element;}}
|
149
|
+
Object.extend(Form.Element,Form.Element.Methods);var Field=Form.Element;Form.Element.Serializers={input:function(element){switch(element.type.toLowerCase()){case'checkbox':case'radio':return Form.Element.Serializers.inputSelector(element);default:return Form.Element.Serializers.textarea(element);}
|
150
|
+
return false;},inputSelector:function(element){if(element.checked)
|
151
|
+
return[element.name,element.value];},textarea:function(element){return[element.name,element.value];},select:function(element){return Form.Element.Serializers[element.type=='select-one'?'selectOne':'selectMany'](element);},selectOne:function(element){var value='',opt,index=element.selectedIndex;if(index>=0){opt=Element.extend(element.options[index]);value=opt.hasAttribute('value')?opt.value:opt.text;}
|
152
|
+
return[element.name,value];},selectMany:function(element){var value=[];for(var i=0,length=element.length;i<length;i++){var opt=Element.extend(element.options[i]);if(opt.selected)
|
153
|
+
value.push(opt.hasAttribute('value')?opt.value:opt.text);}
|
154
|
+
return[element.name,value];}}
|
155
|
+
var $F=Form.Element.getValue;Abstract.TimedObserver=function(){}
|
156
|
+
Abstract.TimedObserver.prototype={initialize:function(element,frequency,callback){this.frequency=frequency;this.element=$(element);this.callback=callback;this.lastValue=this.getValue();this.registerCallback();},registerCallback:function(){setInterval(this.onTimerEvent.bind(this),this.frequency*1000);},onTimerEvent:function(){var value=this.getValue();if(this.lastValue!=value){this.callback(this.element,value);this.lastValue=value;}}}
|
157
|
+
Form.Element.Observer=Class.create();Form.Element.Observer.prototype=Object.extend(new Abstract.TimedObserver(),{getValue:function(){return Form.Element.getValue(this.element);}});Form.Observer=Class.create();Form.Observer.prototype=Object.extend(new Abstract.TimedObserver(),{getValue:function(){return Form.serialize(this.element);}});Abstract.EventObserver=function(){}
|
158
|
+
Abstract.EventObserver.prototype={initialize:function(element,callback){this.element=$(element);this.callback=callback;this.lastValue=this.getValue();if(this.element.tagName.toLowerCase()=='form')
|
159
|
+
this.registerFormCallbacks();else
|
160
|
+
this.registerCallback(this.element);},onElementEvent:function(){var value=this.getValue();if(this.lastValue!=value){this.callback(this.element,value);this.lastValue=value;}},registerFormCallbacks:function(){Form.getElements(this.element).each(this.registerCallback.bind(this));},registerCallback:function(element){if(element.type){switch(element.type.toLowerCase()){case'checkbox':case'radio':Event.observe(element,'click',this.onElementEvent.bind(this));break;default:Event.observe(element,'change',this.onElementEvent.bind(this));break;}}}}
|
161
|
+
Form.Element.EventObserver=Class.create();Form.Element.EventObserver.prototype=Object.extend(new Abstract.EventObserver(),{getValue:function(){return Form.Element.getValue(this.element);}});Form.EventObserver=Class.create();Form.EventObserver.prototype=Object.extend(new Abstract.EventObserver(),{getValue:function(){return Form.serialize(this.element);}});if(!window.Event){var Event=new Object();}
|
162
|
+
Object.extend(Event,{KEY_BACKSPACE:8,KEY_TAB:9,KEY_RETURN:13,KEY_ESC:27,KEY_LEFT:37,KEY_UP:38,KEY_RIGHT:39,KEY_DOWN:40,KEY_DELETE:46,KEY_HOME:36,KEY_END:35,KEY_PAGEUP:33,KEY_PAGEDOWN:34,element:function(event){return event.target||event.srcElement;},isLeftClick:function(event){return(((event.which)&&(event.which==1))||((event.button)&&(event.button==1)));},pointerX:function(event){return event.pageX||(event.clientX+
|
163
|
+
(document.documentElement.scrollLeft||document.body.scrollLeft));},pointerY:function(event){return event.pageY||(event.clientY+
|
164
|
+
(document.documentElement.scrollTop||document.body.scrollTop));},stop:function(event){if(event.preventDefault){event.preventDefault();event.stopPropagation();}else{event.returnValue=false;event.cancelBubble=true;}},findElement:function(event,tagName){var element=Event.element(event);while(element.parentNode&&(!element.tagName||(element.tagName.toUpperCase()!=tagName.toUpperCase())))
|
165
|
+
element=element.parentNode;return element;},observers:false,_observeAndCache:function(element,name,observer,useCapture){if(!this.observers)this.observers=[];if(element.addEventListener){this.observers.push([element,name,observer,useCapture]);element.addEventListener(name,observer,useCapture);}else if(element.attachEvent){this.observers.push([element,name,observer,useCapture]);element.attachEvent('on'+name,observer);}},unloadCache:function(){if(!Event.observers)return;for(var i=0,length=Event.observers.length;i<length;i++){Event.stopObserving.apply(this,Event.observers[i]);Event.observers[i][0]=null;}
|
166
|
+
Event.observers=false;},observe:function(element,name,observer,useCapture){element=$(element);useCapture=useCapture||false;if(name=='keypress'&&(navigator.appVersion.match(/Konqueror|Safari|KHTML/)||element.attachEvent))
|
167
|
+
name='keydown';Event._observeAndCache(element,name,observer,useCapture);},stopObserving:function(element,name,observer,useCapture){element=$(element);useCapture=useCapture||false;if(name=='keypress'&&(navigator.appVersion.match(/Konqueror|Safari|KHTML/)||element.detachEvent))
|
168
|
+
name='keydown';if(element.removeEventListener){element.removeEventListener(name,observer,useCapture);}else if(element.detachEvent){try{element.detachEvent('on'+name,observer);}catch(e){}}}});if(navigator.appVersion.match(/\bMSIE\b/))
|
169
|
+
Event.observe(window,'unload',Event.unloadCache,false);var Position={includeScrollOffsets:false,prepare:function(){this.deltaX=window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft||0;this.deltaY=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0;},realOffset:function(element){var valueT=0,valueL=0;do{valueT+=element.scrollTop||0;valueL+=element.scrollLeft||0;element=element.parentNode;}while(element);return[valueL,valueT];},cumulativeOffset:function(element){var valueT=0,valueL=0;do{valueT+=element.offsetTop||0;valueL+=element.offsetLeft||0;element=element.offsetParent;}while(element);return[valueL,valueT];},positionedOffset:function(element){var valueT=0,valueL=0;do{valueT+=element.offsetTop||0;valueL+=element.offsetLeft||0;element=element.offsetParent;if(element){if(element.tagName=='BODY')break;var p=Element.getStyle(element,'position');if(p=='relative'||p=='absolute')break;}}while(element);return[valueL,valueT];},offsetParent:function(element){if(element.offsetParent)return element.offsetParent;if(element==document.body)return element;while((element=element.parentNode)&&element!=document.body)
|
170
|
+
if(Element.getStyle(element,'position')!='static')
|
171
|
+
return element;return document.body;},within:function(element,x,y){if(this.includeScrollOffsets)
|
172
|
+
return this.withinIncludingScrolloffsets(element,x,y);this.xcomp=x;this.ycomp=y;this.offset=this.cumulativeOffset(element);return(y>=this.offset[1]&&y<this.offset[1]+element.offsetHeight&&x>=this.offset[0]&&x<this.offset[0]+element.offsetWidth);},withinIncludingScrolloffsets:function(element,x,y){var offsetcache=this.realOffset(element);this.xcomp=x+offsetcache[0]-this.deltaX;this.ycomp=y+offsetcache[1]-this.deltaY;this.offset=this.cumulativeOffset(element);return(this.ycomp>=this.offset[1]&&this.ycomp<this.offset[1]+element.offsetHeight&&this.xcomp>=this.offset[0]&&this.xcomp<this.offset[0]+element.offsetWidth);},overlap:function(mode,element){if(!mode)return 0;if(mode=='vertical')
|
173
|
+
return((this.offset[1]+element.offsetHeight)-this.ycomp)/element.offsetHeight;if(mode=='horizontal')
|
174
|
+
return((this.offset[0]+element.offsetWidth)-this.xcomp)/element.offsetWidth;},page:function(forElement){var valueT=0,valueL=0;var element=forElement;do{valueT+=element.offsetTop||0;valueL+=element.offsetLeft||0;if(element.offsetParent==document.body)
|
175
|
+
if(Element.getStyle(element,'position')=='absolute')break;}while(element=element.offsetParent);element=forElement;do{if(!window.opera||element.tagName=='BODY'){valueT-=element.scrollTop||0;valueL-=element.scrollLeft||0;}}while(element=element.parentNode);return[valueL,valueT];},clone:function(source,target){var options=Object.extend({setLeft:true,setTop:true,setWidth:true,setHeight:true,offsetTop:0,offsetLeft:0},arguments[2]||{})
|
176
|
+
source=$(source);var p=Position.page(source);target=$(target);var delta=[0,0];var parent=null;if(Element.getStyle(target,'position')=='absolute'){parent=Position.offsetParent(target);delta=Position.page(parent);}
|
177
|
+
if(parent==document.body){delta[0]-=document.body.offsetLeft;delta[1]-=document.body.offsetTop;}
|
178
|
+
if(options.setLeft)target.style.left=(p[0]-delta[0]+options.offsetLeft)+'px';if(options.setTop)target.style.top=(p[1]-delta[1]+options.offsetTop)+'px';if(options.setWidth)target.style.width=source.offsetWidth+'px';if(options.setHeight)target.style.height=source.offsetHeight+'px';},absolutize:function(element){element=$(element);if(element.style.position=='absolute')return;Position.prepare();var offsets=Position.positionedOffset(element);var top=offsets[1];var left=offsets[0];var width=element.clientWidth;var height=element.clientHeight;element._originalLeft=left-parseFloat(element.style.left||0);element._originalTop=top-parseFloat(element.style.top||0);element._originalWidth=element.style.width;element._originalHeight=element.style.height;element.style.position='absolute';element.style.top=top+'px';;element.style.left=left+'px';;element.style.width=width+'px';;element.style.height=height+'px';;},relativize:function(element){element=$(element);if(element.style.position=='relative')return;Position.prepare();element.style.position='relative';var top=parseFloat(element.style.top||0)-(element._originalTop||0);var left=parseFloat(element.style.left||0)-(element._originalLeft||0);element.style.top=top+'px';element.style.left=left+'px';element.style.height=element._originalHeight;element.style.width=element._originalWidth;}}
|
179
|
+
if(/Konqueror|Safari|KHTML/.test(navigator.userAgent)){Position.cumulativeOffset=function(element){var valueT=0,valueL=0;do{valueT+=element.offsetTop||0;valueL+=element.offsetLeft||0;if(element.offsetParent==document.body)
|
180
|
+
if(Element.getStyle(element,'position')=='absolute')break;element=element.offsetParent;}while(element);return[valueL,valueT];}}
|
181
|
+
Element.addMethods();
|
Binary file
|
@@ -0,0 +1,86 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
7
|
+
|
8
|
+
<title>mofo - a ruby microformat parser</title>
|
9
|
+
<link href="http://mofo.rubyforge.org/style.css" rel="stylesheet" type="text/css" />
|
10
|
+
<script type="text/javascript" src="http://mofo.rubyforge.org/p.js"></script>
|
11
|
+
</head>
|
12
|
+
|
13
|
+
<body>
|
14
|
+
<div id="container">
|
15
|
+
<div id="header">
|
16
|
+
<img src="http://mofo.rubyforge.org/mofo-logo.png" alt="mofo!" />
|
17
|
+
<br /><hr />
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<div id="left">
|
21
|
+
<h3>mofo</h3>
|
22
|
+
|
23
|
+
<ul class="xoxo">
|
24
|
+
<li><a target="_top" href="http://mofo.rubyforge.org/try">Try It!</a></li>
|
25
|
+
<li><a target="_top" href="http://mofo.rubyforge.org/#get_started">Get Started</a></li>
|
26
|
+
<li><a target="_top" href="http://mofo.rubyforge.org/#microwhozit">Microwhozit?</a></li>
|
27
|
+
<li><a target="_top" href="http://mofo.rubyforge.org/#find">Mofo#find</a></li>
|
28
|
+
<li><a target="_top" href="http://mofo.rubyforge.org/#supported">Supported Microformats</a></li>
|
29
|
+
<li><a target="_top" href="http://mofo.rubyforge.org/#rails">Ruby on Rails</a></li>
|
30
|
+
<li><a target="_top" href="http://mofo.rubyforge.org/#touch">Get in Touch</a></li>
|
31
|
+
</ul>
|
32
|
+
|
33
|
+
<h3>Points of Interest</h3>
|
34
|
+
|
35
|
+
<ul class="xoxo">
|
36
|
+
<li><a target="_top" href="http://errtheblog.com/post/37">Me and uFormats</a></li>
|
37
|
+
<li><a target="_top" href="http://microformats.org">Microformats HQ</a></li>
|
38
|
+
<li><a target="_top" href="http://microformatique.com">Microformatique</a></li>
|
39
|
+
<li><a target="_top" href="http://labnotes.org">Assaf Arkin</a></li>
|
40
|
+
<li><a target="_top" href="http://allinthehead.com">Drew McClellan</a></li>
|
41
|
+
<li><a target="_top" href="http://tantek.com">Tantek Çelik</a></li>
|
42
|
+
<li><a target="_top" href="http://theryanking.com/blog">Ryan King</a></li>
|
43
|
+
</ul>
|
44
|
+
|
45
|
+
<h3>Other Parsers</h3>
|
46
|
+
|
47
|
+
<ul class="xoxo">
|
48
|
+
<li><a target="_top" href="http://rubyforge.org/projects/scrapi">Scrapi</a> [ruby]</li>
|
49
|
+
<li><a target="_top" href="http://rubyforge.org/projects/uformats">uFormats</a> [ruby]</li>
|
50
|
+
<li><a target="_top" href="http://allinthehead.com/hkit">hKit</a> [php]</li>
|
51
|
+
<li><a target="_top" href="http://www.danwebb.net/2007/2/9/sumo-a-generic-microformats-parser-for-javascript">Sumo</a> [js]</li>
|
52
|
+
<li><a target="_top" href="https://addons.mozilla.org/en-US/firefox/addon/4106">Operator</a> [firefox]</li>
|
53
|
+
</ul>
|
54
|
+
</div>
|
55
|
+
|
56
|
+
<div id="main">
|
57
|
+
<h3 id="get_started">Try Mofo!</h3>
|
58
|
+
<br/>
|
59
|
+
|
60
|
+
<p>Enter a URL you know is home to a microformat or (faster) paste some microformat'd HTML in directly.
|
61
|
+
The URL / text will be parsed with mofo and any microformats it finds will be displayed. Cool.</p>
|
62
|
+
|
63
|
+
<form action="/" onkeypress="return event.keyCode!=13"><p>
|
64
|
+
URL: <input type="text" name="ufurl" id="ufurl" size="25" />
|
65
|
+
<input id="grabit" value="Grab It" type="button" onclick="new Ajax.Updater('out','/trymofo',{method:'post',onComplete:function(request) {$('grabit').value = 'Grab It'; Element.hide('spinner')},onLoading:function(request) {$('grabit').value = 'Be patient...';Element.show('spinner')},postBody:$F('ufurl')});" />
|
66
|
+
<img id="spinner" src="http://mofo.rubyforge.org/spinner.gif" style="display:none;" />
|
67
|
+
<br/><br/>
|
68
|
+
HTML:<br />
|
69
|
+
<textarea name="tryit" id="tryit" cols="84" rows="10"></textarea>
|
70
|
+
<script type="text/javascript">new Form.Element.Observer("tryit",1,function(v){new Ajax.Updater("out","/trymofo",{method:"post",postBody:'text:' + $F("tryit")});})</script>
|
71
|
+
</p></form>
|
72
|
+
<pre id="out" style="font-size:1.3em;"></pre>
|
73
|
+
|
74
|
+
<p>Thanks to <a href="http://twitter.com/sprsquish">Jeff Smick</a> for most of the code driving this mofo.</p>
|
75
|
+
|
76
|
+
</div>
|
77
|
+
|
78
|
+
<div id="footer">
|
79
|
+
<hr />
|
80
|
+
<p class="left">| <a target="_top" href="http://jigsaw.w3.org/css-validator/">CSS</a> | <a target="_top" href="http://validator.w3.org/check?uri=referer">XHTML 1.1</a> |</p>
|
81
|
+
<p class="right">Designed by <a href="mailto:support@syndicateme.net">syndicateme.net</a>. Logo'd by <a href="http://seaofclouds.com/">seaofclouds</a>. Hosted by <a href="http://rubyforge.org">Rubyforge</a>. Birthed by <a href="http://errtheblog.com">Err</a>.</p>
|
82
|
+
<p> </p>
|
83
|
+
</div>
|
84
|
+
</div>
|
85
|
+
</body>
|
86
|
+
</html>
|
data/site/try/trymofo.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
##
|
2
|
+
# Jeff Smick rocks.
|
3
|
+
#
|
4
|
+
%w(rubygems mongrel mofo cgi).each { |r| require r }
|
5
|
+
Hpricot.buffer_size = 5242880
|
6
|
+
Mofo.timeout = 10
|
7
|
+
|
8
|
+
class TryMofo < Mongrel::HttpHandler
|
9
|
+
def html
|
10
|
+
@html ||= File.read('template.html')
|
11
|
+
end
|
12
|
+
|
13
|
+
def process(request, response)
|
14
|
+
response.start(200) do |headers, output|
|
15
|
+
headers['Content-Type'] = 'text/html'
|
16
|
+
output.write request.params['REQUEST_METHOD'].upcase == 'POST' ? serve_post_request(request) : html
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def serve_post_request(request)
|
21
|
+
Microformat.find(:all => target(request.body.read)).inject('') do |html, mofo|
|
22
|
+
html << "<dl><dt><h3>#{mofo.class}</h3></dt><dd>"
|
23
|
+
html << properties(mofo)
|
24
|
+
html << "</dd></dl>"
|
25
|
+
html << "<br/>"
|
26
|
+
end rescue ''
|
27
|
+
end
|
28
|
+
|
29
|
+
def target(text)
|
30
|
+
text[/^text:/] ? { :text => text.sub('text:','') } : clean_url(text)
|
31
|
+
end
|
32
|
+
|
33
|
+
def clean_url(url)
|
34
|
+
'http://' + url.sub('http://','')
|
35
|
+
end
|
36
|
+
|
37
|
+
def properties(mofo)
|
38
|
+
return mofo.to_yaml unless mofo.respond_to? :properties
|
39
|
+
props = mofo.properties.map do |property|
|
40
|
+
"<li><strong>#{property}</strong>: #{show_property(mofo.__send__(property))}</li>"
|
41
|
+
end
|
42
|
+
"<ul>#{props.join('')}</ul>"
|
43
|
+
end
|
44
|
+
|
45
|
+
def show_property(prop)
|
46
|
+
if prop.is_a? Microformat
|
47
|
+
properties(prop)
|
48
|
+
else
|
49
|
+
CGI.escapeHTML(prop.to_s)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
port = 9010
|
55
|
+
|
56
|
+
config = Mongrel::Configurator.new :host => "0.0.0.0" do
|
57
|
+
listener :port => port do
|
58
|
+
uri '/', :handler => TryMofo.new
|
59
|
+
uri '/js', :handler => Mongrel::DirHandler.new('.', false)
|
60
|
+
# daemonize :cwd => '.', :log_file => 'trymofo.log'
|
61
|
+
end
|
62
|
+
run
|
63
|
+
end
|
64
|
+
|
65
|
+
puts "=> Running at #{port}..."
|
66
|
+
config.join
|
data/test/fixtures/hatom.html
CHANGED
@@ -143,6 +143,11 @@
|
|
143
143
|
<span class='keyword'>class </span><span class='class'>Tag</span> <span class='punct'><</span> <span class='constant'>ActiveRecord</span><span class='punct'>::</span><span class='constant'>Base</span>
|
144
144
|
<span class='ident'>has_many_polymorphs</span> <span class='symbol'>:tagged_things</span><span class='punct'>,</span> <span class='symbol'>:from</span> <span class='punct'>=></span> <span class='punct'>[</span><span class='symbol'>:posts</span><span class='punct'>,</span> <span class='symbol'>:files</span><span class='punct'>,</span> <span class='symbol'>:tags</span><span class='punct'>]</span>
|
145
145
|
<span class='keyword'>end</span>
|
146
|
+
</pre>
|
147
|
+
|
148
|
+
<pre>
|
149
|
+
just a normal
|
150
|
+
test okay
|
146
151
|
</pre>
|
147
152
|
|
148
153
|
<p>Yup. Very nice. Also lets you do <span class='code'>Tag.find(:all, :include => :tagged_things)</span> and fetches the result in <strong>one</strong> query. That is, if you’re using MySQL or Postgres.</p>
|
@@ -242,7 +247,7 @@
|
|
242
247
|
<div class="sidebar">
|
243
248
|
|
244
249
|
<div class="title entry-title">“<a href="/post/12" class="reverse" rel="bookmark">Cheat Again!</a>”</div>
|
245
|
-
<div class="secondary byline">– <span class="entry-author">admin</span> on <
|
250
|
+
<div class="secondary byline">– <span class="entry-author">admin</span> on <abbr class="published" title="Sun Oct 15 21:14:00 PDT 2006">October 15th, 2006</abbr></div>
|
246
251
|
|
247
252
|
<br/>
|
248
253
|
<div class="secondary tags">
|
@@ -372,7 +377,7 @@ complete -W "$(cat ~</span><span class='punct'>/.</span><span class='ident'
|
|
372
377
|
<div class="sidebar">
|
373
378
|
|
374
379
|
<div class="title entry-title">“<a href="/post/11" class="reverse" rel="bookmark">Rake Around MySQL</a>”</div>
|
375
|
-
<div class="secondary byline">– <span class="entry-author">admin</span> on <
|
380
|
+
<div class="secondary byline">– <span class="entry-author">admin</span> on <abbr class="published" title="Sat Oct 14 18:39:00 PDT 2006">October 14th, 2006</abbr></div>
|
376
381
|
|
377
382
|
<br/>
|
378
383
|
<div class="secondary tags">
|
@@ -566,7 +571,7 @@ complete -W "$(cat ~</span><span class='punct'>/.</span><span class='ident'
|
|
566
571
|
<div class="sidebar">
|
567
572
|
|
568
573
|
<div class="title entry-title">“<a href="/post/10" class="reverse" rel="bookmark">Strut Your Structs</a>”</div>
|
569
|
-
<div class="secondary byline">– <span class="entry-author">admin</span> on <
|
574
|
+
<div class="secondary byline">– <span class="entry-author">admin</span> on <abbr class="published" title="Tue Sep 26 15:33:00 PDT 2006">September 26th, 2006</abbr></div>
|
570
575
|
|
571
576
|
<br/>
|
572
577
|
<div class="secondary tags">
|
@@ -857,7 +862,7 @@ complete -W "$(cat ~</span><span class='punct'>/.</span><span class='ident'
|
|
857
862
|
<div class="sidebar">
|
858
863
|
|
859
864
|
<div class="title entry-title">“<a href="/post/9" class="reverse" rel="bookmark">Content For Whom?</a>”</div>
|
860
|
-
<div class="secondary byline">– <span class="entry-author">admin</span> on <
|
865
|
+
<div class="secondary byline">– <span class="entry-author">admin</span> on <abbr class="published" title="Sat Sep 16 15:46:00 PDT 2006">September 16th, 2006</abbr></div>
|
861
866
|
|
862
867
|
<br/>
|
863
868
|
<div class="secondary tags">
|
data/test/hatom_test.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
require 'mofo/
|
2
|
+
require 'mofo/hfeed'
|
3
3
|
|
4
4
|
context "A parsed hEntry object" do
|
5
5
|
setup do
|
6
|
-
$hentry ||= HEntry.find(:first => fixture(:hatom))
|
6
|
+
$hentry ||= HEntry.find(:first => fixture(:hatom), :base => 'http://errtheblog.com')
|
7
7
|
end
|
8
8
|
|
9
9
|
specify "should have a title" do
|
@@ -35,4 +35,71 @@ context "A parsed hEntry object" do
|
|
35
35
|
specify "should have an array of tags" do
|
36
36
|
$hentry.tags.should.be.an.instance_of Array
|
37
37
|
end
|
38
|
+
|
39
|
+
specify "should know its Atom representation" do
|
40
|
+
to_atom = $hentry.to_atom
|
41
|
+
expected = <<-end_atom
|
42
|
+
<entry>
|
43
|
+
<id>tag:errtheblog.com,2008
|
44
|
+
<link type="text/html" href="http://errtheblog.com/post/13" rel="alternate"/>
|
45
|
+
<title>“A Rails Toolbox”</title>
|
46
|
+
<content type="html">
|
47
|
+
<img
|
48
|
+
src=
|
49
|
+
http://errtheblog.com/static/images/pink-toolbox.jpg
|
50
|
+
<p>
|
51
|
+
</content>
|
52
|
+
<author>
|
53
|
+
<name>Chris</name>
|
54
|
+
</author>
|
55
|
+
</entry>
|
56
|
+
end_atom
|
57
|
+
|
58
|
+
expected.split("\n").each do |line|
|
59
|
+
to_atom.should.include line.strip
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "An hFeed" do
|
65
|
+
setup do
|
66
|
+
$hentries ||= HEntry.find(:all => fixture(:hatom), :base => 'http://errtheblog.com')
|
67
|
+
end
|
68
|
+
|
69
|
+
specify "should know its Atom representation" do
|
70
|
+
to_atom = $hentries.to_atom(:title => 'Err the Blog')
|
71
|
+
expected = <<-end_atom
|
72
|
+
<entry>
|
73
|
+
<id>tag:errtheblog.com,2008
|
74
|
+
<link type="text/html" href="http://errtheblog.com/post/13" rel="alternate"/>
|
75
|
+
<title>Err the Blog</title>
|
76
|
+
<content type="html">
|
77
|
+
<img
|
78
|
+
src=
|
79
|
+
http://errtheblog.com/static/images/pink-toolbox.jpg
|
80
|
+
<p>
|
81
|
+
<pre>
|
82
|
+
just a normal
|
83
|
+
test okay
|
84
|
+
</pre>
|
85
|
+
</content>
|
86
|
+
<updated>
|
87
|
+
<author>
|
88
|
+
<name>Chris</name>
|
89
|
+
</author>
|
90
|
+
</entry>
|
91
|
+
end_atom
|
92
|
+
|
93
|
+
expected << <<-end_atom
|
94
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
95
|
+
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
|
96
|
+
<link type="text/html" href="
|
97
|
+
<link type="application/atom+xml" href="
|
98
|
+
</feed>
|
99
|
+
end_atom
|
100
|
+
|
101
|
+
expected.split("\n").each do |line|
|
102
|
+
to_atom.should.include line.strip
|
103
|
+
end
|
104
|
+
end
|
38
105
|
end
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: mofo
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date:
|
6
|
+
version: 0.2.11
|
7
|
+
date: 2008-01-22 00:00:00 -08:00
|
8
8
|
summary: mofo is a ruby microformat parser
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -32,6 +32,7 @@ files:
|
|
32
32
|
- ./CHANGELOG
|
33
33
|
- ./init.rb
|
34
34
|
- ./lib/microformat/array.rb
|
35
|
+
- ./lib/microformat/object.rb
|
35
36
|
- ./lib/microformat/simple.rb
|
36
37
|
- ./lib/microformat/string.rb
|
37
38
|
- ./lib/microformat/time.rb
|
@@ -53,10 +54,19 @@ files:
|
|
53
54
|
- ./Manifest.txt
|
54
55
|
- ./Rakefile
|
55
56
|
- ./README
|
57
|
+
- ./site/favicon.ico
|
56
58
|
- ./site/index.html
|
57
59
|
- ./site/mofo-logo.png
|
58
60
|
- ./site/mootools.v1.00.js
|
61
|
+
- ./site/p.js
|
62
|
+
- ./site/spinner.gif
|
59
63
|
- ./site/style.css
|
64
|
+
- ./site/try/index.html
|
65
|
+
- ./site/try/p.js
|
66
|
+
- ./site/try/spinner.gif
|
67
|
+
- ./site/try/template.html
|
68
|
+
- ./site/try/trymofo.rb
|
69
|
+
- ./site/try.html
|
60
70
|
- ./test/base_url_test.rb
|
61
71
|
- ./test/ext_test.rb
|
62
72
|
- ./test/fixtures/bob.html
|
@@ -81,6 +91,7 @@ files:
|
|
81
91
|
- ./test/hreview_test.rb
|
82
92
|
- ./test/include_pattern_test.rb
|
83
93
|
- ./test/reltag_test.rb
|
94
|
+
- ./test/subclass_test.rb
|
84
95
|
- ./test/test_helper.rb
|
85
96
|
- ./test/xfn_test.rb
|
86
97
|
- ./test/xoxo_test.rb
|