storage.cookie¶

webix.storage.cookie¶

webix.storage.cookie helper.

Please look into the linked official documentation.

External references¶

Official documentation page.

Code¶

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
webix.storage.cookie = {
    put:function(name, data, domain, expires ){
        if(name && window.JSON){
            document.cookie = name + "=" + escape(window.JSON.stringify(data)) +
            (( expires && (expires instanceof Date)) ? ";expires=" + expires.toUTCString() : "" ) +
            (( domain ) ? ";domain=" + domain : "" ) +
            (( webix.env.https ) ? ";secure" : "");
        }
    },
    _get_cookie:function(check_name){
        // first we'll split this cookie up into name/value pairs
        // note: document.cookie only returns name=value, not the other components
        var a_all_cookies = document.cookie.split( ';' );
        var a_temp_cookie = '';
        var cookie_name = '';
        var cookie_value = '';
        var b_cookie_found = false; // set boolean t/f default f

        for (var i = 0; i < a_all_cookies.length; i++ ){
            // now we'll split apart each name=value pair
            a_temp_cookie = a_all_cookies[i].split( '=' );

            // and trim left/right whitespace while we're at it
            cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

            // if the extracted name matches passed check_name
            if (cookie_name == check_name ){
                b_cookie_found = true;
                // we need to handle case where cookie has no value but exists (no = sign, that is):
                if ( a_temp_cookie.length > 1 ){
                    cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
                }
                // note that in cases where cookie is initialized but no value, null is returned
                return cookie_value;
            }
            a_temp_cookie = null;
            cookie_name = '';
        }
        if ( !b_cookie_found ){
            return null;
        }
        return null;
    },
    get:function(name){
        if(name && window.JSON){
            var json = this._get_cookie(name);
            if(!json)
                return null;
            return webix.DataDriver.json.toObject(unescape(json));
        }else
            return null;
    },
    remove:function(name, domain){
        if(name && this._get_cookie(name))
            document.cookie = name + "=" + (( domain ) ? ";domain=" + domain : "") + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
    },
    clear:function(domain){
        var cookies = document.cookie.split(";");
        for (var i = 0; i < cookies.length; i++)
            document.cookie = /^[^=]+/.exec(cookies[i])[0] + "=" + (( domain ) ? ";domain=" + domain : "") + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
};

Related Topics

  • Documentation overview
    • Helpers
      • Previous: skin.web
      • Next: storage.local

Table Of Contents

  • Proxy object
  • Components
  • Views
  • Helpers
    • _delays
    • _event
    • _events
    • _modules
    • _ready_code
    • _view
    • _xhr_aborted
    • ajax
    • ajax.count
    • animate
    • animate.breakLine
    • animate.clear
    • animate.defaults
    • animate.end
    • animate.formLine
    • animate.isSupported
    • animate.start
    • assert
    • assert_config
    • assert_core_ready
    • assert_error
    • assert_level
    • assert_level_in
    • assert_level_out
    • bind
    • cdn
    • clipbuffer
    • clone
    • clone._function
    • codebase
    • color
    • copy
    • csv
    • debug_blacklist
    • debug_code
    • debug_ready
    • debug_size_box
    • debug_size_box_end
    • debug_size_box_start
    • debug_size_indent
    • debug_size_step
    • delay
    • delay
    • destructors
    • dp
    • dp._pull
    • editors
    • editors.color
    • editors.combo
    • editors.date
    • editors.password
    • editors.richselect
    • editStop
    • env
    • env.svg
    • env.svganimation
    • event
    • eventRemove
    • exec
    • extend
    • hasMethod
    • history
    • html
    • html.addMeta
    • i18n
    • i18n.locales
    • isArray
    • isDate
    • isUndefined
    • jsonp
    • jsonp.timer
    • locale
    • locale.pager
    • log
    • log_full_time
    • log_time
    • markup
    • name
    • once
    • proto
    • protoUI
    • proxy
    • proxy.binary
    • proxy.cache
    • proxy.connector
    • proxy.debug
    • proxy.faye
    • proxy.indexdb
    • proxy.json
    • proxy.local
    • proxy.offline
    • proxy.post
    • proxy.rest
    • proxy.sync
    • ready
    • remote
    • require
    • rules
    • send
    • single
    • skin
    • skin.air
    • skin.clouds
    • skin.compact
    • skin.contrast
    • skin.flat
    • skin.glamour
    • skin.light
    • skin.material
    • skin.metro
    • skin.set
    • skin.terrace
    • skin.touch
    • skin.web
    • storage.cookie
    • storage.local
    • storage.session
    • template
    • template.bind
    • template.empty
    • toArray
    • toCSV
    • toExcel
    • toFunctor
    • toNode
    • toPDF
    • toPNG
    • type
    • ui
    • ui._detectScrollSize
    • ui._fixHeight
    • ui._namecount
    • ui._popups
    • ui._uid
    • ui.animate
    • ui.animateView
    • ui.datafilter
    • ui.datafilter.dateFilter
    • ui.datafilter.numberFilter
    • ui.datafilter.serverFilter
    • ui.datafilter.serverSelectFilter
    • ui.each
    • ui.fullScreen
    • ui.resize
    • ui.scrollSize
    • ui.zIndex
    • ui.zIndexBase
    • uid
    • version
    • views
    • wrap
  • Mixins

This Page

  • Show Source

Quick search

©2016, Arstecnica. | Powered by Sphinx 1.5.2 & Alabaster 0.7.9 | Page source