Skip to content

Commit

Permalink
this version updates all the node items. it also switches to `cmb2_ad…
Browse files Browse the repository at this point in the history
…min_init` instead of `cmb2_init`
  • Loading branch information
jonathanstegall committed Feb 10, 2022
1 parent 3d7f6b4 commit 8fac21b
Show file tree
Hide file tree
Showing 9 changed files with 4,098 additions and 5,820 deletions.
2 changes: 1 addition & 1 deletion .stylelintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "stylelint-config-wordpress/scss",
"extends": [ "@wordpress/stylelint-config/scss" ],
"rules": {
"selector-class-pattern": null
}
Expand Down
40 changes: 33 additions & 7 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const rename = require("gulp-rename");
const sass = require('gulp-sass')(require('sass'));
const sassGlob = require("gulp-sass-glob");
const sort = require("gulp-sort");
const gulpStylelint = require("gulp-stylelint");
const gulpStylelint = require("@ronilaukkarinen/gulp-stylelint");
const sourcemaps = require("gulp-sourcemaps");
const uglify = require("gulp-uglify");
const wpPot = require("gulp-wp-pot");
Expand Down Expand Up @@ -88,15 +88,21 @@ function adminstyles() {
function adminsasslint() {
return gulp.src(config.styles.admin)
.pipe(gulpStylelint({
fix: true
fix: true,
reporters: [
{formatter: 'string', console: true}
],
}))
.pipe(gulp.dest(config.styles.lint_dest));
}

function frontendsasslint() {
return gulp.src(config.styles.front_end)
.pipe(gulpStylelint({
fix: true
fix: true,
reporters: [
{formatter: 'string', console: true}
]
}))
.pipe(gulp.dest(config.styles.lint_dest));
}
Expand Down Expand Up @@ -141,7 +147,11 @@ function adminscripts() {
)
.pipe(concat(packagejson.name + "-admin.js")) // Concatenate
.pipe(sourcemaps.write())
.pipe(eslint())
.pipe(eslint( {
parserOptions: {
requireConfigFile: false
}}
))
.pipe(iife({
useStrict: false,
params: ['$'],
Expand All @@ -162,7 +172,11 @@ function frontendscripts() {
)
.pipe(concat(packagejson.name + "-front-end.js")) // Concatenate
.pipe(sourcemaps.write())
.pipe(eslint())
.pipe(eslint( {
parserOptions: {
requireConfigFile: false
}}
))
.pipe(iife({
useStrict: false,
params: ['$'],
Expand All @@ -175,7 +189,13 @@ function frontendscripts() {
function adminscriptlint() {
return gulp
.src(config.scripts.admin)
.pipe(eslint({fix:true}))
.pipe(eslint( {
fix:true,
parserOptions: {
requireConfigFile: false
}
}
))
.pipe(eslint.format())
.pipe(gulp.dest(config.scripts.admin_lint))
// Brick on failure to be super strict
Expand All @@ -185,7 +205,13 @@ function adminscriptlint() {
function frontendscriptlint() {
return gulp
.src(config.scripts.front_end)
.pipe(eslint({fix:true}))
.pipe(eslint( {
fix:true,
parserOptions: {
requireConfigFile: false
}
}
))
.pipe(eslint.format())
.pipe(gulp.dest(config.scripts.front_end_lint))
// Brick on failure to be super strict
Expand Down
153 changes: 75 additions & 78 deletions assets/js/src/admin/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
*
* @param {string} selector the div that holds the radio fields
*/
function showTypeField( selector ) {
const value = $( 'input[type="radio"]:checked', selector ).val();
$( '.cmb2-message-type' ).hide();
$( '.cmb2-message-type-' + value ).show();
function showTypeField(selector) {
const value = $('input[type="radio"]:checked', selector).val();
$('.cmb2-message-type').hide();
$('.cmb2-message-type-' + value).show();
}

/**
Expand All @@ -15,19 +15,19 @@ function showTypeField( selector ) {
* @param {string} selector the div that holds the checkboxes
* @param {string} current the currently checked item
*/
function showHideMaximumScreen( selector, current ) {
if ( 'undefined' === typeof current ) {
current = $( 'input[type="checkbox"]:checked', selector );
function showHideMaximumScreen(selector, current) {
if ('undefined' === typeof current) {
current = $('input[type="checkbox"]:checked', selector);
}
if ( $( 'input[type="checkbox"]', selector ).is( ':checked' ) ) {
$( 'input[type="checkbox"]:checked', selector )
.closest( '.cmb-field-list' )
.find( '.cmb2-maximum-screen-width' )
if ($('input[type="checkbox"]', selector).is(':checked')) {
$('input[type="checkbox"]:checked', selector)
.closest('.cmb-field-list')
.find('.cmb2-maximum-screen-width')
.hide();
} else {
$( 'input[type="checkbox"]', selector )
.closest( '.cmb-field-list' )
.find( '.cmb2-maximum-screen-width' )
$('input[type="checkbox"]', selector)
.closest('.cmb-field-list')
.find('.cmb2-maximum-screen-width')
.show();
}
}
Expand All @@ -37,110 +37,107 @@ function showHideMaximumScreen( selector, current ) {
*
* @param {string} value the value of the maximum width <select> field
*/
function showHideMaximumBanner( value ) {
if ( 'custom' === value ) {
$( '.cmb2-custom-maximum-banner-width' ).show();
function showHideMaximumBanner(value) {
if ('custom' === value) {
$('.cmb2-custom-maximum-banner-width').show();
} else {
$( '.cmb2-custom-maximum-banner-width' ).hide();
$('.cmb2-custom-maximum-banner-width').hide();
}
}

/**
* Set up the message admin fields. This runs when a "screen size" gets added to the form
*/
function setupMessage() {
const typeSelector = $( '.cmb2-message-type-selector' );
const noMaxScreenSelector = $( '.cmb2-no-maximum-screen-width' );
const typeSelector = $('.cmb2-message-type-selector');
const noMaxScreenSelector = $('.cmb2-no-maximum-screen-width');
const maxBannerWidthSelector = '.cmb2-maximum-banner-width select';
if ( typeSelector.length > 0 ) {
showTypeField( typeSelector );
$( 'input[type="radio"]', typeSelector ).on( 'change', function () {
showTypeField( typeSelector );
} );
if (typeSelector.length > 0) {
showTypeField(typeSelector);
$('input[type="radio"]', typeSelector).on('change', function () {
showTypeField(typeSelector);
});
}
if ( noMaxScreenSelector.length > 0 ) {
showHideMaximumScreen( noMaxScreenSelector );
$( 'input[type="checkbox"]', noMaxScreenSelector ).on(
if (noMaxScreenSelector.length > 0) {
showHideMaximumScreen(noMaxScreenSelector);
$('input[type="checkbox"]', noMaxScreenSelector).on(
'change',
function ( el ) {
showHideMaximumScreen( noMaxScreenSelector, el );
function (el) {
showHideMaximumScreen(noMaxScreenSelector, el);
}
);
}
if ( $( maxBannerWidthSelector ).length > 0 ) {
showHideMaximumBanner( $( maxBannerWidthSelector ).val() );
$( document ).on( 'change', maxBannerWidthSelector, function () {
showHideMaximumBanner( $( this ).val() );
} );
if ($(maxBannerWidthSelector).length > 0) {
showHideMaximumBanner($(maxBannerWidthSelector).val());
$(document).on('change', maxBannerWidthSelector, function () {
showHideMaximumBanner($(this).val());
});
}
$( '.cmb-type-checkbox:hidden input:checkbox' ).prop( 'checked', false );
$( '.cmb-type-select:hidden option:selected' ).removeAttr( 'selected' );
$( '.cmb-type-text:hidden input[type="text"]' ).val();
$('.cmb-type-checkbox:hidden input:checkbox').prop('checked', false);
$('.cmb-type-select:hidden option:selected').removeAttr('selected');
$('.cmb-type-text:hidden input[type="text"]').val();
}

/**
* When "add another screen size" runs, it adds a CMB2 row to the form. Set up the message form.
*/
$( document ).on( 'cmb2_add_row', function () {
$(document).on('cmb2_add_row', function () {
setupMessage();
} );
});

/**
* When jQuery loads, remove some default WP fields and set up the message form
*/
$( document ).ready( function () {
$( '#pageparentdiv label[for=parent_id]' ).parents( 'p' ).eq( 0 ).remove();
$( '#pageparentdiv select#parent_id' ).remove();
$(document).ready(function () {
$('#pageparentdiv label[for=parent_id]').parents('p').eq(0).remove();
$('#pageparentdiv select#parent_id').remove();
setupMessage();
} );
});

/**
* Make the various <select> fields into select2 fields
*/
if ( jQuery.fn.select2 ) {
$( '.cmb2-insertable-message select' ).select2();
if (jQuery.fn.select2) {
$('.cmb2-insertable-message select').select2();

// Before a new group row is added, destroy Select2. We'll reinitialise after the row is added
$( '.cmb-repeatable-group' ).on(
$('.cmb-repeatable-group').on(
'cmb2_add_group_row_start',
function ( event, instance ) {
function (event, instance) {
const $table = $(
document.getElementById( $( instance ).data( 'selector' ) )
document.getElementById($(instance).data('selector'))
);
const $oldRow = $table.find( '.cmb-repeatable-grouping' ).last();
const $oldRow = $table.find('.cmb-repeatable-grouping').last();

$oldRow.find( '.cmb2_select' ).each( function () {
$( this ).select2( 'destroy' );
} );
$oldRow.find('.cmb2_select').each(function () {
$(this).select2('destroy');
});
}
);

// When a new group row is added, clear selection and initialise Select2
$( '.cmb-repeatable-group' ).on(
'cmb2_add_row',
function ( event, newRow ) {
$( newRow )
.find( '.cmb2_select' )
.each( function () {
$( 'option:selected', this ).removeAttr( 'selected' );
$( this ).select2();
} );
$('.cmb-repeatable-group').on('cmb2_add_row', function (event, newRow) {
$(newRow)
.find('.cmb2_select')
.each(function () {
$('option:selected', this).removeAttr('selected');
$(this).select2();
});

// if it's a custom multiselect cmb2 field, make sure to clear the value because that appears to work differently
$( newRow )
.find( '.cmb2_multi_select' )
.each( function () {
$( this ).val( [] ).change();
$( this ).select2( 'val', '' );
} );
// if it's a custom multiselect cmb2 field, make sure to clear the value because that appears to work differently
$(newRow)
.find('.cmb2_multi_select')
.each(function () {
$(this).val([]).change();
$(this).select2('val', '');
});

// Reinitialise the field we previously destroyed
$( newRow )
.prev()
.find( '.cmb2_select' )
.each( function () {
$( this ).select2();
} );
}
);
// Reinitialise the field we previously destroyed
$(newRow)
.prev()
.find('.cmb2_select')
.each(function () {
$(this).select2();
});
});
}
Loading

0 comments on commit 8fac21b

Please sign in to comment.