Вход Регистрация
Файл: datatables/media/src/core/core.state.js
Строк: 261
<?php
/**
 * Save the state of a table in a cookie such that the page can be reloaded
 *  @param {object} oSettings dataTables settings object
 *  @memberof DataTable#oApi
 */
function _fnSaveState oSettings )
{
    if ( !
oSettings.oFeatures.bStateSave || oSettings.bDestroying )
    {
        return;
    }

    
/* Store the interesting variables */
    
var iiLenbInfinite=oSettings.oScroll.bInfinite;
    var 
oState = {
        
"iCreate":      new Date().getTime(),
        
"iStart":       (bInfinite oSettings._iDisplayStart),
        
"iEnd":         (bInfinite oSettings._iDisplayLength oSettings._iDisplayEnd),
        
"iLength":      oSettings._iDisplayLength,
        
"aaSorting":    $.extendtrue, [], oSettings.aaSorting ),
        
"oSearch":      $.extendtrue, {}, oSettings.oPreviousSearch ),
        
"aoSearchCols": $.extendtrue, [], oSettings.aoPreSearchCols ),
        
"abVisCols":    []
    };

    for ( 
i=0iLen=oSettings.aoColumns.length i<iLen i++ )
    {
        
oState.abVisCols.pushoSettings.aoColumns[i].bVisible );
    }

    
_fnCallbackFireoSettings"aoStateSaveParams"'stateSaveParams', [oSettingsoState] );
    
    
oSettings.fnStateSave.calloSettings.oInstanceoSettingsoState );
}


/**
 * Attempt to load a saved table state from a cookie
 *  @param {object} oSettings dataTables settings object
 *  @param {object} oInit DataTables init object so we can override settings
 *  @memberof DataTable#oApi
 */
function _fnLoadState oSettingsoInit )
{
    if ( !
oSettings.oFeatures.bStateSave )
    {
        return;
    }

    var 
oData oSettings.fnStateLoad.calloSettings.oInstanceoSettings );
    if ( !
oData )
    {
        return;
    }
    
    
/* Allow custom and plug-in manipulation functions to alter the saved data set and
     * cancelling of loading by returning false
     */
    
var abStateLoad _fnCallbackFireoSettings'aoStateLoadParams''stateLoadParams', [oSettingsoData] );
    if ( $.
inArrayfalseabStateLoad ) !== -)
    {
        return;
    }
    
    
/* Store the saved state so it might be accessed at any time */
    
oSettings.oLoadedState = $.extendtrue, {}, oData );
    
    
/* Restore key features */
    
oSettings._iDisplayStart    oData.iStart;
    
oSettings.iInitDisplayStart oData.iStart;
    
oSettings._iDisplayEnd      oData.iEnd;
    
oSettings._iDisplayLength   oData.iLength;
    
oSettings.aaSorting         oData.aaSorting.slice();
    
oSettings.saved_aaSorting   oData.aaSorting.slice();
    
    
/* Search filtering  */
    
$.extendoSettings.oPreviousSearchoData.oSearch );
    $.
extendtrueoSettings.aoPreSearchColsoData.aoSearchCols );
    
    
/* Column visibility state
     * Pass back visibility settings to the init handler, but to do not here override
     * the init object that the user might have passed in
     */
    
oInit.saved_aoColumns = [];
    for ( var 
i=i<oData.abVisCols.length i++ )
    {
        
oInit.saved_aoColumns[i] = {};
        
oInit.saved_aoColumns[i].bVisible oData.abVisCols[i];
    }

    
_fnCallbackFireoSettings'aoStateLoaded''stateLoaded', [oSettingsoData] );
}


/**
 * Create a new cookie with a value to store the state of a table
 *  @param {string} sName name of the cookie to create
 *  @param {string} sValue the value the cookie should take
 *  @param {int} iSecs duration of the cookie
 *  @param {string} sBaseName sName is made up of the base + file name - this is the base
 *  @param {function} fnCallback User definable function to modify the cookie
 *  @memberof DataTable#oApi
 */
function _fnCreateCookie sNamesValueiSecssBaseNamefnCallback )
{
    var 
date = new Date();
    
date.setTimedate.getTime()+(iSecs*1000) );
    
    
/* 
     * Shocking but true - it would appear IE has major issues with having the path not having
     * a trailing slash on it. We need the cookie to be available based on the path, so we
     * have to append the file name to the cookie name. Appalling. Thanks to vex for adding the
     * patch to use at least some of the path
     */
    
var aParts window.location.pathname.split('/');
    var 
sNameFile sName '_' aParts.pop().replace(/[/:]/g,"").toLowerCase();
    var 
sFullCookieoData;
    
    if ( 
fnCallback !== null )
    {
        
oData = (typeof $.parseJSON === 'function') ? 
            $.
parseJSONsValue ) : eval( '('+sValue+')' );
        
sFullCookie fnCallbacksNameFileoDatadate.toGMTString(),
            
aParts.join('/')+"/" );
    }
    else
    {
        
sFullCookie sNameFile "=" encodeURIComponent(sValue) +
            
"; expires=" date.toGMTString() +"; path=" aParts.join('/')+"/";
    }
    
    
/* Are we going to go over the cookie limit of 4KiB? If so, try to delete a cookies
     * belonging to DataTables.
     */
    
var
        
aCookies =document.cookie.split(';'),
        
iNewCookieLen sFullCookie.split(';')[0].length,
        
aOldCookies = [];
    
    if ( 
iNewCookieLen+document.cookie.length+10 4096 /* Magic 10 for padding */
    
{
        for ( var 
i=0iLen=aCookies.length i<iLen i++ )
        {
            if ( 
aCookies[i].indexOfsBaseName ) != -)
            {
                
/* It's a DataTables cookie, so eval it and check the time stamp */
                
var aSplitCookie aCookies[i].split('=');
                try {
                    
oData = eval( '('+decodeURIComponent(aSplitCookie[1])+')' );

                    if ( 
oData && oData.iCreate )
                    {
                        
aOldCookies.push( {
                            
"name"aSplitCookie[0],
                            
"time"oData.iCreate
                        
} );
                    }
                }
                catch( 
) {}
            }
        }

        
// Make sure we delete the oldest ones first
        
aOldCookies.sort( function (ab) {
            return 
b.time a.time;
        } );

        
// Eliminate as many old DataTables cookies as we need to
        
while ( iNewCookieLen document.cookie.length 10 4096 ) {
            if ( 
aOldCookies.length === ) {
                
// Deleted all DT cookies and still not enough space. Can't state save
                
return;
            }
            
            var 
old aOldCookies.pop();
            
document.cookie old.name+"=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path="+
                
aParts.join('/') + "/";
        }
    }
    
    
document.cookie sFullCookie;
}


/**
 * Read an old cookie to get a cookie with an old table state
 *  @param {string} sName name of the cookie to read
 *  @returns {string} contents of the cookie - or null if no cookie with that name found
 *  @memberof DataTable#oApi
 */
function _fnReadCookie sName )
{
    var
        
aParts window.location.pathname.split('/'),
        
sNameEQ sName '_' aParts[aParts.length-1].replace(/[/:]/g,"").toLowerCase() + '=',
         
sCookieContents document.cookie.split(';');
    
    for( var 
i=i<sCookieContents.length i++ )
    {
        var 
sCookieContents[i];
        
        while (
c.charAt(0)==' ')
        {
            
c.substring(1,c.length);
        }
        
        if (
c.indexOf(sNameEQ) === 0)
        {
            return 
decodeURIComponentc.substring(sNameEQ.length,c.length) );
        }
    }
    return 
null;
}
?>
Онлайн: 3
Реклама