Merge branch 'feature/work-on-toggleables' into develop

This commit is contained in:
Flavio Copes
2015-08-07 19:15:15 +02:00
9 changed files with 186 additions and 36 deletions

View File

@@ -16,6 +16,7 @@ use Grav\Common\Backup\ZipBackup;
use Grav\Common\Markdown\Parsedown; use Grav\Common\Markdown\Parsedown;
use Grav\Common\Markdown\ParsedownExtra; use Grav\Common\Markdown\ParsedownExtra;
use RocketTheme\Toolbox\File\JsonFile; use RocketTheme\Toolbox\File\JsonFile;
use Symfony\Component\Yaml\Yaml;
class AdminController class AdminController
{ {
@@ -1164,12 +1165,27 @@ class AdminController
if (isset($input['header'])) { if (isset($input['header'])) {
$header = $input['header']; $header = $input['header'];
foreach($header as $key => $value) {
if ($key == 'metadata') {
foreach($header['metadata'] as $key2 => $value2) {
if (isset($input['toggleable_header']['metadata'][$key2]) && !$input['toggleable_header']['metadata'][$key2]) {
$header['metadata'][$key2] = '';
}
}
} else {
if (isset($input['toggleable_header'][$key]) && !$input['toggleable_header'][$key]) {
$header[$key] = '';
}
}
}
if ($clean_header) { if ($clean_header) {
$header = Utils::arrayFilterRecursive($header, function($k, $v) { $header = Utils::arrayFilterRecursive($header, function($k, $v) {
return !(is_null($v) || $v === ''); return !(is_null($v) || $v === '');
}); });
} }
$page->header((object) $header); $page->header((object) $header);
$page->frontmatter(Yaml::dump((array) $page->header()));
} }
// Fill content last because it also renders the output. // Fill content last because it also renders the output.
if (isset($input['content'])) { if (isset($input['content'])) {

View File

@@ -445,7 +445,7 @@ hr {
*/ */
.switch-grav { .switch-grav {
background-color: #fff; background-color: #fff;
border: 1px solid #d4d4d4; border: 1px solid #d5d5d5;
border-radius: 4px; border-radius: 4px;
/* Selected ON switch-light /* Selected ON switch-light
*/ } */ }
@@ -574,7 +574,7 @@ form .selectize-control.multi .selectize-input {
border-radius: 2px; border-radius: 2px;
line-height: 1.5; } line-height: 1.5; }
form .selectize-control.multi .selectize-input > div.active { form .selectize-control.multi .selectize-input > div.active {
background: #d4d4d4; } background: #d5d5d5; }
form .selectize-control.single .selectize-input:after { form .selectize-control.single .selectize-input:after {
right: 27px; } right: 27px; }
form .selectize-control.single .selectize-input.dropdown-active:after { form .selectize-control.single .selectize-input.dropdown-active:after {
@@ -593,7 +593,7 @@ form .large {
height: 10rem; } height: 10rem; }
form select { form select {
width: 100%; width: 100%;
border: 1px solid #d4d4d4; border: 1px solid #d5d5d5;
background: #fff; background: #fff;
-webkit-appearance: none; -webkit-appearance: none;
-moz-appearance: none; -moz-appearance: none;
@@ -603,17 +603,17 @@ form select {
margin: 0; } margin: 0; }
form input[type=text], form input[type=password], form input[type=email] { form input[type=text], form input[type=password], form input[type=email] {
width: 100%; width: 100%;
border: 1px solid #d4d4d4; border: 1px solid #d5d5d5;
background: #fff; } background: #fff; }
form input[readonly=readonly] { form input[readonly=readonly] {
background: #f2f2f2; background: #f2f2f2;
font-weight: bold; } font-weight: bold; }
form textarea { form textarea {
width: 100%; width: 100%;
border: 1px solid #d4d4d4; border: 1px solid #d5d5d5;
background: #fff; } background: #fff; }
form .form-frontmatter-wrapper { form .form-frontmatter-wrapper {
border: 1px solid #d4d4d4; border: 1px solid #d5d5d5;
border-radius: 4px; } border-radius: 4px; }
form .switch-toggle.medium { form .switch-toggle.medium {
width: 100%; width: 100%;
@@ -662,7 +662,7 @@ form .checkboxes {
margin-right: 10px; margin-right: 10px;
position: absolute; position: absolute;
background: #fff; background: #fff;
border: 1px solid #d4d4d4; border: 1px solid #d5d5d5;
border-radius: 4px; } border-radius: 4px; }
form .checkboxes input[type=checkbox] { form .checkboxes input[type=checkbox] {
display: none; } display: none; }
@@ -679,7 +679,7 @@ form .checkboxes {
margin-bottom: 3rem; } margin-bottom: 3rem; }
.form-frontmatter-wrapper .dragbar { .form-frontmatter-wrapper .dragbar {
height: 4px; height: 4px;
background: #d4d4d4; background: #d5d5d5;
cursor: row-resize; } cursor: row-resize; }
#frontmatter + .CodeMirror { #frontmatter + .CodeMirror {
@@ -694,7 +694,7 @@ form .checkboxes {
.form-order-wrapper ul#ordering li { .form-order-wrapper ul#ordering li {
padding: 0.2rem 1rem; padding: 0.2rem 1rem;
border-radius: 4px; border-radius: 4px;
border: 1px solid #d4d4d4; border: 1px solid #d5d5d5;
background: #f8f8f8; background: #f8f8f8;
color: #8d959a; color: #8d959a;
margin: 3px 0; margin: 3px 0;
@@ -718,7 +718,7 @@ form .checkboxes {
cursor: move; cursor: move;
padding: 1rem; padding: 1rem;
border-radius: 4px; border-radius: 4px;
border: 1px solid #d4d4d4; border: 1px solid #d5d5d5;
background: #f8f8f8; background: #f8f8f8;
color: #8d959a; color: #8d959a;
margin: 3px 0; margin: 3px 0;
@@ -817,16 +817,16 @@ tr {
background: #54c5b0; background: #54c5b0;
color: #fff; } color: #fff; }
.button.dropdown-toggle { .button.dropdown-toggle {
border-left: 1px solid #3aab97; } border-left: 1px solid #3bab97; }
.button.secondary { .button.secondary {
background: #29796b; background: #2a7a6b;
color: rgba(255, 255, 255, 0.85); color: rgba(255, 255, 255, 0.85);
border-radius: 4px; } border-radius: 4px; }
.button.secondary:hover { .button.secondary:hover {
background: #2f8c7c; background: #318d7c;
color: #fff; } color: #fff; }
.button.secondary.dropdown-toggle { .button.secondary.dropdown-toggle {
border-left: 1px solid #2f8c7c; } border-left: 1px solid #318d7c; }
.button-group { .button-group {
position: relative; position: relative;
@@ -868,7 +868,7 @@ tr {
background-color: #41bea8; background-color: #41bea8;
-webkit-background-clip: padding-box; -webkit-background-clip: padding-box;
background-clip: padding-box; background-clip: padding-box;
border: 1px solid #3aab97; border: 1px solid #3bab97;
border: 1px solid rgba(0, 0, 0, 0.15); border: 1px solid rgba(0, 0, 0, 0.15);
border-radius: 4px; border-radius: 4px;
-webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175); -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
@@ -926,7 +926,7 @@ tr {
#admin-login .form-data { #admin-login .form-data {
padding-right: 0; } padding-right: 0; }
#admin-login h1 { #admin-login h1 {
background: #20333e url(../images/logo.png) 50% 50% no-repeat; background: #21333e url(../images/logo.png) 50% 50% no-repeat;
font-size: 0; font-size: 0;
color: transparent; color: transparent;
height: 216px; height: 216px;
@@ -942,15 +942,15 @@ tr {
text-align: center; text-align: center;
font-weight: 300; font-weight: 300;
-webkit-font-smoothing: auto; -webkit-font-smoothing: auto;
border: 1px solid #1d2e38; } border: 1px solid #1e2e39; }
#admin-login form input::-webkit-input-placeholder { #admin-login form input::-webkit-input-placeholder {
color: #83949c; } color: #83949d; }
#admin-login form input::-moz-placeholder { #admin-login form input::-moz-placeholder {
color: #83949c; } color: #83949d; }
#admin-login form input:-moz-placeholder { #admin-login form input:-moz-placeholder {
color: #83949c; } color: #83949d; }
#admin-login form input:-ms-input-placeholder { #admin-login form input:-ms-input-placeholder {
color: #83949c; } color: #83949d; }
#admin-login form .form-actions { #admin-login form .form-actions {
text-align: center; text-align: center;
margin: 0 -3rem -3rem -3rem; margin: 0 -3rem -3rem -3rem;
@@ -974,7 +974,7 @@ tr {
color: #fff; } color: #fff; }
#admin-logo { #admin-logo {
background: #20333e; background: #21333e;
height: 4.2rem; } height: 4.2rem; }
#admin-logo h3 { #admin-logo h3 {
text-transform: uppercase; text-transform: uppercase;
@@ -988,7 +988,7 @@ tr {
#admin-user-details { #admin-user-details {
padding: 2rem; padding: 2rem;
border-bottom: 1px solid #20333e; border-bottom: 1px solid #21333e;
overflow: hidden; } overflow: hidden; }
#admin-user-details img { #admin-user-details img {
-webkit-transition: all 0.5s ease; -webkit-transition: all 0.5s ease;
@@ -1023,7 +1023,7 @@ tr {
#admin-menu li .badges .badge { #admin-menu li .badges .badge {
display: inline-block; display: inline-block;
margin-right: -5px; margin-right: -5px;
color: #e5e5e5; } color: #e6e6e6; }
#admin-menu li .badges .count { #admin-menu li .badges .count {
background-color: #365569; } background-color: #365569; }
#admin-menu li .badges .updates { #admin-menu li .badges .updates {
@@ -1052,7 +1052,7 @@ tr {
color: #afc7d5; color: #afc7d5;
margin-right: 8px; } margin-right: 8px; }
#admin-menu li a:hover { #admin-menu li a:hover {
background: #20333e; background: #21333e;
color: #fff; } color: #fff; }
#admin-menu li a:hover i { #admin-menu li a:hover i {
font-size: 1.2rem; } font-size: 1.2rem; }
@@ -1468,6 +1468,12 @@ tr {
.depth-9 .row { .depth-9 .row {
padding-left: 30rem; } padding-left: 30rem; }
.hidden {
display: none !important; }
.switch-toggle input[type="radio"] {
display: none !important; }
/* /*
* Remodal - v0.2.0 * Remodal - v0.2.0
* Flat, responsive, lightweight, easy customizable modal window plugin with declarative state notation and hash tracking. * Flat, responsive, lightweight, easy customizable modal window plugin with declarative state notation and hash tracking.
@@ -1714,7 +1720,7 @@ body.remodal_active .remodal {
border-radius: 0; } border-radius: 0; }
.grav-mdeditor-navbar { .grav-mdeditor-navbar {
border: 1px solid #d4d4d4; border: 1px solid #d5d5d5;
border-top-right-radius: 4px; border-top-right-radius: 4px;
border-top-left-radius: 4px; border-top-left-radius: 4px;
background: #fbfbfb; } background: #fbfbfb; }
@@ -1733,8 +1739,8 @@ body.remodal_active .remodal {
.grav-mdeditor-navbar ul .mdeditor-active a { .grav-mdeditor-navbar ul .mdeditor-active a {
background: white; background: white;
cursor: auto; cursor: auto;
border-left: 1px solid #d4d4d4; border-left: 1px solid #d5d5d5;
border-right: 1px solid #d4d4d4; } border-right: 1px solid #d5d5d5; }
.grav-mdeditor-navbar ul .mdeditor-active a:hover { .grav-mdeditor-navbar ul .mdeditor-active a:hover {
background: #fff; } background: #fff; }
.grav-mdeditor-navbar ul a { .grav-mdeditor-navbar ul a {
@@ -1757,7 +1763,7 @@ body.remodal_active .remodal {
border-top-right-radius: 4px; } border-top-right-radius: 4px; }
.grav-mdeditor-content { .grav-mdeditor-content {
border: 1px solid #d4d4d4; border: 1px solid #d5d5d5;
border-top: 0; border-top: 0;
border-bottom-right-radius: 4px; border-bottom-right-radius: 4px;
border-bottom-left-radius: 4px; } border-bottom-left-radius: 4px; }
@@ -1801,7 +1807,7 @@ body.remodal_active .remodal {
[data-mode=split] .grav-mdeditor-button-code, [data-mode=split] .grav-mdeditor-button-preview { [data-mode=split] .grav-mdeditor-button-code, [data-mode=split] .grav-mdeditor-button-preview {
display: none; } display: none; }
[data-mode=split] .grav-mdeditor-code { [data-mode=split] .grav-mdeditor-code {
border-right: 1px solid #d4d4d4; } border-right: 1px solid #d5d5d5; }
[data-mode=split] .grav-mdeditor-code, [data-mode=split] .grav-mdeditor-code .grav-mdeditor-preview { [data-mode=split] .grav-mdeditor-code, [data-mode=split] .grav-mdeditor-code .grav-mdeditor-preview {
float: left; float: left;
width: 50%; } width: 50%; }
@@ -1897,7 +1903,7 @@ body.remodal_active .remodal {
.dropzone { .dropzone {
position: relative; position: relative;
border: 1px #d4d4d4 solid; border: 1px #d5d5d5 solid;
border-radius: 4px; border-radius: 4px;
min-height: 4rem; min-height: 4rem;
background: #fff; } background: #fff; }

File diff suppressed because one or more lines are too long

View File

@@ -398,6 +398,35 @@ $(function () {
}); });
}); });
// enable the toggleable checkbox when typing in the corresponding textarea/input element
jQuery(document).on('input propertychange click', '.form-data textarea, .form-data input, .form-data label, .form-data .selectize-input', function() {
var item = this;
var checkbox = $(item).parents('.form-field').find('.toggleable input[type="checkbox"]');
if (checkbox.length > 0) {
checkbox.prop('checked', true);
}
$(this).css('opacity', 1);
$(this).parents('.form-data').css('opacity', 1);
checkbox.css('opacity', 1);
checkbox.prop('checked', true);
checkbox.prop('value', 1);
checkbox.siblings('label').css('opacity', 1);
checkbox.parent().siblings('label').css('opacity', 1);
});
// when clicking the label, click the corresponding checkbox automatically
jQuery(document).on('click', 'label.toggleable', function() {
var input = $(this).siblings('.checkboxes.toggleable').find('input');
var on = !input.is(':checked');
input.prop('checked', on);
input.prop('value', on ? 1 : 0);
$(this).css('opacity', on ? 1 : 0.7);
});
// Thems Switcher Warning // Thems Switcher Warning
$(document).on('mousedown', '[data-remodal-target="theme-switch-warn"]', function(e){ $(document).on('mousedown', '[data-remodal-target="theme-switch-warn"]', function(e){
var name = $(e.target).closest('[data-gpm-theme]').find('.gpm-name a').text(), var name = $(e.target).closest('[data-gpm-theme]').find('.gpm-name a').text(),

View File

@@ -34,6 +34,8 @@ $(document).ready(function(){
// Reset when user manually types in invalid date // Reset when user manually types in invalid date
$input.on('change', function () { $input.on('change', function () {
$input.css('opacity', 1);
$input.parents('.form-data').css('opacity', 1);
var kWidget = $input.data('kendoDateTimePicker'); var kWidget = $input.data('kendoDateTimePicker');
if (kWidget && kWidget.value() === null && $input.val()) { if (kWidget && kWidget.value() === null && $input.val()) {
kWidget.value($input.data('kendo-previous') || ""); kWidget.value($input.data('kendo-previous') || "");

View File

@@ -30,6 +30,80 @@
var el = $(this), var el = $(this),
type = el.data(form.dataIndicator); type = el.data(form.dataIndicator);
if (type == 'textarea' || type == 'toggleable' || type == 'datetime') {
var processSpan = function processSpan(element, toggleable) {
var on = true;
if (!toggleable) {
on = $(element).find('input').is(':checked');
}
$(element).find('label').css('opacity', on ? 1 : 0.7);
$(element).siblings('label').css('opacity', on ? 1 : 0.7);
if (!on) {
$(element).find('input').attr('checked', false).prop('value', 0);
} else {
$(element).find('input').attr('checked', true).prop('value', 1);
}
var form_data = $(element).parent().siblings('.form-data');
if (on) {
form_data.addClass('checked');
} else {
form_data.removeClass('checked');
}
form_data.css('opacity', on ? 1 : 0.6);
form_data.find('textarea').css('opacity', on ? 1 : 0.6);
form_data.find('input').css('opacity', on ? 1 : 0.6);
};
var processToggleables = function processToggleables(element) {
var elType = $(element)[0].tagName.toLowerCase();
if (elType == 'checkbox') {
var on = $(element).is(':checked');
$(element).siblings('label').css('opacity', on ? 1 : 0.7);
$(element).parent().siblings('label').css('opacity', on ? 1 : 0.7);
if (!on) {
$(element).attr('checked', false).prop('value', 0);
} else {
$(element).attr('checked', true).prop('value', 1);
}
var form_data = $(element).parent().parent().siblings('.form-data')
form_data.css('opacity', on ? 1 : 0.6);
form_data.find('textarea').css('opacity', on ? 1 : 0.6);
form_data.find('input').css('opacity', on ? 1 : 0.6);
}
if (elType == 'span') {
processSpan(element);
}
};
el.on('change input propertychange', function() {
processToggleables(this);
});
el.find('input').on('change', function() {
processToggleables(this);
});
if ($(el)[0].className == 'checkboxes toggleable') {
var toggles = $(el).parent().siblings('.form-data').find('label');
toggles.on('click', function() {
processSpan(el, true);
});
}
processToggleables(this);
}
if (form.types[type]) { if (form.types[type]) {
var factory = form.factories[form.types[type]], var factory = form.factories[form.types[type]],
element = new factory(el, form), element = new factory(el, form),
@@ -69,15 +143,20 @@
toggleable.siblings('label').css('opacity', on ? 1 : 0.7); toggleable.siblings('label').css('opacity', on ? 1 : 0.7);
element.disabled(!on); element.disabled(!on);
if (!on) { if (!on) {
element.reset(); element.el.attr('checked', false).prop('value', 0);
} else {
element.el.attr('checked', true).prop('value', 1);
} }
}); });
var on = toggleable.find('input').is(':checked'); var on = toggleable.find('input').is(':checked');
toggleable.siblings('label').css('opacity', on ? 1 : 0.7); toggleable.siblings('label').css('opacity', on ? 1 : 0.7);
element.disabled(!on); element.disabled(!on);
if (!on) { if (!on) {
element.reset(); element.el.attr('checked', false).prop('value', 0);
} else {
element.el.attr('checked', true).prop('value', 1);
} }
} }

View File

@@ -203,3 +203,11 @@
padding-left: 3rem * ($i + 1); padding-left: 3rem * ($i + 1);
} }
} }
.hidden {
display: none!important;
}
.switch-toggle input[type="radio"] {
display: none!important;
}

View File

@@ -10,9 +10,9 @@
<span class="checkboxes toggleable" data-grav-field="toggleable" data-grav-field-name="{{ field.name|fieldName }}"> <span class="checkboxes toggleable" data-grav-field="toggleable" data-grav-field-name="{{ field.name|fieldName }}">
<input type="checkbox" <input type="checkbox"
id="toggleable_{{ field.name }}" id="toggleable_{{ field.name }}"
value="1" {% if originalValue is not null and originalValue is not empty %}value="1"{% endif %}
name="toggleable_{{ (scope ~ field.name)|fieldName }}" name="toggleable_{{ (scope ~ field.name)|fieldName }}"
{% if originalValue is not null %}checked="checked"{% endif %} {% if originalValue is not null and originalValue is not empty %}checked="checked"{% endif %}
> >
<label for="toggleable_{{ field.name }}"></label> <label for="toggleable_{{ field.name }}"></label>
</span> </span>

View File

@@ -3,15 +3,24 @@
{% set value = (value is null ? field.default : value) %} {% set value = (value is null ? field.default : value) %}
{% set value = (value is same as(false) ? 0 : value) %} {% set value = (value is same as(false) ? 0 : value) %}
{% set has_hidden = false %}
{% for key, text in field.options %}
{% if key is empty %}
{% set has_hidden = true %}
{% endif %}
{% endfor %}
{% block global_attributes %} {% block global_attributes %}
{{ parent() }} {{ parent() }}
data-grav-field-name="{{ field.name|fieldName }}" data-grav-field-name="{{ field.name|fieldName }}"
{% endblock %} {% endblock %}
{% block input %} {% block input %}
<div class="switch-toggle switch-grav {{ field.size }} switch-{{ field.options|length }}"> <div class="switch-toggle switch-grav {{ field.size }} switch-{{ field.options|length }}">
{% for key, text in field.options %} {% for key, text in field.options %}
{% set id = "toggle_" ~ field.name ~ key %} {% set id = "toggle_" ~ field.name ~ key %}
<input type="radio" <input type="radio"
value="{{ key }}" value="{{ key }}"
id="{{ id }}" id="{{ id }}"
@@ -20,6 +29,7 @@
class="{{ field.highlight == '' ~ key ? 'highlight' : '' }}" class="{{ field.highlight == '' ~ key ? 'highlight' : '' }}"
{% endif %} {% endif %}
{% if '' ~ key == '' ~ value %}checked="checked" {% endif %} {% if '' ~ key == '' ~ value %}checked="checked" {% endif %}
{% if value is defined and (key == 1 or key == '1') %}checked="checked" {% endif %}
{% if field.validate.required in ['on', 'true', 1] %}required="required"{% endif %} {% if field.validate.required in ['on', 'true', 1] %}required="required"{% endif %}
/> />
<label for="{{ id }}">{{ text }}</label> <label for="{{ id }}">{{ text }}</label>