Javascript 跟踪发生单击事件时执行的大型JS文件的部分?
是否有一个简单的方法可以快速发现在单击事件时执行哪一行代码?我试图在点击products部分时设置一个全局变量,如下图所示 尝试使用下面的代码在Products部分下使用所选品牌的名称设置全局变量无效Javascript 跟踪发生单击事件时执行的大型JS文件的部分?,javascript,events,frontend,Javascript,Events,Frontend,是否有一个简单的方法可以快速发现在单击事件时执行哪一行代码?我试图在点击products部分时设置一个全局变量,如下图所示 尝试使用下面的代码在Products部分下使用所选品牌的名称设置全局变量无效 .delegate("#productsMenu li span",'click',function() { selected_brand = $('#productsMenu select').val(); var selected_brand_obj =
.delegate("#productsMenu li span",'click',function() {
selected_brand = $('#productsMenu select').val();
var selected_brand_obj = $('#productsMenu li span.highlight');
alert(selected_brand_obj.parent().attr('data-id'));
});
我将整个文件粘贴到这里供您查看。谢谢你的建议
var lastIndexProductSelector = 0,
categoryTimer,
alerted=0, // see line 394
$key50=0; // see line 375
//var testglbl = "tester";
//testglblvar = "testervar";
var selected_brand = "";
$editorView
/* none of this stuff works as of 9/14/16 - mosty due to alternate layouts being missing.
function alt_layouts(){
var $op_sel_val = $("#layoutId").val();
if ($op_sel_val==="parts.tpl" || $op_sel_val==="bath_hardware.tpl"){
$(".simpleOptionsDisplay").addClass("simpleOptionsDisplay2");
$(".simpleOptionsDisplay2").removeClass("simpleOptionsDisplay");
$('#new_simpleOption').parent().append(" ENTER ALL ITEMS, DESCRIPTIONS, SKUS, AND IMAGES IN ONLY 1 SELECT ONLY. COLONS (:) IN DESCRIPTION ARE NOT ALLOWED.");
if ($op_sel_val=="bath_hardware.tpl"){
$('#product_description').before("WILL APPEAR TO THE RIGHT OF THE MAIN IMAGE.<br />");
$('#new_feature').parent().append(" BULLET FEATURES WILL APPEAR BENEATH DESCRIPTION, TO THE RIGHT OF THE MAIN IMAGE.");
$('#additionalimages').after(" USE WITH CARE. MOST IMAGES ALREADY APPEAR NEXT TO INDIVIDUAL ITEMS ITEMS.");
}
if ($op_sel_val=="parts.tpl"){
$('#product_description').before("ENTER ONLY BOTTOM-OF-PAGE NOTES OR LEAVE BLANK..<br />");
$('#new_feature').parent().append(" USE WITH CARE. BULLET FEATURES WILL APPEAR AT BOTTOM LEFT OF PAGE, ABOVE BOTTOM-OF-PAGE NOTES.");
$('#edit_indeximage').after(" MAIN IMAGE WILL APPEAR ON THE CATEGORY PAGE ONLY..");
$('#new_feature').parent().append(" USE WITH CARE. BULLET FEATURES WILL APPEAR AT BOTTOM LEFT OF PAGE, ABOVE BOTTOM-OF-PAGE NOTES.");
$('#additionalimages').after(" DO NOT USE.");
}
}
}
$(document).delegate("#layoutId",'change',function(){
alt_layouts();
})
*/
// Accessories and Related Items
.delegate("#editaccessories,#editrelated",'click',function() {
var $p = $("#popup");
switch(this.id) {
case 'editaccessories':
$p.data('type', 'accessories')
.dialog('option', 'title', 'Accessories');
break;
case 'editrelated':
$p.data('type', 'related')
.dialog('option', 'title', 'Related Items');
break;
}
Utils.fillSelect('#p_active', $(this).data('access'));
if($('#p_products option').length === 0) {
$('#p_category').trigger('change');
}
$p.dialog('open');
})
// Badges
.delegate("#badge_add",'click',function() {
var s = $("#product_badges"),
badge = $('option:selected',s).text(),
badgevalue = s.val();
if(badgevalue == 0) {
return;
}
$('#productsForm').data('products')._buildBadge(badgevalue,badge).appendTo('#badge_list');
})
// Categories
.delegate('#product_catlist','mouseover',function(e) {
clearTimeout(categoryTimer);
$(this).attr('size',30);
})
.delegate('#product_catlist','mouseout',function(e) {
var _self = $(this);
categoryTimer = setTimeout(function() {_self.attr('size',5);},300);
})
.delegate('#product_catlist','change',function(e){
$(this).find('option:selected').text()=="-- Clearance" ? alert('Clearance:\n\nIf this is an inventory-only item select Clearance as the PRIMARY category.\n\nAppend the former primary category to these secondary categories.' ) : '';
})
// Custom Code
.delegate('#customCodeSelect','change',function() {
var $this = $(this);
if(this.selectedIndex == 0) { <!-- changed from !==0 5/23/13 See productView.php line 230 -->
$this.next().attr('disabled',true);
} else {
$this.next().removeAttr('disabled');
}
})
.delegate('.addCustomCode','click', function() {
var $select = $('#customCodeSelect'),
type = $select.val(),
data = $select.next().is(':disabled') ? '' : $select.next().val(),
$o = $($('#productsForm').data('products')._buildCustomCode(type,data));
Utils.buttons($o.find('button'));
$o.appendTo("#customCodeList");
})
.delegate('.expandCustomCode','click',function() {
var $area = $(this).next();
$area.toggle($area.is(':hidden'));
})
.delegate('.customCodeDate','click', function() {
$(this).parent().find('input[type=text]').toggle(this.checked);
$(this).parent().find('input[type=text]').val('');
})
// Features
.delegate("#new_feature",'click',function(){
$('#productsForm').data('products')._buildFeature().appendTo("#features");
})
.delegate(".delete_div_feature",'click',function(){
$(this).closest("li").remove();
})
// Images
.delegate('#edit_logoimage,#edit_indeximage,#additionalimages','click',function() {
var single = ((this.id == 'edit_indeximage') || (this.id == 'edit_logoimage')) ? true : false;
$('#imageSelector').imageSelector('show',this,$(this).data('imageSelector'),single);
})
.delegate('.changeImage','hover',function(e) {
var $this = $(this),
$ele = $this.siblings('.imageSwitchPreview');
if(!$this.data('imageSelector')) {
return;
}
switch(e.type) {
case 'mouseover':
$ele.show()
.position({
of: $(this),
my: 'left botton',
at: 'right top',
offset: '5 -10'
});
break;
case 'mouseout':
$ele.hide();
break;
}
})
// Layout
.delegate('#layoutCheckbox','click',function(){
if(this.checked) {
$('#layoutId').hide().attr('disabled',true);
} else {
$('#layoutId').show().attr('disabled',false);
}
})
// Options
.delegate('.simpleOptionsType', 'change', function() {
var $this = $(this);
switch($this.val()) {
case 'text':
var $ul = $this.parent().find('.lineItems');
$this.next().hide();
$ul.empty().append('<li><input size="150" class="simpleOptionsText" /></li>');
break;
case 'images':
$this.parent().find('.simpleOptionsName').val('Images Only');
$this.parent().find('.simpleOptionsOptionType').val('images');
$this.parent().find('.simpleOptionsOptionType').change();
break;
default:
$this.next().show().find('select').trigger('change');
break;
}
})
.delegate("#new_simpleOption", 'click', function(){
$('#productsForm').data('products')._buildOption().appendTo("#simpleOptions");
$('.simpleOptionsName,.simpleOptionsDisplay,.simpleOptionsValue','#simpleOptions').placeholder();
})
.delegate('.addSimpleOption_value','click',function() {
var $products = $('#productsForm').data('products'),
$o = ($(this).parent().parent().parent().find('.simpleOptionsType').val() == 'images')
? $($products._buildOptionSkuImage({},true)) : $($products._buildOptionSelect({},true));
$products._buttons($o.find('button'));
$(this).closest('ul').append($o).end().remove();
$editorView.find('.simpleOptionsDisplay,.simpleOptionsValue','#simpleOptions').placeholder();
})
.delegate('.removeSimpleOption_value','click',function() {
var $this = $(this),
$ul = $this.closest('ul'),
$li = $ul.find('li'),
button = $ul.find('.addSimpleOption_value').detach();
if($li.length > 1) {
$this.parent().remove();
} else {
$li.find('input').each(function() {
this.value = '';
});
}
$ul.find('li:last').append(button);
})
.delegate(".removeSimpleOption",'click',function() {
var $this = $(this);
$infoBox.infoWindow('confirm','Confirm Delete?', function(e) {
$this.parent().remove();
});
})
.delegate('.simpleOptionsOptionType','change',function(e) {
var o = '',
$productForm = $('#productsForm'),
$data = $productForm.data('products');
switch(e.target.value) {
case 'checkbox':
o += $data._buildOptionCheckbox();
break;
case 'hidden':
o += $data._buildOptionHidden();
break;
default:
case 'select':
o += $data._buildOptionSelect(null,true);
break;
case 'images':
o += $data._buildOptionSkuImage(null,true);
break;
case 'text':
o += $data._buildOptionText(null);
break;
}
var $o = $(o);
$data._buttons($o.find('button'));
$(e.target).closest('div').find('.lineItems').empty().append($o);
})
.delegate('.changeImage','click',function(e) {
$('#imageSelector').imageSelector('show',this,$(this).data('imageSelector'),true);
})
// option Options
.delegate('.optionAttributes', 'click', function(e) {
$('#optionAttributes').optionAttributes('show',this);
})
// SKUs
.delegate("#new_sku",'click',function(){
var $skus = $("#skus"),
$skuAddBox = $('#skuAddBox');
$('#productsForm').data('products')._buildSku({sku:$skuAddBox.val()}).appendTo($skus);
$skus.find(".hint").hint();
$skuAddBox.val('');
})
.delegate(".delete_div",'click',function() {
if(confirm('Confirm Delete?')) {
var $li = $(this).closest('li');
$li.find('input.skuValue').val('-1');
$li.hide();
}
})
.delegate('.feedImage','click',function() {
$('#imageSelector').imageSelector('show',this,$(this).data('imageSelector'),true);
})
.delegate('.skuFeeds', 'click', function() {
var $this = $(this),
sku = $this.parent().find('input.skuValue').val();
$feedsDataModal.feedsDataEditor('show',sku, {onProduct: true});
})
.delegate('.skuData', 'click', function() {
var $this = $(this),
sku = $this.parent().find('input.skuValue').val();
$skuModal.singleSkuView('show',sku);
})
.delegate('#skuPaginationFirst','click',function() {
var product = $('#productsForm').data('products'),
high = Math.min(50, product.options.skus.length);
$('#skuPaginationCount').html('1 - ' + high);
$('#skus').data('pagination',1);
$('#productsForm').data('products')._buildSkuList(1, high);
})
.delegate('#skuPaginationPrev','click',function() {
var $skus = $('#skus'),
current = $skus.data('pagination');
if(current !== 1) {
var product = $('#productsForm').data('products'),
low = Math.max(1, current - 50),
high = Math.min(low + 49, product.options.skus.length),
str = low + ' - ' + high;
$skus.data('pagination', low);
$('#skuPaginationCount').html(str);
$('#productsForm').data('products')._buildSkuList(low, high);
}
})
.delegate('#skuPaginationNext','click',function() {
var $skus = $('#skus'),
current = $skus.data('pagination'),
product = $('#productsForm').data('products'),
low = ((current + 50) < product.options.skus.length) ? current + 50 : current,
high = Math.min(low + 49, product.options.skus.length),
str = low + ' - ' + high,
products = $('#productsForm').data('products');
$skus.data('pagination', low);
$('#skuPaginationCount').html(str);
products._buildSkuList(low, high);
})
.delegate('#skuPaginationLast','click',function() {
var page = $('#skus').data('pagination'),
product = $('#productsForm').data('products'),
high = product.options.skus.length,
leftover = high % 50,
low = Math.max(1, (leftover == 0) ? high - 49 : high - leftover + 1),
str = low + ' - ' + high;
if(low !== page) {
$('#skus').data('pagination',low);
$('#skuPaginationCount').html(str);
product._buildSkuList(low,high);
}
})
.delegate("#addMultipleSkus", "click", function() {
$("#addMultiSkusModal").addMultiSkus("show", this);
})
// Status
.delegate('#product_status','change',function(e) {
var $this = $(this),
colors = $this.find(':selected').attr('data-color').split('|'),
bg = colors[0] || '#ffffff',
fg = colors[1] || '#000000';
$this.css({'background-color': bg, 'color': fg});
})
// Tabs
.delegate(".delete_tab",'click',function() {
$(this).parent().remove();
})
.delegate("#pTabList",'change',function() {
var t = $("option",this);
$("#pTabName").val($(t[this.selectedIndex]).attr('data-defaultname'));
})
.delegate("#tab_add",'click',function() {
var name = $("input[name=tabname]").val(),
s = $("select[name=tablist] option:selected"),
tab = s.text(),
tabvalue = s.val();
if(tabvalue == 0) {
return;
}
$('#productsForm').data('products')._buildTab(name,tabvalue,tab).appendTo("#tabs_list");
})
// Custom Title and metaKeywords
.delegate('.customBox','click',function(e) {
if(this.checked) {
$(this).parent().next().show();
} else {
$(this).parent().next().val('').hide();
}
})
.delegate('#product_metaDescription','keyup', function(){
if ($(this).val().length<72){
$('#metaDescriptionLength').css("color","#FF0000");
}else{
$('#metaDescriptionLength').css("color","#000000");
}
$('#metaDescriptionLength').html("Qty: "+$(this).val().length);
})
.delegate('#product_metaKeywords','keyup',function(){
$key50 = $(this).val();
if (parseInt($key50.length - $key50.lastIndexOf(",")) > 50 ){
alert("You've reached the maximum 50 characters per keyword.\nThe next character must be a comma.");
}
})
// Update URI
.delegate("#product_name",'keyup change',function() {
if ($(this).val().length > 100 && alerted == 0){
alert("\nMaximum length 100 characters and spaces.\n");
alerted = 1;
$(this).val($(this).val().substr(0,$(this).val().length-1));
} else {
alerted = 0
}
if (!($("#changeUri").is(":checked"))) {
return;
}
var uri = Utils.fixString(this.value);
$("#product_uriid").val(uri);
})
.delegate("#changeUri", "click", function() {
$("#product_uriid").attr('readonly', !this.checked);
})
// Version
.delegate('#product_oldway','change',function() {
$('#productsForm').data('products').versionSwitch();
})
// productsForm
.delegate(".productsSelector tr",'hover',function() {
$(this).toggleClass("over");
})
.delegate(".productsSelector tr",'dblclick',function(e) {
if(e.target.nodeName == "TH") {
return;
}
var productId = $(this).attr('data-id');
Utils.clearSelection();
$editorView.trigger('loadProductView',{id: productId});
})
.delegate(".productsSelector tr", 'click', function(e) {
$ps = $('#editorView table');
e.preventDefault();
if (!e.ctrlKey && !e.shiftKey) {
// Remove all old selections, since neither Ctrl key nor Shift key was pressed.
$ps.find('tr').removeClass('selected');
}
if (e.shiftKey) {
if ($ps.find('tr.selected').length) {
if (lastIndexProductSelector == 0) {
// No last selection for Shift Key processing. Just select this row only.
$(this).addClass('selected');
} else {
// Select all rows from start to end. Start was last selection. End is current selection.
var endIndex = $(this).index();
var startIndex;
if (endIndex > lastIndexProductSelector) {
startIndex = lastIndexProductSelector;
} else {
// Current Index is less than last Index. Re-adjust start and end so that start < end.
startIndex = endIndex;
endIndex = lastIndexProductSelector;
}
$ps.find('tr').each(function() {
// Select all rows from start to end (inclusive)
var curIndex = $(this).index();
if (curIndex >= startIndex && curIndex <= endIndex) {
$(this).addClass('selected');
}
});
}
} else {
$(this).toggleClass('selected');
}
} else {
// Handle it like a Ctrl Key press. Toggle status.
$(this).toggleClass('selected');
}
lastIndexProductSelector = $(this).is('.selected') ? $(this).index() : 0;
})
.delegate('.gotoButton', 'click', function(e) {
var $select = $('#toolbar select[name=quickSelect]'),
val = $(this).attr('rel') == 'next' ? $select.find('option:selected').next().attr('value') : $select.find('option:selected').prev().attr('value');
if($select.is(':visible')) {
$select.val(val).trigger('change');
e.preventDefault();
}
});
/**
* Popup box
* Accessories / Related Items
* Needs to be made into its own widget
*/
$('#popup')
.delegate("#p_up",'click',function() {
var m = $("#p_active option:selected");
if(m.prev().val() === '')
return;
m.prev().before(m);
})
.delegate("#p_down",'click',function() {
var m = $("#p_active option:selected");
if(m.next().val() === '')
return;
m.next().after(m);
})
.delegate("#p_category,#p_filter","change",function() {
var id = this.value,
filter = $("#p_filter").val();
$("#p_products").html('<option>Loading...</option>');
$.ajax({
type: "GET",
url: "request.php",
cache: false,
data: {calls:[{call:'treeSelector',which:'products',selectcat:id,filter:filter}]},
dataType: 'json',
success: function(data){
Utils.fillSelect("#p_products",data.treeSelector.productList,filter);
}
});
})
.delegate("#p_products option","dblclick",function() {
var v = this.value,
found = false;
if(v == -1) {
return;
}
$("#p_active option").each(function() {
if(v==this.value) {
found = true;
}
});
if(found) {
return;
}
$(this).clone().appendTo("#p_active");
})
.delegate("#p_active option","dblclick",function() {
$(this).remove();
});
$editorView.bind('loadProductView',function(target,data) {
var activeEditor = editor.getActive(),
id = data.id,
productTypeId = data.productType || $editorView.data('currentId'),
getData = {
calls:[{
call: 'productInfo',
productId: id,
productListingType: $('#productsMenu select').val(),
productTypeId: productTypeId
}]
};
editor.layout.contentLayout.open('north');
editor.setState(1);
editor.toolbar.updateToolbar();
$editorView.html($loading);
$.ajax({
type: "GET",
url: "request.php",
cache: false,
data: getData,
dataType: 'json',
success: function(data){
$editorView.empty();
if (data.errors) {
$infoBox.infoWindow('alert', 'Error:<br />'+data.errors);
} else {
if (data.info) {
$infoBox.infoWindow('alert', 'Information:<br />'+data.info);
}
$('#productViewTemplate').render( data ).appendTo($editorView);
activeEditor.states[activeEditor.state].viewCallback( data );
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
//(besides null) are "timeout", "error", "notmodified" and "parsererror"
$editorView.empty();
console.error('ajax error: ',textStatus, errorThrown);
$infoBox.infoWindow('alert','<p>Error:</p><p>'+textStatus+'</p><p>'+errorThrown+'</p>');
}
});
});
.delegate("#productsMenu li span",'click',function() {
selected_brand = $('#productsMenu select').val();
var selected_brand_obj = $('#productsMenu li span.highlight');
alert(selected_brand_obj.parent().attr('data-id'));
});
var lastIndexProductSelector=0,
分类单体,
alerted=0,//参见第394行
$key50=0;//见第375行
//var testglbl=“tester”;
//testglblvar=“testervar”;
var选定品牌=”;
$editorView
/*截至2016年9月14日,这些东西都不起作用,因为缺少备用布局。
函数alt_layouts(){
var$op_sel_val=$(“#layoutId”).val();
如果($op_sel_val==”parts.tpl“| |$op_sel_val===”bath_hardware.tpl”){
$(.SimpleOptions显示”).addClass(“SimpleOptions显示2”);
$(.SimpleOptions显示2”).removeClass(“SimpleOptions显示”);
$('#new_simpleOption').parent().append(“仅在1中输入所有项目、说明、SKU和图像,仅限选择。说明中不允许使用冒号(:)”);
如果($op_sel_val==“bath_hardware.tpl”){
$(“#产品描述”)。之前(“将显示在主图像的右侧。
”;
$(“#新建#功能”).parent().append(“项目符号功能将显示在主图像右侧的“说明”下方”);
$(“#additionalimages”)。之后(“小心使用。大多数图像已显示在单个项目旁边。”);
}
如果($op_sel_val==“parts.tpl”){
$(“#产品描述”)。在(“只输入页面底部的注释或留空..
”)之前;
$(“#新功能”).parent().append(“小心使用。项目符号功能将显示在页面左下角,页面底部注释上方”);
$('edit#u indeximage')。之后(“主图像将仅显示在类别页面上…”);
$(“#新功能”).parent().append(“小心使用。项目符号功能将显示在页面左下角,页面底部注释上方”);
$(“#additionalimages”)。在(“请勿使用”)之后;
}
}
}
$(document).delegate(“#layoutId”,'change',function(){
alt_布局();
})
*/
//附件及有关物品
.delegate(“#编辑附件,#编辑相关“,“单击”,函数(){
var$p=$(“#弹出”);
开关(this.id){
“编辑附件”案例:
$p.data('类型','附件')
.对话框(“选项”、“标题”、“附件”);
打破
“编辑相关”案例:
$p.data('类型','相关')
.对话框(“选项”、“标题”、“相关项”);
打破
}
Utils.fillSelect('p#u active',$(this.data('access');
if($('#p#U产品选项')。长度==0){
$('p#u category')。触发器('change');
}
$p.dialog(“打开”);
})
//徽章
.delegate(“#徽章_添加”,“单击”,函数(){
var s=$(“#产品#徽章”),
badge=$('option:selected',s).text(),
badgevalue=s.val();
如果(badgevalue==0){
返回;
}
$('productsForm')。数据('products')。_buildBadge(badgevalue,badge)。附录('#badge_列表');
})
//类别
.delegate(“#产品_目录”,“鼠标悬停”,函数(e){
clearTimeout(categoryTimer);
$(此).attr('size',30);
})
.delegate(“#产品_目录”,“鼠标输出”,函数(e){
var _self=$(本);
categoryTimer=setTimeout(函数(){u self.attr('size',5);},300);
})
.delegate(“#产品_目录”、“更改”和函数(e){
$(this).find('option:selected').text()=“--Clearance”?警报('Clearance:\n\n如果这是仅库存的项目,请选择Clearance作为主要类别。\n\n将以前的主要类别添加到这些次要类别中。“):”;
})
//自定义代码
.delegate(“#customCodeSelect”、“change”、函数(){
var$this=$(this);
如果(this.selectedIndex==0){
$this.next().attr('disabled',true);
}否则{
$this.next().removeAttr('disabled');
}
})
.delegate('.addCustomCode',单击',函数(){
var$select=$(“#customCodeSelect”),
type=$select.val(),
数据=$select.next().is(':disabled')?':$select.next().val(),
$o=$($('productsForm').data('products')。\u buildCustomCode(类型,数据));
Utils.button($o.find('button'));
$o.appendTo(“#customCodeList”);
})
.delegate('.expandCustomCode','click',函数(){
var$area=$(this.next();
$area.toggle($area.is(':hidden'));
})
.delegate('.customCodeDate',单击',函数(){
$(this.parent().find('input[type=text]')。切换(this.checked);
$(this).parent().find('input[type=text]').val(“”);
})
//特征
.delegate(“#新建#功能”,“单击”,函数(){
$('productsForm')。数据('products')。'u buildFeature()。附加到('features');
})
.delegate(“.delete\u div\u feature”,“单击”,函数(){
$(this).最近的(“li”).remove();
})
//图像
.delegate(“#编辑#logoimage,#编辑#indeximage,#additionalimages”,“单击”,函数(){
var single=((this.id='edit_indeximage')| |(this.id='edit_logoimage'))?true:false;
$('#imageSelector').imageSelector('show',this,$(this).data('imageSelector'),single);
})
.delegate('.changeImage',hover',函数(e){
变量$this=$(this),
$ele=$this.sides('.imageSwitchPreview');
if(!$this.data('imageSelector')){
返回;
}
开关(e型){
案例“鼠标悬停”:
$ele.show()
.职位({
其中:$(本),
我的‘左波顿’,
在“右上角”,
偏移量:“5-10”
});
打破
“鼠标出”一案:
$ele.hide();
打破
}
})
//布局
.delegate(“#layoutCheckbox”、“单击”和函数(){
如果(选中此项){
$('#layoutId').hide().attr('di')