encode() публичный статический Метод

Example: $options['onLoading'] = "doit"; $options['onComplete'] = "more"; echo TJavaScript::encode($options); expects the following javascript code {'onLoading':'doit','onComplete':'more'} For higher complexity data structures use {@link jsonEncode} and {@link jsonDecode} to serialize and unserialize.
С версии: 3.1.5
public static encode ( $value, $toMap = true, $encodeEmptyStrings = false ) : string
Результат string the encoded string
Пример #1
0
 /**
  * Register a default button to panel. When the $panel is in focus and
  * the 'enter' key is pressed, the $button will be clicked.
  * @param TControl|string panel (or its unique ID) to register the default button action
  * @param TControl|string button (or its unique ID) to trigger a postback
  */
 public function registerDefaultButton($panel, $button)
 {
     $panelID = is_string($panel) ? $panel : $panel->getUniqueID();
     if (is_string($button)) {
         $buttonID = $button;
     } else {
         $button->setIsDefaultButton(true);
         $buttonID = $button->getUniqueID();
     }
     $options = TJavaScript::encode($this->getDefaultButtonOptions($panelID, $buttonID));
     $code = "new Prado.WebUI.DefaultButton({$options});";
     $this->_endScripts['prado:' . $panelID] = $code;
     $this->registerPradoScriptInternal('prado');
     $params = array($panelID, $buttonID);
     $this->_page->registerCachingAction('Page.ClientScript', 'registerDefaultButton', $params);
 }
Пример #2
0
 /**
  * Ensure that the ID attribute is rendered and registers the javascript code
  * for initializing the active control.
  */
 protected function addAttributesToRender($writer)
 {
     parent::addAttributesToRender($writer);
     $cs = $this->getPage()->getClientScript();
     if ($this->getGhosting() == TDraggableGhostingOptions::SuperGhosting) {
         $cs->registerPradoScript('dragdropextra');
     } else {
         $cs->registerPradoScript('dragdrop');
     }
     $writer->addAttribute('id', $this->getClientID());
     $options = TJavaScript::encode($this->getPostBackOptions());
     $class = $this->getClientClassName();
     $code = "new {$class}('{$this->getClientId()}', {$options}) ";
     $cs->registerEndScript(sprintf('%08X', crc32($code)), $code);
 }
Пример #3
0
 /**
  * Ensure that the ID attribute is rendered and registers the javascript code
  * for initializing the active control. Also registers language specific global
  * settings for the first used date picker.
  */
 protected function addAttributesToRender($writer)
 {
     $cs = $this->getPage()->getClientScript();
     if (self::$_first) {
         $code = "jQuery(document).ready(function(){jQuery.datepicker.setDefaults(jQuery.datepicker.regional['{$this->getCurrentCulture()}']);});";
         $cs->registerEndScript(sprintf('%08X', crc32($code)), $code);
         self::$_first = false;
     }
     parent::addAttributesToRender($writer);
     $options = TJavaScript::encode($this->getOptions()->toArray());
     $code = "jQuery('#" . $this->getWidgetID() . "')." . $this->getWidget() . "(" . $options . ");";
     $cs->registerEndScript(sprintf('%08X', crc32($code)), $code);
 }
Пример #4
0
 /**
  * @return Array of active control options
  */
 public function toArray()
 {
     $ret = $this->_options === null ? array() : $this->_options;
     foreach ($this->_control->getValidEvents() as $event) {
         if ($this->_control->hasEventHandler('on' . $event)) {
             $ret[$event] = new TJavaScriptLiteral("function( event, ui ) { Prado.JuiCallback(" . TJavaScript::encode($this->_control->getUniqueID()) . ", " . TJavaScript::encode($event) . ", event, ui, this); }");
         }
     }
     return $ret;
 }
Пример #5
0
 /**
  * Ensure that the ID attribute is rendered and registers the javascript code
  * for initializing the active control.
  */
 protected function addAttributesToRender($writer)
 {
     parent::addAttributesToRender($writer);
     $writer->addAttribute('id', $this->getClientID());
     $options = TJavaScript::encode($this->getPostBackOptions());
     $cs = $this->getPage()->getClientScript();
     $code = "jQuery('#" . $this->getWidgetID() . "')." . $this->getWidget() . "(" . $options . ");";
     $cs->registerEndScript(sprintf('%08X', crc32($code)), $code);
 }
Пример #6
0
 /**
  * Publish the color picker assets.
  */
 protected function publishColorPickerAssets()
 {
     $cs = $this->getPage()->getClientScript();
     $key = "prado:" . get_class($this);
     $imgs['button.gif'] = $this->getAssetUrl('button.gif');
     $imgs['background.png'] = $this->getAssetUrl('background.png');
     $options = TJavaScript::encode($imgs);
     $code = "Prado.WebUI.TColorPicker.UIImages = {$options};";
     $cs->registerEndScript($key, $code);
     $cs->registerPradoScript("colorpicker");
     $url = $this->getAssetUrl($this->getColorPickerStyle() . '.css');
     if (!$cs->isStyleSheetFileRegistered($url)) {
         $cs->registerStyleSheetFile($url, $url);
     }
 }
Пример #7
0
 /**
  * Registers the individual validator client-side javascript code.
  */
 protected function registerClientScriptValidator()
 {
     $key = 'prado:' . $this->getClientID();
     if (!$this->getPage()->getClientScript()->isEndScriptRegistered($key)) {
         $options = TJavaScript::encode($this->getClientScriptOptions());
         $script = 'new ' . $this->getClientClassName() . '(' . $options . ');';
         $this->getPage()->getClientScript()->registerEndScript($key, $script);
     }
 }
Пример #8
0
 /**
  * Registers the relevant JavaScript.
  */
 protected function registerClientScript()
 {
     $id = $this->getClientID();
     $options = TJavaScript::encode($this->getClientOptions());
     $className = $this->getClientClassName();
     $cs = $this->getPage()->getClientScript();
     $cs->registerPradoScript('tabpanel');
     $code = "new {$className}({$options});";
     $cs->registerEndScript("prado:{$id}", $code);
     // ensure an item is always active and visible
     $index = $this->getActiveViewIndex();
     if (!$this->getViews()->itemAt($index)->Visible) {
         $index = 0;
     }
     $cs->registerHiddenField($id . '_1', $index);
 }
Пример #9
0
 protected function registerClientScript()
 {
     $id = $this->getClientID();
     $options = TJavaScript::encode($this->getClientOptions());
     $className = $this->getClientClassName();
     $cs = $this->Page->ClientScript;
     $code = "new {$className}({$options});";
     $cs->registerPradoScript('ajax');
     $cs->registerEndScript("grecaptcha:{$id}", $code);
 }
Пример #10
0
 public function renderContents($writer)
 {
     $readyscript = 'jQuery(document).trigger(' . TJavaScript::quoteString('captchaready:' . $this->getClientID()) . ')';
     $cs = $this->Page->ClientScript;
     $id = $this->getClientID();
     $divid = $id . '_1_recaptchadiv';
     $writer->write('<div id="' . htmlspecialchars($divid) . '">');
     if (!$this->Page->IsCallback) {
         $writer->write(TJavaScript::renderScriptBlock('var RecaptchaOptions = ' . TJavaScript::jsonEncode($this->getClientSideOptions()) . ';'));
         $html = $this->recaptcha_get_html($this->getPublicKey());
         /*
         reCAPTCHA currently does not support multiple validations per page
         $html = str_replace(
         	array(self::ChallengeFieldName,self::ResponseFieldName),
         	array($this->getChallengeFieldName(),$this->getResponseFieldName()),
         	$html
         );
         */
         $writer->write($html);
         $cs->registerEndScript('ReCaptcha::EventScript', 'jQuery(document).ready(function() { ' . $readyscript . '; } );');
     } else {
         $options = $this->getClientSideOptions();
         $options['callback'] = new TJavaScriptLiteral('function() { ' . $readyscript . '; ' . $this->getCallbackScript() . '; }');
         $cs->registerScriptFile('ReCaptcha::AjaxScript', self::RECAPTCHA_JS);
         $cs->registerEndScript('ReCaptcha::CreateScript::' . $id, implode(' ', array('if (!jQuery(' . TJavaScript::quoteString('#' . $this->getResponseFieldName()) . '))', '{', 'Recaptcha.destroy();', 'Recaptcha.create(', TJavaScript::quoteString($this->getPublicKey()) . ', ', TJavaScript::quoteString($divid) . ', ', TJavaScript::encode($options), ');', '}')));
     }
     $writer->write('</div>');
 }
Пример #11
0
 protected function renderClientControlScript($writer)
 {
     $cs = $this->getPage()->getClientScript();
     if (!$cs->isEndScriptRegistered('TDatePicker.spacer')) {
         $spacer = $this->getAssetUrl('spacer.gif');
         $code = "Prado.WebUI.TDatePicker.spacer = '{$spacer}';";
         $cs->registerEndScript('TDatePicker.spacer', $code);
     }
     $options = TJavaScript::encode($this->getDatePickerOptions());
     $code = "new Prado.WebUI.TActiveDatePicker({$options});";
     $cs->registerEndScript("prado:" . $this->getClientID(), $code);
 }
Пример #12
0
 /**
  * Registers the editor javascript file and code to initialize the editor.
  */
 protected function registerEditorClientScript($writer)
 {
     $this->loadJavascriptLibrary();
     $scripts = $this->getPage()->getClientScript();
     $options = array('EditorOptions' => $this->getEditorOptions());
     $options = TJavaScript::encode($options, true, true);
     $script = "new {$this->getClientClassName()}({$options})";
     $scripts->registerEndScript('prado:THtmlArea4' . $this->ClientID, $script);
 }
Пример #13
0
 /**
  * @param string callback requestion options as javascript code.
  */
 public function getJsCallbackOptions()
 {
     return TJavaScript::encode($this->getClientSideOptions());
 }
Пример #14
0
 /**
  * Registers the relevant JavaScript.
  */
 protected function registerClientScript()
 {
     $options = TJavaScript::encode($this->getClientOptions());
     $className = $this->getClientClassName();
     $cs = $this->getPage()->getClientScript();
     $cs->registerPradoScript('keyboard');
     $cs->registerEndScript('prado:' . $this->getClientID(), "new {$className}({$options});");
 }
Пример #15
0
 /**
  * Render the javascript for validation summary.
  * @param array list of options for validation summary.
  */
 protected function renderJsSummary()
 {
     if (!$this->getEnabled(true) || !$this->getEnableClientScript()) {
         return;
     }
     $cs = $this->getPage()->getClientScript();
     $cs->registerPradoScript('validator');
     //need to register the validation manager is validation summary is alone.
     $formID = $this->getPage()->getForm()->getClientID();
     $scriptKey = "TBaseValidator:{$formID}";
     if ($this->getEnableClientScript() && !$cs->isEndScriptRegistered($scriptKey)) {
         $manager['FormID'] = $formID;
         $options = TJavaScript::encode($manager);
         $cs->registerPradoScript('validator');
         $cs->registerEndScript($scriptKey, "new Prado.ValidationManager({$options});");
     }
     $options = TJavaScript::encode($this->getClientScriptOptions());
     $script = "new Prado.WebUI.TValidationSummary({$options});";
     $cs->registerEndScript($this->getClientID(), $script);
 }