Example #1
0
 /**
  * Init widget
  */
 public function init()
 {
     $assetsUrl = Yii::app()->assetManager->publish(dirname(__FILE__) . '/assets', false, -1, YII_DEBUG);
     $this->cs = Yii::app()->getClientScript();
     $this->cs->registerCoreScript('cookie');
     $this->cs->registerScriptFile($assetsUrl . '/jstree.js');
     $this->cs->registerCssFile($assetsUrl . '/themes/default/style.css');
     $this->cs->registerCssFile($assetsUrl . '/themes/default/filebrowser.css');
 }
Example #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        ");
 }
Example #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");
 }
 /**
  * Inserts the scripts in the head section.
  * @param string $output the output to be inserted with scripts.
  */
 public function renderHead(&$output)
 {
     $this->filterScripts();
     $this->reorderFiles();
     $this->processFiles();
     parent::renderHead($output);
 }
 public function registerCssFile($name, $media = '')
 {
     if (in_array($name, $this->bannedCssFiles)) {
         return $this;
     }
     parent::registerCssFile($name, $media);
 }
 /**
  * Extension of default {@link CClientScript::renderHead} that creates a big combo of minified CSS and compiled CSSP files.
  */
 public function renderHead(&$output)
 {
     $html = '';
     $origCssFiles = $this->cssFiles;
     $files_per_midia = array();
     foreach ($origCssFiles as $css => $media) {
         foreach ($this->excludeFromCompiling as $regexp) {
             if (preg_match($regexp, $css)) {
                 continue 2;
             }
         }
         if (!isset($files_per_midia[$media])) {
             $files_per_midia[$media] = array();
         }
         $files_per_midia[$media][] = preg_replace('/^\\/assets\\//', '../assets/', $css);
         unset($this->cssFiles[$css]);
     }
     foreach ($files_per_midia as $media => $files) {
         $html .= $this->compile($files, $media) . "\n";
     }
     if ($html !== '') {
         $count = 0;
         $output = preg_replace('/(<title\\b[^>]*>|<\\/head\\s*>)/is', '<###head###>$1', $output, 1, $count);
         if ($count) {
             $output = str_replace('<###head###>', $html, $output);
         } else {
             $output = $html . $output;
         }
     }
     parent::renderHead($output);
     $this->cssFiles = $origCssFiles;
 }
 /**
  * Renders the registered scripts.
  * Prevents rendering at the end of the controller, and waits until $this->render is true.
  *
  * @param string $output the existing output that needs to be inserted with script tags
  */
 public function render(&$output)
 {
     if (!$this->render) {
         return;
     }
     parent::render($output);
 }
 /**
  * {@inheritDoc}
  */
 public function registerCssFile($url, $media = '')
 {
     if ($this->isBundled($url)) {
         return $this;
     }
     return parent::registerCssFile($url, $media);
 }
 /**
  * Inserts the scripts at the end of the body section.
  * @param string $output the output to be inserted with scripts.
  */
 public function renderBodyEnd(&$output)
 {
     if ($this->packScriptFiles && $this->enableJavaScript) {
         $this->packScriptFiles(self::POS_END);
     }
     parent::renderBodyEnd($output);
 }
Example #10
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);
     }
 }
 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);
 }
Example #12
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);
 }
Example #13
0
 /**
  * Method override to call @see removeAllPageLoadedScriptFilesWhenRenderingInAjaxMode
  * (non-PHPdoc)
  * @see CClientScript::render()
  */
 public function render(&$output)
 {
     if ($this->isAjaxMode()) {
         $this->removeAllPageLoadedScriptFilesWhenRenderingInAjaxMode();
     }
     parent::render($output);
 }
Example #14
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");
 }
Example #15
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;
    }
Example #16
0
 public function registerScriptFile($url, $position = self::POS_HEAD)
 {
     if (!Yii::app()->request->isAjaxRequest) {
         return parent::registerScriptFile($url, $position);
     } else {
         echo '<script type="text/javascript" src="' . CHtml::encode($url) . '"></script>';
         return $this;
     }
 }
Example #17
0
 /**
  * Registers a script file
  *
  * @param String $src
  * @param String $position
  */
 public function registerScriptFile($src, $position = NULL)
 {
     #    if(Yii::app()->getRequest()->getIsAjaxRequest()) {
     #         Yii::app()->clientScript->registerScript('loadScript_'.$src, "loadJavaScript(\"".$src."\");", CClientScript::POS_BEGIN);
     #      } else {
     return parent::registerScriptFile($src, $position);
     #        }
     #registerScriptFile
 }
 /**
  * @depends testRegisterMetaTag
  */
 public function testRegisterDuplicatingMetaTag()
 {
     $content = 'Test meta tag content';
     $name = 'test_meta_tag_name';
     $this->_clientScript->registerMetaTag($content, $name);
     $this->_clientScript->registerMetaTag($content, $name);
     $metaTagData = array('name' => $name, 'content' => $content);
     $assertion = array($metaTagData, $metaTagData);
     $this->assertAttributeEquals($assertion, 'metaTags', $this->_clientScript);
 }
 /**
  * @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;
 }
 public function registerCssFile($url, $media = '')
 {
     //if the file extension is .less, use the lessparser.
     $file_extension = end(explode('.', $url));
     if ($file_extension == 'less') {
         $url = $this->compileLess($url, false);
     }
     //run the parent method to parse the less/css file like Yii normally does.
     return parent::registerCssFile($url, $media);
 }
 /**
  * @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'));
 }
 protected function unifyScripts()
 {
     parent::unifyScripts();
     $this->afterUnifyScripts();
     // raise our event
     // after all manipulations and filtration of registered resources
     $this->_publishExtensionClientInit();
     // this js code should be included on each AJAX request
     $this->_publishRegisteredResourcesUpdater();
 }
Example #23
0
 /**
  * Registers a piece of Less code.
  * @param string $id ID that uniquely identifies this piece of Less code
  * @param string $less the Less code
  * @param string $media media that the CSS code should be applied to. If empty, it means all media types.
  * @return CClientScript the CClientScript object itself (to support method chaining, available since version 1.1.5).
  */
 public function registerLess($id, $less, $media = '')
 {
     $this->jLessOptions['type'] = 'string';
     $this->jLessOptions['string'] = $less;
     $this->jLessOptions = CMap::mergeArray($this->_jLessOptions, $this->jLessOptions);
     $classa = "JLess\\vendors\\" . $this->jLessOptions[$this->jLessOptions['vendor']]['class'];
     $compiler = new $classa($this->jLessOptions);
     $compiler->compileString();
     return parent::registerCss($id, $compiler->getCss(), $media);
 }
Example #24
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);
         }
     }
 }
 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);
 }
Example #26
0
 /**
  * add JSONP-supporting functionality
  * using: $.getJSON('url?callback=?', function(html) {alert(html);});
  * see(http://api.jquery.com/jQuery.getJSON/#jsonp)
  * all registered scripts (non file) will evaluate on client automatically
  *
  * @param string $output
  */
 public function render(&$output)
 {
     if (Yii::app()->request->getIsAjaxRequest() && isset($_GET['callback'])) {
         $scripts = '';
         foreach ($this->scripts as $pos) {
             foreach ($pos as $script) {
                 $scripts .= $script;
             }
         }
         $output = $scripts . "\n" . $_GET['callback'] . '("' . addslashes($output) . '")';
     } else {
         parent::render($output);
     }
 }
Example #27
0
 protected function filterCommonScripts($requires)
 {
     $commonPathes = array();
     foreach ($requires['js'] as $index => $path) {
         if (preg_match('/^aes:(.*)$/', $path)) {
             list($commonPack, $path) = explode(':', $path);
             $commonPathes[] = $path;
             unset($requires['js'][$index]);
         }
     }
     $this->clientScript->addPackage($commonPack, array('baseUrl' => 'js/libs/aes', 'js' => $commonPathes));
     $requires['depends'][] = $commonPack;
     return $requires;
 }
Example #28
0
 /**
  * Initialize the minScript application component.
  * @throws CException if the minScript controller is not defined in CWebApplication::$controllerMap.
  */
 public function init()
 {
     parent::init();
     // Initialize the cache application component instance for minScript
     if (($minScriptCache = Yii::app()->getComponent($this->minScriptCacheId)) !== null) {
         $this->_minScriptCache = $minScriptCache;
     } else {
         Yii::app()->setComponents(array('minScriptCache' => array('class' => 'system.caching.CFileCache', 'cachePath' => Yii::app()->runtimePath . '/minScript/cache/', 'cacheFileSuffix' => '')), false);
         $this->_minScriptCache = Yii::app()->getComponent('minScriptCache');
     }
     // Check for existence of the minScript controller inside CWebApplication::$controllerMap
     if (!isset(Yii::app()->controllerMap[$this->minScriptControllerId])) {
         throw new CException('The minScript controller with ID "' . $this->minScriptControllerId . '" needs to be defined in CWebApplication::$controllerMap.');
     }
 }
Example #29
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);
    }
Example #30
0
 public function renderHead(&$output)
 {
     $folder = 'frontend.tmp';
     $path = Yii::getPathOfAlias($folder);
     $root = Yii::getPathOfAlias('webroot');
     $filePath = $root . '/../../Makefile';
     $fullPaths = array();
     $cssPaths = array();
     foreach ($this->scriptFiles[0] as $from => $to) {
         $fullPaths[] = $root . $to;
     }
     foreach ($this->cssFiles as $path => $media) {
         $cssPaths[] = $root . $path;
     }
     $makefileTemplate = file_get_contents($root . '/../../Makefile.template');
     $makefile = str_replace('{{jsFiles}}', implode(" \\\n", $fullPaths), $makefileTemplate);
     $makefile = str_replace('{{cssFiles}}', implode(" \\\n", $cssPaths), $makefile);
     file_put_contents($filePath, $makefile);
     parent::renderHead($output);
 }