📄 vbulletin_global.js
字号:
{
exclude = new Array();
exclude[0] = 'keepattachments';
exclude[1] = 'allbox';
exclude[2] = 'removeall';
js_toggle_all(formobj, 'checkbox', '', exclude, formobj.allbox.checked);
}
/**
* Sets all <input type="radio" /> groups to have a particular option checked
*
* @param object Form object
* @param mixed Selected option
*/
function js_check_all_option(formobj, option)
{
exclude = new Array();
exclude[0] = 'useusergroup';
js_toggle_all(formobj, 'radio', option, exclude, true);
}
/**
* Alias to js_check_all
*/
function checkall(formobj)
{
js_check_all(formobj);
}
/**
* Alias to js_check_all_option
*/
function checkall_option(formobj, option)
{
js_check_all_option(formobj, option);
}
/**
* Resize function for CP textareas
*
* @param integer If positive, size up, otherwise size down
* @param string ID of the textarea
*
* @return boolean false
*/
function resize_textarea(to, id)
{
if (to < 0)
{
var rows = -5;
var cols = -10;
}
else
{
var rows = 5;
var cols = 10;
}
var textarea = fetch_object(id);
if (typeof textarea.orig_rows == 'undefined')
{
textarea.orig_rows = textarea.rows;
textarea.orig_cols = textarea.cols;
}
var newrows = textarea.rows + rows;
var newcols = textarea.cols + cols;
if (newrows >= textarea.orig_rows && newcols >= textarea.orig_cols)
{
textarea.rows = newrows;
textarea.cols = newcols;
}
return false;
}
// #############################################################################
// Collapsible element handlers
/**
* Toggles the collapse state of an object, and saves state to 'vbulletin_collapse' cookie
*
* @param string Unique ID for the collapse group
*
* @return boolean false
*/
function toggle_collapse(objid)
{
if (!is_regexp)
{
return false;
}
obj = fetch_object('collapseobj_' + objid);
img = fetch_object('collapseimg_' + objid);
cel = fetch_object('collapsecel_' + objid);
if (!obj)
{
// nothing to collapse!
if (img)
{
// hide the clicky image if there is one
img.style.display = 'none';
}
return false;
}
if (obj.style.display == 'none')
{
obj.style.display = '';
save_collapsed(objid, false);
if (img)
{
img_re = new RegExp("_collapsed\\.gif$");
img.src = img.src.replace(img_re, '.gif');
}
if (cel)
{
cel_re = new RegExp("^(thead|tcat)(_collapsed)$");
cel.className = cel.className.replace(cel_re, '$1');
}
}
else
{
obj.style.display = 'none';
save_collapsed(objid, true);
if (img)
{
img_re = new RegExp("\\.gif$");
img.src = img.src.replace(img_re, '_collapsed.gif');
}
if (cel)
{
cel_re = new RegExp("^(thead|tcat)$");
cel.className = cel.className.replace(cel_re, '$1_collapsed');
}
}
return false;
}
/**
* Updates vbulletin_collapse cookie with collapse preferences
*
* @param string Unique ID for the collapse group
* @param boolean Add a cookie
*/
function save_collapsed(objid, addcollapsed)
{
var collapsed = fetch_cookie('vbulletin_collapse');
var tmp = new Array();
if (collapsed != null)
{
collapsed = collapsed.split('\n');
for (var i in collapsed)
{
if (collapsed[i] != objid && collapsed[i] != '')
{
tmp[tmp.length] = collapsed[i];
}
}
}
if (addcollapsed)
{
tmp[tmp.length] = objid;
}
expires = new Date();
expires.setTime(expires.getTime() + (1000 * 86400 * 365));
set_cookie('vbulletin_collapse', tmp.join('\n'), expires);
}
// #############################################################################
// Event Handlers for PageNav menus
/**
* Class to handle pagenav events
*/
function vBpagenav()
{
}
/**
* Handles clicks on pagenav menu control objects
*/
vBpagenav.prototype.controlobj_onclick = function(e)
{
this._onclick(e);
var inputs = fetch_tags(this.menu.menuobj, 'input');
for (var i = 0; i < inputs.length; i++)
{
if (inputs[i].type == 'text')
{
inputs[i].focus();
break;
}
}
};
/**
* Submits the pagenav form... sort of
*/
vBpagenav.prototype.form_gotopage = function(e)
{
if ((pagenum = parseInt(fetch_object('pagenav_itxt').value, 10)) > 0)
{
window.location = this.addr + '&page=' + pagenum;
}
return false;
};
/**
* Handles clicks on the 'Go' button in pagenav popups
*/
vBpagenav.prototype.ibtn_onclick = function(e)
{
return this.form.gotopage();
};
/**
* Handles keypresses in the text input of pagenav popups
*/
vBpagenav.prototype.itxt_onkeypress = function(e)
{
return ((e ? e : window.event).keyCode == 13 ? this.form.gotopage() : true);
};
// #############################################################################
// DHTML Popup Menu Handling (complements vbulletin_menu.js)
/**
* Wrapper for vBmenu.register
*
* @param string Control ID
* @param boolean No image (true)
* @param boolean Does nothing any more
*/
function vbmenu_register(controlid, noimage, datefield)
{
if (typeof(vBmenu) == "object")
{
return vBmenu.register(controlid, noimage);
}
else
{
return false;
}
}
// #############################################################################
// Stuff that really doesn't fit anywhere else
/**
* Sets an element and all its children to be 'unselectable'
*
* @param object Object to be made unselectable
*/
function set_unselectable(obj)
{
if (!is_ie4 && typeof obj.tagName != 'undefined')
{
if (obj.hasChildNodes())
{
for (var i = 0; i < obj.childNodes.length; i++)
{
set_unselectable(obj.childNodes[i]);
}
}
obj.unselectable = 'on';
}
}
/**
* Fetches the sessionhash from the SESSIONURL variable
*
* @return string
*/
function fetch_sessionhash()
{
return (SESSIONURL == '' ? '' : SESSIONURL.substr(2, 32));
}
/**
* Emulates the PHP version of vBulletin's construct_phrase() sprintf wrapper
*
* @param string String containing %1$s type replacement markers
* @param string First replacement
* @param string Nth replacement
*
* @return string
*/
function construct_phrase()
{
if (!arguments || arguments.length < 1 || !is_regexp)
{
return false;
}
var args = arguments;
var str = args[0];
var re;
for (var i = 1; i < args.length; i++)
{
re = new RegExp("%" + i + "\\$s", 'gi');
str = str.replace(re, args[i]);
}
return str;
}
/**
* Handles the quick style/language options in the footer
*
* @param object Select object
* @param string Type (style or language)
*/
function switch_id(selectobj, type)
{
var id = selectobj.options[selectobj.selectedIndex].value;
if (id == '')
{
return;
}
var url = new String(window.location);
var fragment = new String('');
// get rid of fragment
url = url.split('#');
// deal with the fragment first
if (url[1])
{
fragment = '#' + url[1];
}
// deal with the main url
url = url[0];
// remove id=x& from main bit
if (url.indexOf(type + 'id=') != -1 && is_regexp)
{
re = new RegExp(type + "id=\\d+&?");
url = url.replace(re, '');
}
// add the ? to the url if needed
if (url.indexOf('?') == -1)
{
url += '?';
}
else
{
// make sure that we have a valid character to join our id bit
lastchar = url.substr(url.length - 1);
if (lastchar != '&' && lastchar != '?')
{
url += '&';
}
}
window.location = url + type + 'id=' + id + fragment;
}
/**
* Takes the 'alt' attribute for an image and attaches it to the 'title' attribute
*
* @param object Image object
*/
function img_alt_2_title(img)
{
if (!img.title && img.alt != '')
{
img.title = img.alt;
}
}
// #############################################################################
// Initialize a PostBit
/**
* This function runs all the necessary Javascript code on a PostBit
* after it has been loaded via AJAX. Don't use this method before a
* complete page load or you'll have problems.
*
* @param object Object containing postbits
*/
function PostBit_Init(obj, postid)
{
console.log("PostBit Init: %d", postid);
if (typeof vBmenu != 'undefined')
{
// init profile menu(s)
var divs = fetch_tags(obj, 'div');
for (var i = 0; i < divs.length; i++)
{
if (divs[i].id && divs[i].id.substr(0, 9) == 'postmenu_')
{
vBmenu.register(divs[i].id, true);
}
}
}
if (typeof vB_QuickEditor != 'undefined')
{
// init quick edit controls
vB_AJAX_QuickEdit_Init(obj);
}
if (typeof vB_QuickReply != 'undefined')
{
// init quick reply button
qr_init_buttons(obj);
}
if (typeof mq_init != 'undefined')
{
// init quick reply button
mq_init(obj);
}
if (typeof vBrep != 'undefined')
{
if (typeof postid != 'undefined' && typeof postid != 'null')
{
vbrep_register(postid);
}
}
if (typeof inlineMod != 'undefined')
{
im_init(obj);
}
}
// #############################################################################
// Main vBulletin Javascript Initialization
/**
* This function runs (almost) at the end of script loading on most vBulletin pages
*
* It sets up things like image alt->title tags, turns on the popup menu system etc.
*
* @return boolean
*/
function vBulletin_init()
{
// don't bother doing any exciting stuff for WebTV
if (is_webtv)
{
return false;
}
// set 'title' tags for image elements
var imgs = fetch_tags(document, 'img');
for (var i = 0; i < imgs.length; i++)
{
img_alt_2_title(imgs[i]);
}
// finalize popup menus
if (typeof vBmenu == 'object')
{
// close all menus on document click or resize
if (typeof(YAHOO) != "undefined")
{
YAHOO.util.Event.on(document, "click", vbmenu_hide);
YAHOO.util.Event.on(window, "resize", vbmenu_hide);
}
else if (window.attachEvent && !is_saf)
{
document.attachEvent('onclick', vbmenu_hide);
window.attachEvent('onresize', vbmenu_hide);
}
else if (document.addEventListener && !is_saf)
{
document.addEventListener('click', vbmenu_hide, false);
window.addEventListener('resize', vbmenu_hide, false);
}
else
{
window.onclick = vbmenu_hide;
window.onresize = vbmenu_hide;
}
// add popups to pagenav elements
var pagenavs = fetch_tags(document, 'td');
for (var n = 0; n < pagenavs.length; n++)
{
if (pagenavs[n].hasChildNodes() && pagenavs[n].firstChild.name && pagenavs[n].firstChild.name.indexOf('PageNav') != -1)
{
var addr = pagenavs[n].title;
pagenavs[n].title = '';
pagenavs[n].innerHTML = '';
pagenavs[n].id = 'pagenav.' + n;
var pn = vBmenu.register(pagenavs[n].id);
if (is_saf)
{
pn.controlobj._onclick = pn.controlobj.onclick;
pn.controlobj.onclick = vBpagenav.prototype.controlobj_onclick;
}
}
}
// process the pagenavs popup form
if (typeof addr != 'undefined')
{
fetch_object('pagenav_form').addr = addr;
fetch_object('pagenav_form').gotopage = vBpagenav.prototype.form_gotopage;
fetch_object('pagenav_ibtn').onclick = vBpagenav.prototype.ibtn_onclick;
fetch_object('pagenav_itxt').onkeypress = vBpagenav.prototype.itxt_onkeypress;
}
// activate the menu system
vBmenu.activate(true);
}
// the new init system
vBulletin.init();
return true;
}
// #############################################################################
// vBulletin Javascript Framework
/**
* General class for handling custom events and custom controls
*/
function vBulletin_Framework()
{
/**
* @var array Array of elements to be passed to control init functions
* @var array Array of AJAX load/save URLs
* @var array Array of YUI custom events
* @var date Current time
*/
this.elements = new Array();
this.ajaxurls = new Array();
this.events = new Array();
this.time = new Date();
// custom event to fire during class init
this.add_event("systemInit");
}
/**
* Initializes the object - usually called at end of footer template
*/
vBulletin_Framework.prototype.init = function()
{
this.events.systemInit.fire();
console.info("System Init Fired");
}
/**
* Emulates OOP class extension
*
* @param object Extended class
* @param object Base class
*/
vBulletin_Framework.prototype.extend = function(subClass, baseClass)
{
function inheritance() {}
inheritance.prototype = baseClass.prototype;
subClass.prototype = new inheritance();
subClass.prototype.constructor = subClass;
subClass.baseConstructor = baseClass;
subClass.superClass = baseClass.prototype;
}
/**
* Registers a custom control for later initialization
* Arguments 1-n are stored for later use
*
* @param string Control type (vB_DatePicker etc.)
* @param string HTML element ID
*/
vBulletin_Framework.prototype.register_control = function(controltype, element)
{
var args = new Array();
for (var i = 1; i < arguments.length; i++)
{
args.push(arguments[i]);
}
if (!this.elements[controltype])
{
console.info("Creating array vBulletin.elements[\"%s\"]", controltype);
this.elements[controltype] = new Array();
}
var x = this.elements[controltype].push(args);
console.log("vBulletin.elements[\"%s\"][%d] = %s", controltype, x-1, args.join(", "));
}
/**
* Registers AJAX load/save urls for a control
*
* @param Fetch URL
* @param Save URL
* @param List of elements to which these URLs apply
*/
vBulletin_Framework.prototype.register_ajax_urls = function(fetch, save, elements)
{
var fetch = fetch.split("?"); fetch[1] = SESSIONURL + "ajax=1&" + fetch[1].replace(/\{(\d+)(:\w+)?\}/gi, '%$1$s');
var save = save.split("?"); save[1] = SESSIONURL + "ajax=1&" + save[1].replace(/\{(\d+)(:\w+)?\}/gi, '%$1$s');
console.log("Register AJAX URLs for %s", elements);
for (var i = 0; i < elements.length; i++)
{
this.ajaxurls[elements[i]] = new Array(fetch, save);
}
}
/**
* Register a custom event
*
* @param string Event name
*/
vBulletin_Framework.prototype.add_event = function(eventname)
{
this.events[eventname] = (typeof YAHOO != 'undefined' ? new YAHOO.util.CustomEvent(eventname) : new null_event());
}
/**
* BC: Pass console calls to Firebug if it's available
*/
vBulletin_Framework.prototype.console = console.log;
// #############################################################################
// initialize the PHP function emulator
var PHP = new vB_PHP_Emulator();
// Create an instance of the vBulletin Framework object
var vBulletin = new vBulletin_Framework();
/*======================================================================*\
|| ####################################################################
|| # Downloaded: Sat Sep 29th 2007 21:52:37
|| # CVS: $RCSfile$ - $Revision: 17556 $
|| ####################################################################
\*======================================================================*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -