From: ScottDowne Date: Thu, 14 Oct 2010 16:14:44 +0000 (-0400) Subject: tic #105 twitter and jquery scripts loaded internally X-Git-Tag: v0.1~19 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=bad5e7c78042e825a4b0512d616f12b23dc46bef;p=popcorn-js.git tic #105 twitter and jquery scripts loaded internally --- diff --git a/demos/universalSubtitles/index.html b/demos/universalSubtitles/index.html index e7eeab1..4add41f 100644 --- a/demos/universalSubtitles/index.html +++ b/demos/universalSubtitles/index.html @@ -1,9 +1,9 @@ html5 video demo - + - + diff --git a/popcorn.js b/popcorn.js index 04726d4..04f82ca 100644 --- a/popcorn.js +++ b/popcorn.js @@ -694,62 +694,65 @@ Popcorn.TwitterCommand = function(name, params, text, videoManager) { Popcorn.VideoCommand.call(this, name, params, text, videoManager); - // All data from Universal Subtitles comes from the text attribute - // so the data from that needs to enter the appropriate fields - if (typeof text === "string" && text !== "") { - this.params.source = text; - // Universal Subtitles has no target attribute, so we create a default - this.params.target = "twitterdiv"; - } + var that = this; + getScript("http://widgets.twimg.com/j/2/widget.js", typeof TWTR, function() { + // All data from Universal Subtitles comes from the text attribute + // so the data from that needs to enter the appropriate fields + if (typeof text === "string" && text !== "") { + that.params.source = text; + // Universal Subtitles has no target attribute, so we create a default + that.params.target = "twitterdiv"; + } - // Setup a default, hidden div to hold the feed - this.target = document.createElement('div'); - this.target.setAttribute('id', this.id); - document.getElementById(this.params.target).appendChild(this.target); - - // Div is hidden by default - this.target.setAttribute('style', 'display:none'); - var widget = new TWTR.Widget({ - creator: true, - version: 2, - type: 'search', - id: this.target.getAttribute('id'), - search: this.params.source, - title: this.params.title || null, - subject: this.params.subject || null, - rpp: 30, - width: this.params.width || 250, - height: this.params.height || 200, - interval: 6000, - theme: { - shell: { - background: '#ffffff', - color: '#000000' + // Setup a default, hidden div to hold the feed + that.target = document.createElement('div'); + that.target.setAttribute('id', that.id); + document.getElementById(that.params.target).appendChild(that.target); + + // Div is hidden by default + that.target.setAttribute('style', 'display:none'); + var widget = new TWTR.Widget({ + creator: true, + version: 2, + type: 'search', + id: that.target.getAttribute('id'), + search: that.params.source, + title: that.params.title || null, + subject: that.params.subject || null, + rpp: 30, + width: that.params.width || 250, + height: that.params.height || 200, + interval: 6000, + theme: { + shell: { + background: '#ffffff', + color: '#000000' + }, + tweets: { + background: '#ffffff', + color: '#444444', + links: '#1985b5' + } }, - tweets: { - background: '#ffffff', - color: '#444444', - links: '#1985b5' + features: { + loop: true, + timestamp: true, + avatars: true, + hashtags: true, + toptweets: true, + live: true, + scrollbar: false, + behavior: 'default' } - }, - features: { - loop: true, - timestamp: true, - avatars: true, - hashtags: true, - toptweets: true, - live: true, - scrollbar: false, - behavior: 'default' - } - }).render().start(); - this.onIn = function() { - this.target.setAttribute('style', 'display:inline'); - }; - this.onOut = function() { - this.target.setAttribute('style', 'display:none'); - }; - this.preload = function() {}; // Probably going to need to preload this. + }).render().start(); + that.onIn = function() { + that.target.setAttribute('style', 'display:inline'); + }; + that.onOut = function() { + that.target.setAttribute('style', 'display:none'); + }; + that.preload = function() {}; // Probably going to need to preload this. + }); }; //////////////////////////////////////////////////////////////////////////// @@ -1136,36 +1139,57 @@ } }; + function getScript(url, test, success) { + if (test === 'undefined') { + var script = document.createElement('script'); + script.src = url; + var head = document.getElementsByTagName('head')[0], + done = false; + script.onload = script.onreadystatechange = function () { + if (!done && (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete')) { + done = true; + success(); + } + }; + head.appendChild(script); + } else { + alert(test); + success(); + } + } + // Automatic Initialization Method var init = function() { - var video = document.getElementsByTagName('video'); - for (var i = 0, l = video.length; i < l; i++) { - var ind = i; - var videoSources = video[ind].getAttribute('data-timeline-sources'); - if (videoSources) { - var filename = videoSources, - dataXML = "", - dataJSON = ""; - var ext = (filename.toLowerCase()).match(/\.xml$/); - var manager = new Popcorn.VideoManager(video[ind]); - if (ext !== null) { - convertData(video[ind], manager, getTimelineData(filename).responseXML, convertXML); - } else { - $.getJSON("http://dev.universalsubtitles.org/api/subtitles/?video_url=" + filename + "&callback=?", function(data) { - convertData(video[ind], manager, data, convertJSON, "subtitle"); - $.getJSON("http://dev.universalsubtitles.org/api/subtitles/?video_url=" + filename + "&language=meta-geo&callback=?", function(data) { - convertData(video[ind], manager, data, convertJSON, "location"); - $.getJSON("http://dev.universalsubtitles.org/api/subtitles/?video_url=" + filename + "&language=meta-tw&callback=?", function(data) { - convertData(video[ind], manager, data, convertJSON, "twitter"); - $.getJSON("http://dev.universalsubtitles.org/api/subtitles/?video_url=" + filename + "&language=meta-wiki&callback=?", function(data) { - convertData(video[ind], manager, data, convertJSON, "wiki"); + getScript('http://code.jquery.com/jquery.js', typeof jQuery, function() { + var video = document.getElementsByTagName('video'); + for (var i = 0, l = video.length; i < l; i++) { + var ind = i; + var videoSources = video[ind].getAttribute('data-timeline-sources'); + if (videoSources) { + var filename = videoSources, + dataXML = "", + dataJSON = ""; + var ext = (filename.toLowerCase()).match(/\.xml$/); + var manager = new Popcorn.VideoManager(video[ind]); + if (ext !== null) { + convertData(video[ind], manager, getTimelineData(filename).responseXML, convertXML); + } else { + $.getJSON("http://dev.universalsubtitles.org/api/subtitles/?video_url=" + filename + "&callback=?", function(data) { + convertData(video[ind], manager, data, convertJSON, "subtitle"); + $.getJSON("http://dev.universalsubtitles.org/api/subtitles/?video_url=" + filename + "&language=meta-geo&callback=?", function(data) { + convertData(video[ind], manager, data, convertJSON, "location"); + $.getJSON("http://dev.universalsubtitles.org/api/subtitles/?video_url=" + filename + "&language=meta-tw&callback=?", function(data) { + convertData(video[ind], manager, data, convertJSON, "twitter"); + $.getJSON("http://dev.universalsubtitles.org/api/subtitles/?video_url=" + filename + "&language=meta-wiki&callback=?", function(data) { + convertData(video[ind], manager, data, convertJSON, "wiki"); + }); }); }); - }); - }); + }); + } } } - } + }); }; document.addEventListener('DOMContentLoaded', init, false);