From 5a1b2ab4b46147e84f48f73dceb0261a5a6aca55 Mon Sep 17 00:00:00 2001 From: "Benjamin \"balupton\" Lupton" Date: Fri, 7 Jan 2011 01:13:42 +0800 Subject: [PATCH] Updated for jQuery Ajaxy Helper --- lib/Bal/View/Helper/App.php | 240 +++++++++++++++++++----------------- 1 file changed, 124 insertions(+), 116 deletions(-) diff --git a/lib/Bal/View/Helper/App.php b/lib/Bal/View/Helper/App.php index 14eafa6..2b788b7 100755 --- a/lib/Bal/View/Helper/App.php +++ b/lib/Bal/View/Helper/App.php @@ -3,13 +3,13 @@ class Bal_View_Helper_App extends Zend_View_Helper_Abstract { # ======================== # CONSTRUCTORS - + /** * The View in use * @var Zend_View_Interface */ public $view; - + /** * Apply View * @param Zend_View_Interface $view @@ -17,11 +17,11 @@ class Bal_View_Helper_App extends Zend_View_Helper_Abstract { public function setView (Zend_View_Interface $view) { # Set $this->view = $view; - + # Chain return $this; } - + /** * Self reference */ @@ -29,17 +29,17 @@ public function app ( ) { # Chain return $this; } - + # ======================== # PARENT - + /** * Returns @see Bal_Controller_Plugin_App */ public function getApp(){ return Bal_Controller_Plugin_App::getInstance(); } - + /** * Magic * @return mixed @@ -53,21 +53,21 @@ function __call ( $method, $args ) { } return false; } - + # ======================== # NAVIGATION - + public function getNavigation ( $code ) { # Prepare $NavigationMenu = delve($this->view,'Navigation.'.$code); if ( !$NavigationMenu ) { throw new Zend_Exception('Could not find Navigation Menu: '.$code); } - + # Return return $NavigationMenu; } - + public function getNavigationMenu ( $code ) { # Prepare if ( $code instanceOf Zend_Navigation ) { @@ -82,78 +82,78 @@ public function getNavigationMenu ( $code ) { throw new Zend_Exception('Could not find Navigation Menu: '.$code); } } - + # Render $result = $this->view->navigation()->menu()->setContainer($NavigationMenu); - + # Return return $result; } - - + + # ======================== # CUSTOM - + public function get ( ) { # Prepare $result = null; $args = func_get_args(); - + # Cycle $result = delver_array($this->view, $args); - + # Done return $result; } - + public function getStylesheetUrl ( $file, $for = null ) { $file = 'styles/' . $file; $url = $this->getApp()->getFileUrl($file, $for); return $url; } - + public function getScriptUrl ( $file, $for = null ) { $file = 'scripts/' . $file; $url = $this->getApp()->getFileUrl($file, $for); return $url; } - + public function getLocaleStylesheetUrl ( $for = null ) { # Attempt Locale $file = 'locale/'.$this->view->locale()->getFullLocale().'.css'; $url = $this->getStylesheetUrl($file, $for); - + # Attempt Language if ( !$url ) { $file = 'locale/'.$this->view->locale()->getLanguage().'.css'; $url = $this->getStylesheetUrl($file, $for); } - + # Done return $url; } - + public function headStyle ( ) { return $this->view->headStyle(); } - + public function headTitle ( ) { return $this->view->headTitle(); } - + public function headMeta ( ) { # Meta $this->view->headMeta(); - + # Done return $this->view->headMeta(); } - + public function headLink ( array $options = array() ) { # Prepare $App = $this->getApp(); $layout = $App->getMvc()->getLayout(); - + # Options $default = array_merge( array( @@ -178,7 +178,7 @@ public function headLink ( array $options = array() ) { ); $options = handle_options($default,$options,true); extract($options); - + # Bundle if ( $bundle ) $headLink = $this->view->getHelper('headLinkBundler') @@ -186,17 +186,17 @@ public function headLink ( array $options = array() ) { ->setCompiledOffset($compiled); else $headLink = $this->view->getHelper('headLink'); - + # URLs $public_url = $App->getPublicUrl(); $script_url = $public_url.'/scripts'; - + # Locale if ( $locale ) { $url = $this->getLocaleStylesheetUrl(); if ( $url ) $headLink->offsetSetStylesheet($locale, $url); } - + # Browser if ( $browser ) { $url = $this->getBrowserStylesheetUrl(); @@ -204,36 +204,36 @@ public function headLink ( array $options = array() ) { $url = $this->getMobileStylesheetUrl(); if ( $url ) $headLink->offsetSetStylesheet($browser, $url); } - + # jQuery UI if ( $jquery_ui ) { $headLink->offsetSetStylesheet($jquery_ui, $script_url.'/jquery-ui-1.8.5.custom/css/cupertino/jquery-ui-1.8.5.custom.css'); } - + # jQuery Sparkle if ( $jquery_sparkle ) { $jquery_sparkle_url = $script_url.'/jquery-sparkle'; $headLink->offsetSetStylesheet($jquery_sparkle, $jquery_sparkle_url.'/styles/jquery.sparkle.min.css'); } - + # jQuery Lightbox if ( $jquery_lightbox ) { $jquery_lightbox_url = $script_url.'/jquery-lightbox'; $headLink->offsetSetStylesheet($jquery_lightbox, $jquery_lightbox_url.'/styles/jquery.lightbox.min.css'); } - + # Syntax Highlighter if ( $syntax_highlighter ) { # Preset Url $syntax_highlighter_url = $script_url.'/jquery-syntaxhighlighter'; - + # Define Files $syntax_highlighter_scripts = array( '/prettify/prettify'.($minify ? '.min' : '').'.css', '/styles/style'.($minify ? '.min' : '').'.css', '/styles/theme-balupton'.($minify ? '.min' : '').'.css' ); - + # IE if ( $this->isBrowser('ie') ) { $syntax_highlighter_scripts[] = '/styles/ie'.($minify ? '.min' : '').'.css'; @@ -244,7 +244,7 @@ public function headLink ( array $options = array() ) { $headLink->offsetSetStylesheet($syntax_highlighter++, $syntax_highlighter_url.'/'.$syntax_highlighter_scripts[$i]); } } - + # Editor if ( $editor ) { switch ( $this->getConfig('editor.code') ) { @@ -260,11 +260,11 @@ public function headLink ( array $options = array() ) { ); $headLink->offsetSetStylesheet($editor, $bespin_url.'/BespinEmbedded.css'); break; - + case 'aloha': # Preset Urls $aloha_scripts_url = $script_url.'/aloha-nightly/compressed'; - + # Define Files $aloha_scripts = array( 'deps/extjs/resources/css/ext-all.css', @@ -278,22 +278,22 @@ public function headLink ( array $options = array() ) { $headLink->offsetSetStylesheet($editor++, $aloha_scripts_url.'/'.$aloha_scripts[$i]); } break; - + case 'tinymce': break; - + default: throw new Exception('Unknown Editor Code'); break; } } - + # Style if ( $style ) { $url = $this->getStylesheetUrl('style.css', 'public'); if ( $url ) $headLink->offsetSetStylesheet($style, $url); } - + # Theme if ( $theme ) { $url = $this->getStylesheetUrl($layout === 'layout' ? 'style.css' : 'style-'.$layout.'.css', 'theme'); @@ -301,13 +301,13 @@ public function headLink ( array $options = array() ) { elseif ( $scaffold ) $url .= '?scaffold'; if ( $url ) $headLink->offsetSetStylesheet($theme, $url); } - + # Favicon if ( $favicon ) { $url = $App->getFileUrl('favicon.ico'); $this->view->headLink(array('rel' => 'icon', 'href' => $url, 'type' => 'image/x-icon'), 'PREPEND'); } - + # Feeds if ( $feeds ) { $url = $App->getUrl()->route('feed')->action('rss')->toString(); @@ -315,42 +315,43 @@ public function headLink ( array $options = array() ) { //$url = $App->getUrl()->route('feed')->action('atom')->toString(); //$this->view->headLink(array('rel' => 'alternate', 'title' => 'Atom Feed', 'href' => $url, 'type' => 'application/atom+xml'), 'PREPEND'); } - + # Return headLink return $headLink; } - + public function headScript ( array $options = array() ) { # Prepare $App = $this->getApp(); $layout = $App->getMvc()->getLayout(); $browserInfo = $this->getBrowserInfo(); - + # Options $default = array_merge( array( - 'bundle' => true, - 'minify' => true, - 'modernizr' => 100, - 'json' => 110, - 'ie9_js' => 120, - 'jquery' => 200, - 'jquery_ui' => 210, - 'jquery_plugins' => 220, - 'jquery_sparkle' => 230, - 'jquery_ajaxy' => 240, - 'jquery_lightbox' => false, //250, - 'syntax_highlighter' => 300, - 'editor' => 400, - 'script' => 500, - 'theme' => 600, - 'compiled' => 10 + 'bundle' => true, + 'minify' => true, + 'modernizr' => 100, + 'json' => 110, + 'ie9_js' => 120, + 'jquery' => 200, + 'jquery_ui' => 210, + 'jquery_plugins' => 220, + 'jquery_sparkle' => 230, + 'jquery_ajaxy' => 240, + 'jquery_lightbox' => false, //250, + 'syntax_highlighter' => 300, + 'editor' => 400, + 'script' => 500, + 'jquery_ajaxy_helper' => 510, + 'theme' => 600, + 'compiled' => 10 ), $App->getConfig('headScript', array()) ); $options = handle_options($default,$options,true); extract($options); - + # Bundle if ( $bundle ) $headScript = $this->view->getHelper('HeadScriptBundler') @@ -359,65 +360,69 @@ public function headScript ( array $options = array() ) { ->setCompiledOffset($compiled); else $headScript = $this->view->getHelper('HeadScript'); - + # URLs $public_url = $App->getPublicUrl(); $back_url = $App->getAreaUrl('back'); $front_url = $App->getAreaUrl('front'); $script_url = PUBLIC_SCRIPTS_URL; - + # Modernizr if ( $modernizr ) { $headScript->offsetSetFile($modernizr, $script_url.'/modernizr-1.6.min.js'); } - + # jQuery if ( $jquery ) { $headScript->offsetSetFile($jquery, $script_url.'/jquery-1.4.4.min.js'); } - + # jQuery UI if ( $jquery_ui ) { $headScript->offsetSetFile($jquery_ui, $script_url.'/jquery-ui-1.8.5.custom/js/jquery-ui-1.8.5.custom.min.js'); $headScript->offsetSetScript($jquery_ui+1,'$.datepicker.setDefaults({dateFormat: "yy-mm-dd"});'); - } - + } + # JSON if ( $json ) { $headScript->offsetSetScript($json, 'if ( typeof JSON === "undefined" ) $.appendScript("'.$script_url.'/json2.min.js");'); - } - + } + # jQuery Plugins if ( $jquery_plugins ) { $headScript->offsetSetFile($jquery_plugins, $script_url.'/jquery.autogrow.min.js'); - } - + } + # jQuery Sparkle if ( $jquery_sparkle ) { // Prepare $jquery_sparkle_url = $script_url.'/jquery-sparkle'; $headScript->offsetSetFile($jquery_sparkle, $jquery_sparkle_url.'/scripts/jquery.sparkle'.($minify ? '.min' : '').'.js'); $headScript->offsetSetScript($jquery_sparkle+1,'$.Help.setDefaults({icon: \'help\'});'); - } - + } + # jQuery Ajaxy if ( $jquery_ajaxy ) { // Prepare $jquery_ajaxy_url = $script_url.'/jquery-ajaxy'; $headScript->offsetSetFile($jquery_ajaxy, $jquery_ajaxy_url.'/scripts/jquery.ajaxy'.($minify ? '.min' : '').'.js'); + // Helper + if ( $jquery_ajaxy_helper ) { + $headScript->offsetSetFile($jquery_ajaxy_helper, $script_url.'/jquery.ajaxy.helper.js'); + } } - + # jQuery Lightbox if ( $jquery_lightbox ) { $jquery_lightbox_url = $script_url.'/jquery-lightbox'; $headScript->offsetSetFile($jquery_lightbox, $jquery_lightbox_url.'/scripts/jquery.lightbox'.($minify ? '.min' : '').'.js'); } - + # Syntax Highlighter if ( $syntax_highlighter ) { # Preset Url $syntax_highlighter_url = $script_url.'/jquery-syntaxhighlighter'; - + # Define Files $syntax_highlighter_scripts = array( '/scripts/jquery.syntaxhighlighter'.($minify ? '.min' : '').'.js', @@ -428,7 +433,7 @@ public function headScript ( array $options = array() ) { for ( $i=0,$n=sizeof($syntax_highlighter_scripts); $i<$n; ++$i ) { $headScript->offsetSetFile($syntax_highlighter++, $syntax_highlighter_url.'/'.$syntax_highlighter_scripts[$i]); } - + # Init $headScript->offsetSetScript($syntax_highlighter++, '$.SyntaxHighlighter.init({ @@ -439,7 +444,7 @@ public function headScript ( array $options = array() ) { });' ); } - + # Editor if ( $editor ) { switch ( $this->getConfig('editor.code') ) { @@ -448,15 +453,15 @@ public function headScript ( array $options = array() ) { $headScript->offsetSetFile($editor,$tiny_mce_url.'/jquery.tinymce.js'); $headScript->offsetSetScript($editor+1,'$.Tinymce.applyConfig("default",{script_url: "'.$tiny_mce_url.'/tiny_mce.js", content_css: "'.$front_url.'/styles/content.css"});'); break; - + case 'aloha': # Preset Urls $aloha_scripts_url = $script_url.'/aloha-nightly/compressed'; $aloha_plugins_url = $script_url.'/aloha-plugins'; - + # Include Base Script $headScript->offsetSetScript($editor++, 'window.GENTICS_Aloha_base = "'.$aloha_scripts_url.'/"; window.GENTICS_Aloha_autoloadcss = false;'); - + # Define Files $aloha_scripts = array( 'aloha-ext.js', @@ -471,7 +476,7 @@ public function headScript ( array $options = array() ) { $aloha_plugins = array( 'com.bal.aloha.plugins.Attacher/plugin.js' ); - + # Include Files for ( $i=0,$n=sizeof($aloha_scripts); $i<$n; ++$i ) { $headScript->offsetSetFile($editor++, $aloha_scripts_url.'/'.$aloha_scripts[$i]); @@ -480,40 +485,43 @@ public function headScript ( array $options = array() ) { $headScript->offsetSetFile($editor++, $aloha_plugins_url.'/'.$aloha_plugins[$i]); } break; - + case 'bespin': $bespin_url = $script_url.'/bespin-0.9a2-custom'; $headScript->offsetSetFile($editor,$bespin_url.'/BespinEmbedded.js'); break; - + default: throw new Exception('Unknown Editor Code'); break; } } - + # Script if ( $script ) { $url = $this->getScriptUrl('script.js', 'public'); - if ( $url ) { - $headScript->offsetSetFile($script, $url); - } + $headScript->offsetSetFile($script, $url); + + // Configure + $root_url = $this->app()->getRootUrl(); + $base_url = $this->app()->getBaseUrl(); + $headScript->offsetSetScript($script+1,'$.BalCMS.options.root_url = "'.$root_url.'"; $.BalCMS.options.base_url = "'.$base_url.'"; $.BalCMS.options.debug = '.(DEBUG_MODE ? 'true' : 'false').';'); } - + # Theme if ( $theme ) { $url = $this->getScriptUrl($layout === 'layout' ? 'script.js' : 'script-'.$layout.'.js', 'theme'); if ( $url ) $headScript->offsetSetFile($theme, $url); } - + # Return headScript return $headScript; } - + public function getBrowserInfo() { return get_browser_info(); } - + public function isBrowser($browser, $version = null, $mobile = null){ $browserInfo = $this->getBrowserInfo(); $result = $browserInfo['browser'] === $browser && (!$mobile || $browserInfo['mobile'] === $mobile); @@ -527,7 +535,7 @@ public function isBrowser($browser, $version = null, $mobile = null){ } return $result; } - + public function getHtmlClassAttribute ( ) { $browserInfo = $this->getBrowserInfo(); $class = array(); @@ -536,12 +544,12 @@ public function getHtmlClassAttribute ( ) { if ( $browserInfo['version'] ) $class[] = $browserInfo['browser'].$browserInfo['version']; return implode(' ',$class); } - + public function getMobileStylesheetUrl ( ) { # Prepare $browser = $this->getBrowserInfo(); $url = false; - + if ( $browser['mobile'] ) { # Attempt Browser with Version $file = 'browser/'.$browser['browser'].$browser['version'].'mobile.css'; @@ -557,15 +565,15 @@ public function getMobileStylesheetUrl ( ) { } } } - + # Return url return $url; } - + public function getBrowserStylesheetUrl ( ) { # Prepare $browser = $this->getBrowserInfo(); - + # Attempt Browser with Version $file = 'browser/'.$browser['browser'].$browser['version'].'.css'; $url = $this->getStylesheetUrl($file); @@ -574,16 +582,16 @@ public function getBrowserStylesheetUrl ( ) { $file = 'browser/'.$browser['browser'].'.css'; $url = $this->getStylesheetUrl($file); } - + # Return url return $url; } - + public function footer ( ) { # Prepare $analytics_code = $this->app()->getConfig('services.analytics.code'); $reinvigorate_code = $this->app()->getConfig('services.reinvigorate.code'); - + # Analytics if ( $analytics_code ) : ?> @@ -642,15 +650,15 @@ public function footer ( ) { getApp()->fetchRecord($table,$params); } - + /** * Get Records based upon fetch standards * @version 1.1, April 12, 2010 @@ -684,5 +692,5 @@ public function fetchRecords ( $table, array $params = array() ) { # Forward return $this->getApp()->fetchRecords($table,$params); } - -} \ No newline at end of file + +}