toggle_docker = (ele) -> ele.toggleClass 'docker-off' ele.toggleClass 'docker-on' disqus_shortname = 'sunnghomepage' disqus_url = 'http://sunng.info/' yahoo_pipe_url = "http://pipes.yahoo.com/pipes/pipe.run?_id=7NxhUNSA3RG_BCC6BBNMsA&_render=json" google_latitude_iframe = '' initDisqus = -> dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); bindCommentsLabelAction = -> label = document.id "commentsLabel" label.onclick = -> container = document.id "disqus_thread" unless container container = new Element("div", { "id": "disqus_thread" "class": "docker docker-off" }) comments_container = document.id "comments" comments_label = document.id "commentsLabel" container.inject comments_label, "before" initDisqus() toggle_docker container window.lifeStreamCallback = (stream) -> lifeStreamRootDom = document.id "lifestream" try list = lifeStreamRootDom.getElement("ul") list.destroy() catch e lifeStreamListDom = new Element("ul", {"class": "docker docker-off"}) for item in stream.value.items itemDomElement = new Element("li") titleDomElement = new Element("p", { text : item.title}) titleDomElement.inject itemDomElement content = if item.description.length>500 then item.description[0..497]+"..." else item.description content += '\u2197' descDomElement = new Element("p", { "class": "streamDesc", "html": content}) descDomElement.inject itemDomElement dateDomElement = new Element("p", { "class": "streamDate", text: item.pubDate }) dateDomElement.inject itemDomElement itemDomElement.inject lifeStreamListDom lifeStreamListDom.inject document.id("lifestreamLabel"), "before" script_tag = document.id "lifeStreamScriptTag" script_tag.destroy() loadLifeStream = -> url = "#{yahoo_pipe_url}&_callback=lifeStreamCallback" scriptTag = new Element("script", { src: url, type: "text/javascript", id: "lifeStreamScriptTag" }) scriptTag.inject document.head, "bottom" ## reload every 3 minutes setTimeout loadLifeStream,5*60*1000 bindLSLabelAction = -> ele = document.id "lifestreamLabel" onclick = -> try lifeStreamRootDom = document.id "lifestream" list = lifeStreamRootDom.getElement "ul" toggle_docker list catch e ele.addEvent "click", onclick bindLocationLabelAction = -> label = document.id "locationLabel" onclick = -> mapContainer = document.id "mapcontainer" unless mapContainer mapContainer = new Element("div", { "html": google_latitude_iframe, "id": "mapcontainer", "class": "docker docker-off" }) location_label = document.id "locationLabel" mapContainer.inject location_label, "before" toggle_docker mapContainer label.addEvent "click", onclick window.addEvent 'domready', loadLifeStream window.addEvent 'domready', bindLSLabelAction window.addEvent 'domready', bindLocationLabelAction window.addEvent 'domready', bindCommentsLabelAction # vim: et sts=2 sw=2