Commit 1ea7b90a authored by alexpott's avatar alexpott
Browse files

Issue #2470069 by wadmiraal, Manjit.Singh, pjbaert, zakxxi, LewisNyman:...

Issue #2470069 by wadmiraal, Manjit.Singh, pjbaert, zakxxi, LewisNyman: Refactor color module CSS inline with our CSS standards
parent 9166525d
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
var focused = null; var focused = null;
// Add Farbtastic. // Add Farbtastic.
$('<div id="placeholder"></div>').once('color').prependTo(form); $('<div class="color-placeholder"></div>').once('color').prependTo(form);
var farb = $.farbtastic('#placeholder'); var farb = $.farbtastic('.color-placeholder');
// Decode reference colors to HSL. // Decode reference colors to HSL.
var reference = settings.color.reference; var reference = settings.color.reference;
...@@ -41,8 +41,8 @@ ...@@ -41,8 +41,8 @@
for (i in settings.gradients) { for (i in settings.gradients) {
if (settings.gradients.hasOwnProperty(i)) { if (settings.gradients.hasOwnProperty(i)) {
// Add element to display the gradient. // Add element to display the gradient.
$('#preview').once('color').append('<div id="gradient-' + i + '"></div>'); $('.color-preview').once('color').append('<div id="gradient-' + i + '"></div>');
var gradient = $('#preview #gradient-' + i); var gradient = $('.color-preview #gradient-' + i);
// Add height of current gradient to the list (divided by 10). // Add height of current gradient to the list (divided by 10).
height.push(parseInt(gradient.css('height'), 10) / 10); height.push(parseInt(gradient.css('height'), 10) / 10);
// Add width of current gradient to the list (divided by 10). // Add width of current gradient to the list (divided by 10).
...@@ -146,14 +146,14 @@ ...@@ -146,14 +146,14 @@
if (propagate) { if (propagate) {
i = input.i; i = input.i;
for (j = i + 1; ; ++j) { for (j = i + 1; ; ++j) {
if (!locks[j - 1] || $(locks[j - 1]).is('.unlocked')) { if (!locks[j - 1] || $(locks[j - 1]).is('.is-unlocked')) {
break; break;
} }
matched = shift_color(color, reference[input.key], reference[inputs[j].key]); matched = shift_color(color, reference[input.key], reference[inputs[j].key]);
callback(inputs[j], matched, false); callback(inputs[j], matched, false);
} }
for (j = i - 1; ; --j) { for (j = i - 1; ; --j) {
if (!locks[j] || $(locks[j]).is('.unlocked')) { if (!locks[j] || $(locks[j]).is('.is-unlocked')) {
break; break;
} }
matched = shift_color(color, reference[input.key], reference[inputs[j].key]); matched = shift_color(color, reference[input.key], reference[inputs[j].key]);
...@@ -201,7 +201,7 @@ ...@@ -201,7 +201,7 @@
} }
// Initialize color fields. // Initialize color fields.
form.find('#palette input.form-text') form.find('.js-color-palette input.form-text')
.each(function () { .each(function () {
// Extract palette field name // Extract palette field name
this.key = this.id.substring(13); this.key = this.id.substring(13);
...@@ -213,24 +213,24 @@ ...@@ -213,24 +213,24 @@
i = inputs.length; i = inputs.length;
if (inputs.length) { if (inputs.length) {
var toggleClick = true; var toggleClick = true;
var lock = $('<button class="lock link">' + Drupal.t('Unlock') + '</button>').on('click', function (e) { var lock = $('<button class="color-palette__lock link">' + Drupal.t('Unlock') + '</button>').on('click', function (e) {
e.preventDefault(); e.preventDefault();
if (toggleClick) { if (toggleClick) {
$(this).addClass('unlocked').html(Drupal.t('Lock')); $(this).addClass('is-unlocked').html(Drupal.t('Lock'));
$(hooks[i - 1]).attr('class', $(hooks[i - 1]).attr('class',
locks[i - 2] && $(locks[i - 2]).is(':not(.unlocked)') ? 'hook up' : 'hook' locks[i - 2] && $(locks[i - 2]).is(':not(.is-unlocked)') ? 'color-palette__hook is-up' : 'color-palette__hook'
); );
$(hooks[i]).attr('class', $(hooks[i]).attr('class',
locks[i] && $(locks[i]).is(':not(.unlocked)') ? 'hook down' : 'hook' locks[i] && $(locks[i]).is(':not(.is-unlocked)') ? 'color-palette__hook is-down' : 'color-palette__hook'
); );
} }
else { else {
$(this).removeClass('unlocked').html(Drupal.t('Unlock')); $(this).removeClass('is-unlocked').html(Drupal.t('Unlock'));
$(hooks[i - 1]).attr('class', $(hooks[i - 1]).attr('class',
locks[i - 2] && $(locks[i - 2]).is(':not(.unlocked)') ? 'hook both' : 'hook down' locks[i - 2] && $(locks[i - 2]).is(':not(.is-unlocked)') ? 'color-palette__hook is-both' : 'color-palette__hook is-down'
); );
$(hooks[i]).attr('class', $(hooks[i]).attr('class',
locks[i] && $(locks[i]).is(':not(.unlocked)') ? 'hook both' : 'hook up' locks[i] && $(locks[i]).is(':not(.is-unlocked)') ? 'color-palette__hook is-both' : 'color-palette__hook is-up'
); );
} }
toggleClick = !toggleClick; toggleClick = !toggleClick;
...@@ -240,17 +240,17 @@ ...@@ -240,17 +240,17 @@
} }
// Add hook. // Add hook.
var hook = $('<div class="hook"></div>'); var hook = $('<div class="color-palette__hook"></div>');
$(this).after(hook); $(this).after(hook);
hooks.push(hook); hooks.push(hook);
$(this).parent().find('.lock').trigger('click'); $(this).parent().find('.color-palette__lock').trigger('click');
this.i = i; this.i = i;
inputs.push(this); inputs.push(this);
}) })
.on('focus', focus); .on('focus', focus);
form.find('#palette label'); form.find('.js-color-palette label');
// Focus first color. // Focus first color.
inputs[0].focus(); inputs[0].focus();
......
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
margin: 0 auto; margin: 0 auto;
} }
.color-form .form-item { .color-form .form-item {
overflow: hidden;
margin: 0.5em 0; margin: 0.5em 0;
height: 2em;
padding: 0.5em;
} }
.color-form label { .color-form label {
clear: left; /* LTR */ clear: left; /* LTR */
...@@ -27,57 +28,68 @@ ...@@ -27,57 +28,68 @@
[dir="rtl"] .color-form .form-text { [dir="rtl"] .color-form .form-text {
float: right; float: right;
} }
#palette .hook { .color-palette__hook {
float: left; /* LTR */ float: left; /* LTR */
width: 16px; width: 16px;
height: 16px; height: 16px;
} }
[dir="rtl"] #palette .hook { [dir="rtl"] .color-palette__hook {
float: right; float: right;
} }
#palette .down, .color-palette__hook.is-down,
#palette .up, .color-palette__hook.is-up,
#palette .both { .color-palette__hook.is-both {
background: url(../images/hook.png) no-repeat 100% 0; /* LTR */ background: url(../images/hook.png) no-repeat 100% 0; /* LTR */
} }
[dir="rtl"] #palette .down, [dir="rtl"] .color-palette__hook.is-down,
[dir="rtl"] #palette .up, [dir="rtl"] .color-palette__hook.is-up,
[dir="rtl"] #palette .both { [dir="rtl"] .color-palette__hook.is-both {
background: url(../images/hook-rtl.png) no-repeat 0 0; background: url(../images/hook-rtl.png) no-repeat 0 0;
} }
#palette .up { .color-palette__hook.is-up {
background-position: 100% -27px; /* LTR */ background-position: 100% -27px; /* LTR */
} }
[dir="rtl"] #palette .up { [dir="rtl"] .color-palette__hook.is-up {
background-position: 0 -27px; background-position: 0 -27px;
} }
#palette .both { .color-palette__hook.is-both {
background-position: 100% -54px; /* LTR */ background-position: 100% -54px; /* LTR */
} }
[dir="rtl"] #palette .both { [dir="rtl"] .color-palette__hook.is-both {
background-position: 0 -54px; background-position: 0 -54px;
} }
#palette .lock { /**
* The button also inherits from .link, which hides the background. Use a more
* specific selector to overwrite.
*/
button.color-palette__lock,
.color-palette__lock {
float: left; /* LTR */ float: left; /* LTR */
width: 20px; width: 20px;
height: 19px; height: 19px;
background: url(../images/lock.png) no-repeat 50% 0; background: url(../images/lock.png) no-repeat 50% 0;
cursor: pointer; cursor: pointer;
position: relative;
top: -1.7em;
left: -10px;
direction: ltr;
text-indent: -9999px; text-indent: -9999px;
} }
[dir="rtl"] #palette .lock { [dir="rtl"] .color-palette__lock {
float: right; float: right;
} }
#palette .unlocked { /* Same as above .color-palette__lock rule. */
button.is-unlocked,
.is-unlocked {
background-position: 50% -22px; background-position: 50% -22px;
} }
/* wide viewport. */ /* wide viewport. */
@media screen and (min-width: 37.5625em) { /* 601px */ @media screen and (min-width: 37.5625em) { /* 601px */
#placeholder { .color-placeholder {
float: right; /* LTR */ float: right; /* LTR */
} }
[dir="rtl"] #placeholder { [dir="rtl"] .color-placeholder {
float: left; float: left;
} }
.color-form .form-item { .color-form .form-item {
...@@ -104,17 +116,18 @@ ...@@ -104,17 +116,18 @@
[dir="rtl"] .color-form .form-select { [dir="rtl"] .color-form .form-select {
float: right; float: right;
} }
#palette .hook { .color-palette__hook {
float: left; /* LTR */ float: left; /* LTR */
margin-top: 3px; margin-top: 3px;
} }
[dir="rtl"] #palette .hook { [dir="rtl"] .color-palette__hook {
float: right; float: right;
} }
#palette .lock { button.color-palette__lock,
.color-palette__lock {
float: left; /* LTR */ float: left; /* LTR */
} }
[dir="rtl"] #palette .lock { [dir="rtl"] .color-palette__lock {
float: right; float: right;
} }
} }
...@@ -123,20 +136,20 @@ ...@@ -123,20 +136,20 @@
} }
/* Preview */ /* Preview */
#preview { .color-preview {
display: none; display: none;
} }
.js #preview { .js .color-preview {
display: block; display: block;
position: relative; position: relative;
float: left; /* LTR */ float: left; /* LTR */
} }
.js[dir="rtl"] #preview { .js[dir="rtl"] .color-preview {
float: right; float: right;
} }
@media screen and (max-width: 30em) { /* 480px */ @media screen and (max-width: 30em) { /* 480px */
.color-form #preview-sidebar, .color-form .color-preview-sidebar,
.color-form #preview-content { .color-form .color-preview-content {
width: auto; width: auto;
margin: 0; margin: 0;
} }
......
<div id="preview"> <div class="color-preview">
<div id="text"> <div id="text">
<h2>Lorem ipsum dolor</h2> <h2>Lorem ipsum dolor</h2>
<p>Sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud <a href="#">exercitation ullamco</a> laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> <p>Sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud <a href="#">exercitation ullamco</a> laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div> </div>
<div id="img"></div> <div id="img"></div>
</div> </div>
\ No newline at end of file
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
var accum; var accum;
var delta; var delta;
// Solid background. // Solid background.
form.find('#preview').css('backgroundColor', form.find('#palette input[name="palette[base]"]').val()); form.find('.color-preview').css('backgroundColor', form.find('.color-palette input[name="palette[base]"]').val());
// Text preview // Text preview
form.find('#text').css('color', form.find('#palette input[name="palette[text]"]').val()); form.find('#text').css('color', form.find('.color-palette input[name="palette[text]"]').val());
form.find('#text a, #text h2').css('color', form.find('#palette input[name="palette[link]"]').val()); form.find('#text a, #text h2').css('color', form.find('.color-palette input[name="palette[link]"]').val());
function gradientLineColor(i, element) { function gradientLineColor(i, element) {
for (var k in accum) { for (var k in accum) {
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
var color_end; var color_end;
for (var i in settings.gradients) { for (var i in settings.gradients) {
if (settings.gradients.hasOwnProperty(i)) { if (settings.gradients.hasOwnProperty(i)) {
color_start = farb.unpack(form.find('#palette input[name="palette[' + settings.gradients[i].colors[0] + ']"]').val()); color_start = farb.unpack(form.find('.color-palette input[name="palette[' + settings.gradients[i].colors[0] + ']"]').val());
color_end = farb.unpack(form.find('#palette input[name="palette[' + settings.gradients[i].colors[1] + ']"]').val()); color_end = farb.unpack(form.find('.color-palette input[name="palette[' + settings.gradients[i].colors[1] + ']"]').val());
if (color_start && color_end) { if (color_start && color_end) {
delta = []; delta = [];
for (var j in color_start) { for (var j in color_start) {
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#} #}
<div class="color-form clearfix"> <div class="color-form clearfix">
{{ form.scheme }} {{ form.scheme }}
<div id="palette" class="clearfix"> <div class="clearfix color-palette js-color-palette">
{{ form.palette }} {{ form.palette }}
</div> </div>
{{ form|without('scheme', 'palette') }} {{ form|without('scheme', 'palette') }}
......
/* ---------- Preview Styles ----------- */ /* ---------- Preview Styles ----------- */
.js #preview { .js .color-preview {
clear: both; clear: both;
float: none !important; float: none !important;
} }
#preview { .color-preview {
background-color: #fff; background-color: #fff;
font-family: Georgia, "Times New Roman", Times, serif; font-family: Georgia, "Times New Roman", Times, serif;
font-size: 14px; font-size: 14px;
...@@ -12,15 +12,15 @@ ...@@ -12,15 +12,15 @@
word-wrap: break-word; word-wrap: break-word;
margin-bottom: 10px; margin-bottom: 10px;
} }
#preview-header { .color-preview-header {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
position: relative; position: relative;
} }
#preview-logo { .color-preview-logo {
float: left; float: left;
padding: 15px; padding: 15px;
} }
#preview-site-name { .color-preview-site-name {
color: #686868; color: #686868;
font-weight: normal; font-weight: normal;
font-size: 1.821em; font-size: 1.821em;
...@@ -29,24 +29,24 @@ ...@@ -29,24 +29,24 @@
margin-left: 15px; /* LTR */ margin-left: 15px; /* LTR */
padding-top: 34px; padding-top: 34px;
} }
[dir="rtl"] #preview-site-name { [dir="rtl"] .color-preview-site-name {
margin-left: 0; margin-left: 0;
margin-right: 15px; margin-right: 15px;
} }
#preview-main-menu { .color-preview-main-menu {
clear: both; clear: both;
padding: 0 15px 3px; padding: 0 15px 3px;
} }
#preview-main-menu-links a { .color-preview-main-menu-links a {
color: #d9d9d9; color: #d9d9d9;
padding: 0.6em 1em 0.4em; padding: 0.6em 1em 0.4em;
} }
#preview-main-menu-links { .color-preview-main-menu-links {
font-size: 0.929em; font-size: 0.929em;
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
#preview-main-menu-links a { .color-preview-main-menu-links a {
color: #333; color: #333;
background: #ccc; background: #ccc;
background: rgba(255, 255, 255, 0.7); background: rgba(255, 255, 255, 0.7);
...@@ -54,54 +54,54 @@ ...@@ -54,54 +54,54 @@
border-top-left-radius: 8px; border-top-left-radius: 8px;
border-top-right-radius: 8px; border-top-right-radius: 8px;
} }
#preview-main-menu-links a:hover, .color-preview-main-menu-links a:hover,
#preview-main-menu-links a:focus { .color-preview-main-menu-links a:focus {
background: #eee; background: #eee;
background: rgba(255, 255, 255, 0.95); background: rgba(255, 255, 255, 0.95);
text-decoration: none; text-decoration: none;
cursor: pointer; cursor: pointer;
} }
#preview-main-menu-links li a.is-active { .color-preview-main-menu-links li a.is-active {
background: #fff; background: #fff;
border-bottom: none; border-bottom: none;
} }
#preview-main-menu-links li { .color-preview-main-menu-links li {
display: inline; display: inline;
list-style-type: none; list-style-type: none;
padding: 0.6em 0 0.4em; padding: 0.6em 0 0.4em;
} }
#preview-sidebar, .color-preview-sidebar,
#preview-content { .color-preview-content {
display: inline; display: inline;
float: left; /* LTR */ float: left; /* LTR */
position: relative; position: relative;
} }
[dir="rtl"] #preview-sidebar, [dir="rtl"] .color-preview-sidebar,
[dir="rtl"] #preview-content { [dir="rtl"] .color-preview-content {
float: right; float: right;
} }
#preview-sidebar { .color-preview-sidebar {
margin-left: 15px; /* LTR */ margin-left: 15px; /* LTR */
width: 210px; width: 210px;
} }
[dir="rtl"] #preview-sidebar { [dir="rtl"] .color-preview-sidebar {
margin-left: 0; margin-left: 0;
margin-right: 15px; margin-right: 15px;
} }
#preview-content { .color-preview-content {
margin-left: 30px; /* LTR */ margin-left: 30px; /* LTR */
width: 26.5em; width: 26.5em;
} }
[dir="rtl"] #preview-content { [dir="rtl"] .color-preview-content {
margin-left: 0; margin-left: 0;
margin-right: 30px; margin-right: 30px;
} }
#preview-sidebar .preview-block { .color-preview-sidebar .preview-block {
border: 1px solid; border: 1px solid;
margin: 20px 0; margin: 20px 0;
padding: 15px 20px; padding: 15px 20px;
} }
#preview-sidebar h2 { .color-preview-sidebar h2 {
border-bottom: 1px solid #d6d6d6; border-bottom: 1px solid #d6d6d6;
font-size: 1.071em; font-size: 1.071em;
font-weight: normal; font-weight: normal;
...@@ -110,62 +110,62 @@ ...@@ -110,62 +110,62 @@
padding-bottom: 5px;