diff --git a/protected/components/Controller.php b/protected/components/Controller.php index 49062122f23..b5ce54c5e10 100644 --- a/protected/components/Controller.php +++ b/protected/components/Controller.php @@ -168,4 +168,24 @@ public function renderModalClose() { //Yii::app()->end(); } + /** + * Add a JavaScript to the renderPartial method to fire an event at the body tag, when the view loaded successfully + */ + public function renderPartial($view, $data = null, $return = false, $processOutput = false) { + + if (Yii::app()->request->isAjaxRequest) { + /** + * Fire an event with the following params: + * @param1 String controllerID + * @param2 String moduleID + * @param3 String actionID + * @param4 String view path + */ + Yii::app()->clientScript->registerScript("autoAjaxEventFire","$('body').trigger('ajaxLoaded', ['". $this->id."', '". $this->module->id ."', '". $this->action->id ."', '". $view ."']);",CClientScript::POS_END); + } + + return parent::renderPartial($view, $data, $return, $processOutput); + } + + } diff --git a/protected/docs/guide/developer/index.md b/protected/docs/guide/developer/index.md index 5053e7aa5a1..ba6bf7e2d39 100644 --- a/protected/docs/guide/developer/index.md +++ b/protected/docs/guide/developer/index.md @@ -30,4 +30,5 @@ - [Settings](settings.md) - [Coding Style](coding_style.md) - [Notifications](notifications.md) +- [JavaScript](javascript.md) - [Zend Framework](zend.md) diff --git a/protected/docs/guide/developer/javascript.md b/protected/docs/guide/developer/javascript.md new file mode 100644 index 00000000000..530d8e68b6b --- /dev/null +++ b/protected/docs/guide/developer/javascript.md @@ -0,0 +1,15 @@ +JavaScript +========== + +Summary of general JavaScript functions and events used in HumHub. + +## Ajax Loaded Event + +Each page that is loading with Ajax via the renderPartial method, fire a JavaScript event named "ajaxLoaded" to signalize that the view is successfully loaded. +To catch this event you have to set a trigger at the body tag: + + $( "body" ).on( "ajaxLoaded", function( event, controllerID, moduleID, actionID, view ) { + alert( controllerID + "\n" + moduleID + "\n" + actionID + "\n" + view ); + }); + +``Note:`` To deliver JavaScript with the view loaded via ajax, you have to set the renderPartial param "$processOutput" to true!