JS bug fixtures

This commit is contained in:
Tony Air 2019-06-01 00:40:32 +07:00
parent 82e0d401ec
commit f62361099c
5 changed files with 87 additions and 38 deletions

28
app/_config/env-check.yml Normal file
View File

@ -0,0 +1,28 @@
---
Name: webapp-env-check
---
SilverStripe\EnvironmentCheck\EnvironmentCheckSuite:
registered_checks:
curl:
definition: 'HasFunctionCheck("curl_init")'
title: 'is curl available?'
gd:
definition: 'HasFunctionCheck("imagecreatetruecolor")'
title: 'Does PHP have GD2 support?'
db:
definition: 'DatabaseCheck("Page")'
title: 'Is the database accessible?'
url:
definition: 'URLCheck()'
title: 'Is the homepage accessible?'
registered_suites:
check:
- curl
- gd
- db
- url
health:
- db
- url

View File

@ -1,6 +1,8 @@
import 'bootstrap-select/js/bootstrap-select';
import $ from 'jquery'; import $ from 'jquery';
import 'bootstrap-select/js/bootstrap-select';
import 'jquery.inputmask/dist/jquery.inputmask.bundle';
import Events from "../_events"; import Events from "../_events";
import SpinnerUI from './_ui.spinner'; import SpinnerUI from './_ui.spinner';
@ -19,10 +21,12 @@ const FormBasics = (($) => {
ui._element = element; ui._element = element;
$element.data(DATA_KEY, this); $element.data(DATA_KEY, this);
$('[data-inputmask]').inputmask();
const $fields = $element.find('input,textarea,select'); const $fields = $element.find('input,textarea,select');
const $selectFields = $element.find('select:not([readonly])'); const $selectFields = $element.find('select:not([readonly])');
const $radioOptions = $element.find('input[type="radio"]'); const $radioOptions = $element.find('input[type="radio"]');
const separator = ', '; const separator = '::;::';
$selectFields.each((i, el) => { $selectFields.each((i, el) => {
const $el = $(el); const $el = $(el);
@ -40,43 +44,46 @@ const FormBasics = (($) => {
})); }));
// wrap options // wrap options
$el.on('rendered.bs.select', () => { if (maxOptions > 1) {
if (!$el.val().length) { $el.on('rendered.bs.select,changed.bs.select,refreshed.bs.select,loaded.bs.select', () => {
return true; if (!$el.val().length) {
} return true;
}
const $container = $el.parent().find('.filter-option-inner-inner'); const $container = $el.parent().find('.filter-option-inner-inner');
const val = $container.text(); const val = $container.text();
const vals = val.split(separator); const vals = val.split(separator);
let html = ''; let html = '';
vals.forEach((opt) => {
const $opt = $el.find('option').filter((i, e) => {
return $(e).text() === opt;
});
html += `<span class="option" data-val=${ $opt.attr('value') }>${ opt
} <i class="fas fa-times btn-remove"></i></span>`;
vals.forEach((opt) => {
const $opt = $el.find('option').filter((i, e) => {
return $(e).text() === opt;
}); });
html += `<span class="option" data-val=${ $opt.attr('value') }>${ opt $container.html(html);
} <i class="fas fa-times btn-remove"></i></span>`;
// remove value
$container.find('.option').on('click', (e) => {
e.preventDefault();
const $opt = $(e.currentTarget);
const val = $opt.data('val').toString();
//$opt.remove();
const vals = $el.selectpicker('val');
const i = vals.indexOf(val);
if (i > -1) {
vals.splice(i, 1);
$el.selectpicker('val', vals);
}
});
}); });
}
$container.html(html);
// remove value
$container.find('.option').on('click', (e) => {
e.preventDefault();
const $opt = $(e.currentTarget);
const val = $opt.data('val').toString();
//$opt.remove();
const vals = $el.selectpicker('val');
const i = vals.indexOf(val);
if (i > -1) {
vals.splice(i, 1);
$el.selectpicker('val', vals);
}
});
});
// FIX: hidden picker // FIX: hidden picker
@ -84,6 +91,7 @@ const FormBasics = (($) => {
$el.selectpicker('refresh'); $el.selectpicker('refresh');
$el.selectpicker('toggle'); $el.selectpicker('toggle');
document.activeElement.blur(); document.activeElement.blur();
window.scroll(0, 0);
//$el.selectpicker('show'); //$el.selectpicker('show');
//$el.selectpicker('hide'); //$el.selectpicker('hide');

View File

@ -39,19 +39,30 @@ const DatetimeUI = (($) => {
$el.datepicker($.extend(datepickerOptions, { $el.datepicker($.extend(datepickerOptions, {
defaultViewDate: defaultDate, defaultViewDate: defaultDate,
multidate: $el.data('multidate'), multidate: $el.data('multidate'),
})); }, $el.data()));
} else } else
// timepicker // timepicker
if ($el.hasClass('time') || $el.attr('type') === 'time') { if ($el.hasClass('time') || $el.attr('type') === 'time') {
$el.attr('readonly', 'true'); $el.attr('readonly', 'true');
$el.timepicker({ $el.timepicker($.extend({
defaultTime: $el.data('default-time'), defaultTime: $el.data('default-time'),
icons: { icons: {
up: 'fas fa-chevron-up', up: 'fas fa-chevron-up',
down: 'fas fa-chevron-down', down: 'fas fa-chevron-down',
}, },
}, $el.data())).on('show.timepicker', (e) => {
const $el = $(e.currentTarget);
const $dropdown = $Body.find('.bootstrap-timepicker-widget');
$dropdown.find('tbody').append('<tr><td colspan="5"><a href="#" data-action="clear">Clear</a></td></tr>');
const $clearBtn = $dropdown.find('[data-action="clear"]');
$clearBtn.on('click', (e) => {
e.preventDefault();
$el.timepicker('clear');
$el.timepicker('hideWidget');
})
}); });
} }
} }

View File

@ -31,7 +31,8 @@
"innoweb/silverstripe-sitemap": "*", "innoweb/silverstripe-sitemap": "*",
"silverstripe/multiuser-editing-alert": "*", "silverstripe/multiuser-editing-alert": "*",
"gorriecoe/silverstripe-link": "*", "gorriecoe/silverstripe-link": "*",
"gorriecoe/silverstripe-linkfield": "*" "gorriecoe/silverstripe-linkfield": "*",
"silverstripe/environmentcheck": "*"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^5.7", "phpunit/phpunit": "^5.7",

View File

@ -42,6 +42,7 @@
"jquery-hammerjs": "^2.0.0", "jquery-hammerjs": "^2.0.0",
"jquery-zoom": "^1.7.21", "jquery-zoom": "^1.7.21",
"jquery.appear": "^1.0.1", "jquery.appear": "^1.0.1",
"jquery.inputmask": "^3.3.4",
"meta-lightbox": "^1.0.0", "meta-lightbox": "^1.0.0",
"offcanvas-bootstrap": "^2.5.2", "offcanvas-bootstrap": "^2.5.2",
"popper.js": "^1.15.0", "popper.js": "^1.15.0",