├── protected
├── .htaccess
├── views
│ ├── site
│ │ ├── confirmLink.php
│ │ ├── inlineScript.php
│ │ ├── index.php
│ │ ├── _menu.php
│ │ ├── prevents.php
│ │ ├── grid.php
│ │ └── events.php
│ └── layouts
│ │ └── main.php
├── config
│ ├── test.php
│ └── main.php
├── controllers
│ └── SiteController.php
└── components
│ └── NLSClientScript.php
├── readme.md
├── .gitignore
├── index.php
└── index-test.php
/protected/.htaccess:
--------------------------------------------------------------------------------
1 | deny from all
2 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | This is a playground of fullajax with Yii. Used by Yii team to check if we have
2 | problems with apps of such type.
--------------------------------------------------------------------------------
/protected/views/site/confirmLink.php:
--------------------------------------------------------------------------------
1 | renderPartial('_menu')?>
2 |
3 | 'Are you sure?'))?> |
--------------------------------------------------------------------------------
/protected/views/site/inlineScript.php:
--------------------------------------------------------------------------------
1 | renderPartial('_menu')?>
2 |
A page with inline script.
3 | clientScript->registerScript('non_unique_id', 'alert("executed.");');?>
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # phpstorm project files
2 | .idea
3 |
4 | # netbeans project files
5 | nbproject
6 |
7 | # zend studio for eclipse project files
8 | .buildpath
9 | .project
10 | .settings
11 |
12 | # windows thumbnail cache
13 | Thumbs.db
14 |
15 | # yii runtime and assets
16 |
17 | assets/*
18 | protected/runtime/*
--------------------------------------------------------------------------------
/protected/views/site/index.php:
--------------------------------------------------------------------------------
1 | renderPartial('_menu')?>
2 |
3 | This is a page w/o any ajaxified stuff.
4 | Just static elements.
5 |
6 | Here is a hashed link
7 |
8 | For example, we can link to 'grid'))?>.
--------------------------------------------------------------------------------
/protected/config/test.php:
--------------------------------------------------------------------------------
1 | array(
7 | 'fixture'=>array(
8 | 'class'=>'system.test.CDbFixtureManager',
9 | ),
10 | /* uncomment the following to provide test database connection
11 | 'db'=>array(
12 | 'connectionString'=>'DSN for test database',
13 | ),
14 | */
15 | ),
16 | )
17 | );
18 |
--------------------------------------------------------------------------------
/protected/controllers/SiteController.php:
--------------------------------------------------------------------------------
1 | request->isAjaxRequest)
9 | {
10 | $this->renderPartial($view, null, false, true);
11 | }
12 | else
13 | {
14 | $this->render($view);
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/protected/views/site/_menu.php:
--------------------------------------------------------------------------------
1 |
2 | |
3 | |
4 | |
5 | |
6 | |
7 |
8 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 | run();
14 |
--------------------------------------------------------------------------------
/index-test.php:
--------------------------------------------------------------------------------
1 | run();
16 |
--------------------------------------------------------------------------------
/protected/config/main.php:
--------------------------------------------------------------------------------
1 | dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
4 | 'name'=>'Fullajax Web Application demo',
5 |
6 | // preloading 'log' component
7 | 'preload'=>array('log'),
8 |
9 | // autoloading model and component classes
10 | 'import'=>array(
11 | 'application.models.*',
12 | 'application.components.*',
13 | ),
14 | 'components'=>array(
15 | // this is required to prevent script and css duplicates
16 | 'clientScript' => array('class' => 'NLSClientScript'),
17 | ),
18 | );
--------------------------------------------------------------------------------
/protected/views/site/prevents.php:
--------------------------------------------------------------------------------
1 | renderPartial('_menu')?>
2 |
3 |
8 |
9 |
--------------------------------------------------------------------------------
/protected/views/site/grid.php:
--------------------------------------------------------------------------------
1 | renderPartial('_menu')?>
2 |
3 | 1,
7 | 'name' => 'Wei Zhuo',
8 | ),
9 | array(
10 | 'id' => 2,
11 | 'name' => 'Qiang Xue',
12 | ),
13 | array(
14 | 'id' => 3,
15 | 'name' => 'Sebastián Thierer',
16 | ),
17 | array(
18 | 'id' => 4,
19 | 'name' => 'Alexander Makarov',
20 | ),
21 | array(
22 | 'id' => 5,
23 | 'name' => 'Maurizio Domba',
24 | ),
25 | array(
26 | 'id' => 6,
27 | 'name' => 'Y!!',
28 | ),
29 | array(
30 | 'id' => 7,
31 | 'name' => 'Jeffrey Winesett',
32 | ),
33 | array(
34 | 'id' => 8,
35 | 'name' => 'Jonah Turnquist',
36 | ),
37 | array(
38 | 'id' => 9,
39 | 'name' => 'István Beregszászi',
40 | ),
41 | ), array(
42 | 'id'=>'user',
43 | 'sort'=>array(
44 | 'attributes'=>array(
45 | 'id', 'name',
46 | ),
47 | ),
48 | 'pagination'=>array(
49 | 'pageSize'=>5,
50 | ),
51 | ));
52 |
53 | $this->widget('zii.widgets.grid.CGridView', array(
54 | 'dataProvider'=>$dataProvider,
55 | ))?>
--------------------------------------------------------------------------------
/protected/views/site/events.php:
--------------------------------------------------------------------------------
1 | renderPartial('_menu')?>
2 |
3 | jQuery events
4 |
5 |
6 |
Simple.
7 |
Test
8 |
16 |
17 |
18 |
19 |
Delegate to container.
20 |
Test
21 |
29 |
30 |
31 |
32 |
Delegate to body. This one will bind additional handler to body every ajax reload.
33 |
Test
34 |
42 |
43 |
44 |
45 |
Live doesn't work for some reason.
46 |
Test
47 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/protected/views/layouts/main.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | pageTitle)?>
6 | clientScript->registerPackage('jquery')?>
7 |
8 |
9 | name)?>
10 |
80 |
81 | URL=static page reload
82 |
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/protected/components/NLSClientScript.php:
--------------------------------------------------------------------------------
1 | array(
14 | * ...
15 | * 'clientScript' => array('class'=>'your.path.to.NLSClientScript')
16 | * ...
17 | * )
18 | * ...
19 | *
20 | * The extension is based on the great idea of Eirik Hoem, see
21 | * http://www.eirikhoem.net/blog/2011/08/29/yii-framework-preventing-duplicate-jscss-includes-for-ajax-requests/
22 | *
23 | */
24 | class NLSClientScript extends CClientScript {
25 |
26 | /**
27 | * Applying global ajax post-filtering
28 | * original source: http://www.eirikhoem.net/blog/2011/08/29/yii-framework-preventing-duplicate-jscss-includes-for-ajax-requests/
29 | */
30 | public function init() {
31 |
32 | parent::init();
33 |
34 | if (Yii::app()->request->isAjaxRequest)
35 | return;
36 |
37 | //we need jquery
38 | $this->registerCoreScript('jquery');
39 |
40 | //Minified code
41 | $this->registerScript('fixDuplicateResources', '$.ajaxSetup({global:true,dataFilter:function(g,e){if(e&&e!="html"&&e!="text")return g;var s="script[src],link[rel=\"stylesheet\"]",h=/(\?+)|(_=\d+)/g,a,c,d,b,f=document.getElementsByTagName("head")[0];if(!$._resMap){$._resMap={};$._holder=$(document.createElement("div"));for(c=0,d=$(document).find(s);cregisterScript('fixDuplicateResources', '
46 |
47 | $.ajaxSetup({
48 | global: true,
49 | dataFilter: function(data,type) {
50 |
51 | //shortcut: only "text" and "html" dataType should be filtered
52 | if (type && type != "html" && type != "text")
53 | return data;
54 |
55 | var selector = "script[src],link[rel=\"stylesheet\"]",rg=/(\?+)|(_=\d+)/g,tmp,i,res,ind,head=document.getElementsByTagName("head")[0];
56 | //var selector = "script[src]",tmp,i,res;
57 |
58 | //things to do only first time
59 | if (!$._resMap) {
60 | $._resMap = {};
61 | $._holder = $(document.createElement("div"));
62 |
63 | //fetching scripts from the DOM
64 | for(i=0,res=$(document).find(selector); i