Skip to content

Commit

Permalink
Merge pull request #3 from MinnPost/expand-conditions
Browse files Browse the repository at this point in the history
Expand conditions
  • Loading branch information
jonathanstegall authored Nov 8, 2019
2 parents 157b3fb + b49c405 commit 05758fa
Show file tree
Hide file tree
Showing 17 changed files with 2,522 additions and 1,476 deletions.
55 changes: 24 additions & 31 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ const config = {
};

function adminstyles() {
return gulp.src(config.styles.admin)
return gulp.src(config.styles.admin, { allowEmpty: true })
.pipe(sourcemaps.init()) // Sourcemaps need to init before compilation
.pipe(sassGlob()) // Allow for globbed @import statements in SCSS
.pipe(sass()) // Compile
.on('error', sass.logError) // Error reporting
.pipe(postcss([
autoprefixer( {
'browsers': [ 'last 2 version' ]
mqpacker( {
'sort': true
} ),
cssnano() // Minify
cssnano( {
'safe': true // Use safe optimizations.
} ) // Minify
]))
.pipe(rename({ // Rename to .min.css
suffix: '.min'
Expand All @@ -66,20 +68,19 @@ function adminstyles() {
}

function frontendstyles() {
return gulp.src(config.styles.front_end)
return gulp.src(config.styles.front_end, { allowEmpty: true } )
.pipe(sourcemaps.init()) // Sourcemaps need to init before compilation
.pipe(sassGlob()) // Allow for globbed @import statements in SCSS
.pipe(sass()) // Compile
.on('error', sass.logError) // Error reporting
.pipe(postcss([
autoprefixer( {
'browsers': [ 'last 2 version' ]
mqpacker( {
'sort': true
} ),
cssnano() // Minify
cssnano( {
'safe': true // Use safe optimizations.
} ) // Minify
]))
.pipe(rename({ // Rename to .min.css
suffix: '.min'
}))
.pipe(sourcemaps.write()) // Write the sourcemap files
.pipe(gulp.dest(config.styles.dest)) // Drop the resulting CSS file in the specified dir
.pipe(browserSync.stream());
Expand All @@ -99,11 +100,7 @@ function adminscripts() {
.pipe(babel({
presets: ['@babel/preset-env']
}))
.pipe(concat('' + packagejson.name + '-admin.js')) // Concatenate
/*.pipe(uglify()) // Minify + compress
.pipe(rename({
suffix: '.min'
}))*/
.pipe(concat(packagejson.name + '-admin.js')) // Concatenate
.pipe(sourcemaps.write())
.pipe(eslint())
.pipe(gulp.dest(config.scripts.dest))
Expand Down Expand Up @@ -175,19 +172,15 @@ function watch() {
}
}

// export tasks
exports.sasslint = sasslint;
exports.adminstyles = adminstyles;
exports.frontendstyles = frontendstyles;
exports.adminscripts = adminscripts;
exports.frontendscripts = frontendscripts;
exports.uglifyscripts = uglifyscripts;
exports.translate = translate;
exports.watch = watch;
// define complex tasks
const styles = gulp.series(sasslint, adminstyles, frontendstyles);
const scripts = gulp.series(adminscripts, frontendscripts, uglifyscripts);
const build = gulp.series(gulp.parallel(styles, scripts, translate));

// What happens when we run gulp?
gulp.task('default',
gulp.series(
gulp.parallel(adminstyles, adminscripts, translate) // run these tasks asynchronously
)
);
// export tasks
exports.styles = styles;
exports.scripts = scripts;
exports.translate = translate;
exports.watch = watch;
exports.build = build;
exports.default = build;
2 changes: 1 addition & 1 deletion assets/css/select2.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/css/selectwoo.min.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions assets/css/wp-message-inserter-plugin-admin.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion assets/js/select2.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/selectwoo.min.js

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions assets/js/src/admin/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@

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( 'cmb2_add_group_row_start', function ( event, instance ) {
var $table = $( document.getElementById( $( instance ).data( 'selector' ) ) );
var $oldRow = $table.find( '.cmb-repeatable-grouping' ).last();

$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();
});

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

}

})(jQuery);
Loading

0 comments on commit 05758fa

Please sign in to comment.