/* * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is SynchroEdit (www.synchroedit.com). * * The Initial Developer of the Original Code is * Kalle Alm (kalle@enrogue.com). * Portions created by the Initial Developer are Copyright (C) 2005 * Alacrity Management Corporations. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL or the LGPL. * * ***** END LICENSE BLOCK ***** --> * * SynchroEditor client. * * Preferences functionality. */ var pref = new Array(); // List of preferences. // Get preference. function prefs_get(name) { var c = document.cookie; var offs = c.indexOf("; " + name + "="); if (offs == -1) { return null; } var offe = c.indexOf(";", offs + 2); if (offe == -1) offe = c.length; return unescape(c.substring(offs + name.length + 3, offe)); } // Set preference. function prefs_set(name, value) { document.cookie = name + "=" + escape(value); } // Initialize preferences service. function prefs_init() { prefs_load("default"); prefs_load_global(); } // Store global settings. function prefs_store_global() { prefs_set("system.default_user", pref["default_user"]); } // Load global settings. function prefs_load_global() { try { pref["default_user"] = prefs_get("system.default_user"); } catch (e) {} if (pref["default_user"] == null) pref["default_user"] = ""; } // Load default preferences. function prefs_load(user) { var ns = user + "."; try { pref["color"] = prefs_get(ns + "color"); } catch (e) {} } // Save preferences. function prefs_save(user) { var ns = user + "."; prefs_set(ns + "color", pref["color"]); } // Input default system preferences. function prefs_system_defaults() { // this is currently static but will most likely not be used // in the final product. pref["system.host"] = DEFAULT_HOST; pref["system.port"] = DEFAULT_PORT; pref["system.user"] = null; pref["default_user"] } // Process the URL of the loaded window and acquire settings. function prefs_system_process_href(href) { // href is "[host/dir/page]?=[&...]" // but it can also be wrapped, in which case we will have two ?'s. var halves = href.split('?'); if (halves.length > 1) { var settings = halves[halves.length-1].split('&'); var ix = settings.length; var pair = null; for (var i = 0; i < ix; i++) { pair = settings[i].split('='); pref["system." + pair[0]] = (pair.length == 1 ? 1 : pair[1]); } } }