--- a/example_slidy/scripts/w3c_talks.js Tue Sep 03 18:33:05 2013 +0900
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,169 +0,0 @@
-(function() {
- 'use strict';
-
- // Polyfill for sessionStorage taken from https://gist.github.com/tagawa/2880273/
- window.sessionStorage = window.sessionStorage || {
- length: 0,
- setItem: function(key, value) {
- document.cookie = key + '=' + value + '; path=/';
- this.length++;
- },
- getItem: function(key) {
- var keyEQ = key + '=';
- var ca = document.cookie.split(';');
- for (var i = 0, len = ca.length; i < len; i++) {
- var c = ca[i];
- while (c.charAt(0) === ' ') c = c.substring(1, c.length);
- if (c.indexOf(keyEQ) === 0) return c.substring(keyEQ.length, c.length);
- }
- return null;
- },
- removeItem: function(key) {
- this.setItem(key, '', -1);
- this.length--;
- },
- clear: function() {
- // Caution: will clear all persistent cookies as well
- var ca = document.cookie.split(';');
- for (var i = 0, len = ca.length; i < len; i++) {
- var c = ca[i];
- while (c.charAt(0) === ' ') c = c.substring(1, c.length);
- var key = c.substring(0, c.indexOf('='));
- this.removeItem(key);
- }
- this.length = 0;
- },
- key: function(n) {
- var ca = document.cookie.split(';');
- if (n >= ca.length || isNaN(parseFloat(n)) || !isFinite(n)) return null;
- var c = ca[n];
- while (c.charAt(0) === ' ') c = c.substring(1, c.length);
- return c.substring(0, c.indexOf('='));
- }
- };
-
- // Add start box to top-right of page
- function makeUI() {
- // Create CSS for start box
- var style = document.createElement('style');
- style.innerHTML = '#w3c_talks {background:rgba(0, 0, 0, 0.7); border-radius:0 0 0 1em; color:#fff; display:inline-block; opacity:1; padding:0.5em 1em 1em; position:absolute; right:0; text-align:center; top:0; z-index:1000;} #w3c_talks.hidden {opacity:0; -webkit-transition:3s; -moz-transition:3s; -ms-transition:3s; -o-transition:3s; transition:3s;} #w3c_talks_start {font-weight:bold; padding:0.5em 1em;} #w3c_talks_start:hover, #w3c_talks_start:focus {color:blue; cursor:pointer;}';
- document.getElementsByTagName('head')[0].appendChild(style);
-
- // Create and append start box
- var ui = document.createElement('ui');
- ui.innerHTML = '<div id="w3c_talks"> <p>W3C talks</p> <button id="w3c_talks_start">Start</button> </div>';
- document.body.appendChild(ui);
-
- // Add functionality to start button
- var start = document.getElementById('w3c_talks_start');
- start.onclick = function(event) {
- window.sessionStorage['accesskey'] = 'asdf1234';
- start.innerHTML = 'Ready';
- start.disabled = true;
- event = event || window.event;
- var target = event.target || event.srcElement;
- target.parentElement.className = 'hidden';
- };
- }
-
- // Global variables for tweet posting
- var url = 'http://www.vodstock.com/w3c_talks/w3c_talks.php';
- var hashtag = getMetaTag('hashtag');
- var author = getMetaTag('author');
- var title = document.title;
- window.sessionStorage['accesskey'] = '';
-
- function getMetaTag(name) {
- var tag = document.querySelector('[name=' + name + ']');
-
- try {
- return tag.content;
- } catch(e) {
- console.log('Unable to get ' + name + ' meta tag');
- return '';
- }
- }
-
- // Use XHR to send data to specified URL
- function doPost(url, data) {
- var httpRequest;
-
- if (window.XMLHttpRequest) { // Modern browsers
- httpRequest = new XMLHttpRequest();
- } else if (window.ActiveXObject) { // Old IE
- try {
- httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (e) {
- try {
- httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
- } catch (e) {}
- }
- }
-
- if (!httpRequest) {
- console.log('Giving up :( Cannot create an XMLHTTP instance');
- return false;
- }
- httpRequest.onreadystatechange = function() {
- if (httpRequest.readyState === 4) {
- if (httpRequest.status !== 200) {
- console.log('There was a problem with the XHR action.');
- }
- }
- };
- httpRequest.open('POST', url);
- httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- httpRequest.send(data);
- }
-
- function sendNote(slide) {
- if (window.sessionStorage['accesskey']) {
- try {
- var note = slide.getAttribute('data-note');
- if (note) {
- var data = 'note=' + encodeURIComponent(note);
- data += '&hashtag=' + encodeURIComponent(hashtag);
- data += '&author=' + encodeURIComponent(author);
- data += '&title=' + encodeURIComponent(title);
- data += '&accesskey=' + window.sessionStorage['accesskey'];
- doPost(url, data);
- }
- } catch(e) {
- console.log('Unable to send note');
- }
- }
- }
-
- makeUI();
-
- // The following is for Slidy:
- if (window.w3c_slidy) {
- // Store original "show_slide" method for later
- w3c_slidy.__show_slide = w3c_slidy.show_slide;
-
- // Hijack "show_slide" method and add action to send note
- w3c_slidy.show_slide = function(slide) {
- this.__show_slide(slide);
-
- sendNote(slide);
- };
- }
-
- // The following is for Shower:
- if (window.shower) {
- var slides = document.querySelectorAll('.slide');
-
- // Store original "go" method for later
- shower.__go = shower.go;
-
- // Hijack "go" method and add action to send note
- shower.go = function(slideNumber, callback) {
- this.__go(slideNumber, callback);
-
- if (slides.length > slideNumber) {
- sendNote(slides[slideNumber]);
- }
- };
- }
-
-})();