Javascript 如何覆盖event.stopPropagation()、preventDefault().stopImmediatePropagation()
我正在尝试修改Jira Tempo插件的计划工作表单。所以在节奏时间表页面上 我有一个按钮,它有两个绑定动作,一个是点击动作,另一个是调出焦点。 单击操作将打开一个弹出窗口。焦点输出验证弹出窗口中的表单。我需要先执行clik操作,然后再调出焦点 问题是当弹出窗口打开时,会调用所有三个函数。Javascript 如何覆盖event.stopPropagation()、preventDefault().stopImmediatePropagation(),javascript,jquery,jira,jira-plugin,Javascript,Jquery,Jira,Jira Plugin,我正在尝试修改Jira Tempo插件的计划工作表单。所以在节奏时间表页面上 我有一个按钮,它有两个绑定动作,一个是点击动作,另一个是调出焦点。 单击操作将打开一个弹出窗口。焦点输出验证弹出窗口中的表单。我需要先执行clik操作,然后再调出焦点 问题是当弹出窗口打开时,会调用所有三个函数。 event.stopPropagation().preventDefault().stopImmediatePropagation()这样在chrome中不会触发焦点输出 在IE10和Firefox中工作得很
event.stopPropagation().preventDefault().stopImmediatePropagation()
这样在chrome中不会触发焦点输出
在IE10和Firefox中工作得很好
我是否可以覆盖event.stopPropagation().preventDefault().stoppimediatepropagation()
的jQuery基本函数以不应用于该按钮?
三个人,也许
我试过这个:
(function () {
jQuery.Event.prototype = {
isDefaultPrevented: returnFalse,
isPropagationStopped: returnFalse,
isImmediatePropagationStopped: returnFalse,
stopPropagation: function () {
if (jQuery('#tempo-plan-button').hasClass(this.currentTarget.className)) {
} else {
var e = this.originalEvent;
this.isPropagationStopped = returnTrue;
if (e && e.stopPropagation) {
e.stopPropagation();
}
}
},
preventDefault: function () {
if (jQuery('#tempo-plan-button').hasClass(this.currentTarget.className)) {
} else {
var e = this.originalEvent;
this.isDefaultPrevented = returnTrue;
if (e && e.preventDefault) {
e.preventDefault();
}
}
},
stopImmediatePropagation: function () {
if (jQuery('#tempo-plan-button').hasClass(this.currentTarget.className)) {
} else {
var e = this.originalEvent;
this.isImmediatePropagationStopped = returnTrue;
if (e && e.stopImmediatePropagation) {
e.stopImmediatePropagation();
}
this.stopPropagation();
}
}
};
function returnFalse() {
return false;
}
function returnTrue() {
return true;
}
})();
更新:
我无法控制单击功能的功能,但我可以控制焦点输出,我做了一些测试,我看起来Chrome没有看到焦点输出事件,因为元素在焦点输出发生之前隐藏(它是一个弹出按钮)。
我设法用mouse out事件调用我的函数,但这在IE上不起作用,所以我必须为IE和Chrome、Firefox、Safari绑定单独的事件侦听器。
你能帮我举一些浏览器检测的例子吗
更新2:
我的问题用另一个弹出元素的侦听器解决了。例:
jQuery(document).ready(function ($) {
var currentUser = null;
var selected = null;
var opened = null;
var formOpened = null;
var activityField = null;
var activitySelected = null;
var popupBody = null;
var formOpened = null;
var periodCheckbox = null;
var dateField = null;
var endDateField = null;
var plannedHours = null;
var periodselected = null;
var days = 1;
var startdate = 0;
var enddate = 0;
var planButton = $('#tempo-plan-button');
//this is the default LM-Holiday activity ID set this
value to corespond with the value on jira tempo form.
var holidayid = "10100";
var holidaysLeft = 21; /*
$('#tempo-plan-button').click(function () {
alert("click event");
});
$('#tempo-plan-button').focusin(function () {
alert("focus event");
});
$('#tempo-plan-button').hover(function () {
alert("hover event");
});
$('#tempo-plan-button').mouseleave(function () {
alert("mouse leave event");
});
$('#tempo-plan-button').mouseout(function () {
alert("mouse out event");
}); */
$('body').one('focus', 'div[class="aui-popup aui-dialog"]', function (event) {
$('div[class="aui-popup aui-dialog"]').each(function () {
popupBody = $(this).find(".dialog-components");
if ($(this).find(".dialog-title").hasClass("tempo-add-button") === false) {
i = 0;
j = 0;
$(popupBody).find(".dialog-page-menu li").each(function () {
if ($(this).attr("class") === "page-menu-item selected") {
button = $(this).find('.item-button');
if ((button).text() === "Internal") {
selected = i;
}
}
i++;
});
$(popupBody).find(".dialog-panel-body").each(function () {
if ($(this).is(":visible")) {
opened = j;
formOpened = $(this).find('form');
}
j++;
});
if (selected === null) {
i = 0;
j = 0;
$(popupBody).find(".dialog-page-menu li").click(function () {
$(popupBody).find(".dialog-page-menu li").each(function () {
if ($(this).attr("class") === "page-menu-item selected") {
button = $(this).find('.item-button');
if ((button).text() === "Internal") {
selected = i;
}
}
i++;
});
$(popupBody).find(".dialog-panel-body").each(function () {
if ($(this).is(":visible")) {
opened = j;
formOpened = $(this).find('form');
}
j++;
});
if (selected === opened) {
activityField = $(formOpened).find('.tempo-activity-picker.select');
periodCheckbox = $(formOpened).find('.showperiod.tempo-show-period');
dateField = $(formOpened).find(' input[name="date"]');
endDateField = $(formOpened).find('input[name="enddate"]');
plannedHours = $(formOpened).find('input[name="time"]');
days = 1;
$(activityField).change(function () {
activitySelected = $(this).val();
});
$(periodCheckbox).change(function () {
if ($(this).prop("checked")) {
periodselected = true;
}
else
{
periodselected = false;
}
});
$(dateField).change(function () {
if (periodselected) {
startdate = parseDate($(this).val());
enddate = parseDate($(endDateField).val());
} else {
days = 1;
}
;
});
$(endDateField).change(function () {
startdatestring = $(dateField).val();
enddatestring = $(this).val();
startdate = parseDate(startdatestring);
enddate = parseDate(enddatestring);
});
$(plannedHours).off("focusin");
$(plannedHours).focusin(function () {
if (activitySelected === holidayid) {
if (periodselected) {
days = calcBusinessDays(startdate, enddate);
if (holidaysLeft >= days) {
holidaysLeft = holidaysLeft - days;
alert("Mai ai " + holidaysLeft + " zile de concediu ramase!");
$(popupBody).find('button[accesskey="s"]').removeAttr('disabled');
}
else {
$(popupBody).find('button[accesskey="s"]').attr('disabled', 'disabled');
alert('trebuie sa selectezi o perioada mai mica de' + holidaysLeft + 'de zile');
}
} else
{
if (holidaysLeft >= days) {
holidaysLeft = holidaysLeft - days;
alert("Mai ai " + holidaysLeft + " zile de concediu ramase!");
$(popupBody).find('button[accesskey="s"]').removeAttr('disabled');
}
else {
$(popupBody).find('button[accesskey="s"]').attr('disabled', 'disabled');
alert('trebuie sa selectezi o perioada mai mica de' + holidaysLeft + 'de zile');
}
}
}
});
}
});
} else {
j = 0;
$(popupBody).find(".dialog-panel-body").each(function () {
if ($(this).is(":visible")) {
opened = j;
formOpened = $(this).find('form');
}
j++;
});
if (selected === opened) {
activityField = $(formOpened).find('.tempo-activity-picker.select');
periodCheckbox = $(formOpened).find('.showperiod.tempo-show-period');
dateField = $(formOpened).find(' input[name="date"]');
endDateField = $(formOpened).find('input[name="enddate"]');
plannedHours = $(formOpened).find('input[name="time"]');
days = 1;
$(activityField).change(function () {
activitySelected = $(this).val();
});
$(periodCheckbox).change(function () {
if ($(this).prop("checked")) {
periodselected = true;
}
else
{
periodselected = false;
}
});
$(dateField).change(function () {
if (periodselected) {
startdate = parseDate($(this).val());
enddate = parseDate($(endDateField).val());
} else {
days = 1;
}
;
});
$(endDateField).change(function () {
startdatestring = $(dateField).val();
enddatestring = $(this).val();
startdate = parseDate(startdatestring);
enddate = parseDate(enddatestring);
});
$(plannedHours).off("focusin");
$(plannedHours).focusin(function () {
if (activitySelected === holidayid) {
if (periodselected) {
days = calcBusinessDays(startdate, enddate);
if (holidaysLeft >= days) {
holidaysLeft = holidaysLeft - days;
alert("Mai ai " + holidaysLeft + " zile de concediu ramase!");
$(popupBody).find('button[accesskey="s"]').removeAttr('disabled');
}
else {
$(popupBody).find('button[accesskey="s"]').attr('disabled', 'disabled');
alert('trebuie sa selectezi o perioada mai mica de' + holidaysLeft + 'de zile');
}
} else
{
if (holidaysLeft >= days) {
holidaysLeft = holidaysLeft - days;
alert("Mai ai " + holidaysLeft + " zile de concediu ramase!");
$(popupBody).find('button[accesskey="s"]').removeAttr('disabled');
}
else {
$(popupBody).find('button[accesskey="s"]').attr('disabled', 'disabled');
alert('trebuie sa selectezi o perioada mai mica de' + holidaysLeft + 'de zile');
}
}
}
});
}
}
;
}
;
return false;
});
$.ajax({
type: "GET",
url: location.protocol + '//' + location.host + "/rest/api/2/myself",
success: function (response) {
currentUser = $.parseJSON(response);
},
error: function (response) {
alert("Eroare" + response.result);
}
});
return false;
});
});
function calcBusinessDays(dDate1, dDate2) { // input given as Date objects
var iWeeks, iDateDiff, iAdjust = 0;
if (dDate2 < dDate1)
return -1; // error code if dates transposed
var iWeekday1 = dDate1.getDay(); // day of week
var iWeekday2 = dDate2.getDay();
iWeekday1 = (iWeekday1 === 0) ? 7 : iWeekday1; // change Sunday from 0 to 7
iWeekday2 = (iWeekday2 === 0) ? 7 : iWeekday2;
if ((iWeekday1 > 5) && (iWeekday2 > 5))
iAdjust = 1; // adjustment if both days on weekend
iWeekday1 = (iWeekday1 > 5) ? 5 : iWeekday1; // only count weekdays
iWeekday2 = (iWeekday2 > 5) ? 5 : iWeekday2;
// calculate differnece in weeks (1000mS * 60sec * 60min * 24hrs * 7 days = 604800000)
iWeeks = Math.floor((dDate2.getTime() - dDate1.getTime()) / 604800000);
if (iWeekday1 <= iWeekday2) {
iDateDiff = (iWeeks * 5) + (iWeekday2 - iWeekday1);
} else {
iDateDiff = ((iWeeks + 1) * 5) - (iWeekday1 - iWeekday2);
}
iDateDiff -= iAdjust // take into account both days on weekend
return (iDateDiff + 1); // add 1 because dates are inclusive
}
function parseDate(s) {
var lastSlash = s.lastIndexOf("/");
var years = s.substring(lastSlash + 1);
years = "20" + years;
s = s.replaceAt(lastSlash + 1, years);
var pattern = /(.*?)\/(.*?)\/(.*?)$/;
var result = s.replace(pattern, function (match, p1, p2, p3) {
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
return (months.indexOf(p2) + 1) + "/" + (p1) + "/" + p3;
});
return new Date(result);
}
String.prototype.replaceAt = function (index, character) {
return this.substr(0, index) + character + this.substr(index + character.length);
};
function propStopped(event) {
var msg = "";
if (event.isPropagationStopped()) {
msg = "called";
} else {
msg = "not called";
}
alert(msg);
}
jQuery(文档).ready(函数($){
var currentUser=null;
选择的var=null;
var=null;
var formOpened=null;
var activityField=null;
var activitySelected=null;
var popubody=null;
var formOpened=null;
var periodCheckbox=null;
var dateField=null;
var endDateField=null;
var plannedHours=null;
var periodselected=null;
风险值天数=1;
var startdate=0;
var enddate=0;
var planButton=$(“#节奏计划按钮”);
//这是为此设置的默认LM假日活动ID
值与jira tempo表单上的值共同响应。
var holidayid=“10100”;
var holidaysLeft=21/*
$(“#节奏计划按钮”)。单击(函数(){
警报(“点击事件”);
});
$(“#节奏计划按钮”).focusin(函数(){
警报(“焦点事件”);
});
$(“#节奏计划按钮”)。悬停(函数(){
警报(“悬停事件”);
});
$(“#节奏计划按钮”).mouseleave(函数(){
警报(“鼠标离开事件”);
});
$(“#节奏计划按钮”).mouseout(函数(){
警报(“鼠标移出事件”);
}); */
$('body').one('focus','div[class=“aui popup aui dialog”]”,函数(事件){
$('div[class=“aui弹出aui对话框”]”)。每个(函数(){
popubody=$(this.find(“.dialog组件”);
if($(this).find(“.dialog title”).hasClass(“节奏添加按钮”)==false){
i=0;
j=0;
$(popubody).find(“.dialog page menu li”).each(函数(){
if($(this.attr(“类”)=“已选择页面菜单项”){
按钮=$(this.find('.item按钮');
如果((按钮).text()=“内部”){
选定=i;
}
}
i++;
});
$(popubody).find(“.dialog panel body”).each(函数(){
如果($(this).is(“:可见”)){
打开=j;
formOpened=$(this.find('form');
}
j++;
});
如果(选定===null){
i=0;
j=0;
$(popubody).查找(“.dialog page menu li”).单击(函数(){
$(popubody).find(“.dialog page menu li”).each(函数(){
if($(this.attr(“类”)=“已选择页面菜单项”){
按钮=$(this.find('.item按钮');
如果((按钮).text()=“内部”){
选定=i;
}
}
i++;
});
$(popubody).find(“.dialog panel body”).each(函数(){
如果($(this).is(“:可见”)){
打开=j;
formOpened=$(this.find('form');
}
j++;
});
如果(选定===打开){
activityField=$(formOpened.find('.tempo activity picker.select');
periodCheckbox=$(formOpened.find('.showperiod.tempo show period');
dateField=$(formOpened.find('input[name=“date”]”);
endDateField=$(formOpened.find('input[name=“enddate”]”);
plannedhurs=$(formOpened).find('input[name=“time”]”);
天数=1天;
$(activityField).change(函数(){
activitySelected=$(this.val();
});
$(periodCheckbox).更改(函数(){
如果($(this).prop(“选中”)){
所选周期=真;
}
其他的
{
所选周期=假;
}
});
$(日期字段).更改(函数(){
如果(已选定){
startdate=parseDate($(this.val());
enddate=parseDate($(endDateField).val());
}否则{
天数=1天;
}
;
});
$(endDateField).change(函数(){
startdatestring=$(日期字段).val();
enddatestring=$(this.val();