⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 functions.js

📁 开源MARC数据处理
💻 JS
字号:
/* $Id: functions.js,v 1.18 2002/02/10 09:29:50 loic1 Exp $ *//** * Displays an confirmation box beforme to submit a "DROP/DELETE/ALTER" query. * This function is called while clicking links * * @param   object   the link * @param   object   the sql query to submit * * @return  boolean  whether to run the query or not */function confirmLink(theLink, theSqlQuery, confirmMsg){    // Confirmation is not required in the configuration file    if (confirmMsg == '') {        return true;    }    //var confirmMsg  = 'Do you really want to ';    var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);    if (is_confirmed) {        theLink.href += '&is_js_confirmed=1';    }    return is_confirmed;} // end of the 'confirmLink()' function/** * Displays an error message if a "DROP DATABASE" statement is submitted * while it isn't allowed, else confirms a "DROP/DELETE/ALTER" query before * sumitting it if required. * This function is called by the 'checkSqlQuery()' js function. * * @param   object   the form * @param   object   the sql query textarea * * @return  boolean  whether to run the query or not * * @see     checkSqlQuery() */function confirmQuery(theForm1, sqlQuery1){    // Confirmation is not required in the configuration file    if (confirmMsg == '') {        return true;    }    // The replace function (js1.2) isn't supported    else if (typeof(sqlQuery1.value.replace) == 'undefined') {        return true;    }    // js1.2+ -> validation with regular expressions    else {        // "DROP DATABASE" statement isn't allowed        if (noDropDbMsg) {            var drop_re = new RegExp('DROP\\s+(IF EXISTS\\s+)?DATABASE', 'i');            if (drop_re.test(sqlQuery1.value)) {                alert(noDropDbMsg);                theForm1.reset();                sqlQuery1.focus();                return false;            } // end if        } // end if        // Confirms a "DROP/DELETE/ALTER" statement        var do_confirm_re_0 = new RegExp('DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE)', 'i');        var do_confirm_re_1 = new RegExp('ALTER TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP', 'i');        var do_confirm_re_2 = new RegExp('DELETE FROM', 'i');        if (do_confirm_re_0.test(sqlQuery1.value)            || do_confirm_re_1.test(sqlQuery1.value)            || do_confirm_re_2.test(sqlQuery1.value)) {            var message      = (sqlQuery1.value.length > 100)                             ? sqlQuery1.value.substr(0, 100) + '\n    ...'                             : sqlQuery1.value;            var is_confirmed = confirm(confirmMsg + ' :\n' + message);            // drop/delete/alter statement is confirmed -> update the            // "is_js_confirmed" form field so the confirm test won't be            // run on the server side and allows to submit the form            if (is_confirmed) {                theForm1.elements['is_js_confirmed'].value = 1;                return true;            }            // "DROP/DELETE/ALTER" statement is rejected -> do not submit            // the form            else {                window.focus();                sqlQuery1.focus();                return false;            } // end if (handle confirm box result)        } // end if (display confirm box)    } // end confirmation stuff    return true;} // end of the 'confirmQuery()' function/** * Displays an error message if the user submitted the sql query form with no * sql query, else checks for "DROP/DELETE/ALTER" statements * * @param   object   the form * * @return  boolean  always false * * @see     confirmQuery() */function checkSqlQuery(theForm){    var sqlQuery = theForm.elements['sql_query'];    var isEmpty  = 1;    // The replace function (js1.2) isn't supported -> basic tests    if (typeof(sqlQuery.value.replace) == 'undefined') {        isEmpty      = (sqlQuery.value == '') ? 1 : 0;        if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {            isEmpty  = (theForm.elements['sql_file'].value == '') ? 1 : 0;        }        if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {            isEmpty  = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');        }    }    // js1.2+ -> validation with regular expressions    else {        var space_re = new RegExp('\\s+');        isEmpty      = (sqlQuery.value.replace(space_re, '') == '') ? 1 : 0;        // Checks for "DROP/DELETE/ALTER" statements        if (!isEmpty && !confirmQuery(theForm, sqlQuery)) {            return false;        }        if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {            isEmpty  = (theForm.elements['sql_file'].value.replace(space_re, '') == '') ? 1 : 0;        }        if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {            isEmpty  = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');            isEmpty  = (theForm.elements['id_bookmark'].selectedIndex == 0);        }        if (isEmpty) {            theForm.reset();        }    }    if (isEmpty) {        sqlQuery.select();        alert(errorMsg0);        sqlQuery.focus();        return false;    }    return true;} // end of the 'checkSqlQuery()' function/** * Displays an error message if an element of a form hasn't been completed and * should be * * @param   object   the form * @param   string   the name of the form field to put the focus on * * @return  boolean  whether the form field is empty or not */function emptyFormElements(theForm, theFieldName){    var isEmpty  = 1;    var theField = theForm.elements[theFieldName];    // Whether the replace function (js1.2) is supported or not    var isRegExp = (typeof(theField.value.replace) != 'undefined');    if (!isRegExp) {        isEmpty      = (theField.value == '') ? 1 : 0;    } else {        var space_re = new RegExp('\\s+');        isEmpty      = (theField.value.replace(space_re, '') == '') ? 1 : 0;    }    if (isEmpty) {        theForm.reset();        theField.select();        alert(errorMsg0);        theField.focus();        return false;    }    return true;} // end of the 'emptyFormElements()' function/** * Ensures a value submitted in a form is numeric and is in a range * * @param   object   the form * @param   string   the name of the form field to check * @param   integer  the minimum authorized value * @param   integer  the maximum authorized value * * @return  boolean  whether a valid number has been submitted or not */function checkFormElementInRange(theForm, theFieldName, min, max){    var theField         = theForm.elements[theFieldName];    var val              = parseInt(theField.value);    if (typeof(min) == 'undefined') {        min = 0;    }    if (typeof(max) == 'undefined') {        max = Number.MAX_VALUE;    }    // It's not a number    if (isNaN(val)) {        theField.select();        alert(errorMsg1);        theField.focus();        return false;    }    // It's a number but it is not between min and max    else if (val < min || val > max) {        theField.select();        alert(val + errorMsg2);        theField.focus();        return false;    }    // It's a valid number    else {        theField.value = val;    }    return true;} // end of the 'checkFormElementInRange()' function/** * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped' * checkboxes is consistant * * @param   object   the form * @param   string   a code for the action that causes this function to be run * * @return  boolean  always true */function checkTransmitDump(theForm, theAction){    var formElts = theForm.elements;    // 'zipped' option has been checked    if (theAction == 'zip' && formElts['zip'].checked) {        if (!formElts['asfile'].checked) {            theForm.elements['asfile'].checked = true;        }        if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {            theForm.elements['gzip'].checked = false;        }        if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {            theForm.elements['bzip'].checked = false;        }    }    // 'gzipped' option has been checked    else if (theAction == 'gzip' && formElts['gzip'].checked) {        if (!formElts['asfile'].checked) {            theForm.elements['asfile'].checked = true;        }        if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {            theForm.elements['zip'].checked = false;        }        if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {            theForm.elements['bzip'].checked = false;        }    }    // 'bzipped' option has been checked    else if (theAction == 'bzip' && formElts['bzip'].checked) {        if (!formElts['asfile'].checked) {            theForm.elements['asfile'].checked = true;        }        if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {            theForm.elements['zip'].checked = false;        }        if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {            theForm.elements['gzip'].checked = false;        }    }    // 'transmit' option has been unchecked    else if (theAction == 'transmit' && !formElts['asfile'].checked) {        if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {            theForm.elements['zip'].checked = false;        }        if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {            theForm.elements['gzip'].checked = false;        }        if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {            theForm.elements['bzip'].checked = false;        }    }    return true;} // end of the 'checkTransmitDump()' function/** * The global array below will be used inside the "setPointer()" function */var markedRow = new Array();/** * Sets/unsets the pointer in browse mode * * @param   object   the table row * @param   object   the color to use for this row * @param   object   the background color * * @return  boolean  whether pointer is set or not */function setPointer(theRow, thePointerColor, theNormalBgColor){    var theCells = null;    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {        return false;    }    if (typeof(document.getElementsByTagName) != 'undefined') {        theCells = theRow.getElementsByTagName('td');    }    else if (typeof(theRow.cells) != 'undefined') {        theCells = theRow.cells;    }    else {        return false;    }    var rowCellsCnt  = theCells.length;    var currentColor = null;    var newColor     = null;    // Opera does not return valid values with "getAttribute"    if (typeof(window.opera) == 'undefined'        && typeof(theCells[0].getAttribute) != 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {        currentColor = theCells[0].getAttribute('bgcolor');        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())                     ? theNormalBgColor                     : thePointerColor;        for (var c = 0; c < rowCellsCnt; c++) {            theCells[c].setAttribute('bgcolor', newColor, 0);        } // end for    }    else {        currentColor = theCells[0].style.backgroundColor;        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())                     ? theNormalBgColor                     : thePointerColor;        for (var c = 0; c < rowCellsCnt; c++) {            theCells[c].style.backgroundColor = newColor;        }    }    return true;} // end of the 'setPointer()' function/** * Checks/unchecks all tables * * @param   string   the form name * @param   boolean  whether to check or to uncheck the element * * @return  boolean  always true */function setCheckboxes(the_form, do_check){    var elts      = document.forms[the_form].elements['selected_tbl[]'];    var elts_cnt  = elts.length;    for (var i = 0; i < elts_cnt; i++) {        elts[i].checked = do_check;    } // end for    return true;} // end of the 'setCheckboxes()' function/**  * Checks/unchecks all options of a <select> element  *  * @param   string   the form name  * @param   string   the element name  * @param   boolean  whether to check or to uncheck the element  *  * @return  boolean  always true  */function setSelectOptions(the_form, the_select, do_check){    var selectObject = document.forms[the_form].elements[the_select];    var selectCount  = selectObject.length;    for (var i = 0; i < selectCount; i++) {        selectObject.options[i].selected = do_check;    } // end for    return true;} // end of the 'setSelectOptions()' functionfunction explain(tagnum, tagname, tagdesc, tagdeli, desclang, delilang) {newwin = window.open('','Help','top=150,left=150,width=325,height=300, scrollbars=yes');if (!newwin.opener) newwin.opener = self;with (newwin.document)   {	open();	write('<html><title>PhpMyLibrary USMARC Definition</title>');	write('<body onLoad="document.form.box.focus()"><form name=form>');	write('<b>' + tagnum + '</b>&nbsp;'+ tagname + '<br>');	write('<br><b>' + desclang + ' :</b><br> ' + tagdesc + '<br>');	write('<br><b>' + delilang + ' :</b><br> ' + tagdeli + '<br><br>'); 	write('<input type=button value="Close" onClick=window.close()>');	write('</center></form></body></html>');	close();   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -