Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question CMS needs code on one line; help please...

    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:

    Code:
    <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.

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,349
    Thanks
    11
    Thanked 589 Times in 570 Posts
    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.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #3
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Uglify is great...

    ..but where is the 'Apply Engine' drop-down? I used Uglify on some bloke's website. Gave me this:
    Code:
    <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>

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,677
    Thanks
    6
    Thanked 1,008 Times in 981 Posts
    Sorry, the last post got stuck in the moderation queue; I just noticed it. Hope it’s not too late yet?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •