Removed tiny color picker library
This commit is contained in:
parent
d87eb277dd
commit
9e397a57a9
7 changed files with 80 additions and 2215 deletions
2190
package-lock.json
generated
2190
package-lock.json
generated
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
|
@ -146,7 +146,6 @@ These are the great open-source projects used to help build BookStack:
|
|||
* [Google Material Icons](https://material.io/icons/)
|
||||
* [Dropzone.js](http://www.dropzonejs.com/)
|
||||
* [clipboard.js](https://clipboardjs.com/)
|
||||
* [TinyColorPicker](http://www.dematte.at/tinyColorPicker/index.html)
|
||||
* [markdown-it](https://github.com/markdown-it/markdown-it) and [markdown-it-task-lists](https://github.com/revin/markdown-it-task-lists)
|
||||
* [BarryVD](https://github.com/barryvdh)
|
||||
* [Debugbar](https://github.com/barryvdh/laravel-debugbar)
|
||||
|
|
|
@ -25,6 +25,7 @@ import breadcrumbListing from "./breadcrumb-listing";
|
|||
import permissionsTable from "./permissions-table";
|
||||
import customCheckbox from "./custom-checkbox";
|
||||
import bookSort from "./book-sort";
|
||||
import settingAppColorPicker from "./setting-app-color-picker";
|
||||
|
||||
const componentMapping = {
|
||||
'dropdown': dropdown,
|
||||
|
@ -54,6 +55,7 @@ const componentMapping = {
|
|||
'permissions-table': permissionsTable,
|
||||
'custom-checkbox': customCheckbox,
|
||||
'book-sort': bookSort,
|
||||
'setting-app-color-picker': settingAppColorPicker,
|
||||
};
|
||||
|
||||
window.components = {};
|
||||
|
|
56
resources/assets/js/components/setting-app-color-picker.js
Normal file
56
resources/assets/js/components/setting-app-color-picker.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
|
||||
class SettingAppColorPicker {
|
||||
|
||||
constructor(elem) {
|
||||
this.elem = elem;
|
||||
this.colorInput = elem.querySelector('input[type=color]');
|
||||
this.lightColorInput = elem.querySelector('input[name="setting-app-color-light"]');
|
||||
this.resetButton = elem.querySelector('[setting-app-color-picker-reset]');
|
||||
|
||||
this.colorInput.addEventListener('change', this.updateColor.bind(this));
|
||||
this.colorInput.addEventListener('input', this.updateColor.bind(this));
|
||||
this.resetButton.addEventListener('click', event => {
|
||||
this.colorInput.value = '#0288D1';
|
||||
this.updateColor();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the app colors as a preview, and create a light version of the color.
|
||||
*/
|
||||
updateColor() {
|
||||
const hexVal = this.colorInput.value;
|
||||
const rgb = this.hexToRgb(hexVal);
|
||||
const rgbLightVal = 'rgba('+ [rgb.r, rgb.g, rgb.b, '0.15'].join(',') +')';
|
||||
|
||||
this.lightColorInput.value = rgbLightVal;
|
||||
|
||||
const customStyles = document.getElementById('custom-styles');
|
||||
const oldColor = customStyles.getAttribute('data-color');
|
||||
const oldColorLight = customStyles.getAttribute('data-color-light');
|
||||
|
||||
customStyles.innerHTML = customStyles.innerHTML.split(oldColor).join(hexVal);
|
||||
customStyles.innerHTML = customStyles.innerHTML.split(oldColorLight).join(rgbLightVal);
|
||||
|
||||
customStyles.setAttribute('data-color', hexVal);
|
||||
customStyles.setAttribute('data-color-light', rgbLightVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Covert a hex color code to rgb components.
|
||||
* @attribution https://stackoverflow.com/a/5624139
|
||||
* @param hex
|
||||
* @returns {*}
|
||||
*/
|
||||
hexToRgb(hex) {
|
||||
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||
return {
|
||||
r: result ? parseInt(result[1], 16) : 0,
|
||||
g: result ? parseInt(result[2], 16) : 0,
|
||||
b: result ? parseInt(result[3], 16) : 0
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default SettingAppColorPicker;
|
|
@ -158,7 +158,8 @@ table.form-table {
|
|||
}
|
||||
}
|
||||
|
||||
input[type="text"], input[type="number"], input[type="email"], input[type="date"], input[type="search"], input[type="url"], input[type="password"], select, textarea {
|
||||
input[type="text"], input[type="number"], input[type="email"], input[type="date"], input[type="search"], input[type="url"],
|
||||
input[type="color"], input[type="password"], select, textarea {
|
||||
@extend .input-base;
|
||||
}
|
||||
|
||||
|
@ -166,6 +167,10 @@ input[type=date] {
|
|||
width: 190px;
|
||||
}
|
||||
|
||||
input[type=color] {
|
||||
height: 60px;
|
||||
}
|
||||
|
||||
.toggle-switch {
|
||||
user-select: none;
|
||||
display: inline-grid;
|
||||
|
|
|
@ -134,9 +134,11 @@
|
|||
<label class="setting-list-label">{{ trans('settings.app_primary_color') }}</label>
|
||||
<p class="small">{!! trans('settings.app_primary_color_desc') !!}</p>
|
||||
</div>
|
||||
<div>
|
||||
<input type="text" value="{{ setting('app-color') }}" name="setting-app-color" id="setting-app-color" placeholder="#0288D1">
|
||||
<div setting-app-color-picker class="text-m-right">
|
||||
<input type="color" value="{{ setting('app-color') }}" name="setting-app-color" id="setting-app-color" placeholder="#0288D1">
|
||||
<input type="hidden" value="{{ setting('app-color-light') }}" name="setting-app-color-light" id="setting-app-color-light">
|
||||
<br>
|
||||
<button type="button" class="text-button text-muted mt-s mx-s" setting-app-color-picker-reset>{{ trans('common.reset') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -242,33 +244,4 @@
|
|||
|
||||
@include('components.image-manager', ['imageType' => 'system'])
|
||||
@include('components.entity-selector-popup', ['entityTypes' => 'page'])
|
||||
@stop
|
||||
|
||||
@section('scripts')
|
||||
<script src="{{ baseUrl("/libs/jq-color-picker/tiny-color-picker.min.js?version=1.0.0") }}"></script>
|
||||
<script type="text/javascript">
|
||||
$('#setting-app-color').colorPicker({
|
||||
opacity: false,
|
||||
renderCallback: function($elm, toggled) {
|
||||
const hexVal = '#' + this.color.colors.HEX;
|
||||
const rgb = this.color.colors.RND.rgb;
|
||||
const rgbLightVal = 'rgba('+ [rgb.r, rgb.g, rgb.b, '0.15'].join(',') +')';
|
||||
|
||||
// Set textbox color to hex color code.
|
||||
const isEmpty = $.trim($elm.val()).length === 0;
|
||||
if (!isEmpty) $elm.val(hexVal);
|
||||
$('#setting-app-color-light').val(isEmpty ? '' : rgbLightVal);
|
||||
|
||||
const customStyles = document.getElementById('custom-styles');
|
||||
const oldColor = customStyles.getAttribute('data-color');
|
||||
const oldColorLight = customStyles.getAttribute('data-color-light');
|
||||
|
||||
customStyles.innerHTML = customStyles.innerHTML.split(oldColor).join(hexVal);
|
||||
customStyles.innerHTML = customStyles.innerHTML.split(oldColorLight).join(rgbLightVal);
|
||||
|
||||
customStyles.setAttribute('data-color', hexVal);
|
||||
customStyles.setAttribute('data-color-light', rgbLightVal);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@stop
|
Loading…
Reference in a new issue