Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silverstripe5 compatibility #3

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _config.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php
define("COLOURPICKER_DIR", "colourpicker");
define("COLOURPICKER_DIR", "ninty9notout/colourpicker");
rturevic-mm marked this conversation as resolved.
Show resolved Hide resolved
define("COLOURPICKER_PATH", BASE_PATH . "/" . COLOURPICKER_DIR);
Binary file added code/.DS_Store
Binary file not shown.
12 changes: 8 additions & 4 deletions code/forms/ColourPicker.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php

use SilverStripe\Forms\TextField;
use SilverStripe\View\Requirements;

/**
* Colour input field.
*
Expand All @@ -18,11 +22,11 @@ public function Field($properties = array())
{
$this->addExtraClass("colourpickerinput");

Requirements::javascript(COLOURPICKER_DIR . "/thirdparty/jquery-minicolors/jquery.minicolors.min.js");
Requirements::css(COLOURPICKER_DIR . "/thirdparty/jquery-minicolors/jquery.minicolors.css");
Requirements::javascript(COLOURPICKER_DIR . ":thirdparty/jquery-minicolors/jquery.minicolors.min.js");
Requirements::css(COLOURPICKER_DIR . ":thirdparty/jquery-minicolors/jquery.minicolors.css");

Requirements::css(COLOURPICKER_DIR . "/css/colourpicker.css");
Requirements::javascript(COLOURPICKER_DIR . "/javascript/colourpicker.js");
Requirements::css(COLOURPICKER_DIR . ":css/colourpicker.css");
Requirements::javascript(COLOURPICKER_DIR . ":javascript/colourpicker.js");
rturevic-mm marked this conversation as resolved.
Show resolved Hide resolved

return parent::Field($properties);
}
Expand Down
49 changes: 49 additions & 0 deletions code/models/Colour.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

use SilverStripe\ORM\FieldType\DBVarchar;

class Colour extends DBVarchar
{
public function __construct($name = null, $options = array())
{
parent::__construct($name, 7, $options);
}

/**
* (non-PHPdoc)
* @see DBField::scaffoldFormField()
*/
public function scaffoldFormField($title = null, $params = null) {
return new ColourPicker($this->name, $title);
}

public function getHash()
{
return substr($this->value, 1);
}

public function getRGB()
{
$hash = $this->getHash();
return array(
'R' => hexdec(substr($hash, 0, 2)),
'G' => hexdec(substr($hash, 2, 2)),
'B' => hexdec(substr($hash, 4, 2)),
);
}

public function getRed()
{
return $this->getRGB()['R'];
}

public function getBlue()
{
return $this->getRGB()['B'];
}

public function getGreen()
{
return $this->getRGB()['G'];
}
}
18 changes: 11 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ninty9notout/colourpicker",
"type": "silverstripe-module",
"type": "silverstripe-vendormodule",
"description": "Provides a pop-up colour picker functionality, turning a text field into a colour picker field.",
"keywords": ["silverstripe", "module", "cms", "jquery", "color", "colour", "picker", "form", "field"],
"homepage": "https://github.com/ninty9notout/silverstripe-colourpicker",
Expand All @@ -13,11 +13,15 @@
}
],
"require": {
"php": ">=5.3.2",
"silverstripe/cms": ">=3.1"
"php": ">=8",
"silverstripe/cms": ">=5"
},
"target-dir": "colourpicker",
"extra": {
"installer-name": "colourpicker"
}
"extra": {
"installer-name": "colourpicker",
"expose": [
"css",
"javascript",
"thirdparty"
]
}
}