Change multiple jquery statements to single jquery with on() method to handle events

This commit is contained in:
Hadi Nategh 2014-02-21 16:37:39 +00:00
parent 82704bd0d2
commit cbae6e5722

View File

@ -148,57 +148,63 @@ app.classes.calendar = AppJS.extend(
{ {
var that = this; var that = this;
//Draggable //Draggable & Resizable selector
jQuery("div[id^='drag_']").draggable( jQuery("div[id^='drag_']")
{ //draggable event handler
stack: jQuery("div[id^='drag_']"), .draggable
revert: "invalid", ({
delay: 50, stack: jQuery("div[id^='drag_']"),
revert: "invalid",
delay: 50,
cursorAt:{top:0,left:0}, cursorAt:{top:0,left:0},
containment: ".egw_fw_content_browser_iframe", containment: ".egw_fw_content_browser_iframe",
scroll: true, scroll: true,
opacity: .6, opacity: .6,
cursor: "move", cursor: "move",
/** /**
* Triggered when the dragging of calEvent stoped. * Triggered when the dragging of calEvent stoped.
* *
* @param {event} event * @param {event} event
* @param {Object} ui * @param {Object} ui
*/ */
stop: function(event, ui) stop: function(event, ui)
{
ui.helper.width(oldWidth);
ui.helper[0].innerHTML = oldInnerHTML;
},
/**
* Triggered while dragging a calEvent.
*
* @param {event} event
* @param {Object} ui
*
*/
drag:function(event, ui)
{ {
ui.helper.width(oldWidth); //that.dragEvent();
ui.helper[0].innerHTML = oldInnerHTML; },
},
/** /**
* Triggered while dragging a calEvent. * Triggered when the dragging of calEvent started.
* *
* @param {event} event * @param {event} event
* @param {Object} ui * @param {Object} ui
* *
*/ */
drag:function(event, ui) start: function(event, ui)
{ {
//that.dragEvent(); oldInnerHTML = ui.helper[0].innerHTML;
}, oldWidth = ui.helper.width();
ui.helper.width(jQuery("#calColumn").width());
/** }
* Triggered when the dragging of calEvent started. })
*
* @param {event} event //Resizable event handler
* @param {Object} ui .resizable
* ({
*/
start: function(event, ui)
{
oldInnerHTML = ui.helper[0].innerHTML;
oldWidth = ui.helper.width();
ui.helper.width(jQuery("#calColumn").width());
}
}).resizable({
distance: 10, distance: 10,
@ -281,9 +287,11 @@ app.classes.calendar = AppJS.extend(
} }
}); });
//Droppable //Droppable selector
jQuery("div[id^='drop_']").droppable( jQuery("div[id^='drop_']")
{ //Droppable event handler
.droppable
({
/** /**
* Make all draggable calEvents acceptable * Make all draggable calEvents acceptable
* *
@ -341,10 +349,36 @@ app.classes.calendar = AppJS.extend(
} }
} }
}); });
//jQuery Calendar Event selector
jQuery("body")
//mouseover event handler for calendar tooltip
.on("mouseover", "div[data-tooltip]",function(){
var ttp = jQuery(this).tooltip({
items: "[data-tooltip]",
content: function()
{
var elem = jQuery(this);
if (elem.is("[data-tooltip]"))
return this.getAttribute('data-tooltip') ;
},
track:true,
//onClick Handler for calender entries open: function(event,ui){
jQuery("div.calendar_calEvent").on({ ui.tooltip.removeClass("ui-tooltip");
click:function(ev){ ui.tooltip.addClass("calendar_uitooltip");
}
});
ttp.tooltip("enable");
})
// mousedown event handler for calendar tooltip to remove disable tooltip
.on("mousedown", "div[data-tooltip]", function(){
jQuery(this).tooltip("disable");
})
//onClick event handler for calendar Events
.on("click", "div.calendar_calEvent", function(ev){
var Id = ev.currentTarget.id.replace(/drag_/g,'').split("_")[0]; var Id = ev.currentTarget.id.replace(/drag_/g,'').split("_")[0];
var eventId = Id.match(/-?\d+\.?\d*/g)[0]; var eventId = Id.match(/-?\d+\.?\d*/g)[0];
var appName = Id.replace(/-?\d+\.?\d*/g,''); var appName = Id.replace(/-?\d+\.?\d*/g,'');
@ -358,45 +392,10 @@ app.classes.calendar = AppJS.extend(
{ {
that.edit_series(eventId,startDate); that.edit_series(eventId,startDate);
} }
}, })
mouseover: function(){
var ttp = jQuery(this).tooltip({ //Click event handler for integrated apps
items: "[data-tooltip]", .on("click","div.calendar_plannerEvent",function(ev){
content: function()
{
var elem = jQuery(this);
if (elem.is("[data-tooltip]"))
return this.getAttribute('data-tooltip') ;
},
track:true,
open: function(event,ui){
ui.tooltip.removeClass("ui-tooltip");
ui.tooltip.addClass("calendar_uitooltip");
}
});
ttp.tooltip("enable");
},
mousedown: function(){
jQuery(this).tooltip("disable");
}
});
//Click handler for calendar todos
jQuery("div.calendar_calDayTodos").find("[data-todo^='app|']").on({
click:function(ev)
{
var windowSize = ev.currentTarget.getAttribute('data-todo').split("|")[1];
var link = ev.currentTarget.getAttribute('href');
that.egw.open_link(link,'_blank',windowSize);
return false;
}
});
//Click Handler for calendar planner
jQuery("div.calendar_plannerEvent").on({
click:function(ev){
var eventId = ev.currentTarget.getAttribute('data-date').split("|")[1]; var eventId = ev.currentTarget.getAttribute('data-date').split("|")[1];
var startDate = ev.currentTarget.getAttribute('data-date').split("|")[0]; var startDate = ev.currentTarget.getAttribute('data-date').split("|")[0];
var recurrFlag = ev.currentTarget.getAttribute('data-date').split("|")[2]; var recurrFlag = ev.currentTarget.getAttribute('data-date').split("|")[2];
@ -408,58 +407,41 @@ app.classes.calendar = AppJS.extend(
{ {
that.edit_series(eventId,startDate); that.edit_series(eventId,startDate);
} }
}, })
mouseover: function(){
var ttp = jQuery(this).tooltip({ //Click event handler for calendar cells
items: "[data-tooltip]", .on("click","div.calendar_calAddEvent",function(ev){
content: function() var timestamp = ev.target.getAttribute('data-date').split("|");
{ var owner = ev.target.getAttribute('id').split("_");
var elem = jQuery(this);
if (elem.is("[data-tooltip]"))
return this.getAttribute('data-tooltip') ;
},
track:true,
open: function(event,ui){ var ownerId = owner[2].match( /Ogroup/g)?owner[2].replace( /Ogroup/g, '-'):owner[2].replace( /^\D+/g, '');
ui.tooltip.removeClass("ui-tooltip"); if (owner[2].match( /Or/g))
ui.tooltip.addClass("calendar_uitooltip");
}
});
ttp.tooltip("enable");
},
mousedown: function(){
jQuery(this).tooltip("disable");
}
});
//onClick Handler for calendar cells
jQuery("div.calendar_calAddEvent").click(function(ev)
{
var timestamp = ev.target.getAttribute('data-date').split("|");
var owner = ev.target.getAttribute('id').split("_");
var ownerId = owner[2].match( /Ogroup/g)?owner[2].replace( /Ogroup/g, '-'):owner[2].replace( /^\D+/g, '');
if (owner[2].match( /Or/g))
{
ownerId = 'r' + ownerId;
}
var eventInfo =
{ {
date: timestamp[0], ownerId = 'r' + ownerId;
hour: timestamp[1], }
minute: timestamp[2]
};
if (ownerId != 0) var eventInfo =
{ {
$j(eventInfo).extend(eventInfo,{owner: ownerId}); date: timestamp[0],
} hour: timestamp[1],
minute: timestamp[2]
};
that.egw.open(null, 'calendar', 'add', eventInfo , '_blank'); if (ownerId != 0)
}); {
$j(eventInfo).extend(eventInfo,{owner: ownerId});
}
that.egw.open(null, 'calendar', 'add', eventInfo , '_blank');
})
//Click event handler for calendar todos
.on("click", "a[data-todo]",function(ev){
var windowSize = ev.currentTarget.getAttribute('data-todo').split("|")[1];
var link = ev.currentTarget.getAttribute('href');
that.egw.open_link(link,'_blank',windowSize);
return false;
});
}, },
/** /**