CC-3174 : showbuilder

replacing context menus on calendar screen.
This commit is contained in:
Naomi Aro 2012-02-09 21:19:21 +01:00
parent 4691799326
commit fdd962f5ce
8 changed files with 103 additions and 815 deletions

View file

@ -40,7 +40,7 @@ class LibraryController extends Zend_Controller_Action
$request = $this->getRequest();
$baseUrl = $request->getBaseUrl();
$this->view->headScript()->appendFile($baseUrl.'/js/contextmenu/jjmenu.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/contextmenu/jquery.contextMenu.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/js/jquery.dataTables.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.pluginAPI.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.fnSetFilteringDelay.js?'.$CC_CONFIG['airtime_version'],'text/javascript');

View file

@ -51,14 +51,14 @@ class ScheduleController extends Zend_Controller_Action
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/schedule/full-calendar-functions.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/fullcalendar/fullcalendar.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/timepicker/jquery.ui.timepicker-0.0.6.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/timepicker/jquery.ui.timepicker.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/colorpicker/js/colorpicker.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/schedule/add-show.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/schedule/schedule.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/meioMask/jquery.meio.mask.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headLink()->appendStylesheet($baseUrl.'/css/jquery-ui-timepicker.css?'.$CC_CONFIG['airtime_version']);
$this->view->headLink()->appendStylesheet($baseUrl.'/css/jquery.ui.timepicker.css?'.$CC_CONFIG['airtime_version']);
$this->view->headLink()->appendStylesheet($baseUrl.'/css/fullcalendar.css?'.$CC_CONFIG['airtime_version']);
$this->view->headLink()->appendStylesheet($baseUrl.'/css/colorpicker/css/colorpicker.css?'.$CC_CONFIG['airtime_version']);
$this->view->headLink()->appendStylesheet($baseUrl.'/css/add-show.css?'.$CC_CONFIG['airtime_version']);
@ -195,16 +195,14 @@ class ScheduleController extends Zend_Controller_Action
return false;
}
$showStartLocalDT = Application_Model_DateHelper::ConvertToLocalDateTime($show->getShowInstanceStart());
$showEndLocalDT = Application_Model_DateHelper::ConvertToLocalDateTime($show->getShowInstanceEnd());
$showStartLocalDT = Application_Model_DateHelper::ConvertToLocalDateTime($instance->getShowInstanceStart());
$showEndLocalDT = Application_Model_DateHelper::ConvertToLocalDateTime($instance->getShowInstanceEnd());
/*
if ($epochNow < $showStartDateHelper->getTimestamp()) {
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST),$show->getShowId()) && !$show->isRecorded() && !$show->isRebroadcast()) {
//$menu["edit"] = array("name"=> "Edit Metadata", "icon" => "edit", "url" => "/library/edit-file-md/id/{$id}");
$menu[] = array('action' => array('type' => 'ajax', 'url' => '/Schedule/schedule-show-dialog'.$params,
'callback' => 'window["buildScheduleDialog"]'), 'title' => 'Add / Remove Content');
@ -213,48 +211,38 @@ class ScheduleController extends Zend_Controller_Action
}
}
if(!$show->isRecorded()) {
$menu[] = array('action' => array('type' => 'ajax', 'url' => '/Schedule/show-content-dialog'.$params,
'callback' => 'window["buildContentDialog"]'), 'title' => 'Show Content');
}
if ($showEndDateHelper->getTimestamp() <= $epochNow
&& $show->isRecorded()
&& Application_Model_Preference::GetUploadToSoundcloudOption()) {
if(is_null($show->getSoundCloudFileId())){
$menu[] = array('action' => array('type' => 'fn',
'callback' => "window['uploadToSoundCloud']($id)"),
'title' => 'Upload to SoundCloud');
}else{
$menu[] = array('action' => array('type' => 'fn',
'callback' => "window['uploadToSoundCloud']($id)"),
'title' => 'Re-upload to SoundCloud');
}
}
if ($showStartDateHelper->getTimestamp() <= $epochNow &&
$epochNow < $showEndDateHelper->getTimestamp() &&
$user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
if ($show->isRecorded()) {
$menu[] = array('action' => array('type' => 'fn',
'callback' => "window['confirmCancelRecordedShow']($id)"),
'title' => 'Cancel Current Show');
} else {
$menu[] = array('action' => array('type' => 'fn',
'callback' => "window['confirmCancelShow']($id)"),
'title' => 'Cancel Current Show');
}
}
*/
if (!$instance->isRecorded()) {
$menu["content"] = array("name"=> "Show Content", "url" => "/schedule/show-content-dialog");
}
if ($showEndLocalDT->getTimestamp() <= $epochNow
&& $instance->isRecorded()
&& Application_Model_Preference::GetUploadToSoundcloudOption()) {
$text = is_null($instance->getSoundCloudFileId()) ? 'Upload to SoundCloud' : 'Re-upload to SoundCloud';
$menu["soundcloud"] = array("name"=> $text, "icon" => "soundcloud");
}
if ($showStartLocalDT->getTimestamp() <= $epochNow &&
$epochNow < $showEndLocalDT->getTimestamp() &&
$user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
if ($instance->isRecorded()) {
$menu["cancel_recorded"] = array("name"=> "Cancel Current Show", "icon" => "delete");
} else {
$menu["cancel"] = array("name"=> "Cancel Current Show", "icon" => "delete");
}
}
if ($epochNow < $showStartLocalDT->getTimestamp()) {
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
//callback window["beginEditShow"] /format/json/id/{$id}
$menu["edit"] = array("name"=> "Edit Show", "icon" => "edit", "url" => "/Schedule/edit-show");
if ($instance->getShow()->isRepeating()) {
@ -262,30 +250,14 @@ class ScheduleController extends Zend_Controller_Action
//create delete sub menu.
$menu["del"] = array("name"=> "Delete", "icon" => "delete", "items" => array());
//window["scheduleRefetchEvents"]
$menu["del"]["items"]["single"] = array("name"=> "Delete", "icon" => "delete", "url" => "/schedule/delete-show");
$menu["del"]["items"]["single"] = array("name"=> "Delete This Instance", "icon" => "delete", "url" => "/schedule/delete-show");
//window["scheduleRefetchEvents"]
$menu["del"]["items"]["following"] = array("name"=> "Delete", "icon" => "delete", "url" => "/schedule/cancel-show");
$menu["del"]["items"]["following"] = array("name"=> "Delete This Instance and All Following", "icon" => "delete", "url" => "/schedule/cancel-show");
}
else {
//window["scheduleRefetchEvents"]'
$menu["del"] = array("name"=> "Delete", "icon" => "delete", "url" => "/schedule/delete-show");
}
/*
$menu[] = array('action' => array('type' => 'ajax', 'url' => '/Schedule/delete-show'.$params,
'callback' => 'window["scheduleRefetchEvents"]'), 'title' => 'Delete This Instance');
if ($show->getShow()->isRepeating()) {
//create delete sub menu.
//$menu["del"] = array("name"=> "Delete", "icon" => "delete", "items" => array());
$menu[] = array('action' => array('type' => 'ajax', 'url' => '/Schedule/cancel-show'.$params,
'callback' => 'window["scheduleRefetchEvents"]'), 'title' => 'Delete This Instance and All Following');
}
*/
}
}

View file

@ -326,7 +326,9 @@ class Application_Model_Schedule {
JOIN cc_show AS showt ON (showt.id = si.show_id)
)
WHERE si.starts >= '{$p_startDateTime}' AND si.starts <= '{$p_endDateTime}'
WHERE si.modified_instance = false AND
si.starts >= '{$p_startDateTime}' AND si.starts <= '{$p_endDateTime}'
ORDER BY si.starts, sched.starts;";

View file

@ -223,6 +223,8 @@ class Application_Model_Scheduler {
$this->insertAfter($scheduleItems, $schedFiles, $adjustSched);
$this->con->commit();
Application_Model_RabbitMq::PushSchedule();
}
catch (Exception $e) {
$this->con->rollback();
@ -277,6 +279,8 @@ class Application_Model_Scheduler {
$this->insertAfter($afterItem, array($data), $adjustSched);
$this->con->commit();
Application_Model_RabbitMq::PushSchedule();
}
catch (Exception $e) {
$this->con->rollback();
@ -310,6 +314,8 @@ class Application_Model_Scheduler {
}
$this->con->commit();
Application_Model_RabbitMq::PushSchedule();
}
catch (Exception $e) {
$this->con->rollback();

View file

@ -390,16 +390,79 @@ $(window).load(function() {
oItems.edit.callback = callback;
}
//define a content callback.
if (oItems.content !== undefined) {
//delete a single instance
callback = function() {
$.get(oItems.content.url, {format: "json", id: data.id}, function(json){
buildContentDialog(json);
});
};
oItems.content.callback = callback;
}
//define a soundcloud callback.
if (oItems.soundcloud !== undefined) {
callback = function() {
uploadToSoundCloud(data.id);
};
oItems.soundcloud.callback = callback;
}
//define a cancel recorded show callback.
if (oItems.cancel_recorded !== undefined) {
callback = function() {
confirmCancelRecordedShow(data.id);
};
oItems.cancel_recorded.callback = callback;
}
//define a cancel callback.
if (oItems.cancel !== undefined) {
callback = function() {
confirmCancelShow(data.id);
};
oItems.cancel.callback = callback;
}
//define a delete callback.
if (oItems.del !== undefined) {
//repeating show multiple delete options
if (oItems.del.items !== undefined) {
var del = oItems.del.items;
//delete a single instance
callback = function() {
$.get(oItems.edit.url, {format: "json", id: data.id}, function(json){
beginEditShow(json);
$.post(del.single.url, {format: "json", id: data.id}, function(json){
scheduleRefetchEvents(json);
});
};
del.single.callback = callback;
//delete this instance and all following instances.
callback = function() {
$.post(del.following.url, {format: "json", id: data.id}, function(json){
scheduleRefetchEvents(json);
});
};
del.following.callback = callback;
}
//single show
else {
callback = function() {
$.post(oItems.del.url, {format: "json", id: data.id}, function(json){
scheduleRefetchEvents(json);
});
};
oItems.del.callback = callback;
}
}
items = oItems;
}

View file

@ -1,13 +0,0 @@
* jjmenu library file has to be modified in order to handle some error cases.
* see line 87 in jjemenu.js. Following code was added:
/* jjmenu doesn't provide ability to add callback function
in case of error. So the error handling has to be included in
the library itself */
if(data.show_error == true){
alert("The show doesn't exist anymore!");
window.location.reload();
}else if(data.playlist_error == true){
alert("The playlist doesn't exist anymore!");
window.location.reload();
}

View file

@ -1,377 +0,0 @@
/* jjmenu - context menu jquery plugin
* http://jursza.net/dev/jjmenu/
*
* @author Jacek Jursza (okhan.pl@gmail.com)
* @version 1.1.2
* @date 2010-08-28
* @category jQuery plugin
* @copyright (c) 2009 Jacek Jursza (http://jursza.net/)
* @licence MIT [http://www.opensource.org/licenses/mit-license.php]
*/
(function($){
$.fn.jjmenu = function (clickEvent, param, myReplaces, effect) {
var global = this;
var acceptEvent = false;
if ( clickEvent == "rightClick" || clickEvent == "both" )
{
global.mousedown(function(event) {
if (event.button == 2 && (clickEvent == "rightClick" || clickEvent == "both")) { // right click
global.pageX = event.pageX;
global.pageY = event.pageY;
event.preventDefault();
event.stopPropagation();
var mmain = new menu("main", param, myReplaces, this, effect);
$(this)[0].oncontextmenu = function() {
return false;
}
$(this).unbind('mouseup');
$(this).blur();
return false;
}
});
document.body.oncontextmenu = function() {
if ($("div[id^=jjmenu_main]").length) return false;
}
}
if ( clickEvent == "click" || clickEvent == "both" )
{
global.click(
function(event) {
if (this == event.currentTarget) {
global.pageX = event.pageX;
global.pageY = event.pageY;
event.preventDefault();
event.stopPropagation();
var mmain = new menu("main", param, myReplaces, this, effect);
$(this).blur();
return false;
}
});
}
$(document).click(function(event) { if (event.button!=2) $("div[id^=jjmenu]").remove(); });
/* Menu obeject */
function menu(id,param,myReplaces,el,effect) {
var effect = getEffect(id, effect);
if (id == "main") window.triggerElement = el;
$("div[id^=jjmenu_"+id+"]").remove();
var m = document.createElement('div');
var ms = document.createElement('span');
$(m).append(ms);
m.className = "jjmenu"; m.id = "jjmenu_"+id;
$(m).css({display:'none'});
$(document.body).append(m);
positionMenu();
var dynamicItems = false;
for (var i in param) {
if (param[i].get) {
dynamicItems = true;
$.getJSON(uReplace(param[i].get), function(data) {
/* jjmenu doesn't provide ability to add callback function
in case of error. So the error handling has to be included in
the library itself */
if(data.show_error == true){
alert("The show instance doesn't exist anymore!");
window.location.reload();
}else if(data.playlist_error == true){
alert("The playlist doesn't exist anymore!");
window.location.reload();
}
for (var ii in data) {
putItem(data[ii]);
}
checkPosition();
})
$(this).ajaxError( function() {
checkPosition();
});
}
else if (param[i].getByFunction) {
if (typeof(param[i].getByFunction) == "function") {
var uF = param[i].getByFunction;
}
else {
var uF = eval(param[i].getByFunction);
}
var uItems = uF(myReplaces);
for (var ii in uItems) {
putItem(uItems[ii]);
}
checkPosition();
}
else {
putItem(param[i]);
}
}
if (!dynamicItems) checkPosition();
showMenu();
/* first position menu */
function positionMenu() {
var pos = $(el).offset();
var t = pos.top;
if (effect.xposition == "left") {
var l = pos.left;
}
else {
var l = pos.left+$(el).width()+10;
}
if (effect.xposition == "mouse") {
l = global.pageX;
}
if (effect.yposition == "mouse") {
t = global.pageY;
}
$(m).css({position:"absolute",top:t+"px",left:l+"px"});
}
/* correct menu position */
function checkPosition() {
var isHidden = $(m).css("display") == "none" ? true : false;
var noAuto = false;
if (effect.orientation == "top" || effect.orientation == "bottom") {
noAuto = true;
}
if (isHidden) $(m).show();
var positionTop = $(m).offset().top;
var positionLeft = $(m).offset().left;
if (isHidden) $(m).hide();
var xPos = positionTop - $(window).scrollTop();
$(m).css({left:"0px"});
var menuHeight = $(m).outerHeight();
var menuWidth = $(m).outerWidth();
$(m).css({left:positionLeft+"px"});
var nleft = positionLeft;
if ( positionLeft + menuWidth > $(window).width() ) {
nleft = $(window).width() - menuWidth;
}
var spaceBottom = true;
if (effect.yposition == "auto" && effect.xposition == "left") {
if ( xPos + menuHeight + $(el).outerHeight() > $(window).height()) {
spaceBottom = false;
}
}
else {
if ( xPos + menuHeight > $(window).height()) {
spaceBottom = false;
}
}
var spaceTop = true;
if (positionTop - menuHeight < 0) {
spaceTop = false;
}
if (effect.yposition == "bottom") {
positionTop = positionTop + $(el).outerHeight();
}
if ( (effect.orientation == "auto" && spaceBottom == false && spaceTop == true) || effect.orientation == "top") {
// top orientation
var ntop = parseInt(positionTop,10) - parseInt(menuHeight,10);
$(m).addClass("topOriented");
} else {
// bottom orientation
$(m).addClass("bottomOriented");
if (effect.yposition == "auto" && effect.xposition == "left") {
positionTop = positionTop + $(el).outerHeight();
}
var ntop = parseInt(positionTop,10);
}
$(m).css({"top":ntop+"px", "left":nleft+"px"});
}
/* show menu depends to effect.show */
function showMenu() {
if (!effect || effect.show == "default") {
$(m).show();
return false;
}
var speed = parseInt(effect.speed);
speed = isNaN(speed) ? 500 : speed;
switch (effect.show)
{
case "fadeIn":
$(m).fadeIn(speed);
break;
case "slideDown":
$(m).slideDown(speed);
break;
default:
$(m).show();
break;
}
}
/* put item to menu */
function putItem(n) {
var item = document.createElement('div');
$(item).hover(function(){
$(this).addClass("jj_menu_item_hover")
},
function(){
$(this).removeClass("jj_menu_item_hover")
});
$(item).click( function(event) {
event.stopPropagation();
doAction(n.action);
});
var span = document.createElement('span');
$(item).append(span);
switch (n.type)
{
case "sub":
item.className = "jj_menu_item jj_menu_item_more";
$(item).click(function() {
if ($("#jjmenu_"+id+"_sub").length > 0) {
$("div[id^=jjmenu_"+id+"_sub]").remove();
}
else {
var sub = new menu(id+"_sub", n.src, myReplaces, this, effect);
}
});
break;
default:
$(item).hover(function() { $("div[id^=jjmenu_"+id+"_sub]").remove(); });
item.className = "jj_menu_item";
break;
}
if (n.customClass && n.customClass.length>0) {
jQuery(span).addClass(n.customClass);
}
$(span).html(uReplace(n.title));
$(ms).append(item);
}
/* do action on menu item */
function doAction(act) {
$("#jjmenu_main").hide();
if (act) {
switch (act.type) {
case "gourl":
if (act.target) {
var newWindow = window.open(uReplace(act.url), act.target);
newWindow.focus();
return false;
}
else {
document.location.href=uReplace(act.url);
}
break;
case "ajax":
$.getJSON(uReplace(act.url), function(data) {
var cb = eval(act.callback);
if (typeof(cb) == "function") {
cb(data);
}
});
break;
case "fn":
var callfn = 'var cb = '+act.callback;
jQuery.globalEval(callfn);
if (typeof(cb) == "function") {
cb(myReplaces);
}
break;
}
}
}
/* replace string with user parameters */
function uReplace(str) {
if (myReplaces) {
for (var u in myReplaces) {
str = str.replace("#"+u+"#", eval("myReplaces."+u));
}
}
return str;
}
/* get effect opbject */
function getEffect(id, effect) {
var defEffect = {
show:"default",
xposition:"right",
yposition:"auto",
orientation:"auto"
};
if (!effect) { return defEffect; }
if (!effect.show) effect.show = "default";
var show = effect.show;
if (!effect.xposition) effect.xposition = "right";
if (!effect.yposition) effect.yposition = "auto";
if (!effect.orientation) effect.orientation = "auto";
if (id != "main") {
var subeffect = defEffect;
subeffect.show = show;
}
return ( id == "main" ) ? effect : subeffect;
}
} // !menu
};
})(jQuery);

View file

@ -1,365 +0,0 @@
/* jjmenu - context menu jquery plugin
* http://jursza.net/dev/jjmenu/
*
* @author Jacek Jursza (okhan.pl@gmail.com)
* @version 1.1.2
* @date 2010-08-28
* @category jQuery plugin
* @copyright (c) 2009 Jacek Jursza (http://jursza.net/)
* @licence MIT [http://www.opensource.org/licenses/mit-license.php]
*/
(function($){
$.fn.jjmenu = function (clickEvent, param, myReplaces, effect) {
var global = this;
var acceptEvent = false;
if ( clickEvent == "rightClick" || clickEvent == "both" )
{
global.mousedown(function(event) {
if (event.button == 2 && (clickEvent == "rightClick" || clickEvent == "both")) { // right click
global.pageX = event.pageX;
global.pageY = event.pageY;
event.preventDefault();
event.stopPropagation();
var mmain = new menu("main", param, myReplaces, this, effect);
$(this)[0].oncontextmenu = function() {
return false;
}
$(this).unbind('mouseup');
$(this).blur();
return false;
}
});
document.body.oncontextmenu = function() {
if ($("div[id^=jjmenu_main]").length) return false;
}
}
if ( clickEvent == "click" || clickEvent == "both" )
{
global.click(
function(event) {
if (this == event.target) {
global.pageX = event.pageX;
global.pageY = event.pageY;
event.preventDefault();
event.stopPropagation();
var mmain = new menu("main", param, myReplaces, this, effect);
$(this).blur();
return false;
}
});
}
$(document).click(function(event) { if (event.button!=2) $("div[id^=jjmenu]").remove(); });
/* Menu obeject */
function menu(id,param,myReplaces,el,effect) {
var effect = getEffect(id, effect);
if (id == "main") window.triggerElement = el;
$("div[id^=jjmenu_"+id+"]").remove();
var m = document.createElement('div');
var ms = document.createElement('span');
$(m).append(ms);
m.className = "jjmenu"; m.id = "jjmenu_"+id;
$(m).css({display:'none'});
$(document.body).append(m);
positionMenu();
var dynamicItems = false;
for (var i in param) {
if (param[i].get) {
dynamicItems = true;
$.getJSON(uReplace(param[i].get), function(data) {
for (var ii in data) {
putItem(data[ii]);
}
checkPosition();
})
$(this).ajaxError( function() {
checkPosition();
});
}
else if (param[i].getByFunction) {
if (typeof(param[i].getByFunction) == "function") {
var uF = param[i].getByFunction;
}
else {
var uF = eval(param[i].getByFunction);
}
var uItems = uF(myReplaces);
for (var ii in uItems) {
putItem(uItems[ii]);
}
checkPosition();
}
else {
putItem(param[i]);
}
}
if (!dynamicItems) checkPosition();
showMenu();
/* first position menu */
function positionMenu() {
var pos = $(el).offset();
var t = pos.top;
if (effect.xposition == "left") {
var l = pos.left;
}
else {
var l = pos.left+$(el).width()+10;
}
if (effect.xposition == "mouse") {
l = global.pageX;
}
if (effect.yposition == "mouse") {
t = global.pageY;
}
$(m).css({position:"absolute",top:t+"px",left:l+"px"});
}
/* correct menu position */
function checkPosition() {
var isHidden = $(m).css("display") == "none" ? true : false;
var noAuto = false;
if (effect.orientation == "top" || effect.orientation == "bottom") {
noAuto = true;
}
if (isHidden) $(m).show();
var positionTop = $(m).offset().top;
var positionLeft = $(m).offset().left;
if (isHidden) $(m).hide();
var xPos = positionTop - $(window).scrollTop();
$(m).css({left:"0px"});
var menuHeight = $(m).outerHeight();
var menuWidth = $(m).outerWidth();
$(m).css({left:positionLeft+"px"});
var nleft = positionLeft;
if ( positionLeft + menuWidth > $(window).width() ) {
nleft = $(window).width() - menuWidth;
}
var spaceBottom = true;
if (effect.yposition == "auto" && effect.xposition == "left") {
if ( xPos + menuHeight + $(el).outerHeight() > $(window).height()) {
spaceBottom = false;
}
}
else {
if ( xPos + menuHeight > $(window).height()) {
spaceBottom = false;
}
}
var spaceTop = true;
if (positionTop - menuHeight < 0) {
spaceTop = false;
}
if (effect.yposition == "bottom") {
positionTop = positionTop + $(el).outerHeight();
}
if ( (effect.orientation == "auto" && spaceBottom == false && spaceTop == true) || effect.orientation == "top") {
// top orientation
var ntop = parseInt(positionTop,10) - parseInt(menuHeight,10);
$(m).addClass("topOriented");
} else {
// bottom orientation
$(m).addClass("bottomOriented");
if (effect.yposition == "auto" && effect.xposition == "left") {
positionTop = positionTop + $(el).outerHeight();
}
var ntop = parseInt(positionTop,10);
}
$(m).css({"top":ntop+"px", "left":nleft+"px"});
}
/* show menu depends to effect.show */
function showMenu() {
if (!effect || effect.show == "default") {
$(m).show();
return false;
}
var speed = parseInt(effect.speed);
speed = isNaN(speed) ? 500 : speed;
switch (effect.show)
{
case "fadeIn":
$(m).fadeIn(speed);
break;
case "slideDown":
$(m).slideDown(speed);
break;
default:
$(m).show();
break;
}
}
/* put item to menu */
function putItem(n) {
var item = document.createElement('div');
$(item).hover(function(){
$(this).addClass("jj_menu_item_hover")
},
function(){
$(this).removeClass("jj_menu_item_hover")
});
$(item).click( function(event) {
event.stopPropagation();
doAction(n.action);
});
var span = document.createElement('span');
$(item).append(span);
switch (n.type)
{
case "sub":
item.className = "jj_menu_item jj_menu_item_more";
$(item).click(function() {
if ($("#jjmenu_"+id+"_sub").length > 0) {
$("div[id^=jjmenu_"+id+"_sub]").remove();
}
else {
var sub = new menu(id+"_sub", n.src, myReplaces, this, effect);
}
});
break;
default:
$(item).hover(function() { $("div[id^=jjmenu_"+id+"_sub]").remove(); });
item.className = "jj_menu_item";
break;
}
if (n.customClass && n.customClass.length>0) {
jQuery(span).addClass(n.customClass);
}
$(span).html(uReplace(n.title));
$(ms).append(item);
}
/* do action on menu item */
function doAction(act) {
if (act) {
switch (act.type) {
case "gourl":
if (act.target) {
var newWindow = window.open(uReplace(act.url), act.target);
newWindow.focus();
return false;
}
else {
document.location.href=uReplace(act.url);
}
break;
case "ajax":
$.getJSON(uReplace(act.url), function(data) {
var cb = eval(act.callback);
if (typeof(cb) == "function") {
cb(data);
}
});
break;
case "fn":
var callfn = 'var cb = '+act.callback;
jQuery.globalEval(callfn);
if (typeof(cb) == "function") {
cb(myReplaces);
}
break;
}
}
}
/* replace string with user parameters */
function uReplace(str) {
if (myReplaces) {
for (var u in myReplaces) {
str = str.replace("#"+u+"#", eval("myReplaces."+u));
}
}
return str;
}
/* get effect opbject */
function getEffect(id, effect) {
var defEffect = {
show:"default",
xposition:"right",
yposition:"auto",
orientation:"auto"
};
if (!effect) { return defEffect; }
if (!effect.show) effect.show = "default";
var show = effect.show;
if (!effect.xposition) effect.xposition = "right";
if (!effect.yposition) effect.yposition = "auto";
if (!effect.orientation) effect.orientation = "auto";
if (id != "main") {
var subeffect = defEffect;
subeffect.show = show;
}
return ( id == "main" ) ? effect : subeffect;
}
} // !menu
};
})(jQuery);