Initial commit.

This commit is contained in:
2026-03-10 21:25:26 +08:00
commit 78739bf725
3089 changed files with 472990 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
/* History: Theory and Culture
* common.js: The common JavaScript subroutines.
*/
/* Copyright (c) 2000-2018 imacat.
*
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Author: imacat <imacat@mail.imacat.idv.tw>
* First written: 2000-07-25
*/
// _: Gettext
function _(msg) {
var i;
for (i = 0; i < lc_messages.length; i++) {
if (lc_messages[i][0] == msg) {
return lc_messages[i][1];
}
}
return msg;
}
// The messages
lc_messages = [];
// isEmail: Check if an email address is legal
function isEmail(a) {
var i, c, re;
if (typeof(RegExp) == "undefined") return true;
re = new RegExp("^[\\w\\-]+(\\.[\\w\\-]+)*\\@([\\w\\-]+\\.)+[\\w\\-]+$");
if (typeof(a) != "string") return false;
a = a.toLowerCase();
if (re.exec(a) == null) return false;
return true;
}
// trim: Trim the leading and tailing spaces
function trim(a) {
var pos, start, len, spaces;
start = 0;
len = a.length;
spaces = " \t\f\n\r";
for (start = 0; start < a.length && spaces.indexOf(a.charAt(start)) >= 0; start++, len--);
for (pos = a.length - 1; pos >= 0 && spaces.indexOf(a.charAt(pos)) >= 0; pos--, len--);
return a.substr(start, len);
}
function trimText(a) {
var pos, start, len, spaces, newlines;
start = 0;
len = a.length;
spaces = " \t\f\n\r";
newlines = "\n\r";
for (start = 0; start < a.length && spaces.indexOf(a.charAt(start)) >= 0; start++, len--);
for ( ; start-1 >= 0 && newlines.indexOf(a.charAt(start-1)) < 0; start--, len++);
for (pos = a.length - 1; pos >= 0 && spaces.indexOf(a.charAt(pos)) >= 0; pos--, len--);
return a.substr(start, len);
}
// replace: Replace one phace with another in a string
function replace(source, oldStr, newStr) {
var pos;
pos = 0;
while (true) {
pos = source.indexOf(oldStr, pos);
if (pos == -1) break;
source = source.substr(0, pos) + newStr + source.substr(pos + oldStr.length)
pos += newStr.length;
}
return source;
}
// clearDefault: Clear the default value of a column
function clearDefault(col, deftext) {
if (col.value == deftext) {
col.value = "";
}
}