...

View Full Version : CMS needs code on one line; help please...



Fugazi1978
09-25-2012, 06:46 PM
The village website I maintain uses a content management system that only allows script if it fits on one line; can anyone make this work on one line:



<script type="text/javascript">
<!--
var BrowserDetect = {
init: function () {
this.browser = this.searchString(this.dataBrowser) || "An unknown

browser";
this.version = this.searchVersion(navigator.userAgent)
|| this.searchVersion(navigator.appVersion)
|| "an unknown version";
this.OS = this.searchString(this.dataOS) || "an unknown OS";
},
searchString: function (data) {
for (var i=0;i<data.length;i++) {
var dataString = data[i].string;
var dataProp = data[i].prop;
this.versionSearchString = data[i].versionSearch ||

data[i].identity;
if (dataString) {
if (dataString.indexOf(data[i].subString) != -1)
return data[i].identity;
}
else if (dataProp)
return data[i].identity;
}
},
searchVersion: function (dataString) {
var index = dataString.indexOf(this.versionSearchString);
if (index == -1) return;
return

parseFloat(dataString.substring(index+this.versionSearchString.length+1));
},
dataBrowser: [
{
string: navigator.userAgent,
subString: "Chrome",
identity: "Chrome"
},
{ string: navigator.userAgent,
subString: "OmniWeb",
versionSearch: "OmniWeb/",
identity: "OmniWeb"
},
{
string: navigator.vendor,
subString: "Apple",
identity: "Safari",
versionSearch: "Version"
},
{
prop: window.opera,
identity: "Opera",
versionSearch: "Version"
},
{
string: navigator.vendor,
subString: "iCab",
identity: "iCab"
},
{
string: navigator.vendor,
subString: "KDE",
identity: "Konqueror"
},
{
string: navigator.userAgent,
subString: "Firefox",
identity: "Firefox"
},
{
string: navigator.vendor,
subString: "Camino",
identity: "Camino"
},
{ // for newer Netscapes (6+)
string: navigator.userAgent,
subString: "Netscape",
identity: "Netscape"
},
{
string: navigator.userAgent,
subString: "MSIE",
identity: "Explorer",
versionSearch: "MSIE"
},
{
string: navigator.userAgent,
subString: "Gecko",
identity: "Mozilla",
versionSearch: "rv"
},
{ // for older Netscapes (4-)
string: navigator.userAgent,
subString: "Mozilla",
identity: "Netscape",
versionSearch: "Mozilla"
}
],
dataOS : [
{
string: navigator.platform,
subString: "Win",
identity: "Windows"
},
{
string: navigator.platform,
subString: "Mac",
identity: "Mac"
},
{
string: navigator.userAgent,
subString: "iPhone",
identity: "iPhone/iPod"
},
{
string: navigator.platform,
subString: "Linux",
identity: "Linux"
}
]

};
BrowserDetect.init();

// -->
</script>
<script type="text/javascript">
<!--
if(BrowserDetect.browser === "Chrome") {document.write('<p class="accent">You\'re using

' + BrowserDetect.browser + ' ' + BrowserDetect.version + ' on ' + BrowserDetect.OS + ',

a great browser.</p>');}
else if(BrowserDetect.browser === "Firefox") {document.write('<p class="accent">You\'re

using ' + BrowserDetect.browser + ' ' + BrowserDetect.version + ' on ' +

BrowserDetect.OS + ', not bad.</p>');}
else if(BrowserDetect.browser === "Explorer") {document.write('<p class="accent">You\'re

using Internet Explorer\; we recommend you <A

HREF="https://www.google.com/chrome/">download Google Chrome</A>.</p>');}
else {document.write('<p class="accent">You\'re not using Chrome or Firefox, how\'s

about <A HREF="https://www.google.com/chrome/">downloading Google Chrome</A>.</p>');}
// -->
</script>


Any help gratefully received.

rnd me
09-25-2012, 09:30 PM
danml.com/slim (http://danml.com/slim)

for one-line output, choose one of jsmin, packer, uglify, slim, or JSON.stringify from the "Apply Engine" drop down.

i'd do it for you, but the formatting looks messed up in the post.

Fugazi1978
09-26-2012, 12:15 PM
..but where is the 'Apply Engine' drop-down? I used Uglify on some bloke's website. Gave me this:


<script type="text/javascript">var BrowserDetect={init:function(){this.browser=this.searchString(this.dataBrowser)||"An unknown browser",this.version=this.searchVersion(navigator.userAgent)||this.searchVersion(navigator.appVersion)||"an unknown version",this.OS=this.searchString(this.dataOS)||"an unknown OS"},searchString:function(e){for(var t=0;t<e.length;t++){var n=e[t].string,r=e[t].prop;this.versionSearchString=e[t].versionSearch||e[t].identity;if(n){if(n.indexOf(e[t].subString)!=-1)return e[t].identity}else if(r)return e[t].identity}},searchVersion:function(e){var t=e.indexOf(this.versionSearchString);if(t==-1)return;return parseFloat(e.substring(t+this.versionSearchString.length+1))},dataBrowser:[{string:navigator.userAgent,subString:"Chrome",identity:"Chrome"},{string:navigator.userAgent,subString:"OmniWeb",versionSearch:"OmniWeb/",identity:"OmniWeb"},{string:navigator.vendor,subString:"Apple",identity:"Safari",versionSearch:"Version"},{prop:window.opera,identity:"Opera",versionSearch:"Version"},{string:navigator.vendor,subString:"iCab",identity:"iCab"},{string:navigator.vendor,subString:"KDE",identity:"Konqueror"},{string:navigator.userAgent,subString:"Firefox",identity:"Firefox"},{string:navigator.vendor,subString:"Camino",identity:"Camino"},{string:navigator.userAgent,subString:"Netscape",identity:"Netscape"},{string:navigator.userAgent,subString:"MSIE",identity:"Explorer",versionSearch:"MSIE"},{string:navigator.userAgent,subString:"Gecko",identity:"Mozilla",versionSearch:"rv"},{string:navigator.userAgent,subString:"Mozilla",identity:"Netscape",versionSearch:"Mozilla"}],dataOS:[{string:navigator.platform,subString:"Win",identity:"Windows"},{string:navigator.platform,subString:"Mac",identity:"Mac"},{string:navigator.userAgent,subString:"iPhone",identity:"iPhone/iPod"},{string:navigator.platform,subString:"Linux",identity:"Linux"}]};BrowserDetect.init()</script><script type="text/javascript">BrowserDetect.browser==="Chrome"?document.write('<p class="accent">You\'re using '+BrowserDetect.browser+" "+BrowserDetect.version+" on "+BrowserDetect.OS+", a great browser.</p>"):BrowserDetect.browser==="Firefox"?document.write('<p class="accent">You\'re using '+BrowserDetect.browser+" "+BrowserDetect.version+" on "+BrowserDetect.OS+", not bad.</p>"):BrowserDetect.browser==="Explorer"?document.write('<p class="accent">You\'re using Internet Explorer; we recommend you <A HREF="https://www.google.com/chrome/">download Google Chrome</A>.</p>'):document.write('<p class="accent">You\'re not using Chrome or Firefox, how\'s about <A HREF="https://www.google.com/chrome/">downloading Google Chrome</A>.</p>')</script>

VIPStephan
10-10-2012, 12:59 AM
Sorry, the last post got stuck in the moderation queue; I just noticed it. Hope it’s not too late yet?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum