[Use flashembed to embed youtube player clinton@unknownlamer.org**20081210100036] hunk ./src/web-frontend.lisp 14 - (<:p :class "video-object" - (<:object - :width "425" :height "355" - (<:param :name "movie" :value (format nil "http://youtube.com/v/~A" - (video-id video))) - (<:embed :src (format nil "http://www.youtube.com/v/~A" - (video-id video)) - :type "application/x-shockwave-flash" - :width "425" :height "355")))) + (let ((id (ps:gen-js-name))) + (<:p :class "video-object" + :id id + (<:as-html "It would appear that you do not have flash.")) + ( " and remove spaces + return String(obj).replace(/\s/g, " ").replace(/\'/g, "\""); +} + + +// private functions +function typeOf(obj) { + if (obj === null || obj === undefined) { return false; } + var type = typeof obj; + return (type == 'object' && obj.push) ? 'array' : type; +} + + +// version 9 bugfix: (http://blog.deconcept.com/2006/07/28/swfobject-143-released/) +if (window.attachEvent) { + window.attachEvent("onbeforeunload", function() { + __flash_unloadHandler = function() {}; + __flash_savedUnloadHandler = function() {}; + }); +} + +function map(arr, func) { + var newArr = []; + for (var i in arr) { + if (arr.hasOwnProperty(i)) { + newArr[i] = func(arr[i]); + } + } + return newArr; +} + +function getEmbedCode(p, c) { + var html = ''; + + var e = extend({}, p); + e.id = e.width = e.height = e.src = null; + + for (var k in e) { + if (e[k] !== null) { + html += '\n\t'; + } + } + + if (c) { + html += '\n\t'; + } + + if (embeddable) { + html += getEmbedCode(p, c); + } + + html += ""; + + return html; +} + +function getFullHTML(p, c) { + return getObjectCode(p, c, true); +} + +function getHTML(p, c) { + var isNav = navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length; + return (isNav) ? getEmbedCode(p, c) : getObjectCode(p, c); +} + +//}}} + + +window.flashembed = function(root, userParams, flashvars) { + + +//{{{ construction + + // setup params + var params = { + + // very common params + src: '#', + width: '100%', + height: '100%', + + // flashembed specific options + version:null, + onFail:null, + expressInstall:null, + debug: false, + + // flashembed defaults + // bgcolor: 'transparent', + allowfullscreen: true, + allowscriptaccess: 'always', + quality: 'high', + type: 'application/x-shockwave-flash', + pluginspage: 'http://www.adobe.com/go/getflashplayer' + }; + + + if (typeof userParams == 'string') { + userParams = {src: userParams}; + } + + extend(params, userParams); + + var version = flashembed.getVersion(); + var required = params.version; + var express = params.expressInstall; + var debug = params.debug; + + + if (typeof root == 'string') { + var el = document.getElementById(root); + if (el) { + root = el; + } else { + domReady(function() { + flashembed(root, userParams, flashvars); + }); + return; + } + } + + if (!root) { return; } + + + // is supported + if (!required || flashembed.isSupported(required)) { + params.onFail = params.version = params.expressInstall = params.debug = null; + + // root.innerHTML may cause broplems: http://domscripting.com/blog/display/99 + // thanks to: Ryan Rud + // var tmp = document.createElement("extradiv"); + // tmp.innerHTML = getHTML(); + // root.appendChild(tmp); + + root.innerHTML = getHTML(params, flashvars); + + // return our API + return root.firstChild; + + // custom fail event + } else if (params.onFail) { + var ret = params.onFail.call(params, flashembed.getVersion(), flashvars); + if (ret === true) { root.innerHTML = ret; } + + + // express install + } else if (required && express && flashembed.isSupported([6,65])) { + + extend(params, {src: express}); + + flashvars = { + MMredirectURL: location.href, + MMplayerType: 'PlugIn', + MMdoctitle: document.title + }; + + root.innerHTML = getHTML(params, flashvars); + + // not supported + } else { + + // minor bug fixed here 08.04.2008 (thanks JRodman) + + if (root.innerHTML.replace(/\s/g, '') !== '') { + // custom content was supplied + + } else { + root.innerHTML = + "

Flash version " + required + " or greater is required

" + + "

" + + (version[0] > 0 ? "Your version is " + version : "You have no flash plugin installed") + + "

" + + "

Download latest version from here

"; + } + } + + return root; + +//}}} + + +}; + + +//{{{ static methods + +extend(window.flashembed, { + + // returns arr[major, fix] + getVersion: function() { + + var version = [0, 0]; + + if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") { + var _d = navigator.plugins["Shockwave Flash"].description; + if (typeof _d != "undefined") { + _d = _d.replace(/^.*\s+(\S+\s+\S+$)/, "$1"); + var _m = parseInt(_d.replace(/^(.*)\..*$/, "$1"), 10); + var _r = /r/.test(_d) ? parseInt(_d.replace(/^.*r(.*)$/, "$1"), 10) : 0; + version = [_m, _r]; + } + + } else if (window.ActiveXObject) { + + try { // avoid fp 6 crashes + var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"); + + } catch(e) { + try { + _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"); + version = [6, 0]; + _a.AllowScriptAccess = "always"; // throws if fp < 6.47 + + } catch(ee) { + if (version[0] == 6) { return; } + } + try { + _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); + } catch(eee) { + + } + + } + + if (typeof _a == "object") { + _d = _a.GetVariable("$version"); // bugs in fp 6.21 / 6.23 + if (typeof _d != "undefined") { + _d = _d.replace(/^\S+\s+(.*)$/, "$1").split(","); + version = [parseInt(_d[0], 10), parseInt(_d[2], 10)]; + } + } + } + + return version; + }, + + isSupported: function(version) { + var now = flashembed.getVersion(); + var ret = (now[0] > version[0]) || (now[0] == version[0] && now[1] >= version[1]); + return ret; + }, + + domReady: domReady, + + // returns a String representation from JSON object + asString: asString, + + getHTML: getHTML, + + getFullHTML: getFullHTML + +}); + +//}}} + + +// setup jquery support +if (jQ) { + + jQuery.prototype.flashembed = function(params, flashvars) { + return this.each(function() { + flashembed(this, params, flashvars); + }); + }; + +} + +})();