📄 vbulletin_global.js
字号:
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 3.6.8
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000-2007 Jelsoft Enterprises Ltd. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/
/**
* Handle Firebug calls when Firebug is not available (getfirebug.com)
*/
if (!window.console || !console.firebug)
{
window.console = {};
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() {};
}
/**
* Handle YUI custom event calls when YUI is not available (clientscript/yui/yahoo-dom-event.js)
*/
if (typeof YAHOO == "undefined")
{
function null_event() { this.fire = function() {}; this.subscribe = function() {}; };
}
/**
* Setup Variables
*
* @var string SESSIONURL - stores the session URL
* @var array vbphrase - stores text phrases
* @var array vB_Editor - array of vB_Text_Editor objects
* @var boolean ignorequotechars - ignore characters inside [quote] tags for message length check
* @var integer pagenavcounter - counts the number of pagenav instances encountered so far
* @var boolean is_regexp - does window.regExp exist? - Catch errors with less capable browsers
* @var boolean AJAX_Compatible - does the current browser support AJAX?
* @var string pointer_cursor - help out old versions of IE that don't understand style.cursor = pointer
*/
var SESSIONURL = (typeof(SESSIONURL) == "undefined" ? "" : SESSIONURL);
var vbphrase = (typeof(vbphrase) == "undefined" ? new Array() : vbphrase);
var vB_Editor = new Array();
var ignorequotechars = false;
var pagenavcounter = 0;
var is_regexp = (window.RegExp) ? true : false;
var AJAX_Compatible = false;
var pointer_cursor = (is_ie ? 'hand' : 'pointer');
/**
* Define the browser loading the page
*
* @var string userAgent Useragent string
* @var boolean is_opera Opera
* @var boolean is_saf Safari
* @var boolean is_webtv WebTV
* @var boolean is_ie Internet Explorer
* @var boolean is_ie4 Internet Explorer 4
* @var boolean is_ie7 Internet Explorer 7
* @var boolean is_ps3 Playstation 3
* @var boolean is_moz Mozilla / Firefox / Camino
* @var boolean is_kon Konqueror
* @var boolean is_ns Netscape
* @var boolean is_ns4 Netscape 4
* @var boolean is_mac Client is running MacOS
*/
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = ((userAgent.indexOf('opera') != -1) || (typeof(window.opera) != 'undefined'));
var is_saf = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == 'Apple Computer, Inc.'));
var is_webtv = (userAgent.indexOf('webtv') != -1);
var is_ie = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4 = ((is_ie) && (userAgent.indexOf('msie 4.') != -1));
var is_ie7 = ((is_ie) && (userAgent.indexOf('msie 7.') != -1));
var is_ps3 = (userAgent.indexOf('playstation 3') != -1);
var is_moz = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon = (userAgent.indexOf('konqueror') != -1);
var is_ns = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4 = ((is_ns) && (parseInt(navigator.appVersion) == 4));
var is_mac = (userAgent.indexOf('mac') != -1);
/**
* Workaround for heinous IE bug - add special vBlength property to all strings
* This method is applied to ALL string objects automatically
*
* @return integer
*/
String.prototype.vBlength = function()
{
return (is_ie && this.indexOf("\n") != -1) ? this.replace(/\r?\n/g, "_").length : this.length;
}
/**
* Overrides IE's original String.prototype.substr to accept negative values
*
* @param integer Substring start position
* @param integer Substring length
*
* @return string
*/
if ("1234".substr(-2, 2) == "12") // (which would be incorrect)
{
String.prototype.substr_orig = String.prototype.substr;
String.prototype.substr = function(start, length)
{
if (typeof(length) == "undefined")
{
return this.substr_orig((start < 0 ? this.length + start : start));
}
else
{
return this.substr_orig((start < 0 ? this.length + start : start), length);
}
};
}
/**
* Define Array.shift() for browsers that don't have it
*/
if (typeof Array.prototype.shift === 'undefined')
{
Array.prototype.shift = function()
{
for(var i = 0, b = this[0], l = this.length-1; i < l; i++)
{
this[i] = this[i + 1];
}
this.length--;
return b;
};
}
/**
* Function to emulate document.getElementById
*
* @param string Object ID
*
* @return mixed null if not found, object if found
*/
function fetch_object(idname)
{
if (document.getElementById)
{
return document.getElementById(idname);
}
else if (document.all)
{
return document.all[idname];
}
else if (document.layers)
{
return document.layers[idname];
}
else
{
return null;
}
}
/**
* Function to emulate document.getElementsByTagName
*
* @param object Parent object (eg: document)
* @param string Tag type (eg: 'td')
*
* @return array
*/
function fetch_tags(parentobj, tag)
{
if (parentobj == null)
{
return new Array();
}
else if (typeof parentobj.getElementsByTagName != 'undefined')
{
return parentobj.getElementsByTagName(tag);
}
else if (parentobj.all && parentobj.all.tags)
{
return parentobj.all.tags(tag);
}
else
{
return new Array();
}
}
/**
* Function to count the number of tags in an object
*
* @param object Parent object (eg: document)
* @param string Tag type (eg: 'td')
*
* @return integer
*/
function fetch_tag_count(parentobj, tag)
{
return fetch_tags(parentobj, tag).length;
}
// #############################################################################
// Event handlers
/**
* Handles the different event models of different browsers and prevents event bubbling
*
* @param event Event object
*
* @return event
*/
function do_an_e(eventobj)
{
if (!eventobj || is_ie)
{
window.event.returnValue = false;
window.event.cancelBubble = true;
return window.event;
}
else
{
eventobj.stopPropagation();
eventobj.preventDefault();
return eventobj;
}
}
/**
* Handles the different event models of different browsers and prevents event bubbling in a lesser way than do_an_e()
*
* @param event Event object
*
* @return event
*/
function e_by_gum(eventobj)
{
if (!eventobj || is_ie)
{
window.event.cancelBubble = true;
return window.event;
}
else
{
if (eventobj.target.type == 'submit')
{
// naughty safari
eventobj.target.form.submit();
}
eventobj.stopPropagation();
return eventobj;
}
}
// #############################################################################
// Message manipulation and validation
/**
* Checks that a message is valid for submission to PHP
*
* @param string Message text
* @param mixed Either subject text (if you want to make sure it exists) or 0 if you don't care
* @param integer Minimum acceptable character limit for the message
*
* @return boolean
*/
function validatemessage(messagetext, subjecttext, minchars)
{
if (is_kon || is_saf || is_webtv)
{
// ignore less-than-capable browsers
return true;
}
else if (subjecttext.length < 1)
{
// subject not specified
alert(vbphrase['must_enter_subject']);
return false;
}
else
{
var stripped = PHP.trim(stripcode(messagetext, false, ignorequotechars));
if (stripped.length < minchars)
{
// minimum message length not met
alert(construct_phrase(vbphrase['message_too_short'], minchars));
return false;
}
else if (typeof(document.forms.vbform) != 'undefined' && typeof(document.forms.vbform.imagestamp) != 'undefined')
{
// This form has image verification enabled
document.forms.vbform.imagestamp.failed = false;
if (document.forms.vbform.imagestamp.value.length != 6)
{
alert(vbphrase['complete_image_verification']);
document.forms.vbform.imagestamp.failed = true;
document.forms.vbform.imagestamp.focus();
return false;
}
else
{
return true;
}
}
else
{
// everything seems ok
return true;
}
}
}
/**
* Strips quotes and bbcode tags from text
*
* @param string Text to manipulate
* @param boolean If true, strip <x> otherwise strip [x]
* @param boolean If true, strip all [quote]...contents...[/quote]
*
* @return string
*/
function stripcode(str, ishtml, stripquotes)
{
if (!is_regexp)
{
return str;
}
if (stripquotes)
{
var start_time = new Date().getTime();
while ((startindex = PHP.stripos(str, '[quote')) !== false)
{
if (new Date().getTime() - start_time > 2000)
{
// while loop has been running for over 2 seconds and has probably gone infinite
break;
}
if ((stopindex = PHP.stripos(str, '[/quote]')) !== false)
{
fragment = str.substr(startindex, stopindex - startindex + 8);
str = str.replace(fragment, '');
}
else
{
break;
}
str = PHP.trim(str);
}
}
if (ishtml)
{
// exempt image tags -- they need to count as characters in the string
// as the do as BB codes
str = str.replace(/<img[^>]+src="([^"]+)"[^>]*>/gi, '$1');
var html1 = new RegExp("<(\\w+)[^>]*>", 'gi');
var html2 = new RegExp("<\\/\\w+>", 'gi');
str = str.replace(html1, '');
str = str.replace(html2, '');
var html3 = new RegExp('( )', 'gi');
str = str.replace(html3, ' ');
}
else
{
var bbcode1 = new RegExp("\\[(\\w+)(=[^\\]]*)?\\]", 'gi');
var bbcode2 = new RegExp("\\[\\/(\\w+)\\]", 'gi');
str = str.replace(bbcode1, '');
str = str.replace(bbcode2, '');
}
return str;
}
// #############################################################################
// vB_PHP_Emulator class
// #############################################################################
/**
* PHP Function Emulator Class
*/
function vB_PHP_Emulator()
{
}
// =============================================================================
// vB_PHP_Emulator Methods
/**
* Find a string within a string (case insensitive)
*
* @param string Haystack
* @param string Needle
* @param integer Offset
*
* @return mixed Not found: false / Found: integer position
*/
vB_PHP_Emulator.prototype.stripos = function(haystack, needle, offset)
{
if (typeof offset == 'undefined')
{
offset = 0;
}
index = haystack.toLowerCase().indexOf(needle.toLowerCase(), offset);
return (index == -1 ? false : index);
}
/**
* Trims leading whitespace
*
* @param string String to trim
*
* @return string
*/
vB_PHP_Emulator.prototype.ltrim = function(str)
{
return str.replace(/^\s+/g, '');
}
/**
* Trims trailing whitespace
*
* @param string String to trim
*
* @return string
*/
vB_PHP_Emulator.prototype.rtrim = function(str)
{
return str.replace(/(\s+)$/g, '');
}
/**
* Trims leading and trailing whitespace
*
* @param string String to trim
*
* @return string
*/
vB_PHP_Emulator.prototype.trim = function(str)
{
return this.ltrim(this.rtrim(str));
}
/**
* Emulation of PHP's preg_quote()
*
* @param string String to process
*
* @return string
*/
vB_PHP_Emulator.prototype.preg_quote = function(str)
{
// replace + { } ( ) [ ] | / ? ^ $ \ . = ! < > : * with backslash+character
return str.replace(/(\+|\{|\}|\(|\)|\[|\]|\||\/|\?|\^|\$|\\|\.|\=|\!|\<|\>|\:|\*)/g, "\\$1");
}
/**
* Emulates PHP's preg_match_all()... sort of
*
* @param string Haystack
* @param string Regular expression - to be inserted into RegExp(x)
*
* @return mixed Array on match, false on no match
*/
vB_PHP_Emulator.prototype.match_all = function(string, regex)
{
var gmatch = string.match(RegExp(regex, "gim"));
if (gmatch)
{
var matches = new Array();
var iregex = new RegExp(regex, "im");
for (var i = 0; i < gmatch.length; i++)
{
matches[matches.length] = gmatch[i].match(iregex);
}
return matches;
}
else
{
return false;
}
}
/**
* Emulates unhtmlspecialchars in vBulletin
*
* @param string String to process
*
* @return string
*/
vB_PHP_Emulator.prototype.unhtmlspecialchars = function(str)
{
f = new Array(/</g, />/g, /"/g, /&/g);
r = new Array('<', '>', '"', '&');
for (var i in f)
{
str = str.replace(f[i], r[i]);
}
return str;
}
/**
* Unescape CDATA from vB_AJAX_XML_Builder PHP class
*
* @param string Escaped CDATA
*
* @return string
*/
vB_PHP_Emulator.prototype.unescape_cdata = function(str)
{
var r1 = /<\=\!\=\[\=C\=D\=A\=T\=A\=\[/g;
var r2 = /\]\=\]\=>/g;
return str.replace(r1, '<![CDATA[').replace(r2, ']]>');
}
/**
* Emulates PHP's htmlspecialchars()
*
* @param string String to process
*
* @return string
*/
vB_PHP_Emulator.prototype.htmlspecialchars = function(str)
{
//var f = new Array(/&(?!#[0-9]+;)/g, /</g, />/g, /"/g);
var f = new Array(
(is_mac && is_ie ? new RegExp('&', 'g') : new RegExp('&(?!#[0-9]+;)', 'g')),
new RegExp('<', 'g'),
new RegExp('>', 'g'),
new RegExp('"', 'g')
);
var r = new Array(
'&',
'<',
'>',
'"'
);
for (var i = 0; i < f.length; i++)
{
str = str.replace(f[i], r[i]);
}
return str;
}
/**
* Searches an array for a value
*
* @param string Needle
* @param array Haystack
* @param boolean Case insensitive
*
* @return integer Not found: -1 / Found: integer index
*/
vB_PHP_Emulator.prototype.in_array = function(ineedle, haystack, caseinsensitive)
{
var needle = new String(ineedle);
if (caseinsensitive)
{
needle = needle.toLowerCase();
for (var i in haystack)
{
if (haystack[i].toLowerCase() == needle)
{
return i;
}
}
}
else
{
for (var i in haystack)
{
if (haystack[i] == needle)
{
return i;
}
}
}
return -1;
}
/**
* Emulates PHP's strpad()
*
* @param string Text to pad
* @param integer Length to pad
* @param string String with which to pad
*
* @return string
*/
vB_PHP_Emulator.prototype.str_pad = function(text, length, padstring)
{
text = new String(text);
padstring = new String(padstring);
if (text.length < length)
{
padtext = new String(padstring);
while (padtext.length < (length - text.length))
{
padtext += padstring;
}
text = padtext.substr(0, (length - text.length)) + text;
}
return text;
}
/**
* A sort of emulation of PHP's urlencode - not 100% the same, but accomplishes the same thing
*
* @param string String to encode
*
* @return string
*/
vB_PHP_Emulator.prototype.urlencode = function(text)
{
text = escape(text.toString()).replace(/\+/g, "%2B");
// this escapes 128 - 255, as JS uses the unicode code points for them.
// This causes problems with submitting text via AJAX with the UTF-8 charset.
var matches = text.match(/(%([0-9A-F]{2}))/gi);
if (matches)
{
for (var matchid = 0; matchid < matches.length; matchid++)
{
var code = matches[matchid].substring(1,3);
if (parseInt(code, 16) >= 128)
{
text = text.replace(matches[matchid], '%u00' + code);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -