Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-minified version #4

Open
joakim opened this issue Nov 27, 2010 · 0 comments
Open

Non-minified version #4

joakim opened this issue Nov 27, 2010 · 0 comments

Comments

@joakim
Copy link

joakim commented Nov 27, 2010

First off all, thanks for the smart script :)

I've just ported it to PHP for a Drupal module (I know about Bastian Allgeier's PHP version, but it wasn't up to date with your latest changes and I wanted to give it a try). To understand the script I had to untangle the one line of JS, which was a bit painful.

Would it be possible to also provide a non-minified version of the script?

For example, here is my untangled version of 0.4.0:

function css_browser_selector(u) {
  var ua = u.toLowerCase(),
  is = function(t) {
    return ua.indexOf(t) > -1
  },
  g = 'gecko',
  w = 'webkit',
  s = 'safari',
  o = 'opera',
  m = 'mobile',
  h = document.documentElement,
  b = [
    (!(/opera|webtv/i.test(ua)) && /msie\s(\d)/.test(ua)) ? ('ie ie' + RegExp.$1)
    : is('firefox/2') ? g + ' ff2'
    : is('firefox/3.5') ? g + ' ff3 ff3_5'
    : is('firefox/3.6') ? g + ' ff3 ff3_6'
    : is('firefox/3') ? g + ' ff3'
    : is('gecko/') ? g
    : is('opera') ? o + (
      /version\/(\d+)/.test(ua) ? ' ' + o + RegExp.$1
      : (
        /opera(\s|\/)(\d+)/.test(ua) ? ' ' + o + RegExp.$2
        : ''
      )
    )
    : is('konqueror') ? 'konqueror'
    : is('blackberry') ? m + ' blackberry'
    : is('android') ? m + ' android'
    : is('chrome') ? w + ' chrome'
    : is('iron') ? w + ' iron'
    : is('applewebkit/') ? w + ' ' + s + (
      /version\/(\d+)/.test(ua) ? ' ' + s + RegExp.$1
      : ''
    )
    : is('mozilla/') ? g
    : '',
    is('j2me') ? m + ' j2me'
    : is('iphone') ? m + ' iphone'
    : is('ipod') ? m + ' ipod'
    : is('ipad') ? m + ' ipad'
    : is('mac') ? 'mac'
    : is('darwin') ? 'mac'
    : is('webtv') ? 'webtv'
    : is('win') ? 'win' + (
      is('windows nt 6.0') ? ' vista'
      : ''
    )
    : is('freebsd') ? 'freebsd'
    : (is('x11') || is('linux')) ? 'linux'
    : '',
    'js'
  ];
  c = b.join(' ');
  h.className += ' ' + c;
  return c;
};
css_browser_selector(navigator.userAgent);

Much more readable :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant