X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=js%2Ffragment.js;fp=js%2Ffragment.js;h=835c05eb8782f81bd7345621e68ef497701ab742;hb=217c4d7a0d5f9fee3a8ef0a05ab8506c7f39d5e5;hp=0000000000000000000000000000000000000000;hpb=bd9caeefe3cfc9b4194c31052b0ddd4da26f604c;p=euphorik.git diff --git a/js/fragment.js b/js/fragment.js new file mode 100644 index 0000000..835c05e --- /dev/null +++ b/js/fragment.js @@ -0,0 +1,69 @@ +// coding: utf-8 +// Copyright 2008 Grégory Burri +// +// This file is part of Euphorik. +// +// Euphorik 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 3 of the License, or +// (at your option) any later version. +// +// Euphorik 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 Euphorik. If not, see . + +/** + * + */ +Fragment = function() { + var thisFragment = this; + this.fragments = {}; + if (!window.location.hash) { + return; + } + try { + var fragmentsStr = window.location.hash.slice(1).split(";"); + fragmentsStr.each(function(i, tuple) { + tuple = tuple.split("="); + thisFragment.fragments[tuple[0]] = JSON.parse(tuple[1]); + }); + } catch(error) { + ;; console.log(error); + } +}; + +Fragment.prototype.setVal = function(name, val) { + this.fragments[name] = val; +} + +Fragment.prototype.getVal = function(name) { + return this.fragments[name]; +} + +Fragment.prototype.delVal = function(name) { + delete this.fragments[name]; +} + +Fragment.prototype.eraseAllVal = function() { + this.fragments = []; +} + +Fragment.prototype.each = function(fun) { + objectEach(this.fragments, function(name, val) { + fun(name, val); + }); +} + +Fragment.prototype.write = function() { + var fragmentsStr = ""; + var first = true; + objectEach(this.fragments, function(name, val) { + fragmentsStr += (first ? "" : ";") + name + "=" + JSON.stringify(val); + first = false; + }); + window.location.hash = fragmentsStr; +}