Hallo,
habe vorhin mein erstes jQuery Plugin erstellt. Und wollte mal fragen ob dies vom Aufbau her korrekt ist.
Hier mal der komplette Code, lässt sich ja so oder so rausfinden -.-
habe vorhin mein erstes jQuery Plugin erstellt. Und wollte mal fragen ob dies vom Aufbau her korrekt ist.
Hier mal der komplette Code, lässt sich ja so oder so rausfinden -.-
PHP-Code:
jQuery.fn.siDialog =
{
/**
* Description
*
* @var string
*/
strRequestPath: '/index.php?loadModule=',
/**
* Description
*
* @var string
*/
strHiddenElements: 'object',
/**
* Description
*
* @var integer
*/
intFadeIn: 100,
/**
* Description
*
* @var integer
*/
intFadeOut: 100,
/**
* Description
*
* @var integer
*/
intAnimateSpeed: 150,
/**
* Method: show
*
* Description
*
* @author Benjamin Funk <bfu@stayinside.de>
*
* @check bfu <00.00.0000>
* @check pma <00.00.0000>
*
* @param string strRequestModule
* @param string strUpdateModule
* @param string strUpdateElement
*
* @return boolean|object
*/
show: function(strDialogTitle, strRequestModule, strUpdateModule, strUpdateElement)
{
if ($("div#siDialogModal").length > 0 ||
$("div#siDialogContainer").length > 0)
{
return (false);
}
var objThis = this;
strDialogTitle ? objThis.strDialogTitle = strDialogTitle
: objThis.strDialogTitle = null;
strRequestModule ? objThis.strRequestModule = strRequestModule
: objThis.strRequestModule = null;
strUpdateModule ? objThis.strUpdateModule = strUpdateModule
: objThis.strUpdateModule = null;
strUpdateElement ? objThis.strUpdateElement = strUpdateElement
: objThis.strUpdateElement = null;
jQuery.ajax(
{
url: objThis.strRequestPath + 'JQueryDialogMdl&innerModule=' + objThis.strRequestModule + '&dialogTitle=' + objThis.strDialogTitle,
success: function(transport)
{
jQuery('body').prepend(transport);
jQuery(objThis.strHiddenElements).each(function()
{
jQuery(this).css(
{
visibility: 'hidden'
})
});
jQuery('div#siDialogModal').fadeIn(objThis.intFadeIn);
jQuery().siDialog.__center('div#siDialogContainer', false);
jQuery('div#siDialogContainer').fadeIn(objThis.intFadeIn);
},
complete: function()
{
$('div#siDialogModal').click(function()
{
jQuery().siDialog.close(objThis.strUpdateModule, objThis.strUpdateElement);
})
$(window).resize(function()
{
jQuery().siDialog.__center('div#siDialogContainer', true);
});
}
});
return (jQuery);
},
/**
* Method: close
*
* Description
*
* @author Benjamin Funk <bfu@stayinside.de>
*
* @check bfu <00.00.0000>
* @check pma <00.00.0000>
*
* @return object
*/
close: function()
{
var objThis = this;
jQuery(objThis.strHiddenElements).each(function()
{
jQuery(this).css(
{
visibility: 'visible'
})
});
jQuery('div#siDialogContainer, div#siDialogModal').fadeOut(objThis.intFadeOut).queue(function()
{
jQuery(this).remove();
});
if (objThis.strUpdateModule != null &&
objThis.strUpdateElement != null)
{
jQuery.ajax(
{
url: objThis.strRequestPath + objThis.strUpdateModule,
success: function(transport)
{
jQuery(objThis.strUpdateElement).html(transport);
}
});
}
return (jQuery);
},
/**
* Method: __center
*
* Description
*
* @author Benjamin Funk <bfu@stayinside.de>
*
* @check bfu <00.00.0000>
* @check pma <00.00.0000>
*
* @param string strElement
* @param boolean blnAnimate
*
* @return boolean|object
*/
__center: function(strElement, blnAnimate)
{
var objThis = this;
var objSize =
{
'windowHeight': jQuery(window).height(),
'windowWidth': jQuery(window).width(),
'elementHeight': jQuery(strElement).height(),
'elementWidth': jQuery(strElement).width()
}
var objCSS =
{
'width': objSize.elementWidth,
'height': objSize.elementHeight,
'top': objSize.windowHeight >= objSize.elementHeight ? (objSize.windowHeight / 2) - (objSize.elementHeight / 2)
: 0,
'left': objSize.windowWidth >= objSize.elementWidth ? (objSize.windowWidth / 2) - (objSize.elementWidth / 2)
: 0
}
if (!blnAnimate)
{
jQuery(strElement).css(objCSS);
}
else
{
jQuery(strElement).animate(objCSS, objThis.intAnimateSpeed);
}
return (jQuery);
}
};
Kommentar