/* * Active Cast * Copyright(c) 2006, Adam Ayres. */ if(typeof LITHIUM=="undefined"){var LITHIUM={};};LITHIUM.extend=function(subc,superc,overrides){var F=function(){};F.prototype=superc.prototype;subc.prototype=new F();subc.prototype.constructor=subc;subc.superclass=superc.prototype;if(superc.prototype.constructor==Object.prototype.constructor){superc.prototype.constructor=superc;} if(overrides){for(var i in overrides){subc.prototype[i]=overrides[i];}}};LITHIUM.augment=function(r,s){var rp=r.prototype,sp=s.prototype,a=arguments,i,p;if(a[2]){for(i=2;i0){string=string.toString();splits=string.split(" ",numberOfWords);truncatedString=splits.join(" ");} return truncatedString;},getElm:function(aID){return(document.getElementById)?document.getElementById(aID):(document.all)?document.all[aID]:(document.layers)?document.layers[aId]:null;},toCharEnt:function(string){var mtoc=/<([^<>]*)>/g;return string.replace(mtoc,"<$1>");},toMarkup:function(string){var ctom=/<([^&]*)>/g;return string.replace(ctom,"<$1>");},stripMarkup:function(string){var newLineToWhiteSpaceRegExp=/<([^<\b\r>]*)>/g;var newLineToWhiteSpace=string.replace(newLineToWhiteSpaceRegExp," ");var mtoc=/<([^<>]*)>/g;return newLineToWhiteSpace.replace(mtoc,"");},stripCharEnt:function(string){var ctom=/<([^&]*)>/g;return string.replace(ctom,"<$1>");},getURLParam:function(strParamName){var regexS="[\\?&]"+strParamName+"=([^&#]*)";var regex=new RegExp(regexS);var tmpURL=window.location.href;var results=regex.exec(tmpURL);if(results==null){return"";} else{return results[1];}},createCookie:function(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString();} else{var expires="";} document.cookie=name+"="+value+expires+"; path=/";},readCookie:function(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i');}catch(e){} if(!element||element.nodeName!=type.toUpperCase()){element=document.createElement(type);element.name=name;} return element;},getElementsByClassName:function(oElm,strTagName,strClassName){var arrElements=(strTagName=="*"&&oElm.all)?oElm.all:oElm.getElementsByTagName(strTagName);var arrReturnElements=new Array();strClassName=strClassName.replace(/\-/g,"\\-");var oRegExp=new RegExp("(^|\\s)"+strClassName+"(\\s|$)");var oElement;for(var i=0;i0){messageReplyLimitParam="&"+this.restPageSizeParam+parseInt(this.maxNumberOfMessages);} var lookupThreadByParam=this.restBoardId;if(this.lookupThreadBy!=""){if(this.lookupThreadBy==LITHIUM.ActiveCast.BOARD){lookupThreadByParam=this.restBoardId;} else if(this.lookupThreadBy==LITHIUM.ActiveCast.CATEGORY){lookupThreadByParam=this.restCategoryId;}} this.restThreadNodeUri=this.communityUrl+this.restApiVer+lookupThreadByParam+this.nodeId +"?"+this.restXsltParam+this.restJsonXslValue;this.restThreadsUri=this.communityUrl+this.restApiVer+lookupThreadByParam+this.nodeId+ this.feature+"?"+this.restXsltParam+this.restJsonXslValue+"&"+this.restFormatDetailParam+ this.restFullListElementValue+messageReplyLimitParam+"&"+this.restMessageViewerParam+ this.restTopicSortOrder+this.restTopicStartDate+"&"+this.restResponseStyle+this.restResponseStyleView;},render:function(){this.messagesContainerElement=this.createMessagesContainer();this.createThreadsScript(this.restThreadsUri);this.parentElement.appendChild(this.messagesContainerElement);},createMessagesContainer:function(){var div_ac_messages=document.createElement('div');div_ac_messages.setAttribute('id',this.messagesElementId);if(this.displayNodeLabel){var h1_ac_messages=document.createElement('h1');h1_ac_messages.setAttribute('id',this.messagesHeaderElementId);div_ac_messages.appendChild(h1_ac_messages);} return div_ac_messages;},createThreadsScript:function(request){var requestUri=request+"&"+this.jsonCallbackParam+this.objName+".createThreads";ThreadsScript=new JSONscriptRequest(requestUri);ThreadsScript.buildScriptTag();ThreadsScript.addScriptTag();},createThreads:function(data){this.messagesContainerElement=this.util.getChildElementByID(this.parentElement,this.messagesElementId);if(data.response.status=="success"){if(this.displayNodeLabel){var h1_ac_messages=this.util.getChildElementByID(this.parentElement,this.messagesHeaderElementId);h1_ac_messages.appendChild(document.createTextNode(this.title));if(this.displayNodeTitle){this.createThreadNodeTitleScript(this.restThreadNodeUri);}} if(this.util.isArray(data.response.threads.thread)){for(var i=0,thread;(thread=data.response.threads.thread[i]);i++){this.messagesContainerElement.appendChild(LITHIUM.ActiveCast.Message.createMessage(this,thread.messages.topic,i));}} else if(data.response.threads.thread){this.messagesContainerElement.appendChild(LITHIUM.ActiveCast.Message.createMessage(this,data.response.threads.thread.messages.topic,i));}}},createThreadNodeTitleScript:function(request){var requestUri=request+"&"+this.jsonCallbackParam+this.objName+".setThreadTitle";var ThreadTitleScript=new JSONscriptRequest(requestUri);ThreadTitleScript.buildScriptTag();ThreadTitleScript.addScriptTag();},setThreadTitle:function(data){this.messagesContainerElement=this.util.getChildElementByID(this.parentElement,this.messagesHeaderElementId);if(data.response.status=="success"){var span_node_title=document.createElement("span");span_node_title.setAttribute('id',this.messagesNodeTitleElementId);if(data.response.board&&data.response.board.title){span_node_title.appendChild(document.createTextNode(": "+data.response.board.title.$));this.messagesContainerElement.appendChild(span_node_title);} else if(data.response.category&&data.response.category.title){span_node_title.appendChild(document.createTextNode(": "+data.response.category.title.$));this.messagesContainerElement.appendChild(span_node_title);}}}}; LITHIUM.ActiveCast.Message={createMessage:function(params,message,numberOffset){this.numberOfReplies=!isNaN(params.numberOfReplies)?params.numberOfReplies:10;this.numSubjectWords=!isNaN(params.numSubjectWords)?params.numSubjectWords:15;this.numBodyWords=!isNaN(params.numBodyWords)?params.numBodyWords:15;this.authorTitle=params.authorTitle||"";this.postedTitle=params.postedTitle||"";this.hrefTarget=params.hrefTarget||"";var threadNumbering="";var msgUrl="#";if(message.view_href){msgUrl=message.view_href;} var div_ac_thread=document.createElement('div');div_ac_thread.setAttribute('class','ac_thread'+((numberOffset+this.numberOfReplies)%2));div_ac_thread.setAttribute('className','ac_thread'+((numberOffset+this.numberOfReplies)%2));if(this.numSubjectWords!=0){if(message.subject){var h2_ac_subject=this.createMessageSubject(message.subject.$,this.numSubjectWords,msgUrl) div_ac_thread.appendChild(h2_ac_subject);}} if(this.numBodyWords!=0){if(message.body){var p_ac_body=this.createMessageBody(message.body.$,this.numBodyWords,msgUrl) div_ac_thread.appendChild(p_ac_body);}} var ul_ac_msginfo=this.createMessageInfo(message);div_ac_thread.appendChild(ul_ac_msginfo);return div_ac_thread;},createMessageBody:function(string,numberOfWords,msgUrl){if(typeof string=='undefined'){string="";} var util=new LITHIUM.ActiveCast.Util();var bodyText="";if(numberOfWords==-1){bodyText=string;} else{bodyText=util.trunCateStringbyWords(string,numberOfWords);} bodyText=util.stripMarkup(bodyText.toString());var p_ac_body=document.createElement('p');p_ac_body.setAttribute('class','ac_body');p_ac_body.setAttribute('className','ac_body');p_ac_body.appendChild(document.createTextNode(bodyText));if(typeof string!='undefined'&&string!=null&&string.length>0) {if(numberOfWords url.indexOf(":")) { url = url.substring(0, url.lastIndexOf(":")); } obj.communityUrl = url; return url; } LITHIUM.ActiveCast.getCommunityUrl = function() { return this.setCommunityUrl(this); } LITHIUM.ActiveCast.getCommunityId = function() { return "lithium"; } LITHIUM.ActiveCast.xipNotAllowedError = ("Permission denied to use this feature from this domain. Please contact your administrator to have this domain added."); /** * Method used by the Dojo iFrame Proxy to check if the request is allowed. */ function isAllowedRequest(request) { var urlBase = getUrlBase(xipClientUrl); var allowedXipClientUrls = new Array('www.lithium.com','lithium.com'); allowedXipClientUrls.push(getUrlBase("http://talk.lithium.com")); for(var i = 0, url; url=allowedXipClientUrls[i]; i++ ) { if (urlBase == url) { return true } } return false; function getUrlBase(strHref) { if ( strHref.indexOf("http://") == 0 || strHref.indexOf("https://")){ var strPrefix = strHref.substring(0, strHref.indexOf("//")+ 2); var strRemainder = strHref.substring(strHref.indexOf("//")+ 2, strHref.length); var strTerminator; if (strRemainder.indexOf("/") > 0) { strTerminator = strRemainder.indexOf("/") } else { strTerminator = strRemainder.length } var strPostfix = strRemainder.substring(0, strTerminator); strReturn = strPostfix; } return strReturn; } }