addScript('js/svg-editor/embedapi.js'); $doc->addScript('js/lib/form-element-svgEditor.js'); $doc->addInitFunction('Qs_Form_Element_SvgEditor.init', array($this->_getScriptOptions())); return $this; } protected function _getEditorOptions() { /** @var Qs_Form_Element_SvgEditor $element */ $element = $this->getElement(); $options = $element->getScriptOptions(); $options['elementName'] = $element->getName(); $options['BasePath'] = Qs_Constant::get('BASE_URL') . '/js/svg-editor/'; $options['ImagePath'] = Qs_Constant::get('BASE_URL') . '/' . Qs_ImageFs::WEB_PATH . '/'; if (null !== ($width = $element->getWidth())) { $options['Width'] = (int) $width; } if (null !== ($height = $element->getHeight())) { $options['Height'] = (int) $height; } else { $options['Height'] = 250; } return $options; } protected function _getScriptOptions() { $options['editorOptions'] = $this->_getEditorOptions(); $value = $this->getElement()->getValue(); $options['currentSvg'] = $value['svgFile']; $options['currentJpg'] = $value['bgFile']; return $options; } public function render($content) { $options = $this-> _getEditorOptions(); $value = $this->getElement()->getValue(); $imageInfo = Qs_ImageFs::getInfo(WWW_PATH . '/' . Qs_ImageFs::WEB_PATH . '/' . $value['bgFile']); $dimensions = (!empty($imageInfo) && $imageInfo['width'] && $imageInfo['height']) ? 'dimensions=' . $imageInfo['width'] . ',' . $imageInfo['height'] . '&' : null; $svgUrlParam = ($value['svgFile']) ? 'url=' . $options['ImagePath'] . rawurlencode($value['svgFile']) . '&' : null; $jpgUrlParam = ($value['bgFile']) ? 'bkgd_url=' . $options['ImagePath'] . rawurlencode($value['bgFile']) . '&' : null; $content = '' . $content; return $content; } }