[MIG] web_editor_background_color: Migrate to v11

- Better JS framework usage.
- Split readme.
- Update bootstrap-colorpicker lib.
- Remove image, serve it from GitHub CDN.
pull/1725/head
Jairo Llopis 2018-10-11 12:53:45 +01:00 committed by Carlos Roca
parent f248ca6ecb
commit 1f0b03532d
20 changed files with 865 additions and 390 deletions

View File

@ -1,17 +1,41 @@
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
==================================
Web Editor Background Color Picker
==================================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
:target: https://github.com/OCA/web/tree/11.0/web_editor_background_color
:alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-11-0/web-11-0-web_editor_background_color
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/162/11.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
This module extends the functionality of the web editor to support
setting a custom background color to any snippet allowing you to customize it.
.. figure:: /web_editor_background_color/static/description/mass_mailing_editor.png
.. figure:: https://user-images.githubusercontent.com/973709/46802401-1c915180-cd55-11e8-9397-f198548a690c.gif
:alt: Screenshot of color picker in mass mailing editor
**Table of contents**
.. contents::
:local:
Usage
=====
@ -26,44 +50,49 @@ To use this module, you need to:
* Writing any valid HTML color code in the text input.
* Selecting a color from the color picker.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/162/10.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/web/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_editor_background_color%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
External libraries
------------------
Authors
~~~~~~~
* Tecnativa
Contributors
~~~~~~~~~~~~
* Jairo Llopis <jairo.llopis@tecnativa.com> - https://www.tecnativa.com
Other credits
~~~~~~~~~~~~~
* This addon includes code copied from bootstrap-colorpicker_
.. _bootstrap-colorpicker: https://github.com/itsjavi/bootstrap-colorpicker/tree/2.5.1
.. _bootstrap-colorpicker: https://github.com/itsjavi/bootstrap-colorpicker/tree/2.5.3
Contributors
------------
Maintainers
~~~~~~~~~~~
* Jairo Llopis <jairo.llopis@tecnativa.com>
Maintainer
----------
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.
This module is part of the `OCA/web <https://github.com/OCA/web/tree/11.0/web_editor_background_color>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Jairo Llopis <jairo.llopis@tecnativa.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
{
"name": "Web Editor Background Color Picker",
"summary": "Set any background color for web editor snippets",
"version": "10.0.1.0.0",
"version": "11.0.1.0.0",
"category": "Website",
"website": "https://www.tecnativa.com",
"author": "Tecnativa, Odoo Community Association (OCA)",

View File

@ -3,7 +3,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"

View File

@ -0,0 +1 @@
* Jairo Llopis <jairo.llopis@tecnativa.com> - https://www.tecnativa.com

View File

@ -0,0 +1,3 @@
* This addon includes code copied from bootstrap-colorpicker_
.. _bootstrap-colorpicker: https://github.com/itsjavi/bootstrap-colorpicker/tree/2.5.3

View File

@ -0,0 +1,5 @@
This module extends the functionality of the web editor to support
setting a custom background color to any snippet allowing you to customize it.
.. figure:: https://user-images.githubusercontent.com/973709/46802401-1c915180-cd55-11e8-9397-f198548a690c.gif
:alt: Screenshot of color picker in mass mailing editor

View File

@ -0,0 +1,10 @@
To use this module, you need to:
#. Install any module that makes use of the web editor, such as
``mass_mailing`` or ``website``.
#. Use that module's facilities to edit some web content.
#. Drag & drop any snippet into the web editor body.
#. Click on *Customize > Text-Image > Background Color > </> icon*.
#. Choose a custom color by either:
* Writing any valid HTML color code in the text input.
* Selecting a color from the color picker.

View File

@ -0,0 +1,445 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.14: http://docutils.sourceforge.net/" />
<title>Web Editor Background Color Picker</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="web-editor-background-color-picker">
<h1 class="title">Web Editor Background Color Picker</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/11.0/web_editor_background_color"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-11-0/web-11-0-web_editor_background_color"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/11.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module extends the functionality of the web editor to support
setting a custom background color to any snippet allowing you to customize it.</p>
<div class="figure">
<img alt="Screenshot of color picker in mass mailing editor" src="https://user-images.githubusercontent.com/973709/46802401-1c915180-cd55-11e8-9397-f198548a690c.gif" />
</div>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
<li><a class="reference internal" href="#other-credits" id="id6">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<p>To use this module, you need to:</p>
<ol class="arabic simple">
<li>Install any module that makes use of the web editor, such as
<tt class="docutils literal">mass_mailing</tt> or <tt class="docutils literal">website</tt>.</li>
<li>Use that modules facilities to edit some web content.</li>
<li>Drag &amp; drop any snippet into the web editor body.</li>
<li>Click on <em>Customize &gt; Text-Image &gt; Background Color &gt; &lt;/&gt; icon</em>.</li>
<li>Choose a custom color by either:
* Writing any valid HTML color code in the text input.
* Selecting a color from the color picker.</li>
</ol>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_editor_background_color%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
<ul class="simple">
<li>Tecnativa</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<ul class="simple">
<li>Jairo Llopis &lt;<a class="reference external" href="mailto:jairo.llopis&#64;tecnativa.com">jairo.llopis&#64;tecnativa.com</a>&gt; - <a class="reference external" href="https://www.tecnativa.com">https://www.tecnativa.com</a></li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#id6">Other credits</a></h2>
<ul class="simple">
<li>This addon includes code copied from <a class="reference external" href="https://github.com/itsjavi/bootstrap-colorpicker/tree/2.5.3">bootstrap-colorpicker</a></li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/11.0/web_editor_background_color">OCA/web</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
</div>
</body>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

View File

@ -1,8 +1,6 @@
/* Copyright 2017 Jairo Llopis <jairo.llopis@tecnativa.com>
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
@colorpicker-img-path: "./";
.colorpicker-element {
@colorpicker-width: 170px;
@colorpicker-height: 118px;

View File

@ -3,23 +3,31 @@
odoo.define("web_editor_background_color.colorpicker", function (require) {
"use strict";
var ajax = require("web.ajax");
var core = require("web.core");
var options = require("web_editor.snippets.options");
var colorpicker = options.registry.colorpicker;
ajax.loadXML(
"/web_editor_background_color/static/src/xml/colorpicker.xml",
core.qweb
);
return options.registry.colorpicker.include({
bind_events: function () {
this._super();
colorpicker.include({
events: _.extend({}, colorpicker.prototype.events, {
"changeColor [data-name=custom_color]":
"set_inline_background_color",
// Remove inline background-color for normal class-based buttons
this.$el.find(".o_colorpicker_section button[data-color]").on(
"click",
$.proxy(this.remove_inline_background_color, this)
);
"click .o_colorpicker_section button[data-color]":
"remove_inline_background_color",
"click [data-name=custom_color] input": "input_select",
"click [data-name=custom_color]": "custom_abort_event",
"keydown [data-name=custom_color]": "custom_abort_event",
"keypress [data-name=custom_color]": "custom_abort_event",
"keyup [data-name=custom_color]": "custom_abort_event",
}),
xmlDependencies: colorpicker.prototype.xmlDependencies.concat([
"/web_editor_background_color/static/src/xml/colorpicker.xml",
]),
/**
* @override
*/
start: function () {
this._super();
// Enable custom color picker
this.$custom = this.$el.find('[data-name="custom_color"]');
this.$custom.colorpicker({
@ -39,38 +47,50 @@ odoo.define("web_editor_background_color.colorpicker", function (require) {
},
},
});
this.$custom.on(
"changeColor",
$.proxy(this.set_inline_background_color, this));
this.$custom.on(
"click keypress keyup keydown",
$.proxy(this.custom_abort_event, this));
this.$custom.on(
"click", "input",
$.proxy(this.input_select, this));
this.$el.find(".note-color-reset").on(
"click",
$.proxy(this.remove_inline_background_color, this));
// Activate border color changes if it matches background's
var style = this.$target.prop("style");
this.change_border =
style["border-color"] &&
style["background-color"] === style["border-color"];
},
/**
* A HACK to avoid dropdown disappearing when picking colors
*
* @param {Event} event
*/
custom_abort_event: function (event) {
// HACK Avoid dropdown disappearing when picking colors
event.stopPropagation();
},
/**
* Select the color picker input
*
* @param {Event} event
*/
input_select: function (event) {
$(event.target).focus().select();
},
remove_inline_background_color: function (event) {
/**
* Undo the inline background color, besides upstream color classes
*
* @override
*/
_onColorResetButtonClick: function (event) {
this._super.apply(this, arguments);
this.$target.css("background-color", "");
if (this.change_border) {
this.$target.css("border-color", "");
}
this.$target.trigger("background-color-event", event.type);
},
/**
* Apply the chosen color as an inline style
*
* @param {Event} event
*/
set_inline_background_color: function (event) {
var color = String(event.color);
this.$target.css("background-color", color);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 557 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 488 B

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
/*!
* Bootstrap Colorpicker v2.5.1
* Bootstrap Colorpicker v2.5.2
* https://itsjavi.com/bootstrap-colorpicker/
*
* Originally written by (c) 2012 Stefan Petre
@ -38,14 +38,9 @@
val, predefinedColors, fallbackColor, fallbackFormat, hexNumberSignPrefix) {
this.fallbackValue = fallbackColor ?
(
fallbackColor && (typeof fallbackColor.h !== 'undefined') ?
fallbackColor :
this.value = {
h: 0,
s: 0,
b: 0,
a: 1
}
(typeof fallbackColor === 'string') ?
this.parse(fallbackColor) :
fallbackColor
) :
null;
@ -345,21 +340,26 @@
a: a
};
},
toHex: function(h, s, b, a) {
if (arguments.length === 0) {
toHex: function(ignoreFormat, h, s, b, a) {
if (arguments.length <= 1) {
h = this.value.h;
s = this.value.s;
b = this.value.b;
a = this.value.a;
}
var prefix = '#';
var rgb = this.toRGB(h, s, b, a);
if (this.rgbaIsTransparent(rgb)) {
return 'transparent';
}
var hexStr = (this.hexNumberSignPrefix ? '#' : '') + (
if (!ignoreFormat) {
prefix = (this.hexNumberSignPrefix ? '#' : '');
}
var hexStr = prefix + (
(1 << 24) +
(parseInt(rgb.r) << 16) +
(parseInt(rgb.g) << 8) +
@ -397,10 +397,10 @@
};
},
toAlias: function(r, g, b, a) {
var c, rgb = (arguments.length === 0) ? this.toHex() : this.toHex(r, g, b, a);
var c, rgb = (arguments.length === 0) ? this.toHex(true) : this.toHex(true, r, g, b, a);
// support predef. colors in non-hex format too, as defined in the alias itself
var original = this.origFormat === 'alias' ? rgb : this.toString(this.origFormat, false);
var original = this.origFormat === 'alias' ? rgb : this.toString(false, this.origFormat);
for (var alias in this.colors) {
c = this.colors[alias].toLowerCase().trim();
@ -475,6 +475,9 @@
* @returns {Object} Object containing h,s,b,a,format properties or FALSE if failed to parse
*/
parse: function(strVal) {
if (typeof strVal !== 'string') {
return this.fallbackValue;
}
if (arguments.length === 0) {
return false;
}
@ -525,9 +528,10 @@
*
* @param {string} [format] (default: rgba)
* @param {boolean} [translateAlias] Return real color for pre-defined (non-standard) aliases (default: false)
* @param {boolean} [forceRawValue] Forces hashtag prefix when getting hex color (default: false)
* @returns {String}
*/
toString: function(format, translateAlias) {
toString: function(forceRawValue, format, translateAlias) {
format = format || this.origFormat || this.fallbackFormat;
translateAlias = translateAlias || false;
@ -563,7 +567,7 @@
break;
case 'hex':
{
return this.toHex();
return this.toHex(forceRawValue);
}
break;
case 'alias':
@ -571,7 +575,7 @@
c = this.toAlias();
if (c === false) {
return this.toString(this.getValidFallbackFormat());
return this.toString(forceRawValue, this.getValidFallbackFormat());
}
if (translateAlias && !(c in Color.webColors) && (c in this.predefinedColors)) {
@ -787,6 +791,8 @@
this.updateData(this.color);
}
this.disabled = false;
// Setup picker
var $picker = this.picker = $(this.options.template);
if (this.options.customClass) {
@ -855,7 +861,7 @@
'keyup.colorpicker': $.proxy(this.keyup, this)
});
this.input.on({
'change.colorpicker': $.proxy(this.change, this)
'input.colorpicker': $.proxy(this.change, this)
});
if (this.component === false) {
this.element.on({
@ -975,12 +981,12 @@
});
},
updateData: function(val) {
val = val || this.color.toString(this.format, false);
val = val || this.color.toString(false, this.format);
this.element.data('color', val);
return val;
},
updateInput: function(val) {
val = val || this.color.toString(this.format, false);
val = val || this.color.toString(false, this.format);
if (this.input !== false) {
this.input.prop('value', val);
this.input.trigger('change');
@ -1011,13 +1017,13 @@
});
this.picker.find('.colorpicker-saturation')
.css('backgroundColor', (this.options.hexNumberSignPrefix ? '' : '#') + this.color.toHex(this.color.value.h, 1, 1, 1));
.css('backgroundColor', this.color.toHex(true, this.color.value.h, 1, 1, 1));
this.picker.find('.colorpicker-alpha')
.css('backgroundColor', (this.options.hexNumberSignPrefix ? '' : '#') + this.color.toHex());
.css('backgroundColor', this.color.toHex(true));
this.picker.find('.colorpicker-color, .colorpicker-color div')
.css('backgroundColor', this.color.toString(this.format, true));
.css('backgroundColor', this.color.toString(true, this.format));
return val;
},
@ -1034,16 +1040,16 @@
var icn = this.component.find('i').eq(0);
if (icn.length > 0) {
icn.css({
'backgroundColor': color.toString(this.format, true)
'backgroundColor': color.toString(true, this.format)
});
} else {
this.component.css({
'backgroundColor': color.toString(this.format, true)
'backgroundColor': color.toString(true, this.format)
});
}
}
return color.toString(this.format, false);
return color.toString(false, this.format);
},
update: function(force) {
var val;
@ -1099,34 +1105,31 @@
return (this.input !== false);
},
isDisabled: function() {
if (this.hasInput()) {
return (this.input.prop('disabled') === true);
}
return false;
return this.disabled;
},
disable: function() {
if (this.hasInput()) {
this.input.prop('disabled', true);
this.element.trigger({
type: 'disable',
color: this.color,
value: this.getValue()
});
return true;
}
return false;
this.disabled = true;
this.element.trigger({
type: 'disable',
color: this.color,
value: this.getValue()
});
return true;
},
enable: function() {
if (this.hasInput()) {
this.input.prop('disabled', false);
this.element.trigger({
type: 'enable',
color: this.color,
value: this.getValue()
});
return true;
}
return false;
this.disabled = false;
this.element.trigger({
type: 'enable',
color: this.color,
value: this.getValue()
});
return true;
},
currentSlider: null,
mousePointer: {
@ -1245,7 +1248,24 @@
return false;
},
change: function(e) {
this.keyup(e);
this.color = this.createColor(this.input.val());
// Change format dynamically
// Only occurs if user choose the dynamic format by
// setting option format to false
if (this.color.origFormat && this.options.format === false) {
this.format = this.color.origFormat;
}
if (this.getValue(false) !== false) {
this.updateData();
this.updateComponent();
this.updatePicker();
}
this.element.trigger({
type: 'changeColor',
color: this.color,
value: this.input.val()
});
},
keyup: function(e) {
if ((e.keyCode === 38)) {
@ -1258,20 +1278,8 @@
this.color.value.a = Math.round((this.color.value.a - 0.01) * 100) / 100;
}
this.update(true);
} else {
this.color = this.createColor(this.input.val());
// Change format dynamically
// Only occurs if user choose the dynamic format by
// setting option format to false
if (this.color.origFormat && this.options.format === false) {
this.format = this.color.origFormat;
}
if (this.getValue(false) !== false) {
this.updateData();
this.updateComponent();
this.updatePicker();
}
}
this.element.trigger({
type: 'changeColor',
color: this.color,

View File

@ -1,273 +0,0 @@
/*!
* Bootstrap Colorpicker v2.5.1
* https://itsjavi.com/bootstrap-colorpicker/
*
* Originally written by (c) 2012 Stefan Petre
* Licensed under the Apache License v2.0
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
*/
@colorpicker-img-path: "../img/bootstrap-colorpicker/";
.bgImg(@imgFilename) {
background-image: url("@{colorpicker-img-path}@{imgFilename}");
}
.borderRadius(@size) {
-webkit-border-radius: @size;
-moz-border-radius: @size;
border-radius: @size;
}
.colorpicker-saturation {
width: 100px;
height: 100px;
.bgImg('saturation.png');
cursor: crosshair;
float: left;
i {
display: block;
height: 5px;
width: 5px;
border: 1px solid #000;
.borderRadius(5px);
position: absolute;
top: 0;
left: 0;
margin: -4px 0 0 -4px;
b {
display: block;
height: 5px;
width: 5px;
border: 1px solid #fff;
.borderRadius(5px);
}
}
}
.colorpicker-hue,
.colorpicker-alpha {
width: 15px;
height: 100px;
float: left;
cursor: row-resize;
margin-left: 4px;
margin-bottom: 4px;
}
.colorpicker-hue i,
.colorpicker-alpha i {
display: block;
height: 1px;
background: #000;
border-top: 1px solid #fff;
position: absolute;
top: 0;
left: 0;
width: 100%;
margin-top: -1px;
}
.colorpicker-hue {
.bgImg('hue.png');
}
.colorpicker-alpha {
.bgImg('alpha.png');
display: none;
}
.colorpicker-saturation,
.colorpicker-hue,
.colorpicker-alpha {
background-size: contain;
}
.colorpicker {
padding: 4px;
min-width: 130px;
margin-top: 1px;
.borderRadius(4px);
z-index: 2500;
}
.colorpicker:before,
.colorpicker:after {
display: table;
content: "";
line-height: 0;
}
.colorpicker:after {
clear: both;
}
.colorpicker:before {
content: '';
display: inline-block;
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-bottom: 7px solid #ccc;
border-bottom-color: rgba(0, 0, 0, 0.2);
position: absolute;
top: -7px;
left: 6px;
}
.colorpicker:after {
content: '';
display: inline-block;
border-left: 6px solid transparent;
border-right: 6px solid transparent;
border-bottom: 6px solid #ffffff;
position: absolute;
top: -6px;
left: 7px;
}
.colorpicker div {
position: relative;
}
.colorpicker.colorpicker-with-alpha {
min-width: 140px;
}
.colorpicker.colorpicker-with-alpha .colorpicker-alpha {
display: block;
}
.colorpicker-color {
height: 10px;
margin-top: 5px;
clear: both;
.bgImg('alpha.png');
background-position: 0 100%;
}
.colorpicker-color div {
height: 10px;
}
.colorpicker-selectors {
display: none;
height: 10px;
margin-top: 5px;
clear: both;
}
.colorpicker-selectors i {
cursor: pointer;
float: left;
height: 10px;
width: 10px;
}
.colorpicker-selectors i + i {
margin-left: 3px;
}
.colorpicker-element .input-group-addon i,
.colorpicker-element .add-on i {
display: inline-block;
cursor: pointer;
height: 16px;
vertical-align: text-top;
width: 16px;
}
.colorpicker.colorpicker-inline {
position: relative;
display: inline-block;
float: none;
z-index: auto;
}
.colorpicker.colorpicker-horizontal {
width: 110px;
min-width: 110px;
height: auto;
}
.colorpicker.colorpicker-horizontal .colorpicker-saturation {
margin-bottom: 4px;
}
.colorpicker.colorpicker-horizontal .colorpicker-color {
width: 100px;
}
.colorpicker.colorpicker-horizontal .colorpicker-hue,
.colorpicker.colorpicker-horizontal .colorpicker-alpha {
width: 100px;
height: 15px;
float: left;
cursor: col-resize;
margin-left: 0px;
margin-bottom: 4px;
}
.colorpicker.colorpicker-horizontal .colorpicker-hue i,
.colorpicker.colorpicker-horizontal .colorpicker-alpha i {
display: block;
height: 15px;
background: #ffffff;
position: absolute;
top: 0;
left: 0;
width: 1px;
border: none;
margin-top: 0px;
}
.colorpicker.colorpicker-horizontal .colorpicker-hue {
.bgImg('hue-horizontal.png');
}
.colorpicker.colorpicker-horizontal .colorpicker-alpha {
.bgImg('alpha-horizontal.png');
}
.colorpicker-right:before {
left: auto;
right: 6px;
}
.colorpicker-right:after {
left: auto;
right: 7px;
}
.colorpicker-no-arrow:before {
border-right: 0;
border-left: 0;
}
.colorpicker-no-arrow:after {
border-right: 0;
border-left: 0;
}
.colorpicker,
.colorpicker-alpha,
.colorpicker-saturation,
.colorpicker-hue,
.colorpicker-selectors {
&.colorpicker-visible {
display: block;
}
}
.colorpicker,
.colorpicker-alpha,
.colorpicker-saturation,
.colorpicker-hue,
.colorpicker-selectors {
&.colorpicker-hidden {
display: none;
}
}
.colorpicker-inline.colorpicker-visible {
display: inline-block;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 478 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 504 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -7,7 +7,7 @@
<template id="assets_editor" inherit_id="web_editor.assets_editor">
<xpath expr=".">
<!-- External library bootstrap-colorpicker -->
<link rel="stylesheet" href="/web_editor_background_color/static/src/lib/bootstrap-colorpicker/colorpicker.less"/>
<link rel="stylesheet" href="/web_editor_background_color/static/src/lib/bootstrap-colorpicker/bootstrap-colorpicker.css"/>
<script type="text/javascript" src="/web_editor_background_color/static/src/lib/bootstrap-colorpicker/bootstrap-colorpicker.js"/>
<!-- Internal assets -->
<link rel="stylesheet" href="/web_editor_background_color/static/src/css/background_color.less"/>