From c03cb12982a04f8904c5d7eb685de39c153eae11 Mon Sep 17 00:00:00 2001 From: pixel Date: Tue, 15 Jan 2008 18:20:23 +0000 Subject: Moving code around a bit, and adding htmllib.lua --- lib/ajaxlib.lua | 4 +- lib/htmllib.lua | 212 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 214 insertions(+), 2 deletions(-) create mode 100644 lib/htmllib.lua (limited to 'lib') diff --git a/lib/ajaxlib.lua b/lib/ajaxlib.lua index b03e71f..398d3b1 100644 --- a/lib/ajaxlib.lua +++ b/lib/ajaxlib.lua @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: ajaxlib.lua,v 1.1 2008-01-15 16:11:27 pixel Exp $ */ +/* $Id: ajaxlib.lua,v 1.2 2008-01-15 18:20:23 pixel Exp $ */ ]]-- @@ -51,7 +51,7 @@ function ajax_dump_table(t, out) end end -function ajax_write_javascript(out) +function write_ajax_javascript(out) out:write(ajaxlib_javascript) end diff --git a/lib/htmllib.lua b/lib/htmllib.lua new file mode 100644 index 0000000..9603b4f --- /dev/null +++ b/lib/htmllib.lua @@ -0,0 +1,212 @@ +--[[ + +/* + * Baltisot + * Copyright (C) 1999-2008 Nicolas "Pixel" Noble + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* $Id: htmllib.lua,v 1.1 2008-01-15 18:20:23 pixel Exp $ */ + +]]-- + +local common_javascript + +function urlEncode(str) + if str then + str = string.gsub(str, "\n", "\r\n") + str = string.gsub(str, "([^%w ])", + function (c) + return string.format("%%%02X", string.byte(c)) + end) + str = string.gsub(str, " ", "+") + end + return str +end + +function write_common_javascript(out) + out:write(common_javascript) +end + +common_javascript = [=[ +function getObjById(id) { + var returnVar = null; + if (document.getElementById) + returnVar = document.getElementById(id); + else if (document.all) + returnVar = document.all[id]; + else if (document.layers) + returnVar = document.layers[id]; + return returnVar; +} + +function removeAllOptions(selectbox) +{ + var i; + selectbox = getObjById(selectbox); + for (i = selectbox.options.length - 1; i >= 0; i--) + { + //selectbox.options.remove(i); + selectbox.remove(i); + } +} + + +function addOption(selectbox, value, text ) +{ + selectbox = getObjById(selectbox); + var optn = document.createElement("OPTION"); + optn.text = text; + optn.value = value; + + selectbox.options.add(optn); +} + +///////////////////////////////////////////////////////////////////// +/*------------------------------------------------------------------- + AKX GetVariables + ------------------------------------------------------------------- + Class to get HTTP GET-style variables from the document URL. + Usage: + 1) declare a variable as GetVariables ex. + vars=new GetVariables(); + 2) call the variable's Init function ex. + vars.Init(); + 3) call IsVar to check whether the named variable is found ex. + vars.IsVar("username"); + IsVar returns either true or false. + 4) call GetVar to retrieve a variable. + alert(vars.GetVar("username")); + GetVar returns "" if the variable is not found. + + You can also iterate through the variables using + for(i=0;i= n) + return this.Values[this.Varslist[n]]; +} + +function GV_GetVarNN(n) { + if (this.Vars >= n) + return this.Varslist[n]; +} + +function GV_ListVars() { + s = ""; + for (i = 0; i < this.VarCount(); i++) { + s += this.GetVarNN(i) + "=" + this.GetVarNV(i) + "\n"; + } + alert(s); +} + +function GetVariables() { + this.Values = new Array(); + this.Varslist = new Array(); + this.Vars = 0; + this.Init = GV_Init; + this.VarCount = GV_Vc; + this.GetVar = GV_GetVar; + this.GetVarNV = GV_GetVarNV; + this.GetVarNN = GV_GetVarNN; + this.IsVar = GV_IsVar; + this.AddVar = GV_AddVar; + this.GetVarPlace = GV_GetVarPlace; + this.ListVars = GV_ListVars; +} +///////////////////////////////////////////////////////////////////// +]=] -- cgit v1.2.3