Javascript JS-Ajax导航-需要一个简单的调整
我需要提供该网站,我错过了一个小功能 以下是网站:Javascript JS-Ajax导航-需要一个简单的调整,javascript,ajax,multi-select,jquery-chosen,layered-navigation,Javascript,Ajax,Multi Select,Jquery Chosen,Layered Navigation,我需要提供该网站,我错过了一个小功能 以下是网站: SIZE和MODEL小部件-它们是Jigoshop增强的分层导航WP插件 我需要知道如何消除所选的搜索值,这样在这种情况下,一个小部件区域中就不会有多个查询,例如SIZE和MODEL 当单击小部件中的新值时,它应该只获取单击的新值,并清除以前的值 目前,插件无法显示来自多个选定分类法的结果,这是进行此调整的主要原因 全部内容如下: /*Ajax Layerd导航小部件 *购物车:Jigoshop *文件:前端JS *许可证:GPL *版权所有
SIZE
和MODEL
小部件-它们是Jigoshop增强的分层导航WP插件
我需要知道如何消除所选的搜索值,这样在这种情况下,一个小部件区域中就不会有多个查询,例如SIZE
和MODEL
当单击小部件中的新值时,它应该只获取单击的新值,并清除以前的值
目前,插件无法显示来自多个选定分类法的结果,这是进行此调整的主要原因
全部内容如下:
/*Ajax Layerd导航小部件
*购物车:Jigoshop
*文件:前端JS
*许可证:GPL
*版权所有:SixtyOneDesigns
*/
/*全球的
*为以下区域设置变量和id:
*要刷新吗
*/
var内容=新数组//要刷新的区域
内容[0]=“产品”//产品标识包装器
内容[1]=“分页包装器”//分页id包装器
var elements_to_remove=新数组//将项目放入和移出此阵列,以便我们知道它们已刷新
var DocReadyReload=false//如果遇到一个javascript问题,请将此设置为true
var isWorking=false//标记以了解我们是否正在获取刷新
var http=getHTTPObject()//Http对象
变量分页
函数checkPagination(){
if(jQuery('nav.pagination')。长度>0){
分页=“”
}
}
/*事件:document.ready
*Desc:Inititalize页面
* 1. 调用函数向小部件区域和产品区域添加实时处理程序fn=pageLoaderInit()
* 2. 构建要重新设置的小部件的ID数组
*/
jQuery(文档).ready(函数(){
pageLoaderInit();
jQuery('.widget\u layered\u nav')。每个(函数(){
content.push(this.id);
});
返回false;
});
/*事件:onpopstate
*Desc:每次浏览器历史记录更改时重新加载页面
*/
window.onpopstate=函数(事件){
if(event.state!=未定义){
loadPage(document.location.toString(),1);
}
};
/*功能:pageLoaderInit
*Desc:将实时单击处理程序添加到锚定和复选框
* 1. 在“单击-加载”页面上,阻止broswer
*a。调用fn=loadPage();
*/
函数pageLoaderInit(){
jQuery('.widget_layered_nav a,a.layerd_nav_clear,.widget_layered_nav input[type=“checkbox”]')。实时('click',函数(事件){
这个。blur();
var caption=this.title | | this.name | |“”;
var group=this.rel | | false;
loadPage(jQuery(this).data('link'));
event.preventDefault();
返回false;
});
}
/*函数:getHTTPObject
*返回:xmlhttprequest对象
*Desc:降级为ActiveXObject以支持旧版IE浏览器
*/
函数getHTTPObject(){
var-xmlhttp;
if(window.XMLHttpRequest){
xmlhttp=新的XMLHttpRequest();
}
其他的
{
if(window.ActiveXObject){
xmlhttp=newActiveXObject('MSXML2.xmlhttp.3.0');
}
}
返回xmlhttp;
}
/*功能:加载页面
*参数:
*@url=目标页面的url,
*@push=是否更新浏览器历史记录
*Desc:重新加载内容区域
*/
函数加载页(url、推送){
//确保你还没有做什么
如果(!正在工作){
//获取域名。。。
nohttp=url.replace(“http://”和“”).replace(“https://”和“”);
firstsla=nohttp.indexOf(“/”);
pathpos=url.indexOf(nohttp);
path=url.substring(pathpos+firstsla);
//仅当在页面上单击时才执行历史记录状态。
如果(推!=1){
var stateObj={foo:1000+Math.random()*1001};
/*如果不是IE,只推历史
*我不支持你
*/
如果(!jQuery.browser.msie){
pushState(stateObj,“加载的ajax页面…”,路径);
}
}
/*循环内容数组()中的每个id*/
每个(内容、函数(索引、值){
/*产品容器
*在产品容器中添加一条img/消息,让用户知道它正在刷新
*/
如果(值=“产品”){
var max=0;
max=jQuery(“#产品”).outerHeight();
jQuery('#'+value+'').fadeOut(“快速”,函数(){
jQuery('#'+value).html('加载…
');
jQuery('#'+value).css({'height':max}).fadeIn(“slow”,function(){});
});
}
http.open('GET',url,true);//获取新内容
isWorking=true;//将isWorking标志设置为true,这样我们就不会一次用一堆请求轰击它
http.onreadystatechange=showPage;//调用showPage()函数
http.send(null);//不发送任何内容
})
}
返回false;
}
/*功能:showPage()
*desc:用新http请求的内容替换目标div的内容
*/
函数showPage(){
如果(http.readyState==4){//请求已完成
如果(http.status==200){//请求正常
isWorking=false;//不再发出请求
元素_至_移除=[];
elements_to_remove=content.slice();
/*更新内容区域*/
每个(内容、函数(索引、值){
var details=http.responseText;//获取ajax响应
//details=details.split('id=“”+value+”)[1];//获取目标区域的内容
//如果(详细信息!=未定义){
if(jQuery
/* Ajax-Layerd Nav Widgets
* Shopping Cart: Jigoshop
* File: Frontend JS
* License: GPL
* Copyright: SixtyOneDesigns
*/
/* Globals
* Setup variables and id for areas that are
* going to be refreshed
*/
var content = new Array; //Areas to be refreshed
content[0] = "products"; //Products id wrapper
content[1] = "pagination-wrapper";//Pagination id wrapper
var elements_to_remove = new Array; //Pop items in and out of this array so we know they've been refreshed
var DocReadyReload = false; //Set this to true if your getting sone javascript problems
var isWorking = false; //Flag to know if we're fetching a refresh
var http = getHTTPObject(); //Http object
var pagination
function checkPagination(){
if(jQuery('nav.pagination').length > 0){
pagination = ''
}
}
/* Event: document.ready
* Desc: Inititalize the page
* 1. Calls function to add Live Handlers to the widget areas, and product area fn= pageLoaderInit()
* 2. Build array of ids of widgets that are going to be refresed
*/
jQuery(document).ready(function(){
pageLoaderInit();
jQuery('.widget_layered_nav').each(function(){
content.push(this.id);
});
return false;
});
/* Event: onpopstate
* Desc: Reload the page every time the browsers history changes
*/
window.onpopstate = function(event) {
if (event.state != undefined) {
loadPage(document.location.toString(),1);
}
};
/* Function: pageLoaderInit
* Desc: Add live click handlers to anchors and checkboxes
* 1. On Click - load page, prevent broswer
* a. Calls fn = loadPage();
*/
function pageLoaderInit(){
jQuery('.widget_layered_nav a, a.layerd_nav_clear, .widget_layered_nav input[type="checkbox"]').live('click', function(event){
this.blur();
var caption = this.title || this.name || "";
var group = this.rel || false;
loadPage(jQuery(this).data('link'));
event.preventDefault();
return false;
});
}
/* Function: getHTTPObject
* Returns: xmlhttprequest object
* Desc: Degrades to ActiveXObject to support older IE browsers
*/
function getHTTPObject() {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
else
{
if (window.ActiveXObject) {
xmlhttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');
}
}
return xmlhttp;
}
/* Function: loadPage
* Params:
* @url = url of target page,
* @push = whether to update browser history
* Desc: Reloads content areas
*/
function loadPage(url, push){
//Make sure wer're not already doing something
if (!isWorking){
//get domain name...
nohttp = url.replace("http://","").replace("https://","");
firstsla = nohttp.indexOf("/");
pathpos = url.indexOf(nohttp);
path = url.substring(pathpos + firstsla);
//Only do a history state if clicked on the page.
if (push != 1) {
var stateObj = { foo: 1000 + Math.random()*1001 };
/*Only push history if not IE
* IE doesn't support
*/
if(!jQuery.browser.msie){
history.pushState(stateObj, "ajax page loaded...", path);
}
}
/* Loop through each id in the content array()*/
jQuery.each(content, function(index, value){
/* Products container
* add an img / message to the products container to let user know it's being refreshed
*/
if(value =="products"){
var max = 0;
max = jQuery('#products').outerHeight();
jQuery('#' + value + '').fadeOut("fast", function() {
jQuery('#' + value).html('<center style="min-height:'+max+'px;"><p>Loading...<br><img src="'+site.loading_img+'" alt="loading"></p></center>');
jQuery('#' + value).css({'height':max}).fadeIn("slow", function() {});
});
}
http.open('GET', url, true); //Get the new content
isWorking = true; //Set the isWorking flag to true so we don't bombard it with a bunch of requests at once
http.onreadystatechange = showPage; //Call showPage() function
http.send(null); //Don't send anything
})
}
return false;
}
/* Function: showPage()
* desc: replaces the contents of the target div with that of the new http request
*/
function showPage(){
if (http.readyState == 4) { //Request has completed
if (http.status == 200) { //Request was good
isWorking = false; //No longer making the request
elements_to_remove=[];
elements_to_remove = content.slice();
/* Update content areas */
jQuery.each(content, function(index, value){
var details = http.responseText; //get the ajax response
//details = details.split('id="' + value + '"')[1]; //get the content for the target areas
//if (details != undefined){
if ( jQuery('#' + value, details).size() > 0 ) {
//details = details.substring(details.indexOf('>') + 1);
var depth = 1;
var output = '';
jQuery('#' + value).fadeOut("fast", function() {
jQuery('#' + value).html( jQuery('#' + value, details).html() );
jQuery('#' + value).fadeIn(1);
if (DocReadyReload == true) {
$(document).trigger("ready");
}
});
} else { //Empty the elements
jQuery.each(elements_to_remove, function(index,value){
jQuery('#'+value).empty();
});
}
});
/* Re-fire the pageLoaderInit() function. This adds the live click handlers to the newly
* readded elemets
*/
pageLoaderInit();
return false
} else {
}
}
return false;
}
/* Function removeByValue
* params:
* @val = value of elment to pop out of array
* desc: Allows us to remove an element from a javascript array by value
*/
Array.prototype.removeByValue = function(val) {
for(var i=0; i<this.length; i++) {
if(this[i] == val) {
this.splice(i, 1);
break;
}
}
}