Форум: Форум PHPФорум ApacheФорум Регулярные ВыраженияФорум MySQLHTML+CSS+JavaScriptФорум FlashРазное
Новые темы: 0000000
PHP 5. На примерах. Авторы: Кузнецов М.В., Симдянов И.В., Голышев С.В. Объектно-ориентированное программирование на PHP. Авторы: Кузнецов М.В., Симдянов И.В. Самоучитель PHP 5 / 6 (3 издание). Авторы: Кузнецов М.В., Симдянов И.В. MySQL 5. В подлиннике. Авторы: Кузнецов М.В., Симдянов И.В. Социальная инженерия и социальные хакеры. Авторы: Кузнецов М.В., Симдянов И.В.
ВСЕ НАШИ КНИГИ
Консультационный центр SoftTime

HTML+CSS+JavaScript

Выбрать другой форум

 

Здравствуйте, Посетитель!

вид форума:
Линейный форум Структурный форум

тема: function getCookie...
 
 автор: Fox   (06.03.2007 в 17:40)   письмо автору
 
 

подскажите как это ггггг. сократить!!!

// --- internal use functions -----------------------------------------------

function getCookie (sName)
{
var aCookie = document.cookie.split ('; ');
for (var i = 0; i < aCookie.length; ++i)
{
var aCrumb = aCookie [i].split ('=');
if (sName == aCrumb [0])
return unescape (aCrumb [1]);
}
return null;
} // getCookie


function setCookie (sName, sValue, iMode)
{
var expDate = new Date ();
if (iMode == 1)
expDate.setDate (expDate.getDate () + 365);
else if (iMode == 2)
expDate.setHours (expDate.getHours () + 12);
document.cookie = sName + '=' + escape (sValue) +
'; expires=' + expDate.toGMTString () + '; path=/';
} // setCookie


function isFeatureSupported (sFeature)
{
return (window.focus) ? // secure (?) check for JS 1.1
// can safely use 'typeof'
eval ('typeof (' + sFeature + ') != "undefined"') :
false; // JS 1.0 supports nothing questionable...
} // isFeatureSupported


function setFontSizeGrade (vValue)
{
if (vValue == null)
return;

document.body.style.fontSize = '' + (100 * Math.pow (1.2, vValue)) + '%';
setCookie ('FontSizeGrade0', vFontSizeGrade, 1);
} // setFontSizeGrade


function isPlatformOk4PageControls ()
{
return isFeatureSupported ('document.body.style.fontSize') &&
isFeatureSupported ('document.getElementById');
} // isPlatformOk4PageControls


function propertiesChunk (sName, sValue)
{
return '&amp;' + sName + '=' + escape (sValue);
} // propertiesChunk


function reportBrowserProperties ()
{
if (getCookie ('BrowserProperties'))
if ((vFontSizeGrade == null) ||
(vFontSizeGrade == getCookie ('FontSizeGrade1')))
return; // avoid repeated reporting

document.cookie = 'BrowserProperties=T; path=/';
var sProperties = 'c=' + ((document.cookie) ? 'Y' : 'N');

sProperties +=
propertiesChunk ('tz', (new Date ()).getTimezoneOffset () / 60 * (-1));

if ((navigator.appVersion.indexOf ('MSIE 5') >= 0 ||
navigator.appVersion.indexOf ('MSIE 6') >= 0 ||
navigator.appVersion.indexOf ('MSIE 7') >= 0) &&
(navigator.userAgent.indexOf ('Opera') < 0))
{
document.write ('<span style="behavior: url(#default#clientCaps)"' +
' id="client-caps"></span>');
var oClientCaps = document.all.item ("client-caps");
var sFlashVersion =
oClientCaps.getComponentVersion
('{D27CDB6E-AE6D-11CF-96B8-444553540000}', 'ComponentID');
sProperties += propertiesChunk ('flash', sFlashVersion);
sProperties += propertiesChunk ('conn', oClientCaps.connectionType);
}

if (isFeatureSupported ('navigator.javaEnabled'))
sProperties +=
propertiesChunk ('java', (navigator.javaEnabled () ? 'Y' : 'N'));

if (isFeatureSupported ('screen.width'))
sProperties += propertiesChunk ('sw', screen.width);
if (isFeatureSupported ('screen.height'))
sProperties += propertiesChunk ('sh', screen.height);

if (isFeatureSupported ('screen.colorDepth'))
sProperties += propertiesChunk ('cld', screen.colorDepth);
if (isFeatureSupported ('screen.pixelDepth'))
sProperties += propertiesChunk ('pxd', screen.pixelDepth);

if (isFeatureSupported ('screen.deviceXDPI'))
{
sProperties += propertiesChunk ('dxdpi', screen.deviceXDPI);
sProperties += propertiesChunk ('dydpi', screen.deviceYDPI);
}
if (isFeatureSupported ('screen.logicalXDPI'))
{
sProperties += propertiesChunk ('lxdpi', screen.logicalXDPI);
sProperties += propertiesChunk ('lydpi', screen.logicalYDPI);
}

// see http://www.howtocreate.co.uk/tutorials/index.php?tut=0&part=16
if (isFeatureSupported ('window.innerWidth'))
{
sProperties += propertiesChunk ('wiw', window.innerWidth);
sProperties += propertiesChunk ('wih', window.innerHeight);
}
else if (isFeatureSupported ('document.documentElement.clientWidth') &&
(document.documentElement.clientWidth))
{
sProperties +=
propertiesChunk ('wiw', document.documentElement.clientWidth);
sProperties +=
propertiesChunk ('wih', document.documentElement.clientHeight);
}
else if (isFeatureSupported ('document.body.clientWidth') &&
(document.body.clientWidth))
{
sProperties += propertiesChunk ('wiw', document.body.clientWidth);
sProperties += propertiesChunk ('wih', document.body.clientHeight);
}

sProperties += propertiesChunk ('nan', navigator.appName);
sProperties += propertiesChunk ('nacn', navigator.appCodeName);
sProperties += propertiesChunk ('nav', navigator.appVersion);
if (isFeatureSupported ('navigator.cpuClass'))
sProperties += propertiesChunk ('cpu', navigator.cpuClass);
if (isFeatureSupported ('navigator.platform'))
sProperties += propertiesChunk ('plat', navigator.platform);
if (isFeatureSupported ('navigator.systemLanguage'))
sProperties += propertiesChunk ('slang', navigator.systemLanguage);
if (isFeatureSupported ('navigator.userLanguage'))
sProperties += propertiesChunk ('ulang', navigator.userLanguage);

if (vFontSizeGrade != null)
{
sProperties += propertiesChunk ('fsg', vFontSizeGrade);
setCookie ('FontSizeGrade1', vFontSizeGrade, 1);
}

document.write ('<img src="/img/transparent1x1.gif?' + sProperties +
'" width="1" height="1">');

setCookie ('BrowserProperties', 'R', 2);
} // reportBrowserProperties


// --- external use functions -----------------------------------------------

function setupFontSize ()
{
if (isPlatformOk4PageControls ())
{
vFontSizeGrade = getCookie ('FontSizeGrade0');
if (vFontSizeGrade != null)
setFontSizeGrade (vFontSizeGrade);
}

reportBrowserProperties (); // a good place to do it...
} // setupFontSize


function showPageControls (sSpecificControlsCode, sRootPfx)
{
if (!isPlatformOk4PageControls ())
return;
var sControlsCode =
(sSpecificControlsCode != null) ?
sSpecificControlsCode :
'<img src="' + sRootPfx + 'img/zoom-in.gif" width="16" ' +
'height="16" alt="&#211;&#226;&#229;&#235;&#232;&#247;&#232;&#242;&#252; &#240;&#224;&#231;&#236;&#229;&#240; &#248;&#240;&#232;&#244;&#242;&#224;" ' +
'title="&#211;&#226;&#229;&#235;&#232;&#247;&#232;&#242;&#252; &#240;&#224;&#231;&#236;&#229;&#240; &#248;&#240;&#232;&#244;&#242;&#224;" ' +
'onclick="increaseFontSize ();"> <img src="' + sRootPfx +
'img/zoom-out.gif" width="16" height="16" ' +
'alt="&#211;&#236;&#229;&#237;&#252;&#248;&#232;&#242;&#252; &#240;&#224;&#231;&#236;&#229;&#240; &#248;&#240;&#232;&#244;&#242;&#224;" title="&#211;&#236;&#229;&#237;&#252;&#248;&#232;&#242;&#252; &#240;&#224;&#231;&#236;&#229;&#240; &#248;&#240;&#232;&#244;&#242;&#224;" ' +
'onclick="decreaseFontSize ();"> <a href="' + sRootPfx +
'ru/help.html" title="&#207;&#238;&#228;&#241;&#234;&#224;&#231;&#234;&#224;"><img src="' + sRootPfx +
'img/help.gif" width="16" height="16" alt="&#207;&#238;&#228;&#241;&#234;&#224;&#231;&#234;&#224;"></a>';
document.write ('<div id="page-controls">' + sControlsCode + '</div>');
} // showPageControls


function decreaseFontSize (sName, sValue)
{
setFontSizeGrade (--vFontSizeGrade);
} // decreaseFontSize


function increaseFontSize (sName, sValue)
{
setFontSizeGrade (++vFontSizeGrade);
} // increaseFontSize


function highlightAnchorRaw ()
{
if (!(document.getElementById))
return; // won't mess with ancient browsers...
var hash = window.location.hash;
if (hash.length <= 1)
return;
var targetName = hash.substring (1);
var targetAnchor = document.getElementById (targetName);
if (!targetAnchor)
return; // might be a hand-crafted URL...
var targetTr = targetAnchor.parentNode.parentNode;
targetTr.style.backgroundColor = '#FFFF00';
} // onPageLoad


// --- global variables -----------------------------------------------------

var vFontSizeGrade = null;

   
 
 автор: mihdan   (07.03.2007 в 11:19)   письмо автору
 
   для: Fox   (06.03.2007 в 17:40)
 


<script>
// Извлекает "Плюшки"
function extractCookieValue(val) {
    if ((endOfCookie = document.cookie.indexOf(";", val)) == -1) {
        endOfCookie = document.cookie.length;
    }
    var s = unescape(document.cookie.substring(val, endOfCookie));
    if (s == '') {
        s = '0';
    }
    return s;  
}

// Читаем "Плюшку"
function ReadCookie(cookiename) {
    var numOfCookies = document.cookie.length;
    var nameOfCookie = cookiename + '=';
    var cookieLen = nameOfCookie.length;
    var x = 0 ;
    while (x <= numOfCookies) {
        var y = (x + cookieLen);
        if (document.cookie.substring(x, y) == nameOfCookie) { 
            return (extractCookieValue(y)); 
        }  
        x = document.cookie.indexOf(' ', x) + 1;
        if (x == 0) { 
            break;
        }  
    }
    return '0';
}

// Удалим "Плюшку"
function  DeleteCookie(name) {
    CreateCookie(name, '', -1);
}

// Создать "Плюшку"
function CreateCookie(name, value, expiredays) {
    var todayDate = new Date();
    todayDate.setDate(todayDate.getDate() + expiredays);
    document.cookie = name + '=' + value + '; expires=' + todayDate.toGMTString() + ';';
}
</script>

   
 
 автор: bronenos   (07.03.2007 в 19:40)   письмо автору
 
   для: mihdan   (07.03.2007 в 11:19)
 

function getcookie (name)
{
  name += '=';
  cookies = document.cookie;
  find = cookies.indexOf (name);
  if (find > -1)
  {
    start = name.length + find;
    end = cookies.indexOf (';', start);
    if (end < 0)
      end = cookies.length;
    value = cookies.substring (start, end);
    return unescape (value);
  }
  return false;
}

   
Rambler's Top100
вверх

Rambler's Top100 Яндекс.Метрика Яндекс цитирования