示例#1
0
    public function run()
    {
        $this->clientScript = Yii::app()->clientScript;
        $this->clientScript->registerPackage('aes-common');
        if (defined('TEST_APP_INSTANCE') && TEST_APP_INSTANCE) {
            $this->clientScript->registerScript('urlMangerInit', 'UrlManager.setBaseUrl("/index-test.php");', CClientScript::POS_HEAD);
        }
        //Registering backbone + marionete
        $this->clientScript->registerPackage('marionette');
        $this->clientScript->registerScriptFile('/js/libs/aes/i18n.js');
        $this->clientScript->registerScriptFile('/js/libs/jquery.dateFormat-1.0.js');
        /**
         * Resolving conflict with jquery.ui.button and bootstrap.button plugins
         * Bootstrap.button will be available by $().bButton
         * 
         * NOTE: You should update js/libs/bootstrap.button.js with the same version
         * of bootstrap if you are updating bootstrap.js
         */
        $this->clientScript->registerScriptFile('/js/libs/bootstrap.button.js', CClientScript::POS_END);
        $this->clientScript->registerScript('resolveBtnConflict', '$(function(){ var btn = $.fn.button.noConflict();
            $.fn.bButton = btn; });', CClientScript::POS_END);
        $this->clientScript->registerScriptFile('/js/libs/bootstrap.tooltip.js', CClientScript::POS_END);
        $this->clientScript->registerScript('resolveTooltipConflict', '$(function(){
               var bTooltip = $.fn.tooltip;

               $.fn.tooltip.noConflict();
               $.fn.jqTooltip = $.fn.tooltip;

               $.fn.tooltip = bTooltip;
            });', CClientScript::POS_END);
        $user = Yii::app()->user;
        /**
         * Initializing webUser for client-side
         */
        $this->clientScript->registerScriptFile('/js/libs/aes/WebUser.js');
        $this->clientScript->registerScript('webUserInit', 'WebUser.initialize({' . (!$user->isGuest ? 'id: ' . $user->id . ', displayName: "' . $user->username . '"' : '') . '});', CClientScript::POS_HEAD);
        if ($this->isolated) {
            $appMain = 'dev/app.dev.js';
            $this->clientScript->registerScriptFile('/js/libs/backbone-faux-server.js');
        } else {
            $appMain = 'app.js';
        }
        $this->requires['basePath'] = 'application.views.' . $this->controller->id . '.assets.' . $this->controller->action->id . '.js.' . $this->appName;
        $fullAppName = ucfirst($this->appName) . 'App';
        $this->requires['js'] = array_merge(array($fullAppName . '.js'), $this->requires['js']);
        $this->requires['js'][] = $appMain;
        $this->requires = $this->filterCommonScripts($this->requires);
        $this->clientScript->packages = array_merge($this->clientScript->packages, array($this->appName => $this->requires));
        $this->clientScript->registerPackage($this->appName);
        foreach ($this->initializers as $index => $initializer) {
            $this->clientScript->registerScript('intlzr' . $index, 'App.addInitializer(function(){ ' . $initializer . ' });');
        }
    }
 /**
  * Override CClientScript::registerPackage() to initialize the compression algorithm
  *
  * @param string $name Name of Package to register
  * @return CClientScript the CClientScript object itself
  */
 public function registerPackage($name)
 {
     if ($this->enableCompression && !in_array($name, $this->_registeredPackages)) {
         $this->hasScripts = true;
         $this->_registeredPackages[$name] = $name;
         // Create compressed package if not done so yet
         if (($info = $this->getCompressedInfo($name)) === null) {
             $mutex = $this->getMutex();
             // Compresssion must only be performed once, even for several parallel requests
             while (!$mutex->lock(self::LOCK_ID, self::LOCK_TIMEOUT)) {
                 if ($this->blockDuringCompression) {
                     sleep(1);
                 } else {
                     return parent::registerPackage($name);
                 }
             }
             // We have a Mutex lock, now check if another process already compressed this package
             if ($this->getCompressedInfo($name, true) !== null) {
                 $mutex->unlock();
                 return $this;
             }
             $this->compressPackage($name);
             $mutex->unlock();
         }
         return $this;
     } else {
         return parent::registerPackage($name);
     }
 }
 /**
  * @dataProvider providerCoreScripts
  * 
  * @param string $name
  * @param array $assertion 
  */
 public function testRegisterPackage($name, $assertion)
 {
     $returnedClientScript = $this->_clientScript->registerPackage($name);
     $this->assertEquals($assertion, $returnedClientScript->corePackages[$name]);
 }