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

📄 zoom_search.js

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JS
📖 第 1 页 / 共 2 页
字号:
// ----------------------------------------------------------------------------
// Zoom Search Engine 4.0 (10/3/2005)
//
// This file (search.js) is the JavaScript search front-end for client side
// searches using index files created by the Zoom Search Engine Indexer.
//
// email: zoom@wrensoft.com
// www: http://www.wrensoft.com
//
// Copyright (C) Wrensoft 2000-2005
//
// This script performs client-side searching with the index data file
// (zoom_index.js) generated by the Zoom Search Engine Indexer. It allows you
// to run searches on mediums such as CD-ROMs, or other local data, where a
// web server is not available.
//
// We recommend against using client-side searches for online websites because
// it requires the entire index data file to be downloaded onto the user's
// local machine. This can be very slow for large websites, and our server-side
// search scripts (search.php and search.asp) are far better suited for this.
// However, JavaScript is still an option for smaller websites in a limited
// hosting situation (eg: no PHP or ASP)
// ----------------------------------------------------------------------------

// Include required files for index data, settings, etc.
document.write("<script language=\"JavaScript\" src=\"zoom_index.js\" charset=\"" + Charset + "\"><\/script>");
document.write("<script language=\"JavaScript\" src=\"zoom_pages.js\" charset=\"" + Charset + "\"><\/script>");
document.write("<script language=\"JavaScript\" src=\"zoom_titles.js\" charset=\"" + Charset + "\"><\/script>");
document.write("<script language=\"JavaScript\" src=\"zoom_descriptions.js\" charset=\"" + Charset + "\"><\/script>");

document.write("<meta http-equiv=\"content-type\" content=\"text/html; charset=" + Charset + "\">");
if (document.charset)
	document.charset = Charset;	// IE4+ only

// ----------------------------------------------------------------------------
// Settings (change if necessary)
// ----------------------------------------------------------------------------

// The options available in the dropdown menu for number of results
// per page
var PerPageOptions = new Array(10, 20, 50, 100);

// Globals
var SkippedWords = 0;
var searchWords = new Array();
var SkippedOutputStr = "";

var months = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

// ----------------------------------------------------------------------------
// Helper Functions
// ----------------------------------------------------------------------------

// This function will return the value of a GET parameter
function getParam(paramName)
{
    paramStr = document.location.search;
    if (paramStr == "")
        return "";

    // remove '?' in front of paramStr
    if (paramStr.charAt(0) == "?")
        paramStr = paramStr.substring(1, paramStr.length);

    arg = (paramStr.split("&"));
    for (i=0; i < arg.length; i++) {
        arg_values = arg[i].split("=")
        if (unescape(arg_values[0]) == paramName) {
            if (UseUTF8 == 1 && self.decodeURIComponent) // check if decodeURIComponent() is defined
                ret = decodeURIComponent(arg_values[1]);
            else
                ret = unescape(arg_values[1]);  // IE 5.0 and older does not have decodeURI
            return ret;
        }
    }
    return "";
}

// Compares the two values, used for sorting output results
// Results that match all search terms are put first, highest score
function SortCompare (a, b)
{
    if (a[2] < b[2]) return 1;
    else if (a[2] > b[2]) return -1;
    else if (a[1] < b[1]) return 1;
    else if (a[1] > b[1]) return -1;
    else return 0;
}

function SortByDate(a, b)
{
	if (datetime[a[0]] < datetime[b[0]]) return 1;
	else if (datetime[a[0]] > datetime[b[0]]) return -1;
	else return SortCompare(a, b);
}


function pattern2regexp(pattern)
{
    pattern = pattern.replace(/\#/g, "\\#");
    pattern = pattern.replace(/\$/g, "\\$");
    pattern = pattern.replace(/\./g, "\\.");
    pattern = pattern.replace(/\*/g, "[\\d\\S]*");
    pattern = pattern.replace(/\?/g, ".?");
    return pattern;
}

function HighlightDescription(line) {
    res = " " + line + " ";
    for (i = 0; i < numwords; i++) {
        if (searchWords[i] == "")
            continue;

        if (SearchAsSubstring == 1)
            res = res.replace(new RegExp("("+searchWords[i]+")", "gi"), "[;:]$1[:;]");
        else
            res = res.replace(new RegExp("(\\W|^|\\b)("+searchWords[i]+")(\\W|$|\\b)", "gi"), "$1[;:]$2[:;]$3");
    }
    // replace the marker text with the html text
    // this is to avoid finding previous <span>'ed text.
    res = res.replace(/\[;:\]/g, "<span class=\"highlight\">");
    res = res.replace(/\[:;\]/g, "</span>");
    return res;
}

function PrintNumResults(num)
{
    if (num == 0)
        return STR_NO_RESULTS;
    else if (num == 1)
        return num + " " + STR_RESULT;
    else
        return num + " " + STR_RESULTS;
}


function SkipSearchWord(sw) {
    if (searchWords[sw] != "") {
        if (SkippedWords > 0)
            SkippedOutputStr += ", ";
        SkippedOutputStr += "\"<b>" + searchWords[sw] + "</b>\"";
        searchWords[sw] = "";
    }
    SkippedWords++;
}


// ----------------------------------------------------------------------------
// Parameters initialisation (globals)
// ----------------------------------------------------------------------------

var query = getParam("zoom_query");

//MODIFIED BY EC SOFTWARE: QUOTED SEARCH -> do not search substring
SearchAsSubstring = 0;
if (query.indexOf('"') == -1) SearchAsSubstring = 1;

query = query.replace(/[\++]/g, " ");  // replace the '+' with spaces
query = query.replace(/[,+]/g, " ");
query = query.replace(/\</g, "&lt;");
query = query.replace(/[\"+]/g, " ");

var per_page = parseInt(getParam("zoom_per_page"));
if (isNaN(per_page)) per_page = 10;

var page = parseInt(getParam("zoom_page"));
if (isNaN(page)) page = 1;

var andq = parseInt(getParam("zoom_and"));
if (isNaN(andq))
{
	if (typeof(DefaultToAnd) != "undefined" && DefaultToAnd == 1)
		andq = 1;
	else
		andq = 0;
}

var cat = parseInt(getParam("zoom_cat"));
if (isNaN(cat)) cat = -1;   // search all categories

// for sorting options. zero is default (relevance)
// 1 is sort by date (if date/time is available)
var sort = parseInt(getParam("zoom_sort"));
if (isNaN(sort)) sort = 0;

var SelfURL = "";
if (typeof(LinkBackURL) == "undefined")
{
    SelfURL = document.location.href;
    var paramIndex = SelfURL.indexOf("?");
    if (paramIndex > -1)
        SelfURL = SelfURL.substr(0, paramIndex);    // strip off the parameters
}
else
    SelfURL = LinkBackURL;

/*
if (typeof(catnames) != "undefined" && typeof(catpages) != "undefined")
    UseCats = true;
else
    UseCats = false;
*/

var data = new Array();
var output = new Array();

target = "";
if (UseLinkTarget == 1)
    target = " target=\"" + LinkTarget + "\" ";



// ----------------------------------------------------------------------------
// Main search function starts here
// ----------------------------------------------------------------------------

function ZoomSearch() {
    var loadingmsg = document.getElementById("loadingmsg");
    if (loadingmsg) loadingmsg.style.display = "None";

    if (Timing == 1) {
        timeStart = new Date();
    }

    // Display the form
    if (FormFormat > 0) {
        document.writeln("<form method=\"get\" action=\"" + SelfURL + "\" class=\"zoom_searchform\">");
	document.writeln("<table class=\"submit\" border=\"0\" cellpadding=\"0\" cellspacing=\"4\">");
        document.write("<tr valign=\"top\"><td align=\"left\" colspan=\"2\"><input type=\"text\" name=\"zoom_query\" size=\"20\" value=\"" + query + "\" class=\"zoom_searchbox\" /> ");
        document.write("<input type=\"submit\" value=\"" + STR_FORM_SUBMIT_BUTTON + "\" class=\"zoom_button\" /></td></tr>");
        if (FormFormat == 2) {
            document.write("<tr valign=\"top\"><td align=\"left\">" + STR_FORM_RESULTS_PER_PAGE + "</td>");
            document.write("<td align=\"left\"><select name='zoom_per_page'>");
            for (i = 0; i < PerPageOptions.length; i++) {
                document.write("<option");
                if (PerPageOptions[i] == per_page)
                    document.write(" selected=\"selected\"");
                document.write(">" + PerPageOptions[i] + "</option>");
            }
            document.writeln("</select></td></tr>");
            if (UseCats) {
                document.write("<tr valign=\"top\"><td align=\"left\">" + STR_FORM_CATEGORY + "</td>");
                document.write("<td align=\"left\"><select name='zoom_cat'>");
                // 'all cats option
                document.write("<option value=\"-1\">" + STR_FORM_CATEGORY_ALL + "</option>");
                for (i = 0; i < catnames.length; i++) {
                    document.write("<option value=\"" + i + "\"");
                    if (i == cat)
                        document.write(" selected=\"selected\"");
                    document.write(">" + catnames[i] + "</option>");
                }
                document.writeln("</select></td></tr>");
            }
            document.write("<tr valign=\"top\"><td align=\"left\">" + STR_FORM_MATCH + "</td>");
            if (andq == 0) {
                document.write("<td align=\"left\"><input type=\"radio\" name=\"zoom_and\" value=\"0\" checked=\"checked\" />" + STR_FORM_ANY_SEARCH_WORDS + "<br />");
                document.write("<input type=\"radio\" name=\"zoom_and\" value=\"1\" />" + STR_FORM_ALL_SEARCH_WORDS + "</td></tr>");                                
            } else {
                document.write("<td align=\"left\"><input type=\"radio\" name=\"zoom_and\" value=\"0\" />" + STR_FORM_ANY_SEARCH_WORDS + "<br />");
                document.write("<input type=\"radio\" name=\"zoom_and\" value=\"1\" checked=\"checked\" />" + STR_FORM_ALL_SEARCH_WORDS + "</td></tr>");                
            }
            document.write("</table>");
	    document.write("<input type=\"hidden\" name=\"zoom_sort\" value=\"" + sort + "\" />");
        }
        else
        {
        	document.writeln("<input type=\"hidden\" name=\"zoom_per_page\" value=\"" + per_page + "\" />");
        	document.writeln("<input type=\"hidden\" name=\"zoom_and\" value=\"" + andq + "\" />");
        	document.writeln("<input type=\"hidden\" name=\"zoom_sort\" value=\"" + sort + "\" />");
        }
        
        document.writeln("</form>");
    }

    // give up early if no search words provided
    if (query.length == 0) {
        //document.writeln("No search query entered.<br />");        
        if (ZoomInfo == 1)
            document.writeln("<center><p><small>" + STR_POWEREDBY + " <a href=\"http://www.wrensoft.com/zoom/\" target=\"_blank\"><b>Zoom Search Engine</b></a></small></p></center>");
        return;
    }

    if (MapAccents == 1) {
        for (i = 0; i < NormalChars.length; i++) {
            query = query.replace(AccentChars[i], NormalChars[i]);
        }
    }


    if (ToLowerSearchWords == 1)
        query = query.toLowerCase();

    // prepare search query, strip quotes, trim whitespace
    if (WordJoinChars.indexOf(".") == -1)
        query = query.replace(/[\.+]/g, " ");

    if (WordJoinChars.indexOf("-") == -1)
        query = query.replace(/[\-+]/g, " ");

    if (WordJoinChars.indexOf("_") == -1)
        query = query.replace(/[\_+]/g, " ");

    if (WordJoinChars.indexOf("'") == -1)
        query = query.replace(/[\'+]/g, " ");

    if (WordJoinChars.indexOf("#") == -1)
        query = query.replace(/[\#+]/g, " ");

    if (WordJoinChars.indexOf("$") == -1)
        query = query.replace(/[\$+]/g, " ");

    //    if (WordJoinChars.indexOf(",") == -1)
    //      query = query.replace(/[\,+]/g, " ");

    // substitute multiple whitespace chars to single character
    query = query.replace(/[\/\s\\\\(\)\^\[\]\|\+\{\}]+/g, " ");    

    // trim trailing/leading whitespace
    query = query.replace(/^\s*|\s*$/g,""); 
    // split search phrase into words
    searchWords = query.split(" "); // split by spaces.

    document.write("<div class=\"searchheading\">" + STR_RESULTS_FOR + " \"" + query + "\"");
    if (UseCats) {
        if (cat == -1)
            document.writeln(" " + STR_RESULTS_IN_ALL_CATEGORIES);
        else
            document.writeln(" " + STR_RESULTS_IN_CATEGORY + " \"" + catnames[cat] + "\"");

⌨️ 快捷键说明

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