Jaydeep Rajput
Jaydeep Rajput

Reputation: 3673

editMe extension is not working because of scriptMap

The performance of my web site was poor due multiple times import of jquery.js(shown by pagespeed plugin) and other scripts. So in my main layout, I added

    <?php
    $cs=Yii::app()->clientScript;
    $cs->scriptMap=array(
        'jquery.js'=>false,
        'jquery.ui.js' => false,
    );?>
 ...
 ...
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js"></script>
    ..
    </head>

But as soon as, I added the above scriptMap in main layout, editMe rich text box editor is not working properly.

Can anybody tell me how to resolve this problem? Also please suggest me how do I resolve multiple script import issue on my website?

I can see following code in ExtEditMe.php

public function run() {
        // Register JavaScript files
        Yii::app() -> clientScript -> registerCoreScript('jquery');
        Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/jquery.js');
        Yii::app() -> clientScript -> registerScriptFile(self::$_ckeAssetUrl . '/' . md5(self::$_ckeAssetUrl) . '.js');
        Yii::app() -> clientScript -> registerScriptFile(self::$_ckeAssetUrl . '/ckeditor.js');
        Yii::app() -> clientScript -> registerScriptFile(self::$_ckeAssetUrl . '/adapters/jquery.js');
        // Generate textarea
        $nameId = $this -> resolveNameID();
        $this -> htmlOptions['id'] = $nameId[1];
        if ($this -> hasModel()) {
            echo CHtml::activeTextArea($this -> model, $this -> attribute, $this -> htmlOptions);
        } else {
            echo CHtml::textArea($this -> name, $this -> value, $this -> htmlOptions);
        }
        // Load CKEditor
        $jquerySelector = CJavaScript::encode('#' . $this -> htmlOptions['id']);
        $ckeConfig = CJavaScript::encode($this -> _ckeGenerateConfig());
        Yii::app() -> clientScript -> registerScript('editMe_' . $this -> htmlOptions['id'], 'jQuery(' . $jquerySelector . ').ckeditor(' . $ckeConfig . ');', 2);
    }

Upvotes: 0

Views: 627

Answers (1)

Jaydeep Rajput
Jaydeep Rajput

Reputation: 3673

As a workaround, I have modified my main layout as below

<?php
$cs=Yii::app()->clientScript;
$cs->scriptMap=array(
    'jquery-ui.min.js' => false,
    'jquery.min.js'=>false,
);?>
 ...
 ...
    <head>
         <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js"></script>
    ..
    </head>

whereas,

ExtEditMe.php is kept as is.Also at all places where I was using jquery.js now uses jquery-min.js.

Upvotes: 1

Related Questions