Skip to content

Commit

Permalink
Merge pull request #64 from mageplaza/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
haitv282 authored Feb 8, 2023
2 parents f105e4b + 8dc3da5 commit 343eea8
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 37 deletions.
74 changes: 74 additions & 0 deletions Block/Adminhtml/System/Config/ColorPicker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Core
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Core\Block\Adminhtml\System\Config;

use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;

/**
* Class ColorPicker
* @package Mageplaza\Core\Block\Adminhtml\System\Config
*/
class ColorPicker extends Field {

/**
* Colorpicker constructor.
*
* @param Context $context
* @param array $data
*/
public function __construct(
Context $context, array $data = []
) {
parent::__construct($context, $data);
}

/**
* @param AbstractElement $element
*
* @return string
*/
protected function _getElementHtml(AbstractElement $element)
{
$html = $element->getElementHtml();
$value = $element->getData('value');

$html .= '<script type="text/javascript">
require(["jquery","jquery/colorpicker/js/colorpicker"], function ($) {
$(document).ready(function () {
var $el = $("#' . $element->getHtmlId() . '");
$el.css("backgroundColor", "' . $value . '");
$el.ColorPicker({
color: "' . $value . '",
onChange: function (hsb, hex, rgb) {
$el.css("backgroundColor", "#" + hex).val("#" + hex);
}
});
});
});
</script>';

return $html;
}

}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mageplaza/module-core",
"description": "Mageplaza Core for Magento 2",
"type": "magento2-module",
"version": "1.5.1",
"version": "1.5.2",
"license": "proprietary",
"authors": [
{
Expand Down
55 changes: 28 additions & 27 deletions view/adminhtml/layout/adminhtml_system_config_edit.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<?xml version="1.0"?>
<!--
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Core
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<script src="Mageplaza_Core::js/jscolor.min.js"/>
</head>
</page>
<?xml version="1.0"?>
<!--
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Core
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<script src="Mageplaza_Core::js/jscolor.min.js"/>
<css src="jquery/colorpicker/css/colorpicker.css"/>
</head>
</page>
Loading

0 comments on commit 343eea8

Please sign in to comment.