It seems to be departing from Yii, because this script is completely written in javascript, however I think it is a kind of a tip for making use of Yii in a sense. Anyway I would like to share this tip with you guys.
I have made our widgets for the blog demo open/close and keep their status between the pages as seen below. Closing a widget is to click the header (title line) of the widget when it is opened. Opening a widget is also to click the header of the widget when it is closed.
[howto begins]
We need to hold the status of the widgets anywhere, because we will see all the widgets are opened when we move to another page without the persistent status of the widgets.
PersistJS
I have designed to make use of persistJS in order to hold the client status without cookies. There are several backend storages which are not unified, for browsers. Thanks to the persistJS
however, we are able to hold the client-side informations in the browser in a unified way.
Installation
- Comment a following line out (for major users who are using IE
).
'urlManager'=>array(
- 'urlFormat'=>'path',
+ // 'urlFormat'=>'path',
'rules'=>array(
- Insert following lines before the title tag of
protected/views/layouts/main.php
.
+ <script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery-1.3.2.min.js"></script>
+ <script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/persist-min.js"></script>
<title><?php echo $this->pageTitle; ?></title>
- Download jQuery from
http://www.yiiframew…16.0;attach=178 and persistJS from http://www.yiiframew…16.0;attach=179 and store them tojs
directory just under the blog demo.
[EDIT]Check following google code out because there must be updates.
Source code
As usual, the source code is available from google code http://code.google.c…demo-enhanced/.
Limitation
In terms of IE, persistJS
uses ie backend storage which seems to be dependent to the absolute path of the page. This is why I have commented this line ('urlFormat'=>'path') out.
On the contrary, it is OK for you to use path format in terms of firefox and chrome, though I have not tested all browsers on all platforms.
Terms & Conditions
This script is fully dependent to JQuery and PersistJS. Please consult the original terms and conditions.
FYI, jQuery: both MIT and GPL licenses, PersistJS: No license?
Have fun