Skip to content

Commit

Permalink
Merge branch 'suit-baze-es6'
Browse files Browse the repository at this point in the history
Suit-baze is now using EcmaScript 6 syntax
  • Loading branch information
ImBobby committed Jul 26, 2016
2 parents 0f9c674 + 1c7c4e6 commit 26a64b7
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 43 deletions.
52 changes: 26 additions & 26 deletions dev/js/main.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/*! [PROJECT_NAME] | Suitmedia */

;(function ( window, document, undefined ) {
((window, document, undefined) => {

var path = {
css: myPrefix + 'assets/css/',
js : myPrefix + 'assets/js/vendor/'
const path = {
css: `${myPrefix}assets/css/`,
js : `${myPrefix}assets/js/vendor/`
};

var assets = {
_jquery_cdn : 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.1/jquery.min.js',
_jquery_local : path.js + 'jquery.min.js',
_fastclick : path.js + 'fastclick.min.js'
const assets = {
_jquery_cdn : `https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js`,
_jquery_local : `${path.js}jquery.min.js`,
_fastclick : `${path.js}fastclick.min.js`
};

var Site = {
const Site = {

init: function () {
init() {
Site.fastClick();
Site.enableActiveStateMobile();
Site.WPViewportFix();
Expand All @@ -24,47 +24,47 @@
window.Site = Site;
},

fastClick: function () {
fastClick() {
Modernizr.load({
load : assets._fastclick,
complete: function () {
complete: () => {
FastClick.attach(document.body);
}
});
},

enableActiveStateMobile: function () {
enableActiveStateMobile() {
if ( document.addEventListener ) {
document.addEventListener('touchstart', function () {}, true);
document.addEventListener('touchstart', () => {}, true);
}
},

WPViewportFix: function () {
WPViewportFix() {
if ( navigator.userAgent.match(/IEMobile\/10\.0/) ) {
var style = document.createElement("style"),
fix = document.createTextNode("@-ms-viewport{width:auto!important}");
let style = document.createElement('style'),
fix = document.createTextNode('@-ms-viewport{width:auto!important}');

style.appendChild(fix);
document.getElementsByTagName('head')[0].appendChild(style);
}
},

loadAdditionalScripts: function () {
var scripts = [].filter.call(document.scripts, function (script) {
var src = $.trim(script.getAttribute('data-src'));
loadAdditionalScripts() {
let scripts = [].filter.call(document.scripts, script => {
let src = $.trim(script.getAttribute('data-src'))

return src && src !== null;
return src && src !== null
});

if ( !scripts.length ) return;

scripts.forEach( function (script) {
Modernizr.load(script.getAttribute('data-src'));
});
scripts.forEach( script => {
Modernizr.load(script.getAttribute('data-src'))
})
}
};

var checkJquery = function () {
let checkJquery = () => {
Modernizr.load([
{
test : window.jQuery,
Expand All @@ -79,4 +79,4 @@
complete: checkJquery
});

})( window, document );
})(window, document);
86 changes: 69 additions & 17 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const autoprefixOpts = {
browsers: ['> 1%', 'last 10 versions', 'Firefox ESR', 'Opera 12.1']
}

const renameOpts = {
suffix: '.min'
}



/* Task: Watch HTML
Expand Down Expand Up @@ -113,37 +117,66 @@ gulp.task('stylesheet:copy_vendor_css', () => {



/* Task: Copy JS
/* Task: Ecmascript next
--------------------------------------------------------------------------------- */

gulp.task('javascript:compile', () => {
let options = {
suffix: '.min'
}
return gulp
.src(`${paths.dev}js/main.js`)
.pipe(plugins.babel({
presets: ['es2015', 'react']
}))
.on('error', (err) => {
console.log('>>> Error', e)

this.emit('end')
})
.pipe(plugins.rename(renameOpts))
.pipe(gulp.dest(`${paths.build}js`))
})

gulp.task('javascript:compile_and_minify', () => {
return gulp
.src(`${paths.dev}js/**/*.js`)
.pipe(plugins.rename(options))
.src(`${paths.dev}js/main.js`)
.pipe(plugins.babel({
presets: ['es2015']
}))
.on('error', (err) => {
console.log('>>> Error', e)

this.emit('end')
})
.pipe(plugins.uglify())
.pipe(plugins.rename(renameOpts))
.pipe(gulp.dest(`${paths.build}js`))
})




/* Task: Minify JS
/* Task: Copy JS
--------------------------------------------------------------------------------- */

gulp.task('javascript:compile_and_minify', () => {
let options = {
suffix: '.min'
}
gulp.task('javascript:copy_vendor_js', () => {
return gulp
.src(`${paths.dev}js/vendor/*.js`)
.pipe(plugins.rename(renameOpts))
.pipe(gulp.dest(`${paths.build}js/vendor/`))
})




/* Task: Minify JS
--------------------------------------------------------------------------------- */

gulp.task('javascript:minify_vendor_js', () => {
return gulp
.src(`${paths.dev}js/**/*.js`)
.src(`${paths.dev}js/vendor/*.js`)
.pipe(plugins.changed(`${paths.build}js`))
.pipe(plugins.uglify())
.pipe(plugins.rename(options))
.pipe(gulp.dest(`${paths.build}js`))
.pipe(plugins.rename(renameOpts))
.pipe(gulp.dest(`${paths.build}js/vendor/`))
})


Expand Down Expand Up @@ -226,7 +259,15 @@ gulp.task('clean', () => {
/* Task: Default
--------------------------------------------------------------------------------- */

gulp.task('default', ['image:compress', 'stylesheet:compile', 'javascript:compile', 'fonts', 'stylesheet:copy_vendor_css', 'image:convert_to_webp'])
gulp.task('default', [
'stylesheet:copy_vendor_css',
'stylesheet:compile',
'javascript:compile',
'javascript:copy_vendor_js',
'image:compress',
'image:convert_to_webp',
'fonts'
])



Expand All @@ -238,8 +279,11 @@ gulp.task('watch', ['default'], () => {
// SASS
gulp.watch(`${paths.dev}sass/**/*.scss`, ['stylesheet:compile'])

// esNext
gulp.watch(`${paths.dev}js/main.js`, ['javascript:compile'])

// Uglify
gulp.watch(`${paths.dev}js/**/*.js`, ['javascript:compile'])
gulp.watch(`${paths.dev}js/vendor/*.js`, ['javascript:copy_vendor_js'])

// Imagemin
gulp.watch(`${paths.dev}img/*`, ['image:compress'])
Expand Down Expand Up @@ -270,7 +314,15 @@ gulp.task('livereload', () => {
/* Task: Build
--------------------------------------------------------------------------------- */

gulp.task('production', ['stylesheet:compile_and_minify', 'javascript:compile_and_minify', 'image:compress', 'image:convert_to_webp', 'fonts', 'stylesheet:copy_vendor_css'])
gulp.task('production', [
'stylesheet:compile_and_minify',
'stylesheet:copy_vendor_css',
'javascript:compile_and_minify',
'javascript:minify_vendor_js',
'image:compress',
'image:convert_to_webp',
'fonts'
])

gulp.task('build', ['clean'], () => {
gulp.start('production')
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
},
"devDependencies": {
"autoprefixer": "^6.3.2",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"del": "^1.1.1",
"gulp": "^3.9.0",
"gulp-babel": "^6.1.2",
"gulp-changed": "^1.0.0",
"gulp-clean-css": "^2.0.4",
"gulp-imagemin": "^3.0.1",
Expand Down

1 comment on commit 26a64b7

@ImBobby
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this commit close #39

Please sign in to comment.