Exemplo n.º 1
0
    public function registerClientScripts()
    {
        //> .register js file;
        $this->cs->registerCoreScript('jquery')->registerScriptFile($this->baseUrl . '/jqueryui.js', CClientScript::POS_END);
        $this->cs->registerCoreScript('jquery')->registerScriptFile($this->baseUrl . '/jquery.iviewer.js', CClientScript::POS_END);
        $this->cs->registerCoreScript('jquery')->registerScriptFile($this->baseUrl . '/jquery.mousewheel.js', CClientScript::POS_END);
        if (empty($this->cssFile)) {
            $this->cs->registerCssFile($this->baseUrl . '/jquery.iviewer.css');
        } else {
            $this->cs->registerCssFile($this->cssFile);
        }
        if (empty($this->selector)) {
            // manually use it ?
            return $this;
        }
        if (empty($this->jsHandlerVar)) {
            $this->jsHandlerVar = 'iviewerHandler';
        }
        $jsCode = '';
        //> handle some settings
        $options = CJavaScript::encode($this->options);
        //>  the js code for setup
        $jsCode .= <<<SETUP
        var {$this->jsHandlerVar}=\$("{$this->selector}").iviewer({$options});
SETUP;
        //> register jsCode
        $this->cs->registerScript(__CLASS__ . '#' . $this->getId(), $jsCode, CClientScript::POS_READY);
        return $this;
    }
Exemplo n.º 2
0
 public function run()
 {
     echo Html::openTag('div', array('id' => $this->id));
     // echo Html::openTag('ul');
     // $this->createHtmlTree2($this->data);
     // echo Html::closeTag('ul');
     echo Html::closeTag('div');
     $options = CJavaScript::encode($this->options);
     $this->cs->registerScript('JsTreeScript', "\n\t\t\t\$('#{$this->id}').jstree({$options});\n\t\n\n\n\n\n\$(document).on('dnd_start.vakata', function (e, data) {\n    console.log(data);\n    console.log(data.data.obj.attr('id').replace('node_',''));\n    console.log(data.data.obj.attr('data-switch'));\n    console.log(data.data.obj.attr('data-key'));\n\n\n});\n\n\n\n\n\n\n\$(document).on('dnd_stop.vakata', function (e, data) {\n    console.log(data);\n    console.log(data.data.obj.attr('id').replace('node_',''));\n    console.log(data.data.obj.attr('data-switch'));\n    console.log(data.data.obj.attr('data-key'));\n    /*\n        \$.ajax({\n            async : false,\n            type: 'GET',\n            url: '/admin/shop/category/moveNode',\n            data : {\n                'id' : data.data.obj.attr('id').replace('node_',''),\n               // 'ref' : data.rslt.cr === -1 ? 1 : data.rslt.np.attr('id').replace('ShopCategoryTreeNode_',''),\n               // 'position' : data.rslt.cp + i\n            }\n\n        });*/\n\n\n});\n        \n        \n        ");
 }
Exemplo n.º 3
0
 public function run()
 {
     echo CHtml::openTag('div', array('id' => $this->id));
     echo CHtml::openTag('ul');
     $this->createHtmlTree($this->data);
     echo CHtml::closeTag('ul');
     echo CHtml::closeTag('div');
     $options = CJavaScript::encode($this->options);
     $this->cs->registerScript('JsTreeScript', "\n\t\t\t\$('#{$this->id}').jstree({$options});\n\t\t");
 }
Exemplo n.º 4
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 . ' });');
        }
    }
Exemplo n.º 5
0
 public function run()
 {
     /* $data = Yii::app()->cache->get($this->cacheid);
        if ($data === false) {
            $data = $this->data;
            Yii::app()->cache->set($this->cacheid, $data);
        }*/
     echo Html::openTag('div', array('id' => $this->id));
     echo Html::openTag('ul');
     $this->createHtmlTree($this->data);
     echo Html::closeTag('ul');
     echo Html::closeTag('div');
     $defaultOptions = array("themes" => array("theme" => "default"));
     $options = CJavaScript::encode(CMap::mergeArray($defaultOptions, $this->options));
     $this->cs->registerScript('JsTreeScript', "\n\t\t\t\$('#{$this->id}').jstree({$options});\n\t\t");
 }
Exemplo n.º 6
0
 public function registerScript($id, $script, $position = null, array $htmlOptions = array())
 {
     // assumed config includes the required path aliases to use
     // EScriptBoost
     $debug = YII_DEBUG;
     // Check if this script is in the exceptions - if so, skip caching.
     foreach ($this->skipList as $s) {
         $skip |= strpos($id, $s) === 0;
         if ($skip) {
             break;
         }
     }
     $compressed = !$debug ? false : Yii::app()->cache->get($id);
     if ($skip) {
         // Skipping scripts that should not be cached.
         $compressed = EScriptBoost::minifyJs($script);
     } elseif ($debug && $compressed !== false) {
         // During debug check that the newly minified script is not different from the cached one.
         // If so, log the difference so that it can be fixed.
         $c = EScriptBoost::minifyJs($script);
         if ($c !== $compressed) {
             Yii::log("Issue with caching of compressed script '{$id}'\n" . CVarDumper::dumpAsString($c) . "\nXXX\n" . CVarDumper::dumpAsString($compressed), CLogger::LEVEL_ERROR);
         }
     } elseif ($compressed === false) {
         $compressed = EScriptBoost::minifyJs($script);
         Yii::app()->cache->set($id, $compressed, $this->cacheDuration);
     }
     parent::registerScript($id, $compressed, $position, $htmlOptions);
 }
Exemplo n.º 7
0
 /**
  * @param bool $registerLocaleJs
  * @return JTimeAgo
  */
 public function handleLocale($registerLocaleJs = true)
 {
     //  $localeId = Yii::app()->getLocale()->getCanonicalID($localeId) ;
     $localeId = Yii::app()->getLocale()->getId();
     if (isset($this->localeIdMap[$localeId])) {
         $localeId = $this->localeIdMap[$localeId];
     }
     $localeJsPath = $this->assetsPath . DIRECTORY_SEPARATOR . 'locales' . DIRECTORY_SEPARATOR . "jquery.timeago.{$localeId}.js";
     // echo $localeJsPath ; die(__FILE__);
     if (!is_file($localeJsPath)) {
         /**
          * try  another locale form :
          */
         $localeId = str_replace('_', '-', $localeId);
         $localeJsPath = $this->assetsPath . DIRECTORY_SEPARATOR . 'locales' . DIRECTORY_SEPARATOR . "jquery.timeago.{$localeId}.js";
         if (!is_file($localeJsPath)) {
             return $this;
         }
     }
     if ($registerLocaleJs == true) {
         $localeJsUrl = $this->baseUrl . '/locales/' . "jquery.timeago.{$localeId}.js";
         $this->cs->registerScriptFile($localeJsUrl);
     } else {
         $localeJsCode = file_get_contents($localeJsPath);
         $this->cs->registerScript(__CLASS__ . '_locale_' . $this->getId(), $localeJsCode, CClientScript::POS_HEAD);
     }
 }
Exemplo n.º 8
0
 /**
  * @depends testRegisterScript
  *
  * @dataProvider providerRenderScripts
  *
  * @param string $id
  * @param string $script
  * @param integer $position
  * @param array $htmlOptions
  * @param string $assertion
  */
 public function testRenderScripts($id, $script, $position, $htmlOptions, $assertion)
 {
     $returnedClientScript = $this->_clientScript->registerScript($id, $script, $position, $htmlOptions);
     $output = '<head></head>';
     $returnedClientScript->render($output);
     $this->assertContains($assertion, $output);
 }
Exemplo n.º 9
0
 protected function assignRoles()
 {
     if (count($this->checkForRoles)) {
         $rolesToAdd = $this->performRolesCheck($this->checkForRoles);
         if (count($rolesToAdd)) {
             $rolesToAdd = json_encode($rolesToAdd);
             $this->_clientScript->registerScript('addingRolesForWidget' . $this->id, "\n                    WebUser.addRoles({$rolesToAdd});\n                ", CClientScript::POS_HEAD);
         }
     }
 }
Exemplo n.º 10
0
 /**
  * @depends testRenderScripts
  *
  * @dataProvider providerRenderScriptsBatch
  *
  * @param array $scriptBatch
  * @param integer $expectedScriptTagCount
  *
  * @see https://github.com/yiisoft/yii/issues/2770
  */
 public function testRenderScriptsBatch(array $scriptBatch, $expectedScriptTagCount)
 {
     $this->_clientScript->reset();
     foreach ($scriptBatch as $scriptParams) {
         $this->_clientScript->registerScript($scriptParams['id'], $scriptParams['script'], $scriptParams['position'], $scriptParams['htmlOptions']);
     }
     $output = '<head></head>';
     $this->_clientScript->render($output);
     $this->assertEquals($expectedScriptTagCount, substr_count($output, '<script'));
 }
Exemplo n.º 11
0
 /**
  * @param string $id
  * @param string $script
  * @param null $position
  * @param array $htmlOptions
  * @return MinifyClientScript
  */
 public function registerScript($id, $script, $position = null, array $htmlOptions = array())
 {
     $script = parent::registerScript($id, $script, $position, $htmlOptions);
     foreach ($script->scripts as $scriptKey => $scriptVal) {
         foreach ($scriptVal as $scriptItemKey => $scriptItem) {
             $script->scripts[$scriptKey][$scriptItemKey] = JSMin::minify($scriptItem);
         }
     }
     return $script;
 }
Exemplo n.º 12
0
 public function registerScript($id, $script, $position = self::POS_READY)
 {
     // assumed config includes the required path aliases to use
     // EScriptBoost
     $compressed = YII_DEBUG ? $script : Yii::app()->cache->get($id);
     if ($compressed === false) {
         $compressed = EScriptBoost::minifyJs($script);
         Yii::app()->cache->set($id, $compressed, $this->cacheDuration);
     }
     parent::registerScript($id, $compressed, $position);
 }
Exemplo n.º 13
0
    public function init()
    {
        parent::init();
        if (!isset($this->debug)) {
            $this->debug = defined(YII_DEBUG) ? YII_DEBUG : true;
        }
        $this->cs = Yii::app()->getClientScript();
        // publish assets and register css/js files
        $this->publishAssets();
        $this->registerClientScripts();
        $options = empty($this->options) ? '' : CJavaScript::encode($this->options);
        $jsSetup = <<<JS_INIT
           \$("{$this->selector}").tagit({$options});
JS_INIT;
        $this->cs->registerScript(__CLASS__ . '#' . $this->getId(), $jsSetup, CClientScript::POS_READY);
    }
Exemplo n.º 14
0
 public function registerScript($id, $script, $position = null, array $options = array())
 {
     if (isset($options['order'])) {
         $order = $options['order'];
         unset($options['order']);
     } else {
         $order = null;
     }
     $order = CPropertyValue::ensureInteger($order);
     if ($order) {
         $this->orderScripts[$position][$id] = $order;
     }
     return parent::registerScript($id, $script, $position);
 }
Exemplo n.º 15
0
 /**
  * Add \t into script codes of READY
  */
 public function registerScript($id, $script, $position = self::POS_READY, array $htmlOptions = array())
 {
     if ($position === self::POS_READY) {
         $script = "\t" . str_replace("\n", "\n\t", $script);
     }
     parent::registerScript($id, $script, $position, $htmlOptions);
 }
Exemplo n.º 16
0
 /**
  * Registers a piece of javascript code.
  * @param string $id ID that uniquely identifies this piece of JavaScript code
  * @param string $script the javascript code
  * @param integer $position the position of the JavaScript code. Valid values include the following:
  * <ul>
  * <li>CClientScript::POS_HEAD : the script is inserted in the head section right before the title element.</li>
  * <li>CClientScript::POS_BEGIN : the script is inserted at the beginning of the body section.</li>
  * <li>CClientScript::POS_END : the script is inserted at the end of the body section.</li>
  * <li>CClientScript::POS_LOAD : the script is inserted in the window.onload() function.</li>
  * <li>CClientScript::POS_READY : the script is inserted in the jQuery's ready function.</li>
  * </ul>
  * @param array $htmlOptions
  * @return CClientScript the CClientScript object itself (to support method chaining, available since version 1.1.5).
  */
 public function registerScript($id, $script, $position = null, array $htmlOptions = array())
 {
     return parent::registerScript($id, $script, $position, $htmlOptions);
 }
Exemplo n.º 17
0
 public function registerScript($id, $script, $position = self::POS_READY, array $htmlOptions = array())
 {
     if ($this->optimizeInlineScript) {
         $script = $this->optimizeScriptCode($script);
     } elseif ($position === self::POS_READY) {
         $script = "\t" . str_replace("\n", "\n\t", $script);
     }
     return parent::registerScript($id, $script, $position, $htmlOptions);
 }
Exemplo n.º 18
0
 /**
  *
  * @param string $id
  * @param string $script
  * @param int $position
  */
 public function registerScript($id, $script, $position = self::POS_READY, array $htmlOptions = array())
 {
     if (YII_DEBUG === true) {
         $content = $script;
     } else {
         $content = JSMin::minify($script);
     }
     return parent::registerScript($id, $content, $position);
 }