Skip to content

Instantly share code, notes, and snippets.

@aarongustafson
Created September 9, 2010 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarongustafson/571780 to your computer and use it in GitHub Desktop.
Save aarongustafson/571780 to your computer and use it in GitHub Desktop.
function adjustViewport( property, value )
{
var
$viewport = $('meta[name=viewport]'),
currently = $viewport.attr('content'),
o_props = currently.split(/\s,\s?/),
n_props = [],
i = o_props.length,
set = false;
while ( i-- )
{
o_props[i] = o_props[i].split(/\s?=\s?/);
if ( o_props[i][0] == property )
{
if ( value !== false )
{
o_props[i][1] = value;
n_props.push( o_props[i].join('=') );
}
set = true;
}
else
{
n_props.push( o_props[i].join('=') );
}
}
if ( ! set )
{
n_props.push(property+'='+value);
}
n_props = n_props.join(',');
$viewport.attr('content',n_props);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment