joonis Logo

KSS Storage Plugin

This KSS plugin adds support for localStorage and sessionStorage. It provides the parameter provider methods localVar and sessionVar and the actions setLocalVar, setSessionVar, delLocalVar and delSessionVar. It can be used in much the same way as stateVar and setStateVar. This plugin does not work with IE6/7 (that could be changed by implementing the userDataBehavior).

  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
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
    storage_plugin.js - Storage plugin for KSS

    Copyright (c) 2011, joonis new media
    Author: Thimo Kraemer <thimo.kraemer@joonis.de>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    MA 02110-1301, USA.
*/

// localStorage

kukit.actionsGlobalRegistry.register('setLocalVar', function(oper) {
;;; oper.componentName = '[setLocalVar] action';
;;; oper.evaluateParameters(['varname', 'value'], {});
    var storage;
    try { storage = window.localStorage; } catch (err) {}
    if (storage) {
        storage.setItem(oper.parms.varname, oper.parms.value);
    }
});
kukit.commandsGlobalRegistry.registerFromAction('setLocalVar',
    kukit.cr.makeGlobalCommand);


kukit.actionsGlobalRegistry.register('delLocalVar', function(oper) {
;;; oper.componentName = '[delLocalVar] action';
;;; oper.evaluateParameters(['varname'], {});
    var storage;
    try { storage = window.localStorage; } catch (err) {}
    if (storage) {
        storage.removeItem(oper.parms.varname);
    }
});
kukit.commandsGlobalRegistry.registerFromAction('delLocalVar',
    kukit.cr.makeGlobalCommand);


kukit.actionsGlobalRegistry.register('clearLocalVars', function(oper) {
;;; oper.componentName = '[clearLocalVars] action';
    var storage;
    try { storage = window.localStorage; } catch (err) {}
    if (storage) {
        storage.clear();
    }
});
kukit.commandsGlobalRegistry.registerFromAction('clearLocalVars',
    kukit.cr.makeGlobalCommand);


kukit.pprovidersGlobalRegistry.register('localVar', function() {

this.check = function(args) {
;;; if (args.length != 1) {
;;;     throw new Error('localVar method needs 1 argument [varname].');
;;; }
};

this.eval = function(args, node) {
    var key = args[0];
    var value;
    var storage;
    try { storage = window.localStorage; } catch (err) {}
    if (storage) {
        value = storage.getItem(key);
    }
    return value || '';
};

});


// sessionStorage

kukit.actionsGlobalRegistry.register('setSessionVar', function(oper) {
;;; oper.componentName = '[setSessionVar] action';
;;; oper.evaluateParameters(['varname', 'value'], {});
    var storage;
    try { storage = window.sessionStorage; } catch (err) {}
    if (storage) {
        storage.setItem(oper.parms.varname, oper.parms.value);
    }
});
kukit.commandsGlobalRegistry.registerFromAction('setSessionVar',
    kukit.cr.makeGlobalCommand);


kukit.actionsGlobalRegistry.register('delSessionVar', function(oper) {
;;; oper.componentName = '[delSessionVar] action';
;;; oper.evaluateParameters(['varname'], {});
    var storage;
    try { storage = window.sessionStorage; } catch (err) {}
    if (storage) {
        storage.removeItem(oper.parms.varname);
    }
});
kukit.commandsGlobalRegistry.registerFromAction('delSessionVar',
    kukit.cr.makeGlobalCommand);


kukit.actionsGlobalRegistry.register('clearSessionVars', function(oper) {
;;; oper.componentName = '[clearSessionVars] action';
    var storage;
    try { storage = window.sessionStorage; } catch (err) {}
    if (storage) {
        storage.clear();
    }
});
kukit.commandsGlobalRegistry.registerFromAction('clearSessionVars',
    kukit.cr.makeGlobalCommand);


kukit.pprovidersGlobalRegistry.register('sessionVar', function() {

this.check = function(args) {
;;; if (args.length != 1) {
;;;     throw new Error('sessionVar method needs 1 argument [varname].');
;;; }
};

this.eval = function(args, node) {
    var key = args[0];
    var value;
    var storage;
    try { storage = window.sessionStorage; } catch (err) {}
    if (storage) {
        value = storage.getItem(key);
    }
    return value || '';
};

});

Kann ich
  Ihnen helfen?


Schreiben Sie mir
doch einfach unter
giraffe@joonis.de