Skip to content

Commit

Permalink
Added a JavaScript event to the renderPartial method for successfully…
Browse files Browse the repository at this point in the history
… loaded views via ajax
  • Loading branch information
andystrobel committed Mar 11, 2014
1 parent 4befd9d commit 4233965
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions protected/components/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


}
1 change: 1 addition & 0 deletions protected/docs/guide/developer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
- [Settings](settings.md)
- [Coding Style](coding_style.md)
- [Notifications](notifications.md)
- [JavaScript](javascript.md)
- [Zend Framework](zend.md)
15 changes: 15 additions & 0 deletions protected/docs/guide/developer/javascript.md
Original file line number Diff line number Diff line change
@@ -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!

0 comments on commit 4233965

Please sign in to comment.