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

📄 common.js

📁 giao trinh cong nghe phan mem
💻 JS
📖 第 1 页 / 共 2 页
字号:
// ===========================================================================// eXe// Copyright 2004-2005, University of Auckland//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA// ===========================================================================// This module is for the common Javascript used in all webpages.// Called upon loading the page this function clears the hidden// action and object fields so they can be used by submitLinkvar objBrowse = navigator.appName;// An array of js strings to evaluate on document loadvar onLoadHandlers = [clearHidden];var beforeSubmitHandlers = new Array();// Called on document loadfunction onLoadHandler() {    runFuncArray(onLoadHandlers)}// Calls function in an array where each 'row' of the array is in the format:// func// or// [func, arg]function runFuncArray(handlers) {    for (var i=0; i < handlers.length; i++) {        var row = handlers[i]         if (typeof row=="function")            row()        else {            // row[0] is a function, row[1] are its args            row[0].apply(this, row[1]);        }    }}// Asks the user for an image, returns the path or an empty stringfunction askUserForImage(multiple) {    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");    var nsIFilePicker = Components.interfaces.nsIFilePicker;    var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);    if (multiple) {        var mode = nsIFilePicker.modeOpenMultiple;    } else {        var mode = nsIFilePicker.modeOpen;    }    fp.init(window, "Select an image", mode);    fp.appendFilter("Image Files", "*.jpg; *.jpeg; *.png; *.gif");    fp.appendFilters(nsIFilePicker.filterAll);    var res = fp.show();    if (res == nsIFilePicker.returnOK) {        if (multiple) {            var result = new String("");            var lastFile = null;            var file     = null;            while (fp.files.hasMoreElements()) {                file = fp.files.getNext().QueryInterface(Components.interfaces.nsIFile)                if (file == lastFile) {                    break;                }                lastFile = file;                if (result != "") {                    result += "&";                }                result += escape(file.path);            }            return result;        } else {            return fp.file.path;        }    } else {        return ""    }}// Called by the user to provide an image or flash file name to add to the packagefunction addImage(elementId) {    var imagePath = askUserForImage()    if (imagePath != "") {        var image = document.getElementById('img'+elementId);        image.removeAttribute('width');        image.removeAttribute('height');        var path  = document.getElementById('path'+elementId);        path.value = imagePath;        image.src  = 'file://'+imagePath;    }}// Called by the user to provide an image or flash file name to add to the packagefunction addJpgImage(elementId) {    var imagePath = askUserForJpgImage()    if (imagePath != "") {        var image = document.getElementById('img'+elementId);        image.removeAttribute('width');        image.removeAttribute('height');        var path  = document.getElementById('path'+elementId);        path.value = imagePath;        image.src  = 'file://'+imagePath;    }}// Asks the user for a jpg image, returns the path or an empty stringfunction askUserForJpgImage(multiple) {    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");    var nsIFilePicker = Components.interfaces.nsIFilePicker;    var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);    if (multiple) {        var mode = nsIFilePicker.modeOpenMultiple;    } else {        var mode = nsIFilePicker.modeOpen;    }    fp.init(window, "Select an image ", mode);    fp.appendFilter("JPEG Files", "*.jpg; *.jpeg");    fp.appendFilters(nsIFilePicker.filterAll);    var res = fp.show();    if (res == nsIFilePicker.returnOK) {        if (multiple) {            var result = new String("");            var lastFile = null;            var file     = null;            while (fp.files.hasMoreElements()) {                file = fp.files.getNext().QueryInterface(Components.interfaces.nsIFile)                if (file == lastFile) {                    break;                }                lastFile = file;                if (result != "") {                    result += "&";                }                result += escape(file.path);            }            return result;        } else {            return fp.file.path;        }    } else {        return ""    }}// Called by the user to provide one or more image files name to add to the packagefunction addGalleryImage(galleryId) {    var imagePath = askUserForImage(true);    if (imagePath != "") {        // Save the change        submitLink("gallery.addImage."+imagePath, galleryId, true);    }}// Called by the user to change an existing gallery imagefunction changeGalleryImage(galleryId, imageId) {    var imagePath = askUserForImage(false)    if (imagePath != "") {        // Save the change        submitLink("gallery.changeImage."+imageId+"."+imagePath, galleryId, true);    }}function imageChanged(event) {    var id = event.currentTarget.getAttribute('id');    var elementId = id.substring(3, id.length);    var image  = document.getElementById('img'+elementId);    var width  = document.getElementById('width'+elementId);    var height = document.getElementById('height'+elementId);    width.value  = image.width;    height.value = image.height;}function magnifierImageChanged(event) {    var id = event.currentTarget.getAttribute('id');    var elementId = id.substring(3, id.length);    var image  = document.getElementById('img'+elementId);    var width  = document.getElementById('width'+elementId);    var height = document.getElementById('height'+elementId);    image.removeAttribute('height');    if (image.width > 700){        image.width = 600                }    if (image.width <= 700 && image.width > 300)        image.width = image.width * 0.7            if (image.height > 270){        width.value = image.width + 84    }else{        width.value = image.width + 144    }    height.value = image.height + 24    if (width.value < 180)        width.value = 180    if (height.value < 160)        height.value = 160}function changeImageWidth(elementId) {    var image  = document.getElementById('img'+elementId);    var width  = document.getElementById('width'+elementId);    var height = document.getElementById('height'+elementId);    image.removeAttribute('height');    if (width.value) {        image.width  = width.value;    } else {        image.removeAttribute('width');        width.value  = image.width;    }    height.value = image.height;}function changeMagnifierImageWidth(elementId) {    var image  = document.getElementById('img'+elementId);    var width  = document.getElementById('width'+elementId);    var height = document.getElementById('height'+elementId);    image.removeAttribute('height');    if (width.value) {        image.width  = width.value - 84;    } else {        image.removeAttribute('width');    }    if (image.width > 600){        image.removeAttribute('height')        image.width = 600;    }    if (image.height > 270){        width.value = image.width + 84    }else{        width.value = image.width + 144    }    height.value = image.height + 24    if (width.value < 180)        width.value = 180    if (height.value < 160)        height.value = 160}function changeMagnifierImageHeight(elementId) {    var image  = document.getElementById('img'+elementId);    var width  = document.getElementById('width'+elementId);    var height = document.getElementById('height'+elementId);    image.removeAttribute('width');    if (height.value) {        image.height = height.value - 24;    } else {        image.removeAttribute('height');    }    if (image.width > 600){        image.removeAttribute('height');        image.width = 600    }    if (image.height > 270){        width.value = image.width + 84    }else{        width.value = image.width + 144    }    height.value = image.height + 24    if (width.value < 180)        width.value = 180    if (height.value < 160)        height.value = 160}function changeImageHeight(elementId) {    var image  = document.getElementById('img'+elementId);    var width  = document.getElementById('width'+elementId);    var height = document.getElementById('height'+elementId);    image.removeAttribute('width');    if (height.value) {        image.height = height.value;    } else {        image.removeAttribute('height');        height.value = image.height;    }    width.value  = image.width;}// Called by the user to provide a flash movie file name to add to the packagefunction addFlashMovie(blockId) {    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");    var nsIFilePicker = Components.interfaces.nsIFilePicker;    var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);    fp.init(window, "Select a file", nsIFilePicker.modeOpen);    fp.appendFilter("Flash Movie", "*.flv");    fp.appendFilters(nsIFilePicker.filterAll);    var res = fp.show();    if (res == nsIFilePicker.returnOK) {        var path  = document.getElementById('path'+blockId);        path.type  = 'text';        path.value = fp.file.path;    }}// Called by the user to provide a flash file name to add to the packagefunction addFlash(blockId) {    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");    var nsIFilePicker = Components.interfaces.nsIFilePicker;    var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);    fp.init(window, "Select a file", nsIFilePicker.modeOpen);    fp.appendFilter("Flash Object", "*.swf");    fp.appendFilters(nsIFilePicker.filterAll);    var res = fp.show();    if (res == nsIFilePicker.returnOK) {        var path  = document.getElementById('path'+blockId);        path.type  = 'text';        path.value = fp.file.path;    }}// Called by the user to provide a file name to add to the packagefunction addFile(blockId) {    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");    var nsIFilePicker = Components.interfaces.nsIFilePicker;    var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);    fp.init(window, "Select a file", nsIFilePicker.modeOpen);    fp.appendFilters(nsIFilePicker.filterAll);    var res = fp.show();    if (res == nsIFilePicker.returnOK) {        var path  = document.getElementById('path'+blockId);        path.value = fp.file.path;    }}function uploadFile(blockId) {    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");    var nsIFilePicker = Components.interfaces.nsIFilePicker;    var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);    fp.init(window, "Select a file", nsIFilePicker.modeOpen);    fp.appendFilters(nsIFilePicker.filterAll);    var res = fp.show();    if (res == nsIFilePicker.returnOK) {        var path  = document.getElementById('path'+blockId);        path.value = fp.file.path;    }    var theForm = top["authoringIFrame1"].document.getElementById('contentForm')    if (!theForm) {        // try and find the form for the authoring page        theForm = document.getElementById('contentForm')    }    theForm.submit();}function showMe(ident, w, h){    var elmDiv = document.getElementById('popupmessage');    hideMe();            if (!elmDiv ||         elmDiv.innerHTML != document.getElementById(ident).innerHTML){        elmDiv = document.createElement('div');        elmDiv.id = 'popupmessage';        elmDiv.className="popupDiv";        elmDiv.style.cssText = 'position:absolute; left: ' +                                (xpos) + 'px; top: '+(ypos - h/2) +                                'px; width: ' + w + 'px;';        elmDiv.innerHTML = document.getElementById(ident).innerHTML;        document.body.appendChild(elmDiv);        new dragElement('popupmessage');    }}            function hideMe() {    var elmDiv = document.getElementById('popupmessage');    if (elmDiv) {        // removes the div from the document        elmDiv.parentNode.removeChild(elmDiv);    }}function updateCoords(e) {    if (objBrowse == "Microsoft Internet Explorer") {        xpos = e.offsetX;        ypos = e.offsetY;    } else {        xpos = e.pageX;        ypos = e.pageY;    }}// Called upon loading the page this function clears the hidden// action and object fields so they can be used by submitLinkfunction clearHidden(){    var theForm = top["authoringIFrame1"].document.getElementById('contentForm')    if (!theForm) {        // try and find the form for the authoring page        theForm = document.getElementById('contentForm')    }    theForm.action.value = "";    theForm.object.value = "";}// Sets the hidden action and object fields, then submits the // contentForm to the serverfunction submitLink(action, object, changed) {    var theForm = top["authoringIFrame1"].document.getElementById('contentForm')    if (!theForm) {        // try and find the form for the authoring page        theForm = document.getElementById('contentForm')    }    theForm.action.value    = action;    theForm.object.value    = object;    theForm.isChanged.value = changed;    runFuncArray(beforeSubmitHandlers)    theForm.submit();}// Check the user really really wants to do this before submittingfunction confirmThenSubmitLink(message, action, object, changed) {    if (confirm(message)) {        submitLink(action, object, changed);    }}

⌨️ 快捷键说明

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