├── joeold.jpg ├── svg ├── p5.jpg ├── svg_test.html └── svg.js ├── favicon.ico ├── clipper ├── icon.png ├── manifest.json ├── background.html ├── Readme.html ├── content_script.js └── popup.html ├── openchrome ├── Readme ├── Makefile ├── generic.html ├── addbookmark.erl ├── demo1.erl ├── README.md ├── demo2.erl ├── demo3.erl ├── MIT-LICENSE ├── test1.html ├── generic.js ├── notes.txt ├── gui1.erl ├── svg_lib.js ├── work └── dragdiv.html ├── raphael.erl ├── svg_test.html ├── drag4.svg ├── sebg.erl ├── index.html ├── raphael-min.js └── jquery-1.5.min.js /joeold.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joearms/SEBG/HEAD/joeold.jpg -------------------------------------------------------------------------------- /svg/p5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joearms/SEBG/HEAD/svg/p5.jpg -------------------------------------------------------------------------------- /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joearms/SEBG/HEAD/favicon.ico -------------------------------------------------------------------------------- /clipper/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joearms/SEBG/HEAD/clipper/icon.png -------------------------------------------------------------------------------- /openchrome: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # an OS independent way to open a URL in a browser 4 | 5 | os=`uname` 6 | 7 | echo "starting $1" 8 | 9 | case $os in 10 | Linux) 11 | firefox $1;; 12 | Darwin) 13 | open -a 'Google Chrome' $1;; 14 | *) 15 | echo unknown OS $os;; 16 | esac 17 | -------------------------------------------------------------------------------- /Readme: -------------------------------------------------------------------------------- 1 | SEBG stands for 2 | 3 | Simple Erlang Browser Graphics 4 | 5 | Read index.html for documentation 6 | 7 | To run type make 8 | 9 | Notes: 10 | 11 | 1) You need a web socket enabled browser 12 | 2) Only tested on mac os-x 13 | 14 | Author: Joe Armstrong 15 | 16 | Contributions: 17 | 18 | Sergio Veiga -- websocket hadshake code 19 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .SUFFIXES: .erl .beam .yrl 2 | 3 | MODS := $(wildcard *.erl) 4 | 5 | %.beam: %.erl 6 | erlc -W $< 7 | 8 | all: beam 9 | (sleep 1 && ./openchrome http://localhost:1234/index.html) & 10 | erl -s sebg start 1234 11 | 12 | 13 | 14 | 15 | 16 | beam: ${MODS:%.erl=%.beam} 17 | 18 | clean: 19 | rm -rf *.beam 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /generic.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Minimal Example

4 | 5 | Javascript from Erlang to the browser. The page will change color and some text will appear. 6 |
  • 7 | 8 |

    Once you have started the brower 9 | click on

    10 | 11 | demo1 13 | 14 |

    Do view source to see the code :-) 15 | -------------------------------------------------------------------------------- /clipper/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Clipper 1.2", 3 | "description": "Clipper release 1 - first production version", 4 | "version": "1.2", 5 | "background_page": "background.html", 6 | "permissions": [ 7 | "tabs", 8 | "http://localhost:*//*/*", 9 | "http://*/*", 10 | "https://*/*" 11 | ], 12 | "browser_action": { 13 | "default_title": "Clipper", 14 | "default_icon": "icon.png", 15 | "popup": "popup.html" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /addbookmark.erl: -------------------------------------------------------------------------------- 1 | -module(addbookmark). 2 | -compile(export_all). 3 | 4 | start(Str) -> 5 | %% io:format("Str=~p~n",[Str]), 6 | T = sebg:parse_uri_args(Str), 7 | %% io:format("add bookmark:~p~n",[T]), 8 | Time = proplists:get_value("time", T), 9 | File = time_to_file(Time), 10 | file:write_file(File, term_to_binary(T)). 11 | 12 | time_to_file([$\s|T]) -> [$_|time_to_file(T)]; 13 | time_to_file([$(|T]) -> [$_|time_to_file(T)]; 14 | time_to_file([$)|T]) -> [$_|time_to_file(T)]; 15 | time_to_file([H|T]) -> [H|time_to_file(T)]; 16 | time_to_file([]) -> ".snip". 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /demo1.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2011 Joe Armstrong 2 | %% See MIT-LICENSE for licensing information. 3 | %% Time-stamp: <2011-02-12 11:57:32 joe> 4 | 5 | -module(demo1). 6 | -export([start/1]). 7 | 8 | %% simple demo 9 | %% once started Pid is a channel that csn be iused to talk 10 | %% to the browser. Pid ! {cmd,Javascript} 11 | 12 | start(Pid) -> 13 | Pid ! {eval, "document.body.innerHTML='';"}, 14 | Pid ! {eval, "document.body.style.backgroundColor='#eeffaa';"}, 15 | Pid ! {eval, "document.body.innerHTML+='

    Hello World

    '"}, 16 | event_loop(Pid). 17 | 18 | event_loop(Pid) -> 19 | receive 20 | Any -> 21 | io:format("??event loop:~p~n",[Any]), 22 | event_loop(Pid) 23 | end. 24 | 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Simple Erlang Browser Graphics 2 | ------------------------------ 3 | 4 | With SEBG you can push asynchronous commands to a browser window. 5 | 6 | For example, the following three Erlang commands: 7 | 8 | Pid ! {eval, "document.body.innerHTML='';"}, 9 | Pid ! {eval, "document.body.style.backgroundColor='red';"}, 10 | Pid ! {eval, "document.body.innerHTML+='

    Hello World

    '"}, 11 | 12 | Will erase all content on the current web page. Make page red and 13 | say hello world. 14 | 15 | The web page runs a universal script. It waits for message containing 16 | Javascript, then evaluates it and waits for the next message. 17 | 18 | Volunteers 19 | ---------- 20 | 21 | Look in drag4.svg and svg_test.html. At the top of svg_test.html I 22 | have some outstanding problems. Try to fix these. 23 | -------------------------------------------------------------------------------- /demo2.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2011 Joe Armstrong 2 | %% See MIT-LICENSE for licensing information. 3 | %% Time-stamp: <2011-02-12 10:51:26 joe> 4 | 5 | -module(demo2). 6 | -export([start/1]). 7 | 8 | %% simple demo 9 | %% once started Pid is a channel that csn be iused to talk 10 | %% to the browser. Pid ! {cmd,Javascript} 11 | 12 | start(Pid) -> 13 | Pid ! {eval,"document.body.innerHTML=''"}, 14 | Pid ! {eval, "document.body.style.backgroundColor='orange';"}, 15 | Pid ! {eval, button("click me")}, 16 | %% now add a link 17 | event_loop(Pid). 18 | 19 | button(X) -> 20 | ["document.body.innerHTML+=", 21 | "\"\";"]. 22 | 23 | event_loop(Pid) -> 24 | receive 25 | Any -> 26 | io:format("??event loop:~p~n",[Any]), 27 | event_loop(Pid) 28 | end. 29 | -------------------------------------------------------------------------------- /demo3.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2011 Joe Armstrong 2 | %% See MIT-LICENSE for licensing information. 3 | %% Time-stamp: <2011-02-12 10:55:22 joe> 4 | 5 | -module(demo3). 6 | -export([start/1]). 7 | 8 | %% simple demo 9 | %% once started Pid is a channel that csn be iused to talk 10 | %% to the browser. Pid ! {cmd,Javascript} 11 | 12 | start(Pid) -> 13 | Pid ! {eval,"document.body.innerHTML=''"}, 14 | Pid ! {eval, "document.body.style.backgroundColor='grey';"}, 15 | Pid ! {eval, button("click me")}, 16 | %% now add a link 17 | event_loop(Pid). 18 | 19 | button(X) -> 20 | ["document.body.innerHTML+=", 21 | "\"\";"]. 22 | 23 | event_loop(Pid) -> 24 | receive 25 | {browser,_,"click me"} -> 26 | Pid ! {eval, button("click me")}, 27 | event_loop(Pid); 28 | Any -> 29 | io:format("??event loop:~p~n",[Any]), 30 | event_loop(Pid) 31 | end. 32 | -------------------------------------------------------------------------------- /clipper/background.html: -------------------------------------------------------------------------------- 1 | 27 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006-2011 Joe Armstrong 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /test1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Dynamically add Textbox, Radio, Button in html Form using JavaScript 4 | 22 | 23 | 24 |
    25 |

    Dynamically add element in form.

    26 | Select the element and hit Add to add it in form. 27 |
    28 | 33 | 34 | 35 | 36 |   37 | 38 |
    39 | 40 | 41 | -------------------------------------------------------------------------------- /clipper/Readme.html: -------------------------------------------------------------------------------- 1 |

    Clipper 1.2

    2 | 3 |

    This is a chrome unpacked extension. 4 | 5 |

    To install goto: 6 |

     7 |    Chrome -> Window -> Extensions
     8 | 
     9 |    click on "Load unpacked extension"
    10 |    and select the directory where this extension is contained
    11 | 
    12 | 13 |

    Help Needed

    14 | 15 |

    This is just a beginning. Better analysis of the selection 16 | is highly desirable. 17 | 18 |

    Credits

    19 | 20 |

    The code in this extension is a modified version of 21 | a chrome extension that I found on the net (and a blog) 22 | article. The name of the extension was: 23 | 24 |

    25 |     "name": "Linx Bookmark 1.1",
    26 |     "description": "Adds the current page to the Linx bookmarking system.",
    27 |     "version": "1.1",
    28 | 
    29 | 30 | 31 |

    Unfortunately I cannot give a more precise reference, and 32 | have not been able to find the original. Mail my if you stumble over 33 | the origonal. 34 | 35 | 36 |

    Some the code in content_script.js 37 | came from 38 | http://dev.day.com/content/ddc/blog/2010/06.html 39 | 40 | 41 | -------------------------------------------------------------------------------- /generic.js: -------------------------------------------------------------------------------- 1 | var websocket; 2 | var output; 3 | var c; 4 | var logdiv; 5 | 6 | window.onload = 7 | function() { 8 | //console.log('

    started'); 9 | } 10 | 11 | function loadScript(File) { 12 | var s = document.createElement('script'); 13 | s.type = 'text/javascript'; 14 | s.src = File; 15 | s.onload = function(){send('loaded')}; 16 | document.body.appendChild(s); 17 | } 18 | 19 | function onClose(evt) { 20 | console.log('

    closed'); 21 | document.body.style.backgroundColor='#aabbcc'; 22 | } 23 | 24 | function onMessage(evt) { 25 | try 26 | { 27 | eval(evt.data); 28 | } 29 | catch(e) 30 | { 31 | alert("oops:"+evt.data); 32 | } 33 | } 34 | 35 | function onError(evt) { 36 | document.body.style.backgroundColor='orange'; 37 | } 38 | 39 | function send(msg) { 40 | websocket.send(msg); 41 | } 42 | 43 | function log(x) { 44 | logdiv.innerHTML += x; 45 | } 46 | 47 | function start_session(wsUri){ 48 | console.log("
    try to connect"); 49 | document.body.style.backgroundColor='#ccaabb'; 50 | websocket = new WebSocket(wsUri); 51 | websocket.onopen = onOpen; 52 | websocket.onclose = onClose; 53 | websocket.onmessage = onMessage; 54 | websocket.onerror = onError; 55 | return(false); 56 | } 57 | 58 | function onOpen(evt) { 59 | console.log("connected"); 60 | } 61 | 62 | -------------------------------------------------------------------------------- /clipper/content_script.js: -------------------------------------------------------------------------------- 1 | // code cut-and-paste from 2 | // http://dev.day.com/content/ddc/blog/2010/06.html 3 | 4 | // console.log('injecting code'); 5 | 6 | function getContent() { 7 | // console.log('getting selection'); 8 | var selection = window.getSelection( ); 9 | var markup = serializeSelection( selection ); 10 | // var finalMarkup = formatPage( markup ); 11 | // return finalMarkup; 12 | return markup; 13 | } 14 | 15 | function serializeSelection( selection ) { 16 | var xmlFragment = ""; 17 | try { 18 | var n = 0, ranges = selection.rangeCount; 19 | // console.log('ranges='+ranges); 20 | while ( n != ranges ) { 21 | var range = selection.getRangeAt( n++ ); 22 | // console.log('here',range); 23 | var content = range.cloneContents( ); 24 | var serializer = new XMLSerializer( ); 25 | xmlFragment += serializer.serializeToString( content ); 26 | } 27 | } 28 | catch( msg ) { } 29 | return xmlFragment; 30 | } 31 | 32 | content = getContent(); 33 | 34 | // console.log('content',content); 35 | 36 | 37 | var pageInfo = { 38 | "title": document.title, 39 | "url": window.location.href, 40 | "text": window.getSelection().toString(), 41 | "html": content 42 | }; 43 | 44 | // console.log('sending page',pageInfo) 45 | // Send the information back to the extension 46 | 47 | chrome.extension.sendRequest(pageInfo); 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /notes.txt: -------------------------------------------------------------------------------- 1 | Two beautiful programs 2 | 3 | For a long time one of my favorite Erlang program was this: 4 | 5 | loop() -> 6 | receive 7 | F -> F(), 8 | loop() 9 | end. 10 | 11 | It's nice because it does very little, but what is does is universal. It 12 | enables mobile code. 13 | 14 | Well now I can do this in Javascript. 15 | 16 | The Javascript equivalent is: 17 | 18 | function onMessage(evt) { 19 | eval(evt.data); 20 | } 21 | 22 | Where the data comes from a websocket. 23 | 24 | Websockets are controlled with a simple API: 25 | 26 | websocket = new WebSocket(wsUri); 27 | websocket.onopen = function(evt) { onOpen(evt) }; 28 | websocket.onclose = function(evt) { onClose(evt) }; 29 | websocket.onmessage = function(evt) { onMessage(evt) }; 30 | 31 | Linking a websocket and Erlang is pretty easy. So now I can write code like this in 32 | erlang 33 | 34 | -module(demo1). 35 | -export([start/1]). 36 | 37 | start(Pid) -> 38 | Pid ! {eval, "document.body.innerHTML='';"}, 39 | Pid ! {eval, "document.body.style.backgroundColor='#eeffaa';"}, 40 | Pid ! {eval, "document.body.innerHTML+='

    Hello World

    '"}, 41 | event_loop(Pid). 42 | 43 | event_loop(Pid) -> 44 | receive 45 | Any -> 46 | io:format("??event loop:~p~n",[Any]), 47 | event_loop(Pid) 48 | end. 49 | 50 | This code pushes asynchronous messages containing javascript to a generic 51 | web page, and the web page evals the result. 52 | 53 | This technique is amazingly powerful. 54 | 55 | So now I only need one generic web page. Think of that. 56 | 57 | Only one page is needed - forever. 58 | 59 | All the genric pages does is: 60 | 61 | loop: 62 | wait for a message containing Javascript 63 | eval the message 64 | 65 | Beautiful 66 | 67 | This is the easiest way to program a GUI I can conceive of. 68 | 69 | You can download and run the examples from: 70 | 71 | https://github.com/joearms/SEBG 72 | 73 | You'll need something like Google chrome to run them. 74 | 75 | Have fun 76 | 77 | -------------------------------------------------------------------------------- /svg/svg_test.html: -------------------------------------------------------------------------------- 1 | 2 | 46 | 47 |

    Tests

    48 |

    Test of svg library. 49 |

    Unsolved problems

    50 |
  • Can only click in left hand side of "Button to click". 51 | -- added button at end of display list. It was partially obscured by a text object. 52 |

    Propertis

    53 |
  • Blue drag circle
  • 54 |
  • Draggable image
  • 55 |
    56 |

    Notes

    57 |

    Q: How should we interact with the svg canvas? 58 |
    A: By sending JSON messages. 59 |

    Q: What objects are clickabkle? 60 |
    A: Only buttons. If we can make anthing clickabkle then it 61 | will not be obvious. 62 |

    Q: What objects are draggable? 63 |
    A: Only drag squares. Again it should be obvious what objects are draggable. 64 |

    Q: What are the drag methods? 65 |
    A: on_drag_start/on_moved/on_dropped 66 | 67 | 68 |

    69 | 70 | 71 | -------------------------------------------------------------------------------- /clipper/popup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | 71 | 72 | 73 |
    74 |


    75 |

    76 |


    77 |

    78 |


    79 |

    80 |


    81 |

    82 |

    83 |
    84 | 85 | 86 | -------------------------------------------------------------------------------- /gui1.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2011 Joe Armstrong 2 | %% See MIT-LICENSE for licensing information. 3 | %% Time-stamp: <2011-02-14 14:54:12 joe> 4 | 5 | -module(gui1). 6 | 7 | %% First attempt at a middle man 8 | %% This demonstrates dynamically sending GUI objects to a window 9 | %% and pushing text and colored things to the browser 10 | 11 | -compile(export_all). 12 | 13 | start(Pid) -> 14 | S = self(), 15 | Logic = spawn_link(fun() -> logic(S) end), 16 | mm(Pid, Logic). 17 | 18 | %%---------------------------------------------------------------------- 19 | 20 | logic(Pid) -> 21 | Pid ! clear_window, 22 | Pid ! {bg, "orange"}, 23 | Pid ! {add_button, "Click me", "zapit"}, 24 | Pid ! {add_div,"a"}, 25 | Pid ! {add_canvas,"c"}, 26 | Pid ! {add_random_rectangle,"c"}, 27 | random_seed(), 28 | spawn(fun() -> ticker(Pid, 0) end), 29 | logic_loop(Pid). 30 | 31 | ticker(Pid, N) -> 32 | receive 33 | after 250 -> 34 | true 35 | end, 36 | Pid ! {add_txt_to_div, "a", "Message number " ++ i2s(N)}, 37 | Pid ! {add_random_rectangle, "c"}, 38 | ticker(Pid, N+1). 39 | 40 | logic_loop(Pid) -> 41 | receive 42 | Any -> 43 | io:format("event loop Msg => ~p~n",[Any]), 44 | logic_loop(Pid) 45 | end. 46 | %%---------------------------------------------------------------------- 47 | 48 | mm(JS, Erlang) -> 49 | receive 50 | {add_canvas, Name} -> 51 | JS ! {eval, add_canvas(Name)}; 52 | {add_random_rectangle, Name} -> 53 | JS ! {eval, add_random_rectangle(Name)}; 54 | {add_div, Name} -> 55 | JS ! {eval, add_div(Name)}; 56 | {add_txt_to_div, Name, Txt} -> 57 | JS ! {eval, add_txt_to_div(Name, Txt)}; 58 | {add_button, Txt, Msg} -> 59 | JS ! {eval,button(Txt,Msg)}; 60 | clear_window -> 61 | JS ! {eval,"document.body.innerHTML=''"}; 62 | {bg, C} -> 63 | JS ! {eval, ["document.body.style.backgroundColor='", C, "';"]}; 64 | {add_text, S} -> 65 | JS ! {eval, ["document.body.innerHTML +='", S, "';"]}; 66 | X -> 67 | io:format("Dropping:~p~n",[X]) 68 | end, 69 | mm(JS, Erlang). 70 | 71 | add_div(X) -> 72 | ["document.body.innerHTML+=\"

    \";"]. 73 | 74 | add_canvas(X) -> 75 | ["document.body.innerHTML+=\"

    \";", 76 | X,"= document.getElementById('",X,"').getContext('2d');"]. 77 | 78 | 79 | add_txt_to_div(X, Y) -> 80 | ["document.getElementById('",X,"').innerHTML = '",Y,"';"]. 81 | 82 | button(Txt, Msg) -> 83 | ["document.body.innerHTML+=", 84 | "\"\";"]. 85 | 86 | i2s(X) -> 87 | integer_to_list(X). 88 | 89 | rgb(R,G,B) -> 90 | ["'rgb(",i2s(R),",",i2s(G),",",i2s(B),")';"]. 91 | 92 | fillRect(X,Y,W,H) -> 93 | ["fillRect(",i2s(X),",",i2s(Y),",",i2s(W),",",i2s(H),")"]. 94 | 95 | add_random_rectangle(Name) -> 96 | %% "c.fillStyle = 'rgb(255,0,0)';c.fillRect(30, 30, 50, 50);". 97 | R=random:uniform(255), 98 | G=random:uniform(255), 99 | B=random:uniform(255), 100 | X=100+random:uniform(100), 101 | Y=100+random:uniform(100), 102 | W=random:uniform(150), 103 | H=random:uniform(150), 104 | %% "c.fillStyle = 'rgb(255,0,0)';c.fillRect(30, 30, 50, 50);". 105 | [Name,".fillStyle=",rgb(R,G,B),Name,".",fillRect(X,Y,W,H),";"]. 106 | 107 | random_seed() -> 108 | {_,_,X} = erlang:now(), 109 | {H,M,S} = time(), 110 | H1 = H * X rem 32767, 111 | M1 = M * X rem 32767, 112 | S1 = S * X rem 32767, 113 | put(random_seed, {H1,M1,S1}). 114 | 115 | -------------------------------------------------------------------------------- /svg_lib.js: -------------------------------------------------------------------------------- 1 | svg_ns = 'http://www.w3.org/2000/svg'; 2 | 3 | document.onkeydown = function(e){update(e);}; 4 | 5 | 6 | var globstr = "Hello World"; 7 | var text; 8 | var svg; 9 | 10 | D = function(x, y){ 11 | return x == undefined ? y : x; 12 | }; 13 | 14 | update = function(e) { 15 | cc = e.keyCode; 16 | // can browse this in the log window 17 | console.log("pressed",e); 18 | console.log("pressed="+e.keyCode+" shift="+e.shiftKey); 19 | globstr += String.fromCharCode(cc); 20 | change_text(globstr); 21 | return false; 22 | } 23 | 24 | 25 | mk_canvas = function(o) { 26 | var x = document.createElementNS(svg_ns, 'svg'); 27 | x.setAttribute("width", D(o.width,700)); 28 | x.setAttribute("height", D(o.height, 200)); 29 | x.setAttribute("style","background-color:" + D(o.color,"red")); 30 | x.setAttribute("id", o.id); 31 | x.addEventListener("mousemove", drag, false); 32 | 33 | // x.addEventListener("mousedown", mouse_down, false); 34 | // x.addEventListener("mouseup", mouse_up, false); 35 | return x; 36 | }; 37 | 38 | mk_rect = function(o) { 39 | var obj = document.createElementNS(svg_ns, 'rect'); 40 | obj.setAttribute('x', D(o.x, 10)); 41 | obj.setAttribute('y', D(o.y,20)); 42 | obj.setAttribute('width', D(o.width,120)); 43 | obj.setAttribute('height', D(o.ht, 40)); 44 | obj.setAttribute('fill', D(o.color,'#aabb11')); 45 | obj.setAttribute('stroke','black'); 46 | obj.setAttribute('stroke-width',3); 47 | obj.setAttribute("rx", D(o.rx, 5)); 48 | obj.setAttribute("ry", D(o.ry, 5)); 49 | obj.addEventListener("click", buttonClicked, false); 50 | obj.addEventListener("mouseover", buttonOver, false); 51 | obj.addEventListener("mouseout", buttonOut, false); 52 | obj.addEventListener("onkeydown", key1, false); 53 | return obj; 54 | }; 55 | 56 | key1 = function(evt){ 57 | console.log("key1"); 58 | } 59 | 60 | buttonClicked = function(evt) { 61 | var x =evt.target; 62 | x.setAttribute("fill", "orange"); 63 | send("YES YOU CLICKED ME"); 64 | }; 65 | 66 | buttonOver = function(evt) { 67 | var x =evt.target; 68 | x.setAttribute("fill", "red"); 69 | }; 70 | 71 | buttonOut = function(evt) { 72 | var x =evt.target; 73 | x.setAttribute("fill", "#aabb11"); 74 | }; 75 | 76 | keypress = function(evt) { 77 | // var x = evt.target; 78 | console.log("pressed"); 79 | } 80 | 81 | mk_text = function(o) { 82 | var text = document.createElementNS(svg_ns, "text"); 83 | text.setAttribute("fill", D(o.fill,"green")); 84 | var size = D(o.size, 1); 85 | text.setAttribute("font-size", size+"px"); 86 | var font = D(o.font,"Courier"); 87 | text.setAttribute("font-family", font); 88 | text.setAttribute("x", D(o.x,10)); 89 | text.setAttribute("y", D(o.y,10)); 90 | text.setAttribute("text-anchor", D(o.anchor,"start")); 91 | var str = D(o.str,"** missing str in text **"); 92 | var data = document.createTextNode(globstr); 93 | text.setAttribute("id", o.id); 94 | text.appendChild(data); 95 | return text; 96 | }; 97 | 98 | change_text = function(x) { 99 | text.textContent=x; 100 | } 101 | 102 | 103 | window.onload = function() { 104 | svg = mk_canvas({width:800, height:200, color:'#ffeecc',id:1}), 105 | c = document.body.appendChild(svg); 106 | c.appendChild(mk_rect({})); 107 | text = mk_text({x:250,y:50, size:24, str:"Hello Joe"}) 108 | c.appendChild(text); 109 | } 110 | 111 | 112 | function drag(evt) 113 | { 114 | var t = evt.target; 115 | // console.log("drag="+t); 116 | } 117 | -------------------------------------------------------------------------------- /work/dragdiv.html: -------------------------------------------------------------------------------- 1 | 35 | 94 | 95 |

    96 |
    Window title
    97 |
    98 | This is the content of this window 99 |
    100 |
    101 |
    102 | 103 | 104 |
    105 |
    Window title
    107 |
    108 | The quick brown rat ran over the lazy cat. 109 |
    110 |
    111 |
    112 | 113 | 114 | -------------------------------------------------------------------------------- /raphael.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2011 Joe Armstrong 2 | %% See MIT-LICENSE for licensing information. 3 | %% Time-stamp: <2011-02-12 11:55:07 joe> 4 | 5 | -module(raphael). 6 | 7 | -compile(export_all). 8 | 9 | start(Pid) -> 10 | random_seed(), 11 | put(pid, Pid), %% Ok since we'll never change this 12 | init(Pid), 13 | %% spawn(fun() -> put(pid,Pid),random_seed(), push() end), 14 | event_loop(Pid). 15 | 16 | init(Pid) -> 17 | %% clear_page(), 18 | %% set_page_color("#ffffaa"), 19 | load_js(Pid, "raphael-min.js"), 20 | load_js(Pid, "jquery-1.5.min.js"), 21 | Pid ! {eval,"document.body.innerHTML=''"}, 22 | Pid ! {eval, "document.body.style.backgroundColor='orange';"}, 23 | mk_div("canvas"), 24 | mk_div("log"), 25 | %% cmd("logit('hello')"), 26 | cmd("c=Raphael('canvas',800,500)"), 27 | cmd("r=c.circle(320,240,60);"), 28 | cmd("c.image('joeold.jpg', 500, 50, 294, 195);"), 29 | cmd("c.text(100,10,'red circle is draggble, blue box is clickable');"), 30 | cmd("r.attr('fill','red');"), 31 | cmd(drag_code()), 32 | cmd("r.drag(move,start,up);"), 33 | cmd("b=c.rect(40,40,50,50,10);"), 34 | cmd("b.attr('fill','blue');"), 35 | cmd("b.node.onclick= function(){send('click 3');};"). 36 | 37 | 38 | drag_code() -> 39 | <<" start = function(){ 40 | 41 | this.ox = this.attr('cx'); 42 | this.oy = this.attr('cy'); 43 | this.attr({opacity: 1}); 44 | } 45 | 46 | move = function (dx, dy) { 47 | // move will be called with dx and dy 48 | this.attr({cx: this.ox + dx, cy: this.oy + dy}); 49 | }, 50 | 51 | up = function () { 52 | // alert('stop'); 53 | // restoring state 54 | this.attr({opacity: .5}); 55 | }; 56 | ">>. 57 | 58 | 59 | 60 | 61 | event_loop(Pid) -> 62 | receive 63 | Any -> 64 | io:format("??event loop:~p~n",[Any]), 65 | event_loop(Pid) 66 | end. 67 | 68 | push() -> 69 | %% every 100 ms push a random rectangle to the browser 70 | sleep(100), 71 | cmd(random_rect()), 72 | push(). 73 | 74 | random_rect() -> 75 | R=random:uniform(255), 76 | G=random:uniform(255), 77 | B=random:uniform(255), 78 | X=400+random:uniform(100), 79 | Y=50+random:uniform(100), 80 | W=random:uniform(250), 81 | H=random:uniform(100), 82 | ["glob[1].rect(",i2s(X),",",i2s(Y),",",i2s(W),",",i2s(H),").", 83 | "attr('fill',", rgb(R,G,B),");"]. 84 | 85 | rgb(R,G,B) -> 86 | ["'rgb(",i2s(R),",",i2s(G),",",i2s(B),")'"]. 87 | 88 | sleep(N) -> 89 | receive 90 | after 91 | N -> 92 | true 93 | end. 94 | 95 | clear_page() -> 96 | cmd("$('body').html('');"). 97 | 98 | set_page_color(C) -> 99 | cmd(["$('body')",css([{"background-color",C}]),";"]). 100 | 101 | css(L) -> 102 | [".css({", [[fmt(I),":",fmt(J)]||{I,J} <- L],"})"]. 103 | 104 | fmt(I) -> 105 | ["'",I,"'"]. 106 | 107 | mk_div(Id) -> 108 | cmd(["$('body').prepend('
    ');"]). 109 | 110 | load_js(Pid, File) -> 111 | %% jQuery magic :-) 112 | cmd(["loadScript('",File,"');"]), 113 | %% wait for the script to run 114 | receive 115 | {browser,_,"loaded"} -> 116 | io:format("script loaded~n"), 117 | true 118 | after 10000 -> 119 | io:format("timeout loading:~p~n",[File]) 120 | end. 121 | 122 | mkCanvas(Tag, Color, Width, Ht) -> 123 | cmd(["$('body').prepend('');"]). 126 | 127 | cmd(Msg) -> 128 | io:format("eval:~s~n",[Msg]), 129 | get(pid) ! {eval, Msg}. 130 | 131 | msg(Pid) -> 132 | Pid ! {send, bgColor("#ffaacc")}. 133 | 134 | bgColor(C) -> 135 | ["$('body').css({'background-color':'",C,"'});"]. 136 | 137 | i2s(I) -> 138 | integer_to_list(I). 139 | 140 | %% @doc Seed the random number generator. 141 | %% This is evaluated for its side effect. Not well tested at all. 142 | 143 | -spec random_seed() -> void. 144 | 145 | random_seed() -> 146 | {_,_,X} = erlang:now(), 147 | {H,M,S} = time(), 148 | H1 = H * X rem 32767, 149 | M1 = M * X rem 32767, 150 | S1 = S * X rem 32767, 151 | put(random_seed, {H1,M1,S1}), 152 | void. 153 | -------------------------------------------------------------------------------- /svg_test.html: -------------------------------------------------------------------------------- 1 | 158 | 159 | 160 | 161 |

    SVT canvas testbed

    162 |
    163 | 164 |

    Unsolved Problems

    165 | 172 | 173 |

    To do

    174 | 178 | 179 | 180 |

    refs

    181 | 187 | 188 | 189 | 190 |

    Log

    191 |
    192 | 193 | 194 | -------------------------------------------------------------------------------- /drag4.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 12 | 13 | Rubber banding 14 | 15 | 16 | Rubber-banding in SVG, Now compute the correct end-points 17 | 18 | 19 | 20 | 21 | 22 | 185 | 186 | 189 | 190 | 191 | 192 | 193 | 194 | Rubber banding - corrects arcs - 195 | text and color - arrows 196 | 197 | Click and drag on the circles 198 | 199 | 200 | 201 | -------------------------------------------------------------------------------- /svg/svg.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file defines a single function SVG to use the module 3 | * var x = SVG(); 4 | * x.mk_canvas({width:200, id:1, ht:100, color:blue}); 5 | * x.mk_circle({parent:1, cx:10, cy:20, r:15, color:"green"}); 6 | * ... 7 | */ 8 | 9 | function SVG(pageId){ 10 | var C = {}; 11 | var V = new Array(); 12 | C.svg_ns = 'http://www.w3.org/2000/svg'; 13 | C.xhtml_ns = 'http://www.w3.org/1999/xhtml'; 14 | C.xlinkns = 'http://www.w3.org/1999/xlink'; 15 | // drag variables 16 | C.xstart = 0; 17 | C.ystart = 0; 18 | C.dragging = false; 19 | C.dragobj = null; 20 | C.canvas = null; 21 | C.pageId = pageId; 22 | // alert("PageId"+pageId); 23 | // mk_canvas is a top-level call 24 | 25 | C.mk_canvas = function(o) 26 | { 27 | var x = document.createElementNS(this.svg_ns, 'svg'); 28 | x.setAttribute("width", D(o.width,700)); 29 | x.setAttribute("height", D(o.ht, 200)); 30 | x.setAttribute("style","background-color:" + D(o.color,"red")); 31 | x.setAttribute("id", o.id); 32 | x.addEventListener("mousemove", drag, false); 33 | x.addEventListener("mousedown", mouse_down, false); 34 | x.addEventListener("mouseup", mouse_up, false); 35 | C.canvas = x; 36 | V[o.id]=x; 37 | return x; 38 | }; 39 | 40 | C.mk_group = function(o) 41 | { 42 | var obj = document.createElementNS(this.svg_ns, 'g'); 43 | var x = D(o.x,10); 44 | var y = D(o.y,10); 45 | var t = "translate("+x+","+y+")"; 46 | obj.setAttribute('transform', t); 47 | obj.setAttribute('x',x); 48 | obj.setAttribute('y',y); 49 | obj.setAttribute('draggable','true'); 50 | obj.setAttribute("id", o.id); 51 | log("draggable "+o.id); 52 | setId(o.id, obj); 53 | V[o.parent].appendChild(obj); 54 | return obj; 55 | }; 56 | 57 | function D(x, y){ 58 | return x == undefined ? y : x; 59 | }; 60 | 61 | // regular DOM objects into the SVG 62 | C.mk_button = function(o) 63 | { 64 | var fo = document.createElementNS(this.svg_ns,"foreignObject"); 65 | fo.setAttribute("x", D(o.x, 10)); 66 | fo.setAttribute("y", D(o.y, 100)); 67 | fo.setAttribute("width", 200); 68 | fo.setAttribute("height", 50); 69 | V[o.parent].appendChild(fo); 70 | setId(o.id, fo); 71 | var n = document.createElement('input'); 72 | n.setAttribute('type','button'); 73 | n.setAttribute('value',D(o.txt, 'click me')); 74 | n.setAttribute('name','joe'); 75 | fo.appendChild(n); 76 | return fo; 77 | }; 78 | 79 | C.mk_rect = function (o) 80 | { 81 | var obj = document.createElementNS(this.svg_ns, 'rect'); 82 | obj.setAttribute('x', o.x); 83 | obj.setAttribute('y', o.y); 84 | obj.setAttribute('width', o.width); 85 | obj.setAttribute('height', o.ht); 86 | obj.setAttribute('fill', o.color); 87 | obj.setAttribute("rx", D(o.rx, 5)); 88 | obj.setAttribute("ry", D(o.ry, 5)); 89 | obj.setAttribute("id", o.id); 90 | setId(o.id, obj); 91 | V[o.parent].appendChild(obj); 92 | return obj; 93 | }; 94 | 95 | function setId(id, obj){ 96 | log("V["+id+"]="+obj); 97 | V[id] = obj; 98 | }; 99 | 100 | C.mk_circle = function(o) 101 | { 102 | var obj = document.createElementNS(this.svg_ns, 'circle'); 103 | obj.setAttribute('cx', o.x); 104 | obj.setAttribute('cy', o.y); 105 | obj.setAttribute('r', o.r); 106 | obj.setAttribute('fill', D(o.color,"red")); 107 | obj.setAttribute("id", o.id); 108 | setId(o.id, obj); 109 | V[o.parent].appendChild(obj); 110 | return obj; 111 | }; 112 | 113 | C.mk_text = function(o) 114 | { 115 | var text = document.createElementNS(this.svg_ns, "text"); 116 | text.setAttribute("fill", D(o.fill,"green")); 117 | var size = D(o.size, 1); 118 | text.setAttribute("font-size", size+"em"); 119 | var font = D(o.font,"Arial"); 120 | text.setAttribute("font-family", font); 121 | text.setAttribute("x", D(o.x,10)); 122 | text.setAttribute("y", D(o.y,10)); 123 | text.setAttribute("text-anchor", D(o.anchor,"start")); 124 | var str = D(o.str,"** missing str in text **"); 125 | var data = document.createTextNode(o.str); 126 | text.setAttribute("id", o.id); 127 | setId(o.id, text); 128 | text.appendChild(data); 129 | V[o.parent].appendChild(text); 130 | return text; 131 | }; 132 | 133 | C.mk_image = function(o) 134 | { 135 | var img = document.createElementNS(this.svg_ns, "image"); 136 | img.setAttribute("x", D(o.x,10)); 137 | img.setAttribute("y", D(o.y,10)); 138 | img.setAttribute("width", D(o.width, 20)); 139 | img.setAttribute("height", D(o.ht, 20)); 140 | img.setAttributeNS(this.xlinkns, "href", o.img); 141 | img.setAttribute("id", o.id); 142 | setId(o.id, img); 143 | V[o.parent].appendChild(img); 144 | return img; 145 | }; 146 | 147 | C.mk_line = function(o) 148 | { 149 | var obj= document.createElementNS(this.svg_ns,"line"); 150 | obj.setAttribute("x1", o.x1); 151 | obj.setAttribute("y1", o.y1); 152 | obj.setAttribute("x2", o.x2); 153 | obj.setAttribute("y2", o.y2); 154 | obj.setAttribute("stroke","black"); 155 | var width = D(o.width,2); 156 | obj.setAttribute("stroke-width",width+"px"); 157 | obj.setAttribute("fill",D(o.fill,"black")); 158 | obj.setAttribute("marker-end","url(./svg2.#myMarker)"); 159 | obj.setAttribute("id", o.id); 160 | V[o.id] = obj; 161 | V[o.parent].appendChild(obj); 162 | return obj; 163 | }; 164 | 165 | C.mk_ellipse = function(o) 166 | { 167 | var obj = document.createElementNS(this.svg_ns, "ellipse"); 168 | obj.setAttribute("cx", o.cx); 169 | obj.setAttribute("cy", o.cy); 170 | obj.setAttribute("rx", o.rx); 171 | obj.setAttribute("ry", o.ry); 172 | obj.setAttribute("fill", D(o.fill,"black")); 173 | obj.setAttribute("id", o.id); 174 | V[o.id] = obj; 175 | V[o.parent].appendChild(obj); 176 | return obj; 177 | }; 178 | 179 | C.configure = function(o) 180 | { 181 | log("config "+V[o.id]+" key="+o.key+" val="+o.val); 182 | V[o.id].setAttribute(o.key, o.val); 183 | log("confok"); 184 | }; 185 | 186 | C.render = function(objs){ 187 | var val; 188 | for(var i = 0; i < objs.length; i++){ 189 | var o = objs[i]; 190 | switch(o.cmd){ 191 | case "mk_canvas": val = C.mk_canvas(o); break; 192 | case "mk_rect": val = C.mk_rect(o); break; 193 | case "mk_circle": val = C.mk_circle(o); break; 194 | case "mk_text": val = C.mk_text(o); break; 195 | case "mk_ellipse": val = C.mk_ellipse(o); break; 196 | case "mk_line": val = C.mk_line(o); break; 197 | case "mk_group": val = C.mk_group(o); break; 198 | case "mk_image": val = C.mk_image(o); break; 199 | case "mk_button": val = C.mk_button(o); break; 200 | case "configure": C.configure(o); break; 201 | default: alert("bad o.cmd ="+o.cmd); 202 | }; 203 | if(o.clickable){ 204 | log("clickable "+o.id + "val="+o.msg); 205 | val.setAttribute("message", D(o.msg, "void")); 206 | val.addEventListener("mousedown", 207 | function(evt){was_clicked(evt)}, 208 | false); 209 | }; 210 | }; 211 | }; 212 | 213 | function was_clicked(evt) 214 | { 215 | obj = evt.target; 216 | var id = obj.getAttribute("id"); 217 | var msg = obj.getAttribute("message"); 218 | var str = "clicked?page=" + 219 | "&id=" + escape(id) + 220 | "&msg=" + escape(msg); 221 | svg_event(str); 222 | }; 223 | 224 | function mouse_down(evt) 225 | { 226 | // log("mouse down"); 227 | var t = evt.target.parentNode; 228 | // log("target="+t); 229 | this.dragging = t.getAttribute("draggable"); 230 | if(this.dragging){ 231 | this.dragobj = t; 232 | var x = evt.clientX + window.scrollX; 233 | var y = evt.clientY + window.scrollY; 234 | var cxstart = parseInt(t.getAttribute("x")); 235 | var cystart = parseInt(t.getAttribute("y")); 236 | this.xstart = x - cxstart; 237 | this.ystart = y - cystart; 238 | } 239 | }; 240 | 241 | function mouse_up(evt) 242 | { 243 | if(this.dragging){ 244 | this.dragging = false; 245 | // log("dragging=false"); 246 | var obj = this.dragobj; 247 | // alert(obj); 248 | var x = obj.getAttribute("x"); 249 | var y = obj.getAttribute("y"); 250 | // log("dragend = " + obj.id + " x=" + x + " y= "+y); 251 | svg_event({pageId:C.pageId, type:"drag", id:obj.id, x:x, y:y}); 252 | }; 253 | }; 254 | 255 | function drag(evt) 256 | { 257 | if (this.dragging) 258 | { 259 | var t = evt.target; 260 | var x = evt.clientX + window.scrollX; 261 | var y = evt.clientY + window.scrollY; 262 | // Move drag element by the same amount the cursor has moved. 263 | var x1 = (x-this.xstart); 264 | var y1 = (y-this.ystart); 265 | this.dragobj.setAttribute("x", x1); 266 | this.dragobj.setAttribute("y", y1); 267 | var t = "translate("+x1+","+y1+")"; 268 | this.dragobj.setAttribute("transform", t); 269 | } 270 | }; 271 | 272 | return C; 273 | } 274 | -------------------------------------------------------------------------------- /sebg.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2011 Joe Armstrong 2 | %% See MIT-LICENSE for licensing information. 3 | %% Time-stamp: <2011-02-19 17:12:50 joe> 4 | 5 | -module(sebg). 6 | 7 | %% Simple Erlang Browser Graphics 8 | 9 | -import(lists, [map/2, reverse/1]). 10 | 11 | -export([start/0, start/1, test/0, parse_uri_args/1, urlencoded2str/1]). 12 | 13 | %% this has been tested run from a makefile not the shell 14 | 15 | start() -> 16 | start_port(1234). 17 | 18 | start([PortAsAtom]) -> 19 | Port = list_to_integer(atom_to_list(PortAsAtom)), 20 | start_port(Port). 21 | 22 | start_port(Port) -> 23 | {ok, Listen} = gen_tcp:listen(Port, [{packet,http}, 24 | {reuseaddr,true}, 25 | {active, false}]), 26 | io:format("Got a listener:~p~n",[Listen]), 27 | spawn(fun() -> par_connect(Listen) end), 28 | %% wait forever. I'm not sure, but I think if the 29 | %% process that owns the listening socket dies we are in trouble 30 | receive 31 | after infinity -> 32 | true 33 | end. 34 | 35 | par_connect(Listen) -> 36 | io:format("waiting for a connection~n"), 37 | case gen_tcp:accept(Listen) of 38 | {ok, Socket} -> 39 | spawn(fun() -> par_connect(Listen) end), 40 | io:format("starting a new session socket=~p~n",[Socket]), 41 | next_request(Socket); 42 | Other -> 43 | io:format("par_connect:Other=~p ~p~n", 44 | [Other,erlang:get_stacktrace()]) 45 | end. 46 | 47 | next_request(Socket) -> 48 | %% io:format("Session ~p waiting~n",[Socket]), 49 | Req = get_request(Socket), 50 | %% io:format("Req=~p~n",[Req]), 51 | %% io:format("req=~p~n",[element(1,Req)]), 52 | do_request(Socket, Req). 53 | 54 | %% Data is sent in the form of UTF-8 text. Each frame of data starts 55 | %% with a 0xFF byte identifying the frame type, followed by the number 56 | %% of bytes in the data expressed as a big-endian 64 bit unsigned 57 | %% integer, followed by the UTF-8 data. 58 | 59 | %% NOTE: The length is the number of UTF-8 _bytes_, and not the number 60 | %% of characters. For example, the string "Hwllo " has 13 Unicode code 61 | %% points, but is 21 bytes long. 62 | 63 | do_request(Socket, {{post, {abs_path,"/mod/" ++ Str}}, L, Data}) -> 64 | %% Str has a trailing "/" 65 | Mod = list_to_atom(reverse(tl(reverse(Str)))), 66 | Mod:start(Data), 67 | gen_tcp:send(Socket, make_response(html,"ok")); 68 | do_request(Socket, {{get, {abs_path,"/connect" ++ _=Path}}, L, _}) -> 69 | io:format("~p is now a web socket~n",[Socket]), 70 | connect(Socket, Path, L); 71 | do_request(Socket,{{get,{abs_path,F0}}, _, _}) -> 72 | %% io:format("Here 1F=~p~n",[F0]), 73 | {F, Args} = parse_uri(F0), 74 | File = case F of 75 | "//" ++ F1 -> "/" ++ F1; 76 | "/" ++ F1 -> "./" ++ F1; 77 | _ -> "./" ++ F 78 | end, 79 | io:format("Session ~p wants:~p Args=~p~n",[Socket,File,Args]), 80 | Response = get_file(File, Args), 81 | gen_tcp:send(Socket, Response), 82 | next_request(Socket). 83 | 84 | get_file(File, Args) -> 85 | case filelib:is_dir(File) of 86 | true -> 87 | {ok, Files} = file:list_dir(File), 88 | L = [li(a(File ++ I, I)) || I <- Files], 89 | make_response(html, L); 90 | false -> 91 | case file:read_file(File) of 92 | {ok, Bin} -> 93 | io:format("sending file:~p~n",[File]), 94 | make_response(classify(File),[Bin]); 95 | _ -> 96 | io:format("missing file:~p Args:~p~n",[File,Args]), 97 | make_response(html,pre({nosuchfile,File,Args})) 98 | end 99 | end. 100 | 101 | li(X) -> ["
  • ",X,"
  • "]. 102 | a(A, B) -> ["",B,""]. 103 | 104 | 105 | get_request(Socket) -> 106 | {Req, Headers} = get_request(Socket, no, []), 107 | case proplists:get_value('Content-Length', Headers, none) of 108 | none -> 109 | {Req, Headers, ""}; 110 | Val -> 111 | N = list_to_integer(Val), 112 | inet:setopts(Socket, [{packet, raw}, {active, false}]), 113 | Body = case gen_tcp:recv(Socket, N, 30000) of 114 | {ok, Str} -> Str; 115 | {error, timeout} -> 116 | <<>>; 117 | _Other -> 118 | <<>> 119 | end, 120 | {Req, Headers, Body} 121 | end. 122 | 123 | get_request(Socket,X,L) -> 124 | %% io:format("here X=~p L=~p~n",[X,L]), 125 | R = gen_tcp:recv(Socket, 0, 30000), 126 | %% io:format("R=~p~n",[R]), 127 | case R of 128 | {ok, {http_request,'GET',Path,_Vsn}} -> 129 | get_request(Socket,{get, Path},L); 130 | {ok, {http_request,'POST',Path,_Vsn}} -> 131 | get_request(Socket,{post, Path},L); 132 | {ok, {http_header, _, Key, _, Val}} -> 133 | get_request(Socket, X, [{Key,Val}|L]); 134 | {ok, http_eoh} -> 135 | {X, L}; 136 | _Other -> 137 | io:format("session ~p ending with timeout in get_request~n", 138 | [Socket]), 139 | exit(timeout) 140 | end. 141 | 142 | connect(Socket, Path, Headers) -> 143 | %% io:format("Headers=~p~n",[Headers]), 144 | Origin = proplists:get_value("Origin", Headers), 145 | Host = proplists:get_value('Host', Headers), 146 | Key1 = proplists:get_value("Sec-Websocket-Key1",Headers, none), 147 | Challenge = case Key1 of 148 | none -> 149 | <<>>; 150 | _ -> 151 | Key2 = proplists:get_value("Sec-Websocket-Key2", Headers), 152 | inet:setopts(Socket, [{packet, raw}, {active, false}]), 153 | Body = case gen_tcp:recv(Socket, 8, 30000) of 154 | {ok, Str} -> list_to_binary(Str); 155 | {error, timeout} -> 156 | <<>>; 157 | _Other -> 158 | <<>> 159 | end, 160 | build_challenge(Key1, Key2, Body) 161 | end, 162 | %% prepare handhsake response 163 | Response = 164 | ["HTTP/1.1 101 WebSocket Protocol Handshake\r\n", 165 | "Upgrade: WebSocket\r\n", 166 | "Connection: Upgrade\r\n", 167 | "Sec-WebSocket-Origin: ", Origin, "\r\n", 168 | "Sec-WebSocket-Location: ws://", lists:concat([Host, Path]), "\r\n\r\n", 169 | Challenge 170 | ], 171 | %% io:format("Response:~p~n",[Response]), 172 | gen_tcp:send(Socket, Response), 173 | inet:setopts(Socket, [{packet, raw}, {active, true}]), 174 | Pid = start_session(Socket, Path), 175 | mm(Socket, Pid, [], 0, 0). 176 | 177 | start_session(Socket, "/connect/" ++ ModStr) -> 178 | io:format("Handler in module ~p connected to socket ~p~n",[ModStr, Socket]), 179 | Mod = list_to_atom(ModStr), 180 | S = self(), 181 | spawn_link(fun() -> Mod:start(S) end). 182 | 183 | mm(Socket, Pid, Buff, Rec, Sent) -> 184 | receive 185 | {tcp, Socket, Str} -> 186 | {Buff1, Rec1} = handle(Pid, Str, Buff, Rec), 187 | mm(Socket, Pid, Buff1, Rec1, Sent); 188 | {eval, Msg} -> 189 | gen_tcp:send(Socket,[0,Msg,255]), 190 | %% io:format("sent:~p~n ~s~n",[Msg,Msg]), 191 | mm(Socket, Pid, Buff, Rec, Sent+1); 192 | {tcp_closed, Socket} -> 193 | exit(Pid, browser); 194 | {'EXIT', Pid, _} -> 195 | get_tcp:closed(Socket); 196 | Other -> 197 | io:format("unexpecte3 message dropped:~p~n",[Other]), 198 | mm(Socket, Pid, Buff, Rec, Sent) 199 | end. 200 | 201 | handle(Pid, [0|K], [], N) -> 202 | handle(Pid, K, [], N); 203 | handle(Pid, [255|K], Buff, N) -> 204 | Pid ! {browser,N,reverse(Buff)}, 205 | handle(Pid, K, [], N+1); 206 | handle(Pid, [H|T], Buff, N) -> 207 | handle(Pid, T, [H|Buff], N); 208 | handle(_Pid, [], Buff, N) -> 209 | {Buff, N}. 210 | 211 | 212 | %% Description: Builds the challenge for a handshake response. 213 | %% Code portions from 214 | %% Sergio Veiga 215 | %% 216 | 217 | build_challenge(Key1, Key2, Key3) -> 218 | Ikey1 = [D || D <- Key1, $0 =< D, D =< $9], 219 | Ikey2 = [D || D <- Key2, $0 =< D, D =< $9], 220 | Blank1 = length([D || D <- Key1, D =:= 32]), 221 | Blank2 = length([D || D <- Key2, D =:= 32]), 222 | Part1 = list_to_integer(Ikey1) div Blank1, 223 | Part2 = list_to_integer(Ikey2) div Blank2, 224 | Ckey = <>, 226 | erlang:md5(Ckey). 227 | 228 | %% error(Code) -> 229 | %% ["HTTP/1.1 ",i2s(Code), 230 | %% " Error\r\nContent-Length:0\r\n\r\n"]. 231 | 232 | %% i2s(I) -> 233 | %% integer_to_list(I). 234 | 235 | make_response(Tag, Data) -> 236 | B1 = list_to_binary(Data), 237 | Len = size(B1), 238 | Mime = mime_type(Tag), 239 | ["HTTP/1.1 200 Ok\r\n", content_type(Mime), 240 | "Content-Length: ", integer_to_list(Len), "\r\n\r\n", 241 | B1]. 242 | 243 | mime_type(gif) -> "image/gif"; 244 | mime_type(jpg) -> "image/jpeg"; 245 | mime_type(png) -> "image/png"; 246 | mime_type(css) -> "text/css"; 247 | mime_type(json) -> "application/json"; 248 | mime_type(swf) -> "application/x-shockwave-flash"; 249 | mime_type(html) -> "text/html"; 250 | mime_type(xhtml) -> "application/xhtml+xml"; 251 | mime_type(xul) -> "application/vnd.mozilla.xul+xml"; 252 | mime_type(js) -> "application/x-javascript"; 253 | mime_type(svg) -> "image/svg+xml"; 254 | mime_type(X) when is_atom(X) -> mime_type(html); 255 | mime_type(FileName) -> mime_type(classify(FileName)). 256 | 257 | classify(FileName) -> 258 | case string:to_lower(filename:extension(FileName)) of 259 | ".gif" -> gif; 260 | ".jpg" -> jpg; 261 | ".jpeg" -> jpg; 262 | ".css" -> css; 263 | ".js" -> js; 264 | ".svg" -> svg; 265 | ".xul" -> xul; 266 | ".html" -> html; 267 | ".xhtml" -> xhtml; 268 | ".htm" -> html; 269 | _ -> html 270 | end. 271 | 272 | content_type(X) -> 273 | ["Content-Type: ", X, "\r\n"]. 274 | 275 | pre(X) -> 276 | ["
    \n",quote(lists:flatten(io_lib:format("~p",[X]))), "
    "]. 277 | 278 | quote("<" ++ T) -> "<" ++ quote(T); 279 | quote("&" ++ T) -> "&" ++ quote(T); 280 | quote([H|T]) -> [H|quote(T)]; 281 | quote([]) -> []. 282 | 283 | test() -> 284 | K1 = "3e6b263 4 17 80", 285 | K2 = "17 9 G`ZD9 2 2b 7X 3 /r90", 286 | K3 = <<"WjN}|M(6">>, 287 | <<"n`9eBk9z$R8pOtVb">> = build_challenge(K1, K2, K3), 288 | checksum_ok. 289 | 290 | %% A typical URI looks 291 | %% like 292 | %% URI = "/a/b/c?password=aaa&invisible=Ahidden+value"+ 293 | 294 | parse_uri(URI) -> 295 | case string:tokens(URI, "?") of 296 | [Root] -> 297 | {Root, []}; 298 | [Root, Args] -> 299 | {Root, parse_uri_args(Args)} 300 | end. 301 | 302 | parse_uri_args(Args) -> 303 | Args1 = string:tokens(Args, "&;"), 304 | map(fun(KeyVal) -> 305 | case string:tokens(KeyVal, "=") of 306 | [Key, Val] -> 307 | {urlencoded2str(Key), urlencoded2str(Val)}; 308 | [Key] -> 309 | {urlencoded2str(Key), ""}; 310 | _ -> 311 | io:format("Invalid str:~p~n",[KeyVal]), 312 | {"error", "error"} 313 | end 314 | end, Args1). 315 | 316 | 317 | urlencoded2str([$%,$u,A,B,C,D|T]) -> [decode_hex(A,B,C,D)|urlencoded2str(T)]; 318 | urlencoded2str([$%,Hi,Lo|T]) -> [decode_hex(Hi, Lo)|urlencoded2str(T)]; 319 | urlencoded2str([$+|T]) -> [$ |urlencoded2str(T)]; 320 | urlencoded2str([H|T]) -> [H|urlencoded2str(T)]; 321 | urlencoded2str([]) -> []. 322 | 323 | %% decode_hex ... 324 | 325 | decode_hex(Hex1, Hex2) -> hex2dec(Hex1)*16 + hex2dec(Hex2). 326 | 327 | decode_hex(Hex1, Hex2, Hex3, Hex4) -> 328 | hex2dec(Hex1)*4096 + hex2dec(Hex2)*256 + hex2dec(Hex3)*16 + hex2dec(Hex4). 329 | 330 | hex2dec(X) when X >=$0, X =<$9 -> X-$0; 331 | hex2dec($A) -> 10; 332 | hex2dec($B) -> 11; 333 | hex2dec($C) -> 12; 334 | hex2dec($D) -> 13; 335 | hex2dec($E) -> 14; 336 | hex2dec($F) -> 15; 337 | hex2dec($a) -> 10; 338 | hex2dec($b) -> 11; 339 | hex2dec($c) -> 12; 340 | hex2dec($d) -> 13; 341 | hex2dec($e) -> 14; 342 | hex2dec($f) -> 15. 343 | 344 | 345 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | Simple Erlang Browser Graphics 10 | 11 |

    SEBG

    12 | 13 |

    This code is changing rapidly. Always get the latest verions from 14 | https://github.com/joearms/SEBG 15 | 16 |

    News

    17 | 21 |

    Some code

    22 | 23 |

    This is a minimal code example. First you need an Erlang handler, for example, 24 | demo1.erl which is as follows: 25 | 26 |

    
     27 | -module(demo1).
     28 | -export([start/1]).
     29 | 
     30 | start(Pid) ->
     31 |     Pid ! {eval, "document.body.innerHTML='';"},
     32 |     Pid ! {eval, "document.body.style.backgroundColor='#eeffaa';"},
     33 |     Pid ! {eval, "document.body.innerHTML+='<h1>Hello World</h1>'"},
     34 |     event_loop(Pid).
     35 | 
     36 | event_loop(Pid) ->
     37 |     receive
     38 | 	Any ->
     39 | 	    io:format("??event loop:~p~n",[Any]),
     40 | 	    event_loop(Pid)
     41 |     end.
     42 |   
     43 | 
    44 | 45 |

    Then you need to some browser code to launch the example. 46 | A minimal code fragment to launch the example is: 47 |

     48 | 
     49 | <script type="text/javascript" src="./generic.js"></script>  
     50 | 
     51 | <a href="#" 
     52 |   onclick="start_session('ws://127.0.0.1:1234/connect/demo1')">demo1</a>
     53 | 
     54 | 
    55 | 56 | run the above code 58 | 59 |
    60 | 61 |

    Running the demos on all platforms

    62 | 63 |
      64 |
    1. Make sure you have a websockets enabled browser. 65 |
    2. Compile all the Erlang programs in this directory, with the 66 | command erlc *.erl 67 |
    3. Start an Erlang shell 68 |
    4. Give the command sebg:start(). in the shell. 69 |
    5. View the page index.html in your browser. 70 |
    71 | 72 |

    Running the demos on Mac OS-X

    73 |

    Type make 74 | 75 |


    76 | 77 |

    The Demos

    78 | 79 |

    Once you have a server running, click on any of the links below: 80 | 81 |

    109 | 110 |
    111 |

    Latest experiments

    112 | 113 |
    114 | 115 | 116 | 117 | 118 | 119 |
    120 | 121 |

    The Handler API

    122 | 123 |

    Writing a handler is trivial. Use the following pattern: 124 |

    125 | 
    126 | -module(myhandler).
    127 | -export([start/1]).
    128 | 
    129 | start(Pid) ->
    130 |     init(Pid), 
    131 |     loop(Pid).
    132 | 
    133 | loop(Pid) ->
    134 |     receive
    135 |        {browser, N, Str} ->
    136 |            ...
    137 |            loop(Pid)
    138 |     end.
    139 | 
    140 |

    141 | Then launch the handler by from the browser by evaluating the 142 | javascript command start_session('ws://127.0.0.1:1234/connect/myhandler') 143 | The start_session command is defined in generic.js 144 | 145 | 146 |

    In the above code Pid is a process that represents the 147 | brower. 148 | 149 |

    Pid ! {send, Msg} sends Msg to the 150 | browser. Msg must contain a valid Javascript expression which 151 | is evaluated in the browser. 152 | 153 |

    Javascript code executing in the browser can evaluate the Javascript 154 | function send(Str) this will emerge as a {browser,N,Str} 155 | message in the handler. N is a sequence number that increases 156 | by one for every message sent. 157 | 158 |


    159 | 160 |

    Simple Erlang Browser Graphics

    161 | 162 |

    Using web sockets and SVG and a bit of Javascript it is pretty easy 163 | to make an impressive GUI in a a few hundred lines of code. 164 | 165 |

    This example contains a complete web server, which supports 166 | web-sockets and shows how to interface web-sockets with jquery and 167 | the Raphael SVG javascript library. Using this we make a simple 168 | interactive graphics demo program. 169 | 170 |

    Note: This is known to work with Google Chrome and Safari 171 | browsers on Mac OS-X and with Chromium on Ubuntu. It does not work with 172 | Firefox. Other browsers are untested

    173 | 174 |

    The code here is also intended an an intermediate example for new 175 | Erlang programmers to study and extend. The code is entirely 176 | self-contained, there are no dependence on any other modules, so you 177 | don't need to know about OTP applications or generic servers or 178 | anything. As such it is suitable for a beginner and for self-study. 179 | 180 |

    I have also included a number of suggestions for small projects 181 | based on this code. We often get questions asking for suggestions for 182 | projects that are suitable for learning Erlang. I have added a list of possible projects based on this code at 184 | the end of this page. 185 | 186 |

    If you are running on mac os-x then all you have to do is type 187 | make. On other platforms start erlang, give the command 188 | segb:start() in the shell. Then view the page 189 | http://localhost:1234/index.html 190 | in your browser. 191 | 192 |

    A Minimal Example

    193 | 194 |

    For a minimal example see http://localhost:1234/generic.html 195 | 196 | 197 |

    Actually what gets pushed is a fragment of Javascript. The Javascript 198 | in the browser just waits for a Javascript fragment, evaluates it, 199 | then waits for the next fragment. It's very easy to understated. 200 | 201 |

    Websockets

    202 | 203 |

    The server itself is a small 300 line program that communicates 204 | with a web socket. Once a web socket has been opened the web server 205 | spawns a handler process to communicate with the web socket and turns 206 | itself into a web socket middleman. 207 | 208 |

    The handler process sends javascript expression to the web 209 | socket. At the client end of the web socket (ie in the server) all we 210 | do is a javascript eval of the data received from the web 211 | socket. The server acts as a middle man taking cars or the framing 212 | protocol between the browser and the server. 213 | 214 |

    The client page in the server in in a sense "universal." All it has 215 | is the ability to execute code, which comes in the form of javascript 216 | messages. 217 | 218 |

    In practise this is somewhat inconvenient. So instead of being 219 | entire universal and only opening a socket and eval'ing data it 220 | receives. The client does a few more thing. It turns the web page red 221 | if the socket connection is broken, and it preloads the jquery. jquery 222 | is so useful that I consider it to almost be a part of javascriopt. 223 | 224 |

    The handler process svg_demo.erl shows how to communicate with 225 | the browser. The first thing svg_demo.erl does, is to send a 226 | request to load the Javascript library raphael-min.js. Raphael 227 | is a well 228 | documented javascript SVG library. 229 | 230 |

    Having loaded Raphael. I create a draggable circle, and a clickable 231 | blue box. Nothing fancy. I deliberately don't want to make the 232 | example too complicated. You should at this stage be able to read and 233 | understand svg_demo.erl and sebg.erl in their 234 | entirely.

    235 | 236 |

    Using websockets, we can create a direct message passing channel 237 | between Erlang and a web server. Once the channel is established we 238 | can asynchronous messages between the an Erlang process and a browser 239 | window. Sending these message has a tidy overhead of 2 bytes per 240 | message. 241 | 242 |

    This demo has only two Erlang modules. sebg.erl and svg_demo.erl. The example is completely 245 | self-contain, so makes no use of any Erlang libaries at all. 246 | 247 |

    The work flow is:

    248 | 249 |
      250 | 251 |
    1. Start a web server. 252 | 253 |
    2. Load a single web page generic.html 254 | 255 |
    3. generic.html requests a web-socket connection to the Erlang web server. 256 | 257 |
    4. When the javascript generic.html has established a web socket 258 | it then changes it's mode of operation, waiting for messages on the web socket. 259 | 260 |
    5. Each message is assumed to contain a javascript expression. 261 | 262 |
    6. All the generic web page does is to eval the java script expressions 263 | received from the web socket. 264 |
    265 | 266 | The crucial code in the generic web page is the part which sets up the 267 | web socket. This code was inspired by the example taken from the 268 | examples at http://websocket.org 269 | 270 |
    271 | 
    272 |    function start_session(mod){
    273 | 	websocket = new WebSocket(wsUri); 
    274 | 	websocket.onopen = function(evt) { onOpen(evt, mod) }; 
    275 | 	websocket.onclose = function(evt) { onClose(evt) }; 
    276 | 	websocket.onmessage = function(evt) { onMessage(evt) }; 
    277 | 	websocket.onerror = function(evt) { onError(evt) };
    278 | 	return(false);
    279 |     }  
    280 | 
    281 |     function onOpen(evt, mod) { 
    282 | 	websocket.send("start:" + mod + ":");
    283 |     }
    284 | 
    285 |     function onClose(evt) { 
    286 | 	$("body").css({'background-color':'red'});
    287 |     }  
    288 | 
    289 |     function onMessage(evt) {
    290 | 	{
    291 | 	    eval(evt.data);
    292 | 	}
    293 | 
    294 | 
    295 | 
    296 | 297 | 298 |

    Plugins

    299 |

    The directory clipper contains a plugin for goole chrome that 300 | talks to the web server. To install this see Readme. 301 | 302 | 303 |

    Once installed you can select any region of the current web page you are browsing 304 | by dragging the mouse over the interesting region. Then click on the extension icon. 305 | A popup menu appears. You can add a few comments, click on save 306 | and a message is sent to a little erlang server sebg.erl the server. 307 | The date extracted from the webpage is put into a snippet file 308 | for future analysis. 309 | 310 |

    Next steps: 311 | 312 |

    in the browser

    313 | 314 |

    We need better javascript to extract information on the web page 315 | make a pluging for firefox etc.

    316 | 317 |

    in the server

    318 | 327 |

    328 | A large amount of assistance is needed here. 329 | 330 | 331 | 332 | 333 |

    Exercises

    334 | 335 |

    Here are few suggestions for improvements and exercises. 336 | 337 |

      338 | 339 |
    1. Make the start script openchome generic so it works on 340 | all platforms. 341 | 342 |
    2. Add native controls to the Raphael canvas, controls like 343 | buttons entries etc. 344 | 345 |
    3. Make a simulated canvas button in Raphael. When you press the button it 346 | should change color and send an event to Erlang. Attach an Erlang fun to the button 347 | so that the fun is evaluated when then then button is clicked. 348 | 349 |
    4. Write a chat client and server. 350 | 351 |
    5. Write a performance monitor. You'll need to call the bif 352 | processes() every few seconds, and then call process_info(Pid, 353 | ...) om all processes to collect the relevant information. 354 | 355 |

      Stare at the code for the function etop_collect/2 in the 356 | module observer_backend.erl which you will find in the standard 357 | distribution.

      Note: cut pates and minimise the code you need from 358 | the library, don't just call the library cut and paste when you need 359 | and understand every line.

      360 | 361 |
    6. Write a chat widget like interface to the system. Assume that the 362 | users that pop up in the right hand users tab of a chat widget are 363 | global processes. Use the entry in the chat lib to connect to and 364 | send message to a global process. Write a gen server that is 365 | controlled from a chat widget, so that it appears like a person that 366 | you chat to. 367 | 368 |
    7. Interface the InfoVis 369 | library to the system. Compute an xref graph of the Erlang module 370 | structure (hint use xref.erl) and display it with one of the 371 | methods in VisLib. 372 | 373 |
    8. Write a parser for GedCom (look it up) interface with InfoVis 374 | 375 |
    9. Add JSON support. 376 | 377 |
    10. Make a plugin for google chrome what works with web 378 | sockets. Extend the message passing to cross-tab messaging, so Erlang 379 | can send an receive messages to any tab.
    11. Download the chrome 380 | plugin called "snippy" stare at the code. With snippy you can grab 381 | fragments of a web page. Modify snippy (or write your own extension) 382 | that can grab a portion of a web page and send it to a web 383 | socket. Make a database at the end of the web socket to store and 384 | analyse the data. 385 | 386 | 387 |

      References

      388 | http://www.switchonthecode.com/tutorials/javascript-draggable-elements 389 | http://billmill.org/static/canvastutorial/bricks.html 390 | 391 |

      Experiments

      392 | 393 |

      Lively

      394 | 395 | Lively 396 | 397 | -------------------------------------------------------------------------------- /raphael-min.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Raphael 1.5.2 - JavaScript Vector Library 3 | * 4 | * Copyright (c) 2010 Dmitry Baranovskiy (http://raphaeljs.com) 5 | * Licensed under the MIT (http://raphaeljs.com/license.html) license. 6 | */ 7 | (function(){function a(){if(a.is(arguments[0],G)){var b=arguments[0],d=bV[m](a,b.splice(0,3+a.is(b[0],E))),e=d.set();for(var g=0,h=b[w];g";bg=bf.firstChild;bg.style.behavior="url(#default#VML)";if(!(bg&&typeof bg.adj=="object"))return a.type=null;bf=null}a.svg=!(a.vml=a.type=="VML");j[e]=a[e];k=j[e];a._id=0;a._oid=0;a.fn={};a.is=function(a,b){b=x.call(b);if(b=="finite")return!O[f](+a);return b=="null"&&a===null||b==typeof a||b=="object"&&a===Object(a)||b=="array"&&Array.isArray&&Array.isArray(a)||J.call(a).slice(8,-1).toLowerCase()==b};a.angle=function(b,c,d,e,f,g){{if(f==null){var h=b-d,i=c-e;if(!h&&!i)return 0;return((h<0)*180+y.atan(-i/-h)*180/D+360)%360}return a.angle(b,c,f,g)-a.angle(d,e,f,g)}};a.rad=function(a){return a%360*D/180};a.deg=function(a){return a*180/D%360};a.snapTo=function(b,c,d){d=a.is(d,"finite")?d:10;if(a.is(b,G)){var e=b.length;while(e--)if(B(b[e]-c)<=d)return b[e]}else{b=+b;var f=c%b;if(fb-d)return c-f+b}return c};function bh(){var a=[],b=0;for(;b<32;b++)a[b]=(~(~(y.random()*16)))[H](16);a[12]=4;a[16]=(a[16]&3|8)[H](16);return"r-"+a[v]("")}a.setWindow=function(a){h=a;g=h.document};var bi=function(b){if(a.vml){var c=/^\s+|\s+$/g,d;try{var e=new ActiveXObject("htmlfile");e.write("");e.close();d=e.body}catch(a){d=createPopup().document.body}var f=d.createTextRange();bi=bm(function(a){try{d.style.color=r(a)[Y](c,p);var b=f.queryCommandValue("ForeColor");b=(b&255)<<16|b&65280|(b&16711680)>>>16;return"#"+("000000"+b[H](16)).slice(-6)}catch(a){return"none"}})}else{var h=g.createElement("i");h.title="Raphaël Colour Picker";h.style.display="none";g.body[l](h);bi=bm(function(a){h.style.color=a;return g.defaultView.getComputedStyle(h,p).getPropertyValue("color")})}return bi(b)},bj=function(){return"hsb("+[this.h,this.s,this.b]+")"},bk=function(){return"hsl("+[this.h,this.s,this.l]+")"},bl=function(){return this.hex};a.hsb2rgb=function(b,c,d,e){if(a.is(b,"object")&&"h"in b&&"s"in b&&"b"in b){d=b.b;c=b.s;b=b.h;e=b.o}return a.hsl2rgb(b,c,d/2,e)};a.hsl2rgb=function(b,c,d,e){if(a.is(b,"object")&&"h"in b&&"s"in b&&"l"in b){d=b.l;c=b.s;b=b.h}if(b>1||c>1||d>1){b/=360;c/=100;d/=100}var f={},g=["r","g","b"],h,i,j,k,l,m;if(c){d<0.5?h=d*(1+c):h=d+c-d*c;i=2*d-h;for(var n=0;n<3;n++){j=b+1/3*-(n-1);j<0&&j++;j>1&&j--;j*6<1?f[g[n]]=i+(h-i)*6*j:j*2<1?f[g[n]]=h:j*3<2?f[g[n]]=i+(h-i)*(2/3-j)*6:f[g[n]]=i}}else f={r:d,g:d,b:d};f.r*=255;f.g*=255;f.b*=255;f.hex="#"+(16777216|f.b|f.g<<8|f.r<<16).toString(16).slice(1);a.is(e,"finite")&&(f.opacity=e);f.toString=bl;return f};a.rgb2hsb=function(b,c,d){if(c==null&&a.is(b,"object")&&"r"in b&&"g"in b&&"b"in b){d=b.b;c=b.g;b=b.r}if(c==null&&a.is(b,F)){var e=a.getRGB(b);b=e.r;c=e.g;d=e.b}if(b>1||c>1||d>1){b/=255;c/=255;d/=255}var f=z(b,c,d),g=A(b,c,d),h,i,j=f;{if(g==f)return{h:0,s:0,b:f,toString:bj};var k=f-g;i=k/f;b==f?h=(c-d)/k:c==f?h=2+(d-b)/k:h=4+(b-c)/k;h/=6;h<0&&h++;h>1&&h--}return{h:h,s:i,b:j,toString:bj}};a.rgb2hsl=function(b,c,d){if(c==null&&a.is(b,"object")&&"r"in b&&"g"in b&&"b"in b){d=b.b;c=b.g;b=b.r}if(c==null&&a.is(b,F)){var e=a.getRGB(b);b=e.r;c=e.g;d=e.b}if(b>1||c>1||d>1){b/=255;c/=255;d/=255}var f=z(b,c,d),g=A(b,c,d),h,i,j=(f+g)/2,k;if(g==f)k={h:0,s:0,l:j};else{var l=f-g;i=j<0.5?l/(f+g):l/(2-f-g);b==f?h=(c-d)/l:c==f?h=2+(d-b)/l:h=4+(b-c)/l;h/=6;h<0&&h++;h>1&&h--;k={h:h,s:i,l:j}}k.toString=bk;return k};a._path2string=function(){return this.join(",")[Y](ba,"$1")};function bm(a,b,c){function d(){var g=Array[e].slice.call(arguments,0),h=g[v]("►"),i=d.cache=d.cache||{},j=d.count=d.count||[];if(i[f](h))return c?c(i[h]):i[h];j[w]>=1000&&delete i[j.shift()];j[L](h);i[h]=a[m](b,g);return c?c(i[h]):i[h]}return d}a.getRGB=bm(function(b){if(!b||!(!((b=r(b)).indexOf("-")+1)))return{r:-1,g:-1,b:-1,hex:"none",error:1};if(b=="none")return{r:-1,g:-1,b:-1,hex:"none"};!(_[f](b.toLowerCase().substring(0,2))||b.charAt()=="#")&&(b=bi(b));var c,d,e,g,h,i,j,k=b.match(N);if(k){if(k[2]){g=T(k[2].substring(5),16);e=T(k[2].substring(3,5),16);d=T(k[2].substring(1,3),16)}if(k[3]){g=T((i=k[3].charAt(3))+i,16);e=T((i=k[3].charAt(2))+i,16);d=T((i=k[3].charAt(1))+i,16)}if(k[4]){j=k[4][s]($);d=S(j[0]);j[0].slice(-1)=="%"&&(d*=2.55);e=S(j[1]);j[1].slice(-1)=="%"&&(e*=2.55);g=S(j[2]);j[2].slice(-1)=="%"&&(g*=2.55);k[1].toLowerCase().slice(0,4)=="rgba"&&(h=S(j[3]));j[3]&&j[3].slice(-1)=="%"&&(h/=100)}if(k[5]){j=k[5][s]($);d=S(j[0]);j[0].slice(-1)=="%"&&(d*=2.55);e=S(j[1]);j[1].slice(-1)=="%"&&(e*=2.55);g=S(j[2]);j[2].slice(-1)=="%"&&(g*=2.55);(j[0].slice(-3)=="deg"||j[0].slice(-1)=="°")&&(d/=360);k[1].toLowerCase().slice(0,4)=="hsba"&&(h=S(j[3]));j[3]&&j[3].slice(-1)=="%"&&(h/=100);return a.hsb2rgb(d,e,g,h)}if(k[6]){j=k[6][s]($);d=S(j[0]);j[0].slice(-1)=="%"&&(d*=2.55);e=S(j[1]);j[1].slice(-1)=="%"&&(e*=2.55);g=S(j[2]);j[2].slice(-1)=="%"&&(g*=2.55);(j[0].slice(-3)=="deg"||j[0].slice(-1)=="°")&&(d/=360);k[1].toLowerCase().slice(0,4)=="hsla"&&(h=S(j[3]));j[3]&&j[3].slice(-1)=="%"&&(h/=100);return a.hsl2rgb(d,e,g,h)}k={r:d,g:e,b:g};k.hex="#"+(16777216|g|e<<8|d<<16).toString(16).slice(1);a.is(h,"finite")&&(k.opacity=h);return k}return{r:-1,g:-1,b:-1,hex:"none",error:1}},a);a.getColor=function(a){var b=this.getColor.start=this.getColor.start||{h:0,s:1,b:a||0.75},c=this.hsb2rgb(b.h,b.s,b.b);b.h+=0.075;if(b.h>1){b.h=0;b.s-=0.2;b.s<=0&&(this.getColor.start={h:0,s:1,b:b.b})}return c.hex};a.getColor.reset=function(){delete this.start};a.parsePathString=bm(function(b){if(!b)return null;var c={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},d=[];a.is(b,G)&&a.is(b[0],G)&&(d=bo(b));d[w]||r(b)[Y](bb,function(a,b,e){var f=[],g=x.call(b);e[Y](bc,function(a,b){b&&f[L](+b)});if(g=="m"&&f[w]>2){d[L]([b][n](f.splice(0,2)));g="l";b=b=="m"?"l":"L"}while(f[w]>=c[g]){d[L]([b][n](f.splice(0,c[g])));if(!c[g])break}});d[H]=a._path2string;return d});a.findDotsAtSegment=function(a,b,c,d,e,f,g,h,i){var j=1-i,k=C(j,3)*a+C(j,2)*3*i*c+j*3*i*i*e+C(i,3)*g,l=C(j,3)*b+C(j,2)*3*i*d+j*3*i*i*f+C(i,3)*h,m=a+2*i*(c-a)+i*i*(e-2*c+a),n=b+2*i*(d-b)+i*i*(f-2*d+b),o=c+2*i*(e-c)+i*i*(g-2*e+c),p=d+2*i*(f-d)+i*i*(h-2*f+d),q=(1-i)*a+i*c,r=(1-i)*b+i*d,s=(1-i)*e+i*g,t=(1-i)*f+i*h,u=90-y.atan((m-o)/(n-p))*180/D;(m>o||n1){x=y.sqrt(x);c=x*c;d=x*d}var z=c*c,A=d*d,C=(f==g?-1:1)*y.sqrt(B((z*A-z*u*u-A*t*t)/(z*u*u+A*t*t))),E=C*c*u/d+(a+h)/2,F=C*-d*t/c+(b+i)/2,G=y.asin(((b-F)/d).toFixed(9)),H=y.asin(((i-F)/d).toFixed(9));G=aH&&(G=G-D*2);!g&&H>G&&(H=H-D*2)}var I=H-G;if(B(I)>k){var J=H,K=h,L=i;H=G+k*(g&&H>G?1:-1);h=E+c*y.cos(H);i=F+d*y.sin(H);m=bt(h,i,c,d,e,0,g,K,L,[H,J,E,F])}I=H-G;var M=y.cos(G),N=y.sin(G),O=y.cos(H),P=y.sin(H),Q=y.tan(I/4),R=4/3*c*Q,S=4/3*d*Q,T=[a,b],U=[a+R*N,b-S*M],V=[h+R*P,i-S*O],W=[h,i];U[0]=2*T[0]-U[0];U[1]=2*T[1]-U[1];{if(j)return[U,V,W][n](m);m=[U,V,W][n](m)[v]()[s](",");var X=[];for(var Y=0,Z=m[w];Y"1e12"&&(l=0.5);B(n)>"1e12"&&(n=0.5);if(l>0&&l<1){q=bu(a,b,c,d,e,f,g,h,l);p[L](q.x);o[L](q.y)}if(n>0&&n<1){q=bu(a,b,c,d,e,f,g,h,n);p[L](q.x);o[L](q.y)}i=f-2*d+b-(h-2*f+d);j=2*(d-b)-2*(f-d);k=b-d;l=(-j+y.sqrt(j*j-4*i*k))/2/i;n=(-j-y.sqrt(j*j-4*i*k))/2/i;B(l)>"1e12"&&(l=0.5);B(n)>"1e12"&&(n=0.5);if(l>0&&l<1){q=bu(a,b,c,d,e,f,g,h,l);p[L](q.x);o[L](q.y)}if(n>0&&n<1){q=bu(a,b,c,d,e,f,g,h,n);p[L](q.x);o[L](q.y)}return{min:{x:A[m](0,p),y:A[m](0,o)},max:{x:z[m](0,p),y:z[m](0,o)}}}),bw=bm(function(a,b){var c=bq(a),d=b&&bq(b),e={x:0,y:0,bx:0,by:0,X:0,Y:0,qx:null,qy:null},f={x:0,y:0,bx:0,by:0,X:0,Y:0,qx:null,qy:null},g=function(a,b){var c,d;if(!a)return["C",b.x,b.y,b.x,b.y,b.x,b.y];!(a[0]in{T:1,Q:1})&&(b.qx=b.qy=null);switch(a[0]){case"M":b.X=a[1];b.Y=a[2];break;case"A":a=["C"][n](bt[m](0,[b.x,b.y][n](a.slice(1))));break;case"S":c=b.x+(b.x-(b.bx||b.x));d=b.y+(b.y-(b.by||b.y));a=["C",c,d][n](a.slice(1));break;case"T":b.qx=b.x+(b.x-(b.qx||b.x));b.qy=b.y+(b.y-(b.qy||b.y));a=["C"][n](bs(b.x,b.y,b.qx,b.qy,a[1],a[2]));break;case"Q":b.qx=a[1];b.qy=a[2];a=["C"][n](bs(b.x,b.y,a[1],a[2],a[3],a[4]));break;case"L":a=["C"][n](br(b.x,b.y,a[1],a[2]));break;case"H":a=["C"][n](br(b.x,b.y,a[1],b.y));break;case"V":a=["C"][n](br(b.x,b.y,b.x,a[1]));break;case"Z":a=["C"][n](br(b.x,b.y,b.X,b.Y));break}return a},h=function(a,b){if(a[b][w]>7){a[b].shift();var e=a[b];while(e[w])a.splice(b++,0,["C"][n](e.splice(0,6)));a.splice(b,1);k=z(c[w],d&&d[w]||0)}},i=function(a,b,e,f,g){if(a&&b&&a[g][0]=="M"&&b[g][0]!="M"){b.splice(g,0,["M",f.x,f.y]);e.bx=0;e.by=0;e.x=a[g][1];e.y=a[g][2];k=z(c[w],d&&d[w]||0)}};for(var j=0,k=z(c[w],d&&d[w]||0);j0.5)*2-1;C(e-0.5,2)+C(f-0.5,2)>0.25&&(f=y.sqrt(0.25-C(e-0.5,2))*g+0.5)&&f!=0.5&&(f=f.toFixed(5)-0.00001*g)}return p});b=b[s](/\s*\-\s*/);if(d=="linear"){var i=b.shift();i=-S(i);if(isNaN(i))return null;var j=[0,0,y.cos(i*D/180),y.sin(i*D/180)],k=1/(z(B(j[2]),B(j[3]))||1);j[2]*=k;j[3]*=k;if(j[2]<0){j[0]=-j[2];j[2]=0}if(j[3]<0){j[1]=-j[3];j[3]=0}}var m=bx(b);if(!m)return null;var n=a.getAttribute(I);n=n.match(/^url\(#(.*)\)$/);n&&c.defs.removeChild(g.getElementById(n[1]));var o=bG(d+"Gradient");o.id=bh();bG(o,d=="radial"?{fx:e,fy:f}:{x1:j[0],y1:j[1],x2:j[2],y2:j[3]});c.defs[l](o);for(var q=0,t=m[w];q1?G.opacity/100:G.opacity});case"stroke":G=a.getRGB(o);h[R](n,G.hex);n=="stroke"&&G[f]("opacity")&&bG(h,{"stroke-opacity":G.opacity>1?G.opacity/100:G.opacity});break;case"gradient":(({circle:1,ellipse:1})[f](c.type)||r(o).charAt()!="r")&&bI(h,o,c.paper);break;case"opacity":i.gradient&&!i[f]("stroke-opacity")&&bG(h,{"stroke-opacity":o>1?o/100:o});case"fill-opacity":if(i.gradient){var H=g.getElementById(h.getAttribute(I)[Y](/^url\(#|\)$/g,p));if(H){var J=H.getElementsByTagName("stop");J[J[w]-1][R]("stop-opacity",o)}break}default:n=="font-size"&&(o=T(o,10)+"px");var K=n[Y](/(\-.)/g,function(a){return V.call(a.substring(1))});h.style[K]=o;h[R](n,o);break}}}bM(c,d);m?c.rotate(m.join(q)):S(j)&&c.rotate(j,true)},bL=1.2,bM=function(b,c){if(b.type!="text"||!(c[f]("text")||c[f]("font")||c[f]("font-size")||c[f]("x")||c[f]("y")))return;var d=b.attrs,e=b.node,h=e.firstChild?T(g.defaultView.getComputedStyle(e.firstChild,p).getPropertyValue("font-size"),10):10;if(c[f]("text")){d.text=c.text;while(e.firstChild)e.removeChild(e.firstChild);var i=r(c.text)[s]("\n");for(var j=0,k=i[w];jb.height&&(b.height=e.y+e.height-b.y);e.x+e.width-b.x>b.width&&(b.width=e.x+e.width-b.x)}}a&&this.hide();return b};bN[e].attr=function(b,c){if(this.removed)return this;if(b==null){var d={};for(var e in this.attrs)this.attrs[f](e)&&(d[e]=this.attrs[e]);this._.rt.deg&&(d.rotation=this.rotate());(this._.sx!=1||this._.sy!=1)&&(d.scale=this.scale());d.gradient&&d.fill=="none"&&(d.fill=d.gradient)&&delete d.gradient;return d}if(c==null&&a.is(b,F)){if(b=="translation")return cz.call(this);if(b=="rotation")return this.rotate();if(b=="scale")return this.scale();if(b==I&&this.attrs.fill=="none"&&this.attrs.gradient)return this.attrs.gradient;return this.attrs[b]}if(c==null&&a.is(b,G)){var g={};for(var h=0,i=b.length;h"));m.W=h.w=m.paper.span.offsetWidth;m.H=h.h=m.paper.span.offsetHeight;m.X=h.x;m.Y=h.y+Q(m.H/2);switch(h["text-anchor"]){case"start":m.node.style["v-text-align"]="left";m.bbx=Q(m.W/2);break;case"end":m.node.style["v-text-align"]="right";m.bbx=-Q(m.W/2);break;default:m.node.style["v-text-align"]="center";break}}};bI=function(a,b){a.attrs=a.attrs||{};var c=a.attrs,d,e="linear",f=".5 .5";a.attrs.gradient=b;b=r(b)[Y](bd,function(a,b,c){e="radial";if(b&&c){b=S(b);c=S(c);C(b-0.5,2)+C(c-0.5,2)>0.25&&(c=y.sqrt(0.25-C(b-0.5,2))*((c>0.5)*2-1)+0.5);f=b+q+c}return p});b=b[s](/\s*\-\s*/);if(e=="linear"){var g=b.shift();g=-S(g);if(isNaN(g))return null}var h=bx(b);if(!h)return null;a=a.shape||a.node;d=a.getElementsByTagName(I)[0]||cd(I);!d.parentNode&&a.appendChild(d);if(h[w]){d.on=true;d.method="none";d.color=h[0].color;d.color2=h[h[w]-1].color;var i=[];for(var j=0,k=h[w];j")}}catch(a){cd=function(a){return g.createElement("<"+a+" xmlns=\"urn:schemas-microsoft.com:vml\" class=\"rvml\">")}}bV=function(){var b=by[m](0,arguments),c=b.container,d=b.height,e,f=b.width,h=b.x,i=b.y;if(!c)throw new Error("VML container not found.");var k=new j,n=k.canvas=g.createElement("div"),o=n.style;h=h||0;i=i||0;f=f||512;d=d||342;f==+f&&(f+="px");d==+d&&(d+="px");k.width=1000;k.height=1000;k.coordsize=b_*1000+q+b_*1000;k.coordorigin="0 0";k.span=g.createElement("span");k.span.style.cssText="position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";n[l](k.span);o.cssText=a.format("top:0;left:0;width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden",f,d);if(c==1){g.body[l](n);o.left=h+"px";o.top=i+"px";o.position="absolute"}else c.firstChild?c.insertBefore(n,c.firstChild):c[l](n);bz.call(k,k,a.fn);return k};k.clear=function(){this.canvas.innerHTML=p;this.span=g.createElement("span");this.span.style.cssText="position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";this.canvas[l](this.span);this.bottom=this.top=null};k.remove=function(){this.canvas.parentNode.removeChild(this.canvas);for(var a in this)this[a]=bF(a);return true}}var ce=navigator.userAgent.match(/Version\\x2f(.*?)\s/);navigator.vendor=="Apple Computer, Inc."&&(ce&&ce[1]<4||navigator.platform.slice(0,2)=="iP")?k.safari=function(){var a=this.rect(-99,-99,this.width+99,this.height+99).attr({stroke:"none"});h.setTimeout(function(){a.remove()})}:k.safari=function(){};var cf=function(){this.returnValue=false},cg=function(){return this.originalEvent.preventDefault()},ch=function(){this.cancelBubble=true},ci=function(){return this.originalEvent.stopPropagation()},cj=(function(){{if(g.addEventListener)return function(a,b,c,d){var e=o&&u[b]?u[b]:b,g=function(e){if(o&&u[f](b))for(var g=0,h=e.targetTouches&&e.targetTouches.length;g1&&(a=Array[e].splice.call(arguments,0,arguments[w]));return new cC(a)};k.setSize=bU;k.top=k.bottom=null;k.raphael=a;function co(){return this.x+q+this.y}bO.resetScale=function(){if(this.removed)return this;this._.sx=1;this._.sy=1;this.attrs.scale="1 1"};bO.scale=function(a,b,c,d){if(this.removed)return this;if(a==null&&b==null)return{x:this._.sx,y:this._.sy,toString:co};b=b||a;!(+b)&&(b=a);var e,f,g,h,i=this.attrs;if(a!=0){var j=this.getBBox(),k=j.x+j.width/2,l=j.y+j.height/2,m=B(a/this._.sx),o=B(b/this._.sy);c=+c||c==0?c:k;d=+d||d==0?d:l;var r=this._.sx>0,s=this._.sy>0,t=~(~(a/B(a))),u=~(~(b/B(b))),x=m*t,y=o*u,z=this.node.style,A=c+B(k-c)*x*(k>c==r?1:-1),C=d+B(l-d)*y*(l>d==s?1:-1),D=a*t>b*u?o:m;switch(this.type){case"rect":case"image":var E=i.width*m,F=i.height*o;this.attr({height:F,r:i.r*D,width:E,x:A-E/2,y:C-F/2});break;case"circle":case"ellipse":this.attr({rx:i.rx*m,ry:i.ry*o,r:i.r*D,cx:A,cy:C});break;case"text":this.attr({x:A,y:C});break;case"path":var G=bp(i.path),H=true,I=r?x:m,J=s?y:o;for(var K=0,L=G[w];Kr)p=n.data[r*l];else{p=a.findDotsAtSegment(b,c,d,e,f,g,h,i,r/l);n.data[r]=p}r&&(k+=C(C(o.x-p.x,2)+C(o.y-p.y,2),0.5));if(j!=null&&k>=j)return p;o=p}if(j==null)return k},cr=function(b,c){return function(d,e,f){d=bw(d);var g,h,i,j,k="",l={},m,n=0;for(var o=0,p=d.length;oe){if(c&&!l.start){m=cq(g,h,i[1],i[2],i[3],i[4],i[5],i[6],e-n);k+=["C",m.start.x,m.start.y,m.m.x,m.m.y,m.x,m.y];if(f)return k;l.start=k;k=["M",m.x,m.y+"C",m.n.x,m.n.y,m.end.x,m.end.y,i[5],i[6]][v]();n+=j;g=+i[5];h=+i[6];continue}if(!b&&!c){m=cq(g,h,i[1],i[2],i[3],i[4],i[5],i[6],e-n);return{x:m.x,y:m.y,alpha:m.alpha}}}n+=j;g=+i[5];h=+i[6]}k+=i}l.end=k;m=b?n:c?l:a.findDotsAtSegment(g,h,i[1],i[2],i[3],i[4],i[5],i[6],1);m.alpha&&(m={x:m.x,y:m.y,alpha:m.alpha});return m}},cs=cr(1),ct=cr(),cu=cr(0,1);bO.getTotalLength=function(){if(this.type!="path")return;if(this.node.getTotalLength)return this.node.getTotalLength();return cs(this.attrs.path)};bO.getPointAtLength=function(a){if(this.type!="path")return;return ct(this.attrs.path,a)};bO.getSubpath=function(a,b){if(this.type!="path")return;if(B(this.getTotalLength()-b)<"1e-6")return cu(this.attrs.path,a).end;var c=cu(this.attrs.path,b,1);return a?cu(c,a).end:c};a.easing_formulas={linear:function(a){return a},"<":function(a){return C(a,3)},">":function(a){return C(a-1,3)+1},"<>":function(a){a=a*2;if(a<1)return C(a,3)/2;a-=2;return(C(a,3)+2)/2},backIn:function(a){var b=1.70158;return a*a*((b+1)*a-b)},backOut:function(a){a=a-1;var b=1.70158;return a*a*((b+1)*a+b)+1},elastic:function(a){if(a==0||a==1)return a;var b=0.3,c=b/4;return C(2,-10*a)*y.sin((a-c)*(2*D)/b)+1},bounce:function(a){var b=7.5625,c=2.75,d;if(a<1/c)d=b*a*a;else if(a<2/c){a-=1.5/c;d=b*a*a+0.75}else if(a<2.5/c){a-=2.25/c;d=b*a*a+0.9375}else{a-=2.625/c;d=b*a*a+0.984375}return d}};var cv=[],cw=function(){var b=+(new Date);for(var c=0;cd)return d;while(cf?c=e:d=e;e=(d-c)/2+c}return e}return n(a,1/(200*f))}bO.onAnimation=function(a){this._run=a||0;return this};bO.animate=function(c,d,e,g){var h=this;h.timeouts=h.timeouts||[];if(a.is(e,"function")||!e)g=e||null;if(h.removed){g&&g.call(h);return h}var i={},j={},k=false,l={};for(var m in c)if(c[f](m)){if(X[f](m)||h.paper.customAttributes[f](m)){k=true;i[m]=h.attr(m);i[m]==null&&(i[m]=W[m]);j[m]=c[m];switch(X[m]){case"along":var n=cs(c[m]),o=ct(c[m],n*!(!c.back)),p=h.getBBox();l[m]=n/d;l.tx=p.x;l.ty=p.y;l.sx=o.x;l.sy=o.y;j.rot=c.rot;j.back=c.back;j.len=n;c.rot&&(l.r=S(h.rotate())||0);break;case E:l[m]=(j[m]-i[m])/d;break;case"colour":i[m]=a.getRGB(i[m]);var q=a.getRGB(j[m]);l[m]={r:(q.r-i[m].r)/d,g:(q.g-i[m].g)/d,b:(q.b-i[m].b)/d};break;case"path":var t=bw(i[m],j[m]);i[m]=t[0];var u=t[1];l[m]=[];for(var v=0,x=i[m][w];v").appendTo("body"),c=b.css("display");b.remove();if(c==="none"||c==="")c="block";bR[a]=c}return bR[a]}function bW(a,b){var c={};d.each(bV.concat.apply([],bV.slice(0,b)),function(){c[this]=a});return c}function bJ(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var e=a.dataTypes,f=a.converters,g,h=e.length,i,j=e[0],k,l,m,n,o;for(g=1;g=0===c})}function N(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function F(a,b){return(a&&a!=="*"?a+".":"")+b.replace(q,"`").replace(r,"&")}function E(a){var b,c,e,f,g,h,i,j,k,l,m,n,p,q=[],r=[],s=d._data(this,u);typeof s==="function"&&(s=s.events);if(a.liveFired!==this&&s&&s.live&&!a.target.disabled&&(!a.button||a.type!=="click")){a.namespace&&(n=new RegExp("(^|\\.)"+a.namespace.split(".").join("\\.(?:.*\\.)?")+"(\\.|$)")),a.liveFired=this;var t=s.live.slice(0);for(i=0;ic)break;a.currentTarget=f.elem,a.data=f.handleObj.data,a.handleObj=f.handleObj,p=f.handleObj.origHandler.apply(f.elem,arguments);if(p===!1||a.isPropagationStopped()){c=f.level,p===!1&&(b=!1);if(a.isImmediatePropagationStopped())break}}return b}}function C(a,b,c){c[0].type=a;return d.event.handle.apply(b,c)}function w(){return!0}function v(){return!1}function f(a,c,f){if(f===b&&a.nodeType===1){f=a.getAttribute("data-"+c);if(typeof f==="string"){try{f=f==="true"?!0:f==="false"?!1:f==="null"?null:d.isNaN(f)?e.test(f)?d.parseJSON(f):f:parseFloat(f)}catch(g){}d.data(a,c,f)}else f=b}return f}var c=a.document,d=function(){function I(){if(!d.isReady){try{c.documentElement.doScroll("left")}catch(a){setTimeout(I,1);return}d.ready()}}var d=function(a,b){return new d.fn.init(a,b,g)},e=a.jQuery,f=a.$,g,h=/^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/,i=/\S/,j=/^\s+/,k=/\s+$/,l=/\d/,m=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,n=/^[\],:{}\s]*$/,o=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,p=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,q=/(?:^|:|,)(?:\s*\[)+/g,r=/(webkit)[ \/]([\w.]+)/,s=/(opera)(?:.*version)?[ \/]([\w.]+)/,t=/(msie) ([\w.]+)/,u=/(mozilla)(?:.*? rv:([\w.]+))?/,v=navigator.userAgent,w,x=!1,y,z="then done fail isResolved isRejected promise".split(" "),A,B=Object.prototype.toString,C=Object.prototype.hasOwnProperty,D=Array.prototype.push,E=Array.prototype.slice,F=String.prototype.trim,G=Array.prototype.indexOf,H={};d.fn=d.prototype={constructor:d,init:function(a,e,f){var g,i,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!e&&c.body){this.context=c,this[0]=c.body,this.selector="body",this.length=1;return this}if(typeof a==="string"){g=h.exec(a);if(!g||!g[1]&&e)return!e||e.jquery?(e||f).find(a):this.constructor(e).find(a);if(g[1]){e=e instanceof d?e[0]:e,k=e?e.ownerDocument||e:c,j=m.exec(a),j?d.isPlainObject(e)?(a=[c.createElement(j[1])],d.fn.attr.call(a,e,!0)):a=[k.createElement(j[1])]:(j=d.buildFragment([g[1]],[k]),a=(j.cacheable?d.clone(j.fragment):j.fragment).childNodes);return d.merge(this,a)}i=c.getElementById(g[2]);if(i&&i.parentNode){if(i.id!==g[2])return f.find(a);this.length=1,this[0]=i}this.context=c,this.selector=a;return this}if(d.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return d.makeArray(a,this)},selector:"",jquery:"1.5",length:0,size:function(){return this.length},toArray:function(){return E.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var e=this.constructor();d.isArray(a)?D.apply(e,a):d.merge(e,a),e.prevObject=this,e.context=this.context,b==="find"?e.selector=this.selector+(this.selector?" ":"")+c:b&&(e.selector=this.selector+"."+b+"("+c+")");return e},each:function(a,b){return d.each(this,a,b)},ready:function(a){d.bindReady(),y.done(a);return this},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(E.apply(this,arguments),"slice",E.call(arguments).join(","))},map:function(a){return this.pushStack(d.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:D,sort:[].sort,splice:[].splice},d.fn.init.prototype=d.fn,d.extend=d.fn.extend=function(){var a,c,e,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i==="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!=="object"&&!d.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j0)return;y.resolveWith(c,[d]),d.fn.trigger&&d(c).trigger("ready").unbind("ready")}},bindReady:function(){if(!x){x=!0;if(c.readyState==="complete")return setTimeout(d.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",A,!1),a.addEventListener("load",d.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",A),a.attachEvent("onload",d.ready);var b=!1;try{b=a.frameElement==null}catch(e){}c.documentElement.doScroll&&b&&I()}}},isFunction:function(a){return d.type(a)==="function"},isArray:Array.isArray||function(a){return d.type(a)==="array"},isWindow:function(a){return a&&typeof a==="object"&&"setInterval"in a},isNaN:function(a){return a==null||!l.test(a)||isNaN(a)},type:function(a){return a==null?String(a):H[B.call(a)]||"object"},isPlainObject:function(a){if(!a||d.type(a)!=="object"||a.nodeType||d.isWindow(a))return!1;if(a.constructor&&!C.call(a,"constructor")&&!C.call(a.constructor.prototype,"isPrototypeOf"))return!1;var c;for(c in a){}return c===b||C.call(a,c)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw a},parseJSON:function(b){if(typeof b!=="string"||!b)return null;b=d.trim(b);if(n.test(b.replace(o,"@").replace(p,"]").replace(q,"")))return a.JSON&&a.JSON.parse?a.JSON.parse(b):(new Function("return "+b))();d.error("Invalid JSON: "+b)},parseXML:function(b,c,e){a.DOMParser?(e=new DOMParser,c=e.parseFromString(b,"text/xml")):(c=new ActiveXObject("Microsoft.XMLDOM"),c.async="false",c.loadXML(b)),e=c.documentElement,(!e||!e.nodeName||e.nodeName==="parsererror")&&d.error("Invalid XML: "+b);return c},noop:function(){},globalEval:function(a){if(a&&i.test(a)){var b=c.getElementsByTagName("head")[0]||c.documentElement,e=c.createElement("script");e.type="text/javascript",d.support.scriptEval()?e.appendChild(c.createTextNode(a)):e.text=a,b.insertBefore(e,b.firstChild),b.removeChild(e)}},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,e){var f,g=0,h=a.length,i=h===b||d.isFunction(a);if(e){if(i){for(f in a)if(c.apply(a[f],e)===!1)break}else for(;g1?(g=Array(c),d.each(b,function(a,b){d.when(b).then(function(b){g[a]=arguments.length>1?E.call(arguments,0):b,--c||e.resolveWith(f,g)},e.reject)})):e!==a&&e.resolve(a);return f},uaMatch:function(a){a=a.toLowerCase();var b=r.exec(a)||s.exec(a)||t.exec(a)||a.indexOf("compatible")<0&&u.exec(a)||[];return{browser:b[1]||"",version:b[2]||"0"}},sub:function(){function a(b,c){return new a.fn.init(b,c)}d.extend(!0,a,this),a.superclass=this,a.fn=a.prototype=this(),a.fn.constructor=a,a.subclass=this.subclass,a.fn.init=function b(b,c){c&&c instanceof d&&!(c instanceof a)&&(c=a(c));return d.fn.init.call(this,b,c,e)},a.fn.init.prototype=a.fn;var e=a(c);return a},browser:{}}),y=d._Deferred(),d.each("Boolean Number String Function Array Date RegExp Object".split(" "),function(a,b){H["[object "+b+"]"]=b.toLowerCase()}),w=d.uaMatch(v),w.browser&&(d.browser[w.browser]=!0,d.browser.version=w.version),d.browser.webkit&&(d.browser.safari=!0),G&&(d.inArray=function(a,b){return G.call(b,a)}),i.test(" ")&&(j=/^[\s\xA0]+/,k=/[\s\xA0]+$/),g=d(c),c.addEventListener?A=function(){c.removeEventListener("DOMContentLoaded",A,!1),d.ready()}:c.attachEvent&&(A=function(){c.readyState==="complete"&&(c.detachEvent("onreadystatechange",A),d.ready())});return a.jQuery=a.$=d}();(function(){d.support={};var b=c.createElement("div");b.style.display="none",b.innerHTML="
      a";var e=b.getElementsByTagName("*"),f=b.getElementsByTagName("a")[0],g=c.createElement("select"),h=g.appendChild(c.createElement("option"));if(e&&e.length&&f){d.support={leadingWhitespace:b.firstChild.nodeType===3,tbody:!b.getElementsByTagName("tbody").length,htmlSerialize:!!b.getElementsByTagName("link").length,style:/red/.test(f.getAttribute("style")),hrefNormalized:f.getAttribute("href")==="/a",opacity:/^0.55$/.test(f.style.opacity),cssFloat:!!f.style.cssFloat,checkOn:b.getElementsByTagName("input")[0].value==="on",optSelected:h.selected,deleteExpando:!0,optDisabled:!1,checkClone:!1,_scriptEval:null,noCloneEvent:!0,boxModel:null,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableHiddenOffsets:!0},g.disabled=!0,d.support.optDisabled=!h.disabled,d.support.scriptEval=function(){if(d.support._scriptEval===null){var b=c.documentElement,e=c.createElement("script"),f="script"+d.now();e.type="text/javascript";try{e.appendChild(c.createTextNode("window."+f+"=1;"))}catch(g){}b.insertBefore(e,b.firstChild),a[f]?(d.support._scriptEval=!0,delete a[f]):d.support._scriptEval=!1,b.removeChild(e),b=e=f=null}return d.support._scriptEval};try{delete b.test}catch(i){d.support.deleteExpando=!1}b.attachEvent&&b.fireEvent&&(b.attachEvent("onclick",function j(){d.support.noCloneEvent=!1,b.detachEvent("onclick",j)}),b.cloneNode(!0).fireEvent("onclick")),b=c.createElement("div"),b.innerHTML="";var k=c.createDocumentFragment();k.appendChild(b.firstChild),d.support.checkClone=k.cloneNode(!0).cloneNode(!0).lastChild.checked,d(function(){var a=c.createElement("div"),b=c.getElementsByTagName("body")[0];if(b){a.style.width=a.style.paddingLeft="1px",b.appendChild(a),d.boxModel=d.support.boxModel=a.offsetWidth===2,"zoom"in a.style&&(a.style.display="inline",a.style.zoom=1,d.support.inlineBlockNeedsLayout=a.offsetWidth===2,a.style.display="",a.innerHTML="
      ",d.support.shrinkWrapBlocks=a.offsetWidth!==2),a.innerHTML="
      t
      ";var e=a.getElementsByTagName("td");d.support.reliableHiddenOffsets=e[0].offsetHeight===0,e[0].style.display="",e[1].style.display="none",d.support.reliableHiddenOffsets=d.support.reliableHiddenOffsets&&e[0].offsetHeight===0,a.innerHTML="",b.removeChild(a).style.display="none",a=e=null}});var l=function(a){var b=c.createElement("div");a="on"+a;if(!b.attachEvent)return!0;var d=a in b;d||(b.setAttribute(a,"return;"),d=typeof b[a]==="function"),b=null;return d};d.support.submitBubbles=l("submit"),d.support.changeBubbles=l("change"),b=e=f=null}})();var e=/^(?:\{.*\}|\[.*\])$/;d.extend({cache:{},uuid:0,expando:"jQuery"+(d.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?d.cache[a[d.expando]]:a[d.expando];return!!a&&!d.isEmptyObject(a)},data:function(a,c,e,f){if(d.acceptData(a)){var g=d.expando,h=typeof c==="string",i,j=a.nodeType,k=j?d.cache:a,l=j?a[d.expando]:a[d.expando]&&d.expando;if((!l||f&&l&&!k[l][g])&&h&&e===b)return;l||(j?a[d.expando]=l=++d.uuid:l=d.expando),k[l]||(k[l]={}),typeof c==="object"&&(f?k[l][g]=d.extend(k[l][g],c):k[l]=d.extend(k[l],c)),i=k[l],f&&(i[g]||(i[g]={}),i=i[g]),e!==b&&(i[c]=e);if(c==="events"&&!i[c])return i[g]&&i[g].events;return h?i[c]:i}},removeData:function(b,c,e){if(d.acceptData(b)){var f=d.expando,g=b.nodeType,h=g?d.cache:b,i=g?b[d.expando]:d.expando;if(!h[i])return;if(c){var j=e?h[i][f]:h[i];if(j){delete j[c];if(!d.isEmptyObject(j))return}}if(e){delete h[i][f];if(!d.isEmptyObject(h[i]))return}var k=h[i][f];d.support.deleteExpando||h!=a?delete h[i]:h[i]=null,k?(h[i]={},h[i][f]=k):g&&(d.support.deleteExpando?delete b[d.expando]:b.removeAttribute?b.removeAttribute(d.expando):b[d.expando]=null)}},_data:function(a,b,c){return d.data(a,b,c,!0)},acceptData:function(a){if(a.nodeName){var b=d.noData[a.nodeName.toLowerCase()];if(b)return b!==!0&&a.getAttribute("classid")===b}return!0}}),d.fn.extend({data:function(a,c){var e=null;if(typeof a==="undefined"){if(this.length){e=d.data(this[0]);if(this[0].nodeType===1){var g=this[0].attributes,h;for(var i=0,j=g.length;i-1)return!0;return!1},val:function(a){if(!arguments.length){var c=this[0];if(c){if(d.nodeName(c,"option")){var e=c.attributes.value;return!e||e.specified?c.value:c.text}if(d.nodeName(c,"select")){var f=c.selectedIndex,g=[],h=c.options,j=c.type==="select-one";if(f<0)return null;for(var k=j?f:0,l=j?f+1:h.length;k=0;else if(d.nodeName(this,"select")){var f=d.makeArray(e);d("option",this).each(function(){this.selected=d.inArray(d(this).val(),f)>=0}),f.length||(this.selectedIndex=-1)}else this.value=e}})}}),d.extend({attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,e,f){if(!a||a.nodeType===3||a.nodeType===8||a.nodeType===2)return b;if(f&&c in d.attrFn)return d(a)[c](e);var g=a.nodeType!==1||!d.isXMLDoc(a),h=e!==b;c=g&&d.props[c]||c;if(a.nodeType===1){var i=j.test(c);if(c==="selected"&&!d.support.optSelected){var n=a.parentNode;n&&(n.selectedIndex,n.parentNode&&n.parentNode.selectedIndex)}if((c in a||a[c]!==b)&&g&&!i){h&&(c==="type"&&k.test(a.nodeName)&&a.parentNode&&d.error("type property can't be changed"),e===null?a.nodeType===1&&a.removeAttribute(c):a[c]=e);if(d.nodeName(a,"form")&&a.getAttributeNode(c))return a.getAttributeNode(c).nodeValue;if(c==="tabIndex"){var o=a.getAttributeNode("tabIndex");return o&&o.specified?o.value:l.test(a.nodeName)||m.test(a.nodeName)&&a.href?0:b}return a[c]}if(!d.support.style&&g&&c==="style"){h&&(a.style.cssText=""+e);return a.style.cssText}h&&a.setAttribute(c,""+e);if(!a.attributes[c]&&(a.hasAttribute&&!a.hasAttribute(c)))return b;var p=!d.support.hrefNormalized&&g&&i?a.getAttribute(c,2):a.getAttribute(c);return p===null?b:p}h&&(a[c]=e);return a[c]}});var o=/\.(.*)$/,p=/^(?:textarea|input|select)$/i,q=/\./g,r=/ /g,s=/[^\w\s.|`]/g,t=function(a){return a.replace(s,"\\$&")},u="events";d.event={add:function(c,e,f,g){if(c.nodeType!==3&&c.nodeType!==8){d.isWindow(c)&&(c!==a&&!c.frameElement)&&(c=a);if(f===!1)f=v;else if(!f)return;var h,i;f.handler&&(h=f,f=h.handler),f.guid||(f.guid=d.guid++);var j=d._data(c);if(!j)return;var k=j[u],l=j.handle;typeof k==="function"?(l=k.handle,k=k.events):k||(c.nodeType||(j[u]=j=function(){}),j.events=k={}),l||(j.handle=l=function(){return typeof d!=="undefined"&&!d.event.triggered?d.event.handle.apply(l.elem,arguments):b}),l.elem=c,e=e.split(" ");var m,n=0,o;while(m=e[n++]){i=h?d.extend({},h):{handler:f,data:g},m.indexOf(".")>-1?(o=m.split("."),m=o.shift(),i.namespace=o.slice(0).sort().join(".")):(o=[],i.namespace=""),i.type=m,i.guid||(i.guid=f.guid);var p=k[m],q=d.event.special[m]||{};if(!p){p=k[m]=[];if(!q.setup||q.setup.call(c,g,o,l)===!1)c.addEventListener?c.addEventListener(m,l,!1):c.attachEvent&&c.attachEvent("on"+m,l)}q.add&&(q.add.call(c,i),i.handler.guid||(i.handler.guid=f.guid)),p.push(i),d.event.global[m]=!0}c=null}},global:{},remove:function(a,c,e,f){if(a.nodeType!==3&&a.nodeType!==8){e===!1&&(e=v);var g,h,i,j,k=0,l,m,n,o,p,q,r,s=d.hasData(a)&&d._data(a),w=s&&s[u];if(!s||!w)return;typeof w==="function"&&(s=w,w=w.events),c&&c.type&&(e=c.handler,c=c.type);if(!c||typeof c==="string"&&c.charAt(0)==="."){c=c||"";for(h in w)d.event.remove(a,h+c);return}c=c.split(" ");while(h=c[k++]){r=h,q=null,l=h.indexOf(".")<0,m=[],l||(m=h.split("."),h=m.shift(),n=new RegExp("(^|\\.)"+d.map(m.slice(0).sort(),t).join("\\.(?:.*\\.)?")+"(\\.|$)")),p=w[h];if(!p)continue;if(!e){for(j=0;j=0&&(a.type=f=f.slice(0,-1),a.exclusive=!0),e||(a.stopPropagation(),d.event.global[f]&&d.each(d.cache,function(){var b=d.expando,e=this[b];e&&e.events&&e.events[f]&&d.event.trigger(a,c,e.handle.elem)}));if(!e||e.nodeType===3||e.nodeType===8)return b;a.result=b,a.target=e,c=d.makeArray(c),c.unshift(a)}a.currentTarget=e;var h=e.nodeType?d._data(e,"handle"):(d._data(e,u)||{}).handle;h&&h.apply(e,c);var i=e.parentNode||e.ownerDocument;try{e&&e.nodeName&&d.noData[e.nodeName.toLowerCase()]||e["on"+f]&&e["on"+f].apply(e,c)===!1&&(a.result=!1,a.preventDefault())}catch(j){}if(!a.isPropagationStopped()&&i)d.event.trigger(a,c,i,!0);else if(!a.isDefaultPrevented()){var k,l=a.target,m=f.replace(o,""),n=d.nodeName(l,"a")&&m==="click",p=d.event.special[m]||{};if((!p._default||p._default.call(e,a)===!1)&&!n&&!(l&&l.nodeName&&d.noData[l.nodeName.toLowerCase()])){try{l[m]&&(k=l["on"+m],k&&(l["on"+m]=null),d.event.triggered=!0,l[m]())}catch(q){}k&&(l["on"+m]=k),d.event.triggered=!1}}},handle:function(c){var e,f,g,h,i,j=[],k=d.makeArray(arguments);c=k[0]=d.event.fix(c||a.event),c.currentTarget=this,e=c.type.indexOf(".")<0&&!c.exclusive,e||(g=c.type.split("."),c.type=g.shift(),j=g.slice(0).sort(),h=new RegExp("(^|\\.)"+j.join("\\.(?:.*\\.)?")+"(\\.|$)")),c.namespace=c.namespace||j.join("."),i=d._data(this,u),typeof i==="function"&&(i=i.events),f=(i||{})[c.type];if(i&&f){f=f.slice(0);for(var l=0,m=f.length;l-1?d.map(a.options,function(a){return a.selected}).join("-"):"":a.nodeName.toLowerCase()==="select"&&(c=a.selectedIndex);return c},B=function B(a){var c=a.target,e,f;if(p.test(c.nodeName)&&!c.readOnly){e=d._data(c,"_change_data"),f=A(c),(a.type!=="focusout"||c.type!=="radio")&&d._data(c,"_change_data",f);if(e===b||f===e)return;if(e!=null||f){a.type="change",a.liveFired=b;return d.event.trigger(a,arguments[1],c)}}};d.event.special.change={filters:{focusout:B,beforedeactivate:B,click:function(a){var b=a.target,c=b.type;if(c==="radio"||c==="checkbox"||b.nodeName.toLowerCase()==="select")return B.call(this,a)},keydown:function(a){var b=a.target,c=b.type;if(a.keyCode===13&&b.nodeName.toLowerCase()!=="textarea"||a.keyCode===32&&(c==="checkbox"||c==="radio")||c==="select-multiple")return B.call(this,a)},beforeactivate:function(a){var b=a.target;d._data(b,"_change_data",A(b))}},setup:function(a,b){if(this.type==="file")return!1;for(var c in z)d.event.add(this,c+".specialChange",z[c]);return p.test(this.nodeName)},teardown:function(a){d.event.remove(this,".specialChange");return p.test(this.nodeName)}},z=d.event.special.change.filters,z.focus=z.beforeactivate}c.addEventListener&&d.each({focus:"focusin",blur:"focusout"},function(a,b){function c(a){a=d.event.fix(a),a.type=b;return d.event.handle.call(this,a)}d.event.special[b]={setup:function(){this.addEventListener(a,c,!0)},teardown:function(){this.removeEventListener(a,c,!0)}}}),d.each(["bind","one"],function(a,c){d.fn[c]=function(a,e,f){if(typeof a==="object"){for(var g in a)this[c](g,e,a[g],f);return this}if(d.isFunction(e)||e===!1)f=e,e=b;var h=c==="one"?d.proxy(f,function(a){d(this).unbind(a,h);return f.apply(this,arguments)}):f;if(a==="unload"&&c!=="one")this.one(a,e,f);else for(var i=0,j=this.length;i0?this.bind(b,a,c):this.trigger(b)},d.attrFn&&(d.attrFn[b]=!0)}),function(){function s(a,b,c,d,e,f){for(var g=0,h=d.length;g0){k=j;break}}j=j[a]}d[g]=k}}}function r(a,b,c,d,e,f){for(var g=0,h=d.length;g+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,e=0,f=Object.prototype.toString,g=!1,h=!0;[0,0].sort(function(){h=!1;return 0});var i=function(b,d,e,g){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!=="string")return e;var l,m,o,p,q,r,s,u,v=!0,w=i.isXML(d),x=[],y=b;do{a.exec(""),l=a.exec(y);if(l){y=l[3],x.push(l[1]);if(l[2]){p=l[3];break}}}while(l);if(x.length>1&&k.exec(b))if(x.length===2&&j.relative[x[0]])m=t(x[0]+x[1],d);else{m=j.relative[x[0]]?[d]:i(x.shift(),d);while(x.length)b=x.shift(),j.relative[b]&&(b+=x.shift()),m=t(b,m)}else{!g&&x.length>1&&d.nodeType===9&&!w&&j.match.ID.test(x[0])&&!j.match.ID.test(x[x.length-1])&&(q=i.find(x.shift(),d,w),d=q.expr?i.filter(q.expr,q.set)[0]:q.set[0]);if(d){q=g?{expr:x.pop(),set:n(g)}:i.find(x.pop(),x.length===1&&(x[0]==="~"||x[0]==="+")&&d.parentNode?d.parentNode:d,w),m=q.expr?i.filter(q.expr,q.set):q.set,x.length>0?o=n(m):v=!1;while(x.length)r=x.pop(),s=r,j.relative[r]?s=x.pop():r="",s==null&&(s=d),j.relative[r](o,s,w)}else o=x=[]}o||(o=m),o||i.error(r||b);if(f.call(o)==="[object Array]")if(v)if(d&&d.nodeType===1)for(u=0;o[u]!=null;u++)o[u]&&(o[u]===!0||o[u].nodeType===1&&i.contains(d,o[u]))&&e.push(m[u]);else for(u=0;o[u]!=null;u++)o[u]&&o[u].nodeType===1&&e.push(m[u]);else e.push.apply(e,o);else n(o,e);p&&(i(p,h,e,g),i.uniqueSort(e));return e};i.uniqueSort=function(a){if(p){g=h,a.sort(p);if(g)for(var b=1;b0},i.find=function(a,b,c){var d;if(!a)return[];for(var e=0,f=j.order.length;e":function(a,b){var c,d=typeof b==="string",e=0,f=a.length;if(d&&!/\W/.test(b)){b=b.toLowerCase();for(;e=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(/\\/g,"")},TAG:function(a,b){return a[1].toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||i.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&i.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(/\\/g,"");!f&&j.attrMap[g]&&(a[1]=j.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(/\\/g,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=i(b[3],null,null,c);else{var g=i.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(j.match.POS.test(b[0])||j.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!i(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){return"text"===a.type},radio:function(a){return"radio"===a.type},checkbox:function(a){return"checkbox"===a.type},file:function(a){return"file"===a.type},password:function(a){return"password"===a.type},submit:function(a){return"submit"===a.type},image:function(a){return"image"===a.type},reset:function(a){return"reset"===a.type},button:function(a){return"button"===a.type||a.nodeName.toLowerCase()==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return bc[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=j.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||i.getText([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,k=g.length;h=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=j.attrHandle[c]?j.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=j.setFilters[e];if(f)return f(a,c,b,d)}}},k=j.match.POS,l=function(a,b){return"\\"+(b-0+1)};for(var m in j.match)j.match[m]=new RegExp(j.match[m].source+/(?![^\[]*\])(?![^\(]*\))/.source),j.leftMatch[m]=new RegExp(/(^(?:.|\r|\n)*?)/.source+j.match[m].source.replace(/\\(\d+)/g,l));var n=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(o){n=function(a,b){var c=0,d=b||[];if(f.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length==="number")for(var e=a.length;c",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(j.find.ID=function(a,c,d){if(typeof c.getElementById!=="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!=="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},j.filter.ID=function(a,b){var c=typeof a.getAttributeNode!=="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(j.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML="",a.firstChild&&typeof a.firstChild.getAttribute!=="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(j.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=i,b=c.createElement("div"),d="__sizzle__";b.innerHTML="

      ";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){i=function(b,e,f,g){e=e||c;if(!g&&!i.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return n(e.getElementsByTagName(b),f);if(h[2]&&j.find.CLASS&&e.getElementsByClassName)return n(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return n([e.body],f);if(h&&h[3]){var k=e.getElementById(h[3]);if(!k||!k.parentNode)return n([],f);if(k.id===h[3])return n([k],f)}try{return n(e.querySelectorAll(b),f)}catch(l){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var m=e.getAttribute("id"),o=m||d,p=e.parentNode,q=/^\s*[+~]/.test(b);m?o=o.replace(/'/g,"\\$&"):e.setAttribute("id",o),q&&p&&(e=e.parentNode);try{if(!q||p)return n(e.querySelectorAll("[id='"+o+"'] "+b),f)}catch(r){}finally{m||e.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)i[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector,d=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(e){d=!0}b&&(i.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!i.isXML(a))try{if(d||!j.match.PSEUDO.test(c)&&!/!=/.test(c))return b.call(a,c)}catch(e){}return i(c,null,null,[a]).length>0})}(),function(){var a=c.createElement("div");a.innerHTML="
      ";if(a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;j.order.splice(1,0,"CLASS"),j.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!=="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?i.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?i.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:i.contains=function(){return!1},i.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var t=function(a,b){var c,d=[],e="",f=b.nodeType?[b]:b;while(c=j.match.PSEUDO.exec(a))e+=c[0],a=a.replace(j.match.PSEUDO,"");a=j.relative[a]?a+"*":a;for(var g=0,h=f.length;g0)for(var g=c;g0},closest:function(a,b){var c=[],e,f,g=this[0];if(d.isArray(a)){var h,i,j={},k=1;if(g&&a.length){for(e=0,f=a.length;e-1:d(g).is(h))&&c.push({selector:i,elem:g,level:k});g=g.parentNode,k++}}return c}var l=L.test(a)?d(a,b||this.context):null;for(e=0,f=this.length;e-1:d.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b)break}}c=c.length>1?d.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a||typeof a==="string")return d.inArray(this[0],a?d(a):this.parent().children());return d.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a==="string"?d(a,b):d.makeArray(a),e=d.merge(this.get(),c);return this.pushStack(N(c[0])||N(e[0])?e:d.unique(e))},andSelf:function(){return this.add(this.prevObject)}}),d.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return d.dir(a,"parentNode")},parentsUntil:function(a,b,c){return d.dir(a,"parentNode",c)},next:function(a){return d.nth(a,2,"nextSibling")},prev:function(a){return d.nth(a,2,"previousSibling")},nextAll:function(a){return d.dir(a,"nextSibling")},prevAll:function(a){return d.dir(a,"previousSibling")},nextUntil:function(a,b,c){return d.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return d.dir(a,"previousSibling",c)},siblings:function(a){return d.sibling(a.parentNode.firstChild,a)},children:function(a){return d.sibling(a.firstChild)},contents:function(a){return d.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:d.makeArray(a.childNodes)}},function(a,b){d.fn[a]=function(c,e){var f=d.map(this,b,c),g=K.call(arguments);G.test(a)||(e=c),e&&typeof e==="string"&&(f=d.filter(e,f)),f=this.length>1&&!M[a]?d.unique(f):f,(this.length>1||I.test(e))&&H.test(a)&&(f=f.reverse());return this.pushStack(f,a,g.join(","))}}),d.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?d.find.matchesSelector(b[0],a)?[b[0]]:[]:d.find.matches(a,b)},dir:function(a,c,e){var f=[],g=a[c];while(g&&g.nodeType!==9&&(e===b||g.nodeType!==1||!d(g).is(e)))g.nodeType===1&&f.push(g),g=g[c];return f},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var P=/ jQuery\d+="(?:\d+|null)"/g,Q=/^\s+/,R=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,S=/<([\w:]+)/,T=/",""],legend:[1,"
      ","
      "],thead:[1,"","
      "],tr:[2,"","
      "],td:[3,"","
      "],col:[2,"","
      "],area:[1,"",""],_default:[0,"",""]};X.optgroup=X.option,X.tbody=X.tfoot=X.colgroup=X.caption=X.thead,X.th=X.td,d.support.htmlSerialize||(X._default=[1,"div
      ","
      "]),d.fn.extend({text:function(a){if(d.isFunction(a))return this.each(function(b){var c=d(this);c.text(a.call(this,b,c.text()))});if(typeof a!=="object"&&a!==b)return this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a));return d.text(this)},wrapAll:function(a){if(d.isFunction(a))return this.each(function(b){d(this).wrapAll(a.call(this,b))});if(this[0]){var b=d(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(d.isFunction(a))return this.each(function(b){d(this).wrapInner(a.call(this,b))});return this.each(function(){var b=d(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){d(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){d.nodeName(this,"body")||d(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=d(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,d(arguments[0]).toArray());return a}},remove:function(a,b){for(var c=0,e;(e=this[c])!=null;c++)if(!a||d.filter(a,[e]).length)!b&&e.nodeType===1&&(d.cleanData(e.getElementsByTagName("*")),d.cleanData([e])),e.parentNode&&e.parentNode.removeChild(e);return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&d.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!0:a,b=b==null?a:b;return this.map(function(){return d.clone(this,a,b)})},html:function(a){if(a===b)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(P,""):null;if(typeof a!=="string"||V.test(a)||!d.support.leadingWhitespace&&Q.test(a)||X[(S.exec(a)||["",""])[1].toLowerCase()])d.isFunction(a)?this.each(function(b){var c=d(this);c.html(a.call(this,b,c.html()))}):this.empty().append(a);else{a=a.replace(R,"<$1>");try{for(var c=0,e=this.length;c1&&l0?this.clone(!0):this).get();d(f[h])[b](j),e=e.concat(j)}return this.pushStack(e,a,f.selector)}}),d.extend({clone:function(a,b,c){var e=a.cloneNode(!0),f,g,h;if(!d.support.noCloneEvent&&(a.nodeType===1||a.nodeType===11)&&!d.isXMLDoc(a)){f=a.getElementsByTagName("*"),g=e.getElementsByTagName("*");for(h=0;f[h];++h)$(f[h],g[h]);$(a,e)}if(b){Z(a,e);if(c&&"getElementsByTagName"in a){f=a.getElementsByTagName("*"),g=e.getElementsByTagName("*");if(f.length)for(h=0;f[h];++h)Z(f[h],g[h])}}return e},clean:function(a,b,e,f){b=b||c,typeof b.createElement==="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);var g=[];for(var h=0,i;(i=a[h])!=null;h++){typeof i==="number"&&(i+="");if(!i)continue;if(typeof i!=="string"||U.test(i)){if(typeof i==="string"){i=i.replace(R,"<$1>");var j=(S.exec(i)||["",""])[1].toLowerCase(),k=X[j]||X._default,l=k[0],m=b.createElement("div");m.innerHTML=k[1]+i+k[2];while(l--)m=m.lastChild;if(!d.support.tbody){var n=T.test(i),o=j==="table"&&!n?m.firstChild&&m.firstChild.childNodes:k[1]===""&&!n?m.childNodes:[];for(var p=o.length-1;p>=0;--p)d.nodeName(o[p],"tbody")&&!o[p].childNodes.length&&o[p].parentNode.removeChild(o[p])}!d.support.leadingWhitespace&&Q.test(i)&&m.insertBefore(b.createTextNode(Q.exec(i)[0]),m.firstChild),i=m.childNodes}}else i=b.createTextNode(i);i.nodeType?g.push(i):g=d.merge(g,i)}if(e)for(h=0;g[h];h++)!f||!d.nodeName(g[h],"script")||g[h].type&&g[h].type.toLowerCase()!=="text/javascript"?(g[h].nodeType===1&&g.splice.apply(g,[h+1,0].concat(d.makeArray(g[h].getElementsByTagName("script")))),e.appendChild(g[h])):f.push(g[h].parentNode?g[h].parentNode.removeChild(g[h]):g[h]);return g},cleanData:function(a){var b,c,e=d.cache,f=d.expando,g=d.event.special,h=d.support.deleteExpando;for(var i=0,j;(j=a[i])!=null;i++){if(j.nodeName&&d.noData[j.nodeName.toLowerCase()])continue;c=j[d.expando];if(c){b=e[c]&&e[c][f];if(b&&b.events){for(var k in b.events)g[k]?d.event.remove(j,k):d.removeEvent(j,k,b.handle);b.handle&&(b.handle.elem=null)}h?delete j[d.expando]:j.removeAttribute&&j.removeAttribute(d.expando),delete e[c]}}}});var ba=/alpha\([^)]*\)/i,bb=/opacity=([^)]*)/,bc=/-([a-z])/ig,bd=/([A-Z])/g,be=/^-?\d+(?:px)?$/i,bf=/^-?\d/,bg={position:"absolute",visibility:"hidden",display:"block"},bh=["Left","Right"],bi=["Top","Bottom"],bj,bk,bl,bm=function(a,b){return b.toUpperCase()};d.fn.css=function(a,c){if(arguments.length===2&&c===b)return this;return d.access(this,a,c,!0,function(a,c,e){return e!==b?d.style(a,c,e):d.css(a,c)})},d.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=bj(a,"opacity","opacity");return c===""?"1":c}return a.style.opacity}}},cssNumber:{zIndex:!0,fontWeight:!0,opacity:!0,zoom:!0,lineHeight:!0},cssProps:{"float":d.support.cssFloat?"cssFloat":"styleFloat"},style:function(a,c,e,f){if(a&&a.nodeType!==3&&a.nodeType!==8&&a.style){var g,h=d.camelCase(c),i=a.style,j=d.cssHooks[h];c=d.cssProps[h]||h;if(e===b){if(j&&"get"in j&&(g=j.get(a,!1,f))!==b)return g;return i[c]}if(typeof e==="number"&&isNaN(e)||e==null)return;typeof e==="number"&&!d.cssNumber[h]&&(e+="px");if(!j||!("set"in j)||(e=j.set(a,e))!==b)try{i[c]=e}catch(k){}}},css:function(a,c,e){var f,g=d.camelCase(c),h=d.cssHooks[g];c=d.cssProps[g]||g;if(h&&"get"in h&&(f=h.get(a,!0,e))!==b)return f;if(bj)return bj(a,c,g)},swap:function(a,b,c){var d={};for(var e in b)d[e]=a.style[e],a.style[e]=b[e];c.call(a);for(e in b)a.style[e]=d[e]},camelCase:function(a){return a.replace(bc,bm)}}),d.curCSS=d.css,d.each(["height","width"],function(a,b){d.cssHooks[b]={get:function(a,c,e){var f;if(c){a.offsetWidth!==0?f=bn(a,b,e):d.swap(a,bg,function(){f=bn(a,b,e)});if(f<=0){f=bj(a,b,b),f==="0px"&&bl&&(f=bl(a,b,b));if(f!=null)return f===""||f==="auto"?"0px":f}if(f<0||f==null){f=a.style[b];return f===""||f==="auto"?"0px":f}return typeof f==="string"?f:f+"px"}},set:function(a,b){if(!be.test(b))return b;b=parseFloat(b);if(b>=0)return b+"px"}}}),d.support.opacity||(d.cssHooks.opacity={get:function(a,b){return bb.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style;c.zoom=1;var e=d.isNaN(b)?"":"alpha(opacity="+b*100+")",f=c.filter||"";c.filter=ba.test(f)?f.replace(ba,e):c.filter+" "+e}}),c.defaultView&&c.defaultView.getComputedStyle&&(bk=function(a,c,e){var f,g,h;e=e.replace(bd,"-$1").toLowerCase();if(!(g=a.ownerDocument.defaultView))return b;if(h=g.getComputedStyle(a,null))f=h.getPropertyValue(e),f===""&&!d.contains(a.ownerDocument.documentElement,a)&&(f=d.style(a,e));return f}),c.documentElement.currentStyle&&(bl=function(a,b){var c,d=a.currentStyle&&a.currentStyle[b],e=a.runtimeStyle&&a.runtimeStyle[b],f=a.style;!be.test(d)&&bf.test(d)&&(c=f.left,e&&(a.runtimeStyle.left=a.currentStyle.left),f.left=b==="fontSize"?"1em":d||0,d=f.pixelLeft+"px",f.left=c,e&&(a.runtimeStyle.left=e));return d===""?"auto":d}),bj=bk||bl,d.expr&&d.expr.filters&&(d.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!d.support.reliableHiddenOffsets&&(a.style.display||d.css(a,"display"))==="none"},d.expr.filters.visible=function(a){return!d.expr.filters.hidden(a)});var bo=/%20/g,bp=/\[\]$/,bq=/\r?\n/g,br=/#.*$/,bs=/^(.*?):\s*(.*?)\r?$/mg,bt=/^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bu=/^(?:GET|HEAD)$/,bv=/^\/\//,bw=/\?/,bx=/)<[^<]*)*<\/script>/gi,by=/^(?:select|textarea)/i,bz=/\s+/,bA=/([?&])_=[^&]*/,bB=/^(\w+:)\/\/([^\/?#:]+)(?::(\d+))?/,bC=d.fn.load,bD={},bE={};d.fn.extend({load:function(a,b,c){if(typeof a!=="string"&&bC)return bC.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var f=a.slice(e,a.length);a=a.slice(0,e)}var g="GET";b&&(d.isFunction(b)?(c=b,b=null):typeof b==="object"&&(b=d.param(b,d.ajaxSettings.traditional),g="POST"));var h=this;d.ajax({url:a,type:g,dataType:"html",data:b,complete:function(a,b,e){e=a.responseText,a.isResolved()&&(a.done(function(a){e=a}),h.html(f?d("
      ").append(e.replace(bx,"")).find(f):e)),c&&h.each(c,[e,b,a])}});return this},serialize:function(){return d.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?d.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||by.test(this.nodeName)||bt.test(this.type))}).map(function(a,b){var c=d(this).val();return c==null?null:d.isArray(c)?d.map(c,function(a,c){return{name:b.name,value:a.replace(bq,"\r\n")}}):{name:b.name,value:c.replace(bq,"\r\n")}}).get()}}),d.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){d.fn[b]=function(a){return this.bind(b,a)}}),d.each(["get","post"],function(a,b){d[b]=function(a,c,e,f){d.isFunction(c)&&(f=f||e,e=c,c=null);return d.ajax({type:b,url:a,data:c,success:e,dataType:f})}}),d.extend({getScript:function(a,b){return d.get(a,null,b,"script")},getJSON:function(a,b,c){return d.get(a,b,c,"json")},ajaxSetup:function(a){d.extend(!0,d.ajaxSettings,a),a.context&&(d.ajaxSettings.context=a.context)},ajaxSettings:{url:location.href,global:!0,type:"GET",contentType:"application/x-www-form-urlencoded",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":"*/*"},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":d.parseJSON,"text xml":d.parseXML}},ajaxPrefilter:bF(bD),ajaxTransport:bF(bE),ajax:function(a,e){function w(a,c,e,l){if(t!==2){t=2,p&&clearTimeout(p),o=b,m=l||"",v.readyState=a?4:0;var n,q,r,s=e?bI(f,v,e):b,u,w;if(a>=200&&a<300||a===304){if(f.ifModified){if(u=v.getResponseHeader("Last-Modified"))d.lastModified[f.url]=u;if(w=v.getResponseHeader("Etag"))d.etag[f.url]=w}if(a===304)c="notmodified",n=!0;else try{q=bJ(f,s),c="success",n=!0}catch(x){c="parsererror",r=x}}else r=c,a&&(c="error",a<0&&(a=0));v.status=a,v.statusText=c,n?i.resolveWith(g,[q,c,v]):i.rejectWith(g,[v,c,r]),v.statusCode(k),k=b,f.global&&h.trigger("ajax"+(n?"Success":"Error"),[v,f,n?q:r]),j.resolveWith(g,[v,c]),f.global&&(h.trigger("ajaxComplete",[v,f]),--d.active||d.event.trigger("ajaxStop"))}}typeof e!=="object"&&(e=a,a=b),e=e||{};var f=d.extend(!0,{},d.ajaxSettings,e),g=(f.context=("context"in e?e:d.ajaxSettings).context)||f,h=g===f?d.event:d(g),i=d.Deferred(),j=d._Deferred(),k=f.statusCode||{},l={},m,n,o,p,q=c.location,r=q.protocol||"http:",s,t=0,u,v={readyState:0,setRequestHeader:function(a,b){t===0&&(l[a.toLowerCase()]=b);return this},getAllResponseHeaders:function(){return t===2?m:null},getResponseHeader:function(a){var b;if(t===2){if(!n){n={};while(b=bs.exec(m))n[b[1].toLowerCase()]=b[2]}b=n[a.toLowerCase()]}return b||null},abort:function(a){a=a||"abort",o&&o.abort(a),w(0,a);return this}};i.promise(v),v.success=v.done,v.error=v.fail,v.complete=j.done,v.statusCode=function(a){if(a){var b;if(t<2)for(b in a)k[b]=[k[b],a[b]];else b=a[v.status],v.then(b,b)}return this},f.url=(""+(a||f.url)).replace(br,"").replace(bv,r+"//"),f.dataTypes=d.trim(f.dataType||"*").toLowerCase().split(bz),f.crossDomain||(s=bB.exec(f.url.toLowerCase()),f.crossDomain=s&&(s[1]!=r||s[2]!=q.hostname||(s[3]||(s[1]==="http:"?80:443))!=(q.port||(r==="http:"?80:443)))),f.data&&f.processData&&typeof f.data!=="string"&&(f.data=d.param(f.data,f.traditional)),bG(bD,f,e,v),f.type=f.type.toUpperCase(),f.hasContent=!bu.test(f.type),f.global&&d.active++===0&&d.event.trigger("ajaxStart");if(!f.hasContent){f.data&&(f.url+=(bw.test(f.url)?"&":"?")+f.data);if(f.cache===!1){var x=d.now(),y=f.url.replace(bA,"$1_="+x);f.url=y+(y===f.url?(bw.test(f.url)?"&":"?")+"_="+x:"")}}if(f.data&&f.hasContent&&f.contentType!==!1||e.contentType)l["content-type"]=f.contentType;f.ifModified&&(d.lastModified[f.url]&&(l["if-modified-since"]=d.lastModified[f.url]),d.etag[f.url]&&(l["if-none-match"]=d.etag[f.url])),l.accept=f.dataTypes[0]&&f.accepts[f.dataTypes[0]]?f.accepts[f.dataTypes[0]]+(f.dataTypes[0]!=="*"?", */*; q=0.01":""):f.accepts["*"];for(u in f.headers)l[u.toLowerCase()]=f.headers[u];if(!f.beforeSend||f.beforeSend.call(g,v,f)!==!1&&t!==2){for(u in {success:1,error:1,complete:1})v[u](f[u]);o=bG(bE,f,e,v);if(o){t=v.readyState=1,f.global&&h.trigger("ajaxSend",[v,f]),f.async&&f.timeout>0&&(p=setTimeout(function(){v.abort("timeout")},f.timeout));try{o.send(l,w)}catch(z){status<2?w(-1,z):d.error(z)}}else w(-1,"No Transport")}else w(0,"abort"),v=!1;return v},param:function(a,c){var e=[],f=function(a,b){b=d.isFunction(b)?b():b,e[e.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=d.ajaxSettings.traditional);if(d.isArray(a)||a.jquery)d.each(a,function(){f(this.name,this.value)});else for(var g in a)bH(g,a[g],c,f);return e.join("&").replace(bo,"+")}}),d.extend({active:0,lastModified:{},etag:{}});var bK=d.now(),bL=/(\=)\?(&|$)|()\?\?()/i;d.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return d.expando+"_"+bK++}}),d.ajaxPrefilter("json jsonp",function(b,c,e){e=typeof b.data==="string";if(b.dataTypes[0]==="jsonp"||c.jsonpCallback||c.jsonp!=null||b.jsonp!==!1&&(bL.test(b.url)||e&&bL.test(b.data))){var f,g=b.jsonpCallback=d.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,h=a[g],i=b.url,j=b.data,k="$1"+g+"$2";b.jsonp!==!1&&(i=i.replace(bL,k),b.url===i&&(e&&(j=j.replace(bL,k)),b.data===j&&(i+=(/\?/.test(i)?"&":"?")+b.jsonp+"="+g))),b.url=i,b.data=j,a[g]=function(a){f=[a]},b.complete=[function(){a[g]=h;if(h)f&&d.isFunction(h)&&a[g](f[0]);else try{delete a[g]}catch(b){}},b.complete],b.converters["script json"]=function(){f||d.error(g+" was not called");return f[0]},b.dataTypes[0]="json";return"script"}}),d.ajaxSetup({accepts:{script:"text/javascript, application/javascript"},contents:{script:/javascript/},converters:{"text script":function(a){d.globalEval(a);return a}}}),d.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),d.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var bM=d.now(),bN={},bO,bP;d.ajaxSettings.xhr=a.ActiveXObject?function(){if(a.location.protocol!=="file:")try{return new a.XMLHttpRequest}catch(b){}try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(c){}}:function(){return new a.XMLHttpRequest};try{bP=d.ajaxSettings.xhr()}catch(bQ){}d.support.ajax=!!bP,d.support.cors=bP&&"withCredentials"in bP,bP=b,d.support.ajax&&d.ajaxTransport(function(b){if(!b.crossDomain||d.support.cors){var c;return{send:function(e,f){bO||(bO=1,d(a).bind("unload",function(){d.each(bN,function(a,b){b.onreadystatechange&&b.onreadystatechange(1)})}));var g=b.xhr(),h;b.username?g.open(b.type,b.url,b.async,b.username,b.password):g.open(b.type,b.url,b.async),(!b.crossDomain||b.hasContent)&&!e["x-requested-with"]&&(e["x-requested-with"]="XMLHttpRequest");try{d.each(e,function(a,b){g.setRequestHeader(a,b)})}catch(i){}g.send(b.hasContent&&b.data||null),c=function(a,e){if(c&&(e||g.readyState===4)){c=0,h&&(g.onreadystatechange=d.noop,delete bN[h]);if(e)g.readyState!==4&&g.abort();else{var i=g.status,j,k=g.getAllResponseHeaders(),l={},m=g.responseXML;m&&m.documentElement&&(l.xml=m),l.text=g.responseText;try{j=g.statusText}catch(n){j=""}i=i===0?!b.crossDomain||j?k?304:0:302:i==1223?204:i,f(i,j,l,k)}}},b.async&&g.readyState!==4?(h=bM++,bN[h]=g,g.onreadystatechange=c):c()},abort:function(){c&&c(0,1)}}}});var bR={},bS=/^(?:toggle|show|hide)$/,bT=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,bU,bV=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]];d.fn.extend({show:function(a,b,c){var e,f;if(a||a===0)return this.animate(bW("show",3),a,b,c);for(var g=0,h=this.length;g=0;a--)c[a].elem===this&&(b&&c[a](!0),c.splice(a,1))}),b||this.dequeue();return this}}),d.each({slideDown:bW("show",1),slideUp:bW("hide",1),slideToggle:bW("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){d.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),d.extend({speed:function(a,b,c){var e=a&&typeof a==="object"?d.extend({},a):{complete:c||!c&&b||d.isFunction(a)&&a,duration:a,easing:c&&b||b&&!d.isFunction(b)&&b};e.duration=d.fx.off?0:typeof e.duration==="number"?e.duration:e.duration in d.fx.speeds?d.fx.speeds[e.duration]:d.fx.speeds._default,e.old=e.complete,e.complete=function(){e.queue!==!1&&d(this).dequeue(),d.isFunction(e.old)&&e.old.call(this)};return e},easing:{linear:function(a,b,c,d){return c+d*a},swing:function(a,b,c,d){return(-Math.cos(a*Math.PI)/2+.5)*d+c}},timers:[],fx:function(a,b,c){this.options=b,this.elem=a,this.prop=c,b.orig||(b.orig={})}}),d.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this),(d.fx.step[this.prop]||d.fx.step._default)(this)},cur:function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];var a=parseFloat(d.css(this.elem,this.prop));return a||0},custom:function(a,b,c){function g(a){return e.step(a)}var e=this,f=d.fx;this.startTime=d.now(),this.start=a,this.end=b,this.unit=c||this.unit||"px",this.now=this.start,this.pos=this.state=0,g.elem=this.elem,g()&&d.timers.push(g)&&!bU&&(bU=setInterval(f.tick,f.interval))},show:function(){this.options.orig[this.prop]=d.style(this.elem,this.prop),this.options.show=!0,this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur()),d(this.elem).show()},hide:function(){this.options.orig[this.prop]=d.style(this.elem,this.prop),this.options.hide=!0,this.custom(this.cur(),0)},step:function(a){var b=d.now(),c=!0;if(a||b>=this.options.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),this.options.curAnim[this.prop]=!0;for(var e in this.options.curAnim)this.options.curAnim[e]!==!0&&(c=!1);if(c){if(this.options.overflow!=null&&!d.support.shrinkWrapBlocks){var f=this.elem,g=this.options;d.each(["","X","Y"],function(a,b){f.style["overflow"+b]=g.overflow[a]})}this.options.hide&&d(this.elem).hide();if(this.options.hide||this.options.show)for(var h in this.options.curAnim)d.style(this.elem,h,this.options.orig[h]);this.options.complete.call(this.elem)}return!1}var i=b-this.startTime;this.state=i/this.options.duration;var j=this.options.specialEasing&&this.options.specialEasing[this.prop],k=this.options.easing||(d.easing.swing?"swing":"linear");this.pos=d.easing[j||k](this.state,i,0,1,this.options.duration),this.now=this.start+(this.end-this.start)*this.pos,this.update();return!0}},d.extend(d.fx,{tick:function(){var a=d.timers;for(var b=0;b
      ";d.extend(b.style,{position:"absolute",top:0,left:0,margin:0,border:0,width:"1px",height:"1px",visibility:"hidden"}),b.innerHTML=j,a.insertBefore(b,a.firstChild),e=b.firstChild,f=e.firstChild,h=e.nextSibling.firstChild.firstChild,this.doesNotAddBorder=f.offsetTop!==5,this.doesAddBorderForTableAndCells=h.offsetTop===5,f.style.position="fixed",f.style.top="20px",this.supportsFixedPosition=f.offsetTop===20||f.offsetTop===15,f.style.position=f.style.top="",e.style.overflow="hidden",e.style.position="relative",this.subtractsBorderForOverflowNotVisible=f.offsetTop===-5,this.doesNotIncludeMarginInBodyOffset=a.offsetTop!==i,a.removeChild(b),a=b=e=f=g=h=null,d.offset.initialize=d.noop},bodyOffset:function(a){var b=a.offsetTop,c=a.offsetLeft;d.offset.initialize(),d.offset.doesNotIncludeMarginInBodyOffset&&(b+=parseFloat(d.css(a,"marginTop"))||0,c+=parseFloat(d.css(a,"marginLeft"))||0);return{top:b,left:c}},setOffset:function(a,b,c){var e=d.css(a,"position");e==="static"&&(a.style.position="relative");var f=d(a),g=f.offset(),h=d.css(a,"top"),i=d.css(a,"left"),j=e==="absolute"&&d.inArray("auto",[h,i])>-1,k={},l={},m,n;j&&(l=f.position()),m=j?l.top:parseInt(h,10)||0,n=j?l.left:parseInt(i,10)||0,d.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):f.css(k)}},d.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),e=bZ.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(d.css(a,"marginTop"))||0,c.left-=parseFloat(d.css(a,"marginLeft"))||0,e.top+=parseFloat(d.css(b[0],"borderTopWidth"))||0,e.left+=parseFloat(d.css(b[0],"borderLeftWidth"))||0;return{top:c.top-e.top,left:c.left-e.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&(!bZ.test(a.nodeName)&&d.css(a,"position")==="static"))a=a.offsetParent;return a})}}),d.each(["Left","Top"],function(a,c){var e="scroll"+c;d.fn[e]=function(c){var f=this[0],g;if(!f)return null;if(c!==b)return this.each(function(){g=b$(this),g?g.scrollTo(a?d(g).scrollLeft():c,a?c:d(g).scrollTop()):this[e]=c});g=b$(f);return g?"pageXOffset"in g?g[a?"pageYOffset":"pageXOffset"]:d.support.boxModel&&g.document.documentElement[e]||g.document.body[e]:f[e]}}),d.each(["Height","Width"],function(a,c){var e=c.toLowerCase();d.fn["inner"+c]=function(){return this[0]?parseFloat(d.css(this[0],e,"padding")):null},d.fn["outer"+c]=function(a){return this[0]?parseFloat(d.css(this[0],e,a?"margin":"border")):null},d.fn[e]=function(a){var f=this[0];if(!f)return a==null?null:this;if(d.isFunction(a))return this.each(function(b){var c=d(this);c[e](a.call(this,b,c[e]()))});if(d.isWindow(f)){var g=f.document.documentElement["client"+c];return f.document.compatMode==="CSS1Compat"&&g||f.document.body["client"+c]||g}if(f.nodeType===9)return Math.max(f.documentElement["client"+c],f.body["scroll"+c],f.documentElement["scroll"+c],f.body["offset"+c],f.documentElement["offset"+c]);if(a===b){var h=d.css(f,e),i=parseFloat(h);return d.isNaN(i)?h:i}return this.css(e,typeof a==="string"?a:a+"px")}})})(window); 17 | --------------------------------------------------------------------------------