Created
March 14, 2010 15:04
-
-
Save kentbrew/332014 to your computer and use it in GitHub Desktop.
SxSW Panel Widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1: copy index.html and sxsw.js to your local hard drive. | |
| (For best results, click the RAW link next to each one.) | |
| 2: drag index.html into your browser. | |
| 3: have fun, and hit me up on Twitter at @kentbrew if you're having trouble. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <title>SxSW Schedule Scraper</title> | |
| </head> | |
| <body> | |
| <script src="sxsw.js"></script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SxSW Schedule Scraper | |
| // Kent Brewster, 3/14/2010 | |
| (function (d, w) { | |
| var $, k; | |
| k = 'kb_' + new Date().getTime(); | |
| var $ = w[k] = {}; | |
| $.k = k; | |
| $.d = d; | |
| $.w = w; | |
| $.f = (function () { | |
| return { | |
| init : function (findMe) { | |
| var i, s; | |
| s = $.d.getElementsByTagName('SCRIPT'); | |
| for (i = 0; i < s.length; i = i + 1) { | |
| if (s[i].src.match(findMe)) { | |
| $.s = $.d.createElement('DIV'); | |
| var settings = s[i].getAttribute('settings'); | |
| s[i].parentNode.insertBefore($.s, s[i]); | |
| s[i].parentNode.removeChild(s[i]); | |
| $.f.houseKeep(); | |
| break; | |
| } | |
| } | |
| }, | |
| houseKeep : function() { | |
| $.a = { | |
| "w": 320, | |
| "h": 480, | |
| "p": 2 | |
| } | |
| $.v = { | |
| "defaultSearch": "[enter search]", | |
| "days": [{ | |
| "name":"Friday", | |
| "value":"2010-03-12" | |
| },{ | |
| "name":"Saturday", | |
| "value":"2010-03-13" | |
| },{ | |
| "name":"Sunday", | |
| "value":"2010-03-14", | |
| "selected": true | |
| },{ | |
| "name":"Monday", | |
| "value":"2010-03-15" | |
| },{ | |
| "name":"Tuesday", | |
| "value":"2010-03-16" | |
| } | |
| ], | |
| "data": {} | |
| }; | |
| $.d.h = $.d.getElementsByTagName('HEAD')[0]; | |
| $.d.b = $.d.getElementsByTagName('BODY')[0]; | |
| $.f.presentation(); | |
| $.f.structure(); | |
| $.f.behavior(); | |
| }, | |
| structure : function () { | |
| $.s.id = $.k; | |
| $.s.k = $.d.createElement('DIV'); | |
| $.s.k.id = $.k + '_inner'; | |
| $.s.q = $.d.createElement('INPUT'); | |
| $.s.q.value = $.v.defaultSearch; | |
| $.s.q.onfocus = function() { | |
| if (this.value === $.v.defaultSearch) { | |
| this.value = ''; | |
| } | |
| }; | |
| $.s.q.onchange = function() { | |
| $.f.filter(); | |
| } | |
| $.s.k.appendChild($.s.q); | |
| $.s.o = $.d.createElement('SELECT'); | |
| for (var i = 0; i < $.v.days.length; i++) { | |
| var o = $.d.createElement('OPTION'); | |
| o.innerHTML = $.v.days[i].name; | |
| o.value = $.v.days[i].value; | |
| if ($.v.days[i].selected) { | |
| o.selected = true; | |
| } | |
| $.s.o.appendChild(o); | |
| } | |
| $.s.o.onchange = function() { | |
| if ($.v.data[this.value]) { | |
| $.f.render(); | |
| } else { | |
| $.f.getData(); | |
| } | |
| }; | |
| $.s.k.appendChild($.s.o); | |
| $.s.ul = $.d.createElement('UL'); | |
| $.s.k.appendChild($.s.ul); | |
| $.s.appendChild($.s.k); | |
| }, | |
| presentation : function () { | |
| var inner, outer, styles, rules, css; | |
| outer = '#' + $.k; | |
| // atri: the open area at the heart of the house | |
| inner = outer + ' #' + $.k + '_inner'; | |
| // high level of CSS specificity should protect most interior content from outside styles | |
| styles = [ | |
| outer + ' { background:#000; border:1px solid #000; -moz-border-radius:3px; -webkit-border-radius:3px; margin:0; outline:0; position:absolute; width:' + $.a.w + 'px;}', | |
| inner + ' * { border:0; color:inherit; font:normal normal normal 12px/16px arial; list-style:none; margin:0; outline:0; padding:0; text-align:inherit; text-indent:0; zoom:1; }', | |
| inner + ' { background:#fff;color:#000;margin:' + $.a.p + 'px;overflow:none;text-align:left;}', | |
| inner + ' input { width:180px; color:#fff; background:#a00 url(http://sxsw.com/favicon.ico) no-repeat scroll 2px 50%; padding:3px 3px 3px 20px; margin:3px;}', | |
| inner + ' input.loading { background-image:url(http://l.yimg.com/us.yimg.com/i/us/my/mw/anim_loading_sm.gif);}', | |
| inner + ' select { width:100px; float:right;margin:3px;background:orange; padding:2px;}', | |
| inner + ' ul { height:' + $.a.h + 'px; overflow: auto; list-style:none; }', | |
| inner + ' li { margin-top:3px;padding:3px 6px; border-top:1px dashed #aaa;}', | |
| inner + ' li.footer { text-align:right;}', | |
| inner + ' li cite { font-weight:bold; }', | |
| inner + ' li a { color:#f00; text-decoration:none; cursor:pointer;}', | |
| inner + ' li img { height:48px; width:48px; float:left; margin:3px 6px 5px 0; }', | |
| inner + ' li date { display:block; color:#a00; font-weight:bold;}', | |
| inner + ' li:after { content:"."; display:block; height:0; clear:both; visibility:hidden; }', | |
| inner + ' .hide { display:none!important; }' | |
| ]; | |
| rules = styles.join("\n"); | |
| css = $.d.createElement('STYLE'); | |
| css.type = 'text/css'; | |
| if (css.styleSheet) { | |
| css.styleSheet.cssText = rules; | |
| } else { | |
| css.appendChild($.d.createTextNode(rules)); | |
| } | |
| $.d.h.appendChild(css); | |
| }, | |
| behavior : function () { | |
| $.f.getData(); | |
| }, | |
| filter : function() { | |
| var i, n; | |
| var li = $.s.ul.getElementsByTagName('LI'); | |
| var v = $.s.q.value.toLowerCase(); | |
| for (var i = 0; i < li.length; i++) { | |
| var t = $.v.title[i].toLowerCase(); | |
| var d = ''; | |
| var k = ''; | |
| if ($.v.description[i]) { | |
| d = $.v.description[i].toLowerCase(); | |
| } | |
| if ($.v.time[i]) { | |
| k = $.v.time[i].toLowerCase(); | |
| } | |
| if (t.indexOf(v) === -1 && d.indexOf(v) === -1 && k.indexOf(v) === -1) { | |
| li[i].className = 'hide'; | |
| } else { | |
| li[i].className = ''; | |
| } | |
| } | |
| }, | |
| getData : function() { | |
| $.s.q.className = 'loading'; | |
| var id, url, s; | |
| var id = $.k + '.f.ping'; | |
| var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fmy.sxsw.com%2Fevents%3Fevent%5Btrack%5D%3DAll%2520Events%26event%5Bcategory%5D%3D%26event%5Bsub_category%5D%3D%26event%5Bconference_day%5D%3D" + $.s.o.value + "%22%20AND%20xpath%3D'%2F%2Fdiv%5B%40class%3D%22events%22%5D%2Fdiv%2F%2Fp'%3B&format=json&callback=" + id; | |
| var s = $.d.createElement('SCRIPT'); | |
| s.type = 'text/javascript'; | |
| s.charset = 'utf-8'; | |
| s.src = url; | |
| $.d.b.appendChild(s); | |
| }, | |
| ping : function (z) { | |
| $.s.q.className = ''; | |
| var i, li, n, r; | |
| if (z && z.query && z.query.results && z.query.results.p && z.query.results.p.length) { | |
| $.v.data[$.s.o.value] = z.query.results.p; | |
| $.f.render(); | |
| } | |
| }, | |
| render : function() { | |
| var n, r; | |
| n = 0; | |
| r = $.v.data[$.s.o.value]; | |
| $.s.ul.innerHTML = ''; | |
| $.v.title = []; | |
| $.v.description = []; | |
| $.v.time = []; | |
| for (i = 0; i < r.length; i = i + 1) { | |
| if (typeof r[i] === 'object') { | |
| var li = $.d.createElement('LI'); | |
| var date = $.d.createElement('DATE'); | |
| date.innerHTML = $.v.time[n] = r[i].content + r[i].span.content + ' - ' + r[i+2]; | |
| li.appendChild(date); | |
| var cite = $.d.createElement('CITE'); | |
| cite.innerHTML = $.v.title[n] = r[i + 1]; | |
| li.appendChild(cite); | |
| var p = $.d.createElement('P'); | |
| if (typeof r[i + 3] === 'string') { | |
| p.innerHTML = $.v.description[n] = r[i + 3]; | |
| } | |
| li.appendChild(p); | |
| $.s.ul.appendChild(li); | |
| n++; | |
| } | |
| } | |
| if ($.s.q.value !== $.v.defaultSearch) { | |
| $.f.filter(); | |
| } | |
| } | |
| }; | |
| }()); | |
| $.f.init(/sxsw\.js$/); | |
| }(document, window)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment