jsoneditor4code
Version:
JSON Editor for UML Diagrams developed with Javascript Code Templates based on JSON Editor of Jeremy Dorn
1 lines • 3.75 kB
JavaScript
function LinkParam(){this.size=0,this.aVars={},this.aLink=""}LinkParam.prototype.init=function(pDoc){this.aDoc=pDoc,this.aLink=pDoc.location,this.aVars=this.parseURL(pDoc.location.search)},LinkParam.prototype.parseURL=function(pLink){var vTokens,vLink=pLink||"",vParams={},vRE=/[?&]?([^=]+)=([^&]*)/g;if(""!=vLink)for(vLink=vLink.split("+").join(" ");vTokens=vRE.exec(vLink);)vParams[this.decodeParam(vTokens[1])]=this.decodeParam(vTokens[2]),this.calcSize();else console.log("parseURL(pLink) - pLink contains no parameters");return vParams},LinkParam.prototype.getURL=function(pVarHash){var vParam="";return vParam=pVarHash?this.getParam4URL(pVarHash):this.getParam4URL(),this.getLink4URL()+vParam},LinkParam.prototype.setValue=function(pVar,pValue){this.aVars.hasOwnProperty(pVar)?console.log("Value of link parameter '"+pVar+"' changed"):(this.calcSize(),console.log("New link parameter '"+pVar+"' created")),this.aVars[pVar]=pValue},LinkParam.prototype.getValue=function(pVar){var vRet="";return this.aVars.hasOwnProperty(pVar)?vRet=this.aVars[pVar]:console.log("ERROR: variable '"+pVar+"' does not exist in LinkParam"),vRet},LinkParam.prototype.deleteValue=function(pVar){var vRet=!1;return this.aVars.hasOwnProperty(pVar)&&(delete this.aVars[pVar],vRet=!0,this.calcSize()),vRet},LinkParam.prototype.getLink4URL=function(){return this.aLink},LinkParam.prototype.getParam4URL=function(){var vHash=this.aVars||{},vOut="",vSep="?";for(var iID in vHash)vHash.hasOwnProperty(iID)&&(vOut+=vSep+this.encodeParam(iID)+"="+this.encodeParam(vHash[iID]),vSep="&");return vOut},LinkParam.prototype.decodeParam=function(pParam){return pParam=pParam.replace(/\+/g," "),pParam=decodeURIComponent(pParam)},LinkParam.prototype.encodeParam=function(pParam){var vParam=encodeURIComponent(pParam);return vParam=vParam.replace(/'/g,"%27").replace(/"/g,"%22")},LinkParam.prototype.getTableHTML=function(){var vOut="",vHash=this.aVars;vOut+="<table border=1>",vOut+="<tr><td><b>Variable</b></td><td>Value</td></tr>";for(var iID in vHash)vHash.hasOwnProperty(iID)&&(vOut+="<tr>",vOut+="<td>",vOut+="<b>"+iID+"</b>",vOut+="</td>",vOut+="<td>",vOut+=this.encodeHTML(vHash[iID],!0),vOut+="</td>",vOut+="</tr>");return vOut+="</table>"},LinkParam.prototype.getEditTableHTML=function(pPrefixID){var vOut=(pPredixID,""),vHash=this.aVars;vOut+="<table border=1>";var vRows=1,vContent="";for(var iID in vHash)vHash.hasOwnProperty(iID)&&(vContent=this.encodeHTML(vHash[iID],!1),vRows=vHash[iID].split("\n").length,vRows>10&&(vRows=10),vOut+="<tr>",vOut+="<td>",vOut+="<b>"+iID+"</b>",vOut+="</td>",vOut+="<td>",vOut+="<textarea id='"+vPrefix+iID+"'' cols='90' rows='"+vRows+"''>",vOut+=vContent,vOut+="</textarea>",vOut+="</td>",vOut+="</tr>");return vOut+="</table>"},LinkParam.prototype.calcSize=function(){var vRet=0;if(this.aVars){var vHash=this.aVars;for(var key in vHash)vRet++}else console.log("ERROR: variable '"+pVar+"' does not exist in LinkParam");return vRet},LinkParam.prototype.encodeHTML=function(pValue,pWrapCode){var vValue=pValue||"";return""!=vValue&&(vValue=vValue.replace(/</g,"<"),vValue=vValue.replace(/>/g,">"),vValue=vValue.replace(/&/g,"&")),pWrapCode&&!0===pWrapCode&&(vValue="<pre><code>"+vValue+"</code></pre>"),vValue},LinkParam.prototype.exists=function(pVar){var vRet=!1;return pVar&&(vRet=this.aVars.hasOwnProperty(pVar)),vRet},LinkParam.prototype.param2DOM=function(pLinkID,pDOMID,pOutType){var vOutType=pOutType||"html";if(this.exists(pLinkID)){var vDOMID=pDOMID||pLinkID,vOutDOM=document.getElementById(vDOMID);vOutDOM?"html"==vOutType?vOutDOM.innerHTML=this.getValue(pLinkID):vOutDOM.value=this.getValue(pLinkID):console.log("DOM node ["+vDOMID+"] does not exist!")}else console.log("pLinkID does not exist in param2DOM-call")};