Initial commit.
This commit is contained in:
88
htdocs/emily/scripts/common.js
Normal file
88
htdocs/emily/scripts/common.js
Normal file
@@ -0,0 +1,88 @@
|
||||
/* Emily Wu's Website
|
||||
* 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 = "";
|
||||
}
|
||||
}
|
||||
55
htdocs/emily/scripts/guestbook.js
Normal file
55
htdocs/emily/scripts/guestbook.js
Normal file
@@ -0,0 +1,55 @@
|
||||
/* Emily Wu's Website
|
||||
* guestbook.js: The guestbook-related 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
|
||||
*/
|
||||
|
||||
// isGuestbookOK: Check if the message is ready to be submitted
|
||||
function isGuestbookOK(form) {
|
||||
|
||||
// Regularize the fields
|
||||
form.message.value = trimText(form.message.value);
|
||||
form.name.value = trim(form.name.value);
|
||||
form.identity.value = trim(form.identity.value);
|
||||
form.location.value = trim(form.location.value);
|
||||
form.email.value = trim(form.email.value);
|
||||
form.url.value = trim(form.url.value);
|
||||
|
||||
// Check the message
|
||||
if (form.message.value == "" || form.message.value == _("Fill in your message here.")) {
|
||||
alert(_("Please fill in your message."));
|
||||
form.message.focus();
|
||||
return false;
|
||||
}
|
||||
if (form.message.value.length > 10240) {
|
||||
alert(_("Your message is too long. (Max. 10,240 letters)"));
|
||||
form.message.focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check the signature
|
||||
if (form.name.value == "") {
|
||||
alert(_("Please fill in your signature."));
|
||||
form.name.focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
30
htdocs/emily/scripts/lang.zh-tw.js
Normal file
30
htdocs/emily/scripts/lang.zh-tw.js
Normal file
@@ -0,0 +1,30 @@
|
||||
/* Emily Wu's Website
|
||||
* lang.zh-tw.js: The Chinese (Taiwan) localized messages.
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2004-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: 2004-11-06
|
||||
*/
|
||||
|
||||
// The messages
|
||||
lc_messages = [
|
||||
["Fill in your message here.", "請填上妳的留言。"],
|
||||
["Please fill in your message.", "請填上妳的留言。"],
|
||||
["Your message is too long. (Max. 10,240 letters)", "妳的留言太長了。(最長 10,240 個字)"],
|
||||
["Please fill in your signature.", "請填上妳的簽名。"],
|
||||
];
|
||||
Reference in New Issue
Block a user