This repository has been archived by the owner on Jan 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #2850131 by mondrake: Add a JQuery Colorpicker color selector p…
…lugin
- Loading branch information
mondrake
authored and
mondrake
committed
Feb 6, 2017
1 parent
e16b53b
commit 32d9e73
Showing
9 changed files
with
261 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* JQuery Colorpicker Color selector */ | ||
|
||
div.image-effects-jquery-colorpicker-color-selector span.image-effects-color-suffix { | ||
left: 40px; | ||
position: absolute; | ||
top: 6px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* @file | ||
* | ||
* JQuery Colorpicker color selector. | ||
* | ||
* Alters field_suffix form element after change to the color field. | ||
*/ | ||
|
||
(function ($) { | ||
'use strict'; | ||
Drupal.behaviors.imageEffectsJqueryColorpickerColorSelector = { | ||
attach: function (context, settings) { | ||
$('.image-effects-jquery-colorpicker-color-selector .image-effects-jquery-colorpicker', context).once('image-effects-jquery-colorpicker-color-selector').each(function (index) { | ||
$(this).parent().append('<span class="image-effects-color-suffix">#' + this.value.toUpperCase() + '</div>'); | ||
$(this).on('change', function (event) { | ||
var suffix = $(this).parent().find('.image-effects-color-suffix').get(0); | ||
$(suffix).text('#' + this.value.toUpperCase()); | ||
}); | ||
}); | ||
} | ||
}; | ||
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Drupal\image_effects; | ||
|
||
use Drupal\Core\Config\ConfigFactoryInterface; | ||
use Drupal\Core\Extension\ModuleUninstallValidatorInterface; | ||
use Drupal\Core\StringTranslation\StringTranslationTrait; | ||
use Drupal\Core\StringTranslation\TranslationInterface; | ||
|
||
/** | ||
* Prevents uninstalling modules that Image Effects configuration require. | ||
*/ | ||
class ImageEffectsUninstallValidator implements ModuleUninstallValidatorInterface { | ||
|
||
use StringTranslationTrait; | ||
|
||
/** | ||
* The configuration factory. | ||
* | ||
* @var \Drupal\Core\Config\ConfigFactoryInterface | ||
*/ | ||
protected $configFactory; | ||
|
||
/** | ||
* Constructs a new ImageEffectsUninstallValidator. | ||
* | ||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory | ||
* The configuration factory. | ||
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation | ||
* The string translation service. | ||
*/ | ||
public function __construct(ConfigFactoryInterface $config_factory, TranslationInterface $string_translation) { | ||
$this->configFactory = $config_factory; | ||
$this->stringTranslation = $string_translation; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function validate($module) { | ||
$reasons = []; | ||
// Prevents uninstalling 'jquery_colorpicker' if its color selector plugin | ||
// is in use. | ||
if ($module == 'jquery_colorpicker' && $this->configFactory->get('image_effects.settings')->get('color_selector.plugin_id') === 'jquery_colorpicker') { | ||
$reasons[] = $this->t('The <em>Image Effects</em> module is using the <em>JQuery Colorpicker</em> color selector'); | ||
} | ||
return $reasons; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/Plugin/image_effects/ColorSelector/JqueryColorPicker.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Drupal\image_effects\Plugin\image_effects\ColorSelector; | ||
|
||
use Drupal\Component\Utility\Unicode; | ||
use Drupal\image_effects\Plugin\ImageEffectsPluginBase; | ||
|
||
/** | ||
* JQuery Colorpicker color selector plugin. | ||
* | ||
* @Plugin( | ||
* id = "jquery_colorpicker", | ||
* title = @Translation("JQuery Colorpicker color selector"), | ||
* short_title = @Translation("JQuery Colorpicker"), | ||
* help = @Translation("Use a JQuery color picker to select colors.") | ||
* ) | ||
*/ | ||
class JqueryColorPicker extends ImageEffectsPluginBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function selectionElement(array $options = []) { | ||
return [ | ||
'#type' => 'jquery_colorpicker', | ||
'#title' => isset($options['#title']) ? $options['#title'] : $this->t('Color'), | ||
'#default_value' => Unicode::substr($options['#default_value'], -6), | ||
'#attributes' => ['class' => ['image-effects-jquery-colorpicker']], | ||
'#wrapper_attributes' => ['class' => ['image-effects-jquery-colorpicker-color-selector']], | ||
'#attached' => ['library' => ['image_effects/image_effects.jquery_colorpicker_color_selector']], | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function isAvailable() { | ||
return \Drupal::service('module_handler')->moduleExists('jquery_colorpicker'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
// @codingStandardsIgnoreFile | ||
|
||
/** | ||
* This file was generated via php core/scripts/generate-proxy-class.php 'Drupal\image_effects\ImageEffectsUninstallValidator' "modules/image_effects/src". | ||
*/ | ||
|
||
namespace Drupal\image_effects\ProxyClass { | ||
|
||
/** | ||
* Provides a proxy class for \Drupal\image_effects\ImageEffectsUninstallValidator. | ||
* | ||
* @see \Drupal\Component\ProxyBuilder | ||
*/ | ||
class ImageEffectsUninstallValidator implements \Drupal\Core\Extension\ModuleUninstallValidatorInterface | ||
{ | ||
|
||
use \Drupal\Core\DependencyInjection\DependencySerializationTrait; | ||
|
||
/** | ||
* The id of the original proxied service. | ||
* | ||
* @var string | ||
*/ | ||
protected $drupalProxyOriginalServiceId; | ||
|
||
/** | ||
* The real proxied service, after it was lazy loaded. | ||
* | ||
* @var \Drupal\image_effects\ImageEffectsUninstallValidator | ||
*/ | ||
protected $service; | ||
|
||
/** | ||
* The service container. | ||
* | ||
* @var \Symfony\Component\DependencyInjection\ContainerInterface | ||
*/ | ||
protected $container; | ||
|
||
/** | ||
* Constructs a ProxyClass Drupal proxy object. | ||
* | ||
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container | ||
* The container. | ||
* @param string $drupal_proxy_original_service_id | ||
* The service ID of the original service. | ||
*/ | ||
public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, $drupal_proxy_original_service_id) | ||
{ | ||
$this->container = $container; | ||
$this->drupalProxyOriginalServiceId = $drupal_proxy_original_service_id; | ||
} | ||
|
||
/** | ||
* Lazy loads the real service from the container. | ||
* | ||
* @return object | ||
* Returns the constructed real service. | ||
*/ | ||
protected function lazyLoadItself() | ||
{ | ||
if (!isset($this->service)) { | ||
$this->service = $this->container->get($this->drupalProxyOriginalServiceId); | ||
} | ||
|
||
return $this->service; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function validate($module) | ||
{ | ||
return $this->lazyLoadItself()->validate($module); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setStringTranslation(\Drupal\Core\StringTranslation\TranslationInterface $translation) | ||
{ | ||
return $this->lazyLoadItself()->setStringTranslation($translation); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters