Permalink
Browse files

initial code

  • Loading branch information...
1 parent d0d23e7 commit eff003ed52dab6b12d7ff6c48fe1828cb3d9b833 @samdark samdark committed Dec 2, 2011
View
18 .gitignore
@@ -0,0 +1,18 @@
+# phpstorm project files
+.idea
+
+# netbeans project files
+nbproject
+
+# zend studio for eclipse project files
+.buildpath
+.project
+.settings
+
+# windows thumbnail cache
+Thumbs.db
+
+# yii runtime and assets
+
+assets/*
+protected/runtime/*
View
15 index-test.php
@@ -0,0 +1,15 @@
+<?php
+/**
+ * This is the bootstrap file for test application.
+ * This file should be removed when the application is deployed for production.
+ */
+
+// change the following paths if necessary
+$yii=dirname(__FILE__).'/../framework/yii.php';
+$config=dirname(__FILE__).'/protected/config/test.php';
+
+// remove the following line when in production mode
+defined('YII_DEBUG') or define('YII_DEBUG',true);
+
+require_once($yii);
+Yii::createWebApplication($config)->run();
View
13 index.php
@@ -0,0 +1,13 @@
+<?php
+
+// change the following paths if necessary
+$yii=dirname(__FILE__).'/../framework/yii.php';
+$config=dirname(__FILE__).'/protected/config/main.php';
+
+// remove the following lines when in production mode
+defined('YII_DEBUG') or define('YII_DEBUG',true);
+// specify how many levels of call stack should be shown in each log message
+defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
+
+require_once($yii);
+Yii::createWebApplication($config)->run();
View
1 protected/.htaccess
@@ -0,0 +1 @@
+deny from all
View
98 protected/components/NLSClientScript.php
@@ -0,0 +1,98 @@
+<?php
+/**
+ * NLSClientScript v3.3
+ *
+ * CClientScript extension for preventing multiple loading of javascript files.
+ * Important! This extension does not prevent to load the same script content from different paths.
+ * So eg. if you published the same js file into different asset directories, this extension won't prevent to load both.
+ *
+ *
+ *
+ * Usage: simply set the class for the clientScript component in /protected/config/main.php, like
+ * ...
+ * 'components'=>array(
+ * ...
+ * 'clientScript' => array('class'=>'your.path.to.NLSClientScript')
+ * ...
+ * )
+ * ...
+ *
+ * The extension is based on the great idea of Eirik Hoem, see
+ * http://www.eirikhoem.net/blog/2011/08/29/yii-framework-preventing-duplicate-jscss-includes-for-ajax-requests/
+ *
+ */
+class NLSClientScript extends CClientScript {
+
+/**
+ * Applying global ajax post-filtering
+ * original source: http://www.eirikhoem.net/blog/2011/08/29/yii-framework-preventing-duplicate-jscss-includes-for-ajax-requests/
+*/
+ public function init() {
+
+ parent::init();
+
+ if (Yii::app()->request->isAjaxRequest)
+ return;
+
+ //we need jquery
+ $this->registerCoreScript('jquery');
+
+ //Minified code
+ $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);c<d.length;c++)a=d[c],b=a.src?a.src:a.href,b=b.replace(h,""),a.href&&a.parentNode!=f&&f.appendChild(a),$._resMap[b]=1}$._holder[0].innerHTML=g;for(c=0,d=$._holder.find(s);c<d.length;c++)a=d[c],b=a.src?a.src:a.href,b=b.replace(h,""),$._resMap[b]?$(a).remove():(a.href&&f.appendChild(a),$._resMap[b]=1);return $._holder[0].innerHTML}});',CClientScript::POS_HEAD);
+
+/*
+//Source code:
+ $this->registerScript('fixDuplicateResources', '
+
+ $.ajaxSetup({
+ global: true,
+ dataFilter: function(data,type) {
+
+ //shortcut: only "text" and "html" dataType should be filtered
+ if (type && type != "html" && type != "text")
+ return data;
+
+ var selector = "script[src],link[rel=\"stylesheet\"]",rg=/(\?+)|(_=\d+)/g,tmp,i,res,ind,head=document.getElementsByTagName("head")[0];
+ //var selector = "script[src]",tmp,i,res;
+
+ //things to do only first time
+ if (!$._resMap) {
+ $._resMap = {};
+ $._holder = $(document.createElement("div"));
+
+ //fetching scripts from the DOM
+ for(i=0,res=$(document).find(selector); i<res.length; i++) {
+ tmp = res[i];
+ ind = tmp.src ? tmp.src : tmp.href;
+ ind = ind.replace(rg,"");
+ if (tmp.href && tmp.parentNode!=head)
+ head.appendChild(tmp);
+ $._resMap[ind] = 1;
+ }
+ }
+
+ $._holder[0].innerHTML = data;
+
+ // iterate over new scripts and remove if source is already in DOM:
+ for(i=0,res=$._holder.find(selector); i<res.length; i++) {
+ tmp = res[i];
+ ind = tmp.src ? tmp.src : tmp.href;
+ ind = ind.replace(rg,"");
+ if ($._resMap[ind])
+ $(tmp).remove();
+ else {
+ if (tmp.href)
+ head.appendChild(tmp);
+ $._resMap[ind] = 1;
+ }
+ }
+
+ return $._holder[0].innerHTML;
+ }
+ });
+
+ ', CClientScript::POS_HEAD);
+ */
+ }
+
+}
View
91 protected/config/main.php
@@ -0,0 +1,91 @@
+<?php
+
+// uncomment the following to define a path alias
+// Yii::setPathOfAlias('local','path/to/local-folder');
+
+// This is the main Web application configuration. Any writable
+// CWebApplication properties can be configured here.
+return array(
+ 'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
+ 'name'=>'My Web Application',
+
+ // preloading 'log' component
+ 'preload'=>array('log'),
+
+ // autoloading model and component classes
+ 'import'=>array(
+ 'application.models.*',
+ 'application.components.*',
+ ),
+
+ 'modules'=>array(
+ // uncomment the following to enable the Gii tool
+ /*
+ 'gii'=>array(
+ 'class'=>'system.gii.GiiModule',
+ 'password'=>'Enter Your Password Here',
+ // If removed, Gii defaults to localhost only. Edit carefully to taste.
+ 'ipFilters'=>array('127.0.0.1','::1'),
+ ),
+ */
+ ),
+
+ // application components
+ 'components'=>array(
+ 'user'=>array(
+ // enable cookie-based authentication
+ 'allowAutoLogin'=>true,
+ ),
+ // uncomment the following to enable URLs in path-format
+ /*
+ 'urlManager'=>array(
+ 'urlFormat'=>'path',
+ 'rules'=>array(
+ '<controller:\w+>/<id:\d+>'=>'<controller>/view',
+ '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
+ '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
+ ),
+ ),
+ */
+ 'db'=>array(
+ 'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
+ ),
+ // uncomment the following to use a MySQL database
+ /*
+ 'db'=>array(
+ 'connectionString' => 'mysql:host=localhost;dbname=testdrive',
+ 'emulatePrepare' => true,
+ 'username' => 'root',
+ 'password' => '',
+ 'charset' => 'utf8',
+ ),
+ */
+ 'errorHandler'=>array(
+ // use 'site/error' action to display errors
+ 'errorAction'=>'site/error',
+ ),
+ 'log'=>array(
+ 'class'=>'CLogRouter',
+ 'routes'=>array(
+ array(
+ 'class'=>'CFileLogRoute',
+ 'levels'=>'error, warning',
+ ),
+ // uncomment the following to show log messages on web pages
+ /*
+ array(
+ 'class'=>'CWebLogRoute',
+ ),
+ */
+ ),
+ ),
+ 'clientScript' => array('class' => 'NLSClientScript'),
+ ),
+
+ // application-level parameters that can be accessed
+ // using Yii::app()->params['paramName']
+ 'params'=>array(
+ // this is used in contact page
+ 'adminEmail'=>'webmaster@example.com',
+ ),
+);
View
17 protected/config/test.php
@@ -0,0 +1,17 @@
+<?php
+
+return CMap::mergeArray(
+ require(dirname(__FILE__).'/main.php'),
+ array(
+ 'components'=>array(
+ 'fixture'=>array(
+ 'class'=>'system.test.CDbFixtureManager',
+ ),
+ /* uncomment the following to provide test database connection
+ 'db'=>array(
+ 'connectionString'=>'DSN for test database',
+ ),
+ */
+ ),
+ )
+);
View
17 protected/controllers/SiteController.php
@@ -0,0 +1,17 @@
+<?php
+class SiteController extends CController
+{
+ public function actionIndex($view="index")
+ {
+ // we can do it in custom controller so it will be transparent for
+ // apps
+ if(Yii::app()->request->isAjaxRequest)
+ {
+ $this->renderPartial($view, null, false, true);
+ }
+ else
+ {
+ $this->render($view);
+ }
+ }
+}
View
52 protected/views/layouts/main.php
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8" />
+ <title><?php echo CHtml::encode($this->pageTitle)?></title>
+ <?php Yii::app()->clientScript->registerPackage('jquery')?>
+</head>
+<body>
+ <h1><?php echo CHtml::encode(Yii::app()->name)?></h1>
+ <script>
+ jQuery(function($){
+ var lastUrl = '#';
+ function load(url){
+ // if URL is a hashtag no need to reload it
+ if(url.match(/^#/)){
+ window.location.hash = url.replace(/^#/, '');
+ return;
+ }
+
+ $('#container').load(url, function(response, status, xhr){
+ if(status == 'success'){
+ lastUrl = url;
+ $("#url").html(url);
+ }
+ else {
+ $("#url").html(status);
+ }
+ });
+ }
+
+ $("#reload-page").click(function(e){
+ e.preventDefault();
+ load(lastUrl);
+ });
+
+ // adds AJAX handler to all links
+ $("#container").delegate("a", "click", function(e){
+ if(e.isDefaultPrevented()){
+ return false;
+ }
+ e.preventDefault();
+ load(e.target.href);
+ });
+ });
+ </script>
+
+ <h2>URL=<span id="url">static page</span> <a href="#" id="reload-page">reload</a></h2>
+ <div id="container">
+ <?php echo $content?>
+ </div>
+</body>
+</html>
View
7 protected/views/site/_menu.php
@@ -0,0 +1,7 @@
+<div>
+ <?php echo CHtml::link("index", array('site/index'))?> |
+ <?php echo CHtml::link("inline script", array('site/index/view/inlineScript'))?> |
+ <?php echo CHtml::link("prevents", array('site/index/view/prevents'))?> |
+ <?php echo CHtml::link("grid", array('site/index/view/grid'))?> |
+ <?php echo CHtml::link("link with confirm", array('site/index/view/confirmLink'))?>
+</div>
View
14 protected/views/site/confirmLink.php
@@ -0,0 +1,14 @@
+<?php $this->renderPartial('_menu')?>
+
+<?php echo CHtml::link('Default Yii confirm.', array('site/index'), array('confirm' => 'Are you sure?'))?> |
+<a href="#new-page" id="confirm">Confirm</a>
+
+<script>
+ jQuery(function($){
+ $('#new-page').click(function(e){
+ if(confirm('Cancel?')){
+ e.preventDefault();
+ }
+ });
+ });
+</script>
View
1 protected/views/site/grid.php
@@ -0,0 +1 @@
+<?php $this->renderPartial('_menu')?>
View
8 protected/views/site/index.php
@@ -0,0 +1,8 @@
+<?php $this->renderPartial('_menu')?>
+
+<p>This is a page w/o any ajaxified stuff.</p>
+<p>Just static elements.</p>
+
+<p>Here is a <a href="#hashed">hashed link</a></p>
+
+<p>For example, we can link to <?php echo CHtml::link('grid page', array('site/index', 'view' => 'grid'))?>.</p>
View
3 protected/views/site/inlineScript.php
@@ -0,0 +1,3 @@
+<?php $this->renderPartial('_menu')?>
+<p>A page with inline script.</p>
+<?php Yii::app()->clientScript->registerScript('non_unique_id', 'alert("executed.");');?>
View
23 protected/views/site/prevents.php
@@ -0,0 +1,23 @@
+<?php $this->renderPartial('_menu')?>
+
+<div>
+ <a href="#default" id="default">preventDefault</a> |
+ <a href="#bubble" id="bubble">cancelBubble</a> |
+ <a href="#false" id="false">return false</a>
+</div>
+
+<script>
+ jQuery(function($){
+ $('#default').click(function(e){
+ e.preventDefault();
+ });
+
+ $('#bubble').click(function(e){
+ e.stopPropagation();
+ });
+
+ $('#false').click(function(e){
+ return false;
+ });
+ });
+</script>

0 comments on commit eff003e

Please sign in to comment.