refactoring (gulp and libraries) + some fixing

This commit is contained in:
Bachir Soussi Chiadmi
2018-04-04 12:58:58 +02:00
parent c8f54cb9f1
commit 6263b674b8
31 changed files with 13519 additions and 150 deletions
@@ -1,3 +1,19 @@
// https://plainjs.com/javascript/utilities/set-cookie-get-cookie-and-delete-cookie-5/
function setCookie(name, value, days) {
var d = new Date;
d.setTime(d.getTime() + 24*60*60*1000*days);
document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString();
}
function setCookie(name,value,days){var d=new Date;d.setTime(d.getTime()+24*60*60*1000*days);document.cookie=name+"="+value+";path=/;expires="+d.toGMTString();}
if(edlp.redirect){document.body.style.visibility='hidden';var cookiename="edlp_origin_path";var cookie_value=edlp.sys_path.replace(/^\//,'')+'~~'+window.location.pathname;setCookie(cookiename,cookie_value,1);window.location.replace(window.location.origin);}else{document.body.style.visibility='visible';}
// var edlp is provided by edlp_ajax.module file
if(edlp.redirect){
document.body.style.visibility = 'hidden';
// record current (will be origin) sys_path in cookie
var cookiename = "edlp_origin_path";
var cookie_value = edlp.sys_path.replace(/^\//, '') + '~~' + window.location.pathname;
setCookie(cookiename, cookie_value, 1);
// redirect to home
window.location.replace(window.location.origin);
}else{
document.body.style.visibility = 'visible';
}
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
@@ -18,22 +18,21 @@
function init(){
// console.log("EdlpTheme init()");
// redirect all no-front pages to front with right url ajax load
initHistory();
_$body.on('corpus-map-ready', onCorpusMapReady);
if(!drupalSettings.path.isFront)
return;
initEvents();
_audioPlayer = new AudioPlayer();
_compoPlayer = new CompoPlayer();
initAjaxLinks();
if (_$body.is('.path-productions')) initProductions();
if(_$body.is('.path-frontpage')) initHome();
// if (_$body.is('.path-productions')) initProductions();
// if(_$body.is('.path-frontpage')) initHome();
// initScrollbars();
initEvents();
};
// ___ _
@@ -41,7 +40,8 @@
// | _|\ V / -_) ' \ _(_-<
// |___|\_/\___|_||_\__/__/
function initEvents(){
$('body')
_$body
.on('corpus-map-ready', onCorpusMapReady)
.on('on-studio-chutier-updated', initAjaxLinks)
.on('studio-initialized', function(e){
_compoPlayer.newCompo();
@@ -118,32 +118,18 @@
var path = window.location.origin + Drupal.url(ajax_path);
$.getJSON(path, {})
.done(function(data){
onAjaxLoaded(data, sys_path, selector);
onAjaxLoaded(data, url, ajax_path, sys_path, selector);
})
.fail(function(jqxhr, textStatus, error){
onAjaxLoadError(jqxhr, textStatus, error, sys_path);
});
var state = {
ajax_path:ajax_path,
sys_path:sys_path,
};
// url is null means that we are loading content on popState event
// so we don't record the state again
if(url){
// console.log('url:'+url+' ; state',state);
// we can not pushestate with absolute url
history.pushState(state, null, url);
}
};
function onAjaxLoadError(jqxhr, textStatus, error, sys_path){
console.warn('ajaxlink load failed for '+sys_path+' : '+error, jqxhr.responseText);
$('.ajax-loading').removeClass('ajax-loading');
_$body.removeClass('ajax-loading');
};
function onAjaxLoaded(data, sys_path, selector){
function onAjaxLoaded(data, url, ajax_path, sys_path, selector){
// console.log('ajax loaded : data', data);
// reset all style may been added by other pages (like masonry for productions)
@@ -217,6 +203,18 @@
_$body.attr('booted', 'booted');
_$body.removeClass('ajax-loading');
var state = {
ajax_path:ajax_path,
sys_path:sys_path,
};
// url is null means that we are loading content on popState event
// so we don't record the state again
if(url){
// console.log('url:'+url+' ; state',state);
// we can not pushestate with absolute url
history.pushState(state, null, url);
}
};
function addCloseBtnToCols(){
@@ -304,10 +302,8 @@
.add('a', '.productions-subtree')
.add('a', '.productions-parent')
// .add('a.index-link, a.notice-link', '#block-edlpentreesblock')
// .addClass('use-ajax')
.addClass('ajax-link');
Drupal.ajax.bindAjaxLinks('#block-footer.menu--footer');
_$ajaxLinks = $('.ajax-link:not(.ajax-enabled)')
.each(function(i,e){
var $this = $(this);
@@ -464,7 +460,6 @@
this.$previous.on('click', this.playPrevious.bind(this));
this.$playpause.on('click', this.togglePlayPause.bind(this));
this.$next.on('click', this.playNext.bind(this));
// TODO: previous and next btns
},
openDocument(node, caller){
// console.log('AudioPlayer openDocument', node);
@@ -796,7 +791,7 @@
this.refresh();
this.active = true; // TODO: set active false
this.active = true;
// this.newCompo();
}
},
@@ -1069,7 +1064,6 @@
d.setTime(d.getTime() + 24*60*60*1000*days);
document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString();
}
function deleteCookie(name) { setCookie(name, '', -1); }
init();
@@ -18,14 +18,18 @@ global-js:
assets/dist/scripts/main.min.js: { scope: footer }
dependencies:
- core/drupal
- core/drupal.autocomplete
# - core/drupal.ajax
# - core/drupal.autocomplete
- core/matchmedia
- core/matchmedia.addListener
- core/jquery
- core/jquery.once
- core/jquery.ui.draggable
- core/jquery.ui.dropable
- core/jquery.ui.sortable
# - core/jquery.once
# - core/jquery.ui.draggable
# - core/jquery.ui.dropable
# - core/jquery.ui.sortable
- edlp_corpus/corpus
- edlp_studio/edlp_studio-library
- edlp_search/edlp_search-library
- url_to_video_filter/player_embed
- url_to_video_filter/vimeo_embed
- url_to_video_filter/youtube_embed
+11 -11
View File
@@ -1,7 +1,7 @@
'use strict';
var gulp = require('gulp');
var util = require('gulp-util');
var gulpif = require('gulp-if');
var sass = require('gulp-sass');
var watch = require('gulp-watch');
var autoprefixer = require('gulp-autoprefixer');
@@ -11,7 +11,6 @@ var rename = require('gulp-rename');
var mainBowerFiles = require('main-bower-files');
// var jsonToSass = require('gulp-json-to-sass');
// var concat = require('gulp-concat');
// var through = require('through2');
var svgmin = require('gulp-svgmin');
// var fs = require('fs');
// var json2js = require('gulp-json2js');
@@ -19,20 +18,20 @@ var svgmin = require('gulp-svgmin');
// var shared_variables = JSON.parse(fs.readFileSync('./assets/json/shared_variables.json'));
// to get minified assets run `gulp --env=prod`
var argv = require('minimist')(process.argv.slice(2));
console.dir(argv);
var prod = argv.env == 'prod' ? true : false;
function handleError(err) {
console.log(err.toString());
}
var config = {
assetsDir : './assets',
production: !!util.env.production
}
gulp.task('scripts', function () {
gulp.src(['./assets/scripts/main.js', './assets/scripts/history.js']) // './assets/scripts/shared_variables.js',
// .pipe(concat('main.js'))
// .pipe(config.production ? jsmin() : util.noop())
.pipe(jsmin())
.pipe(gulpif(prod, jsmin()))
// .pipe(jsmin())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./assets/dist/scripts/'));
});
@@ -44,8 +43,9 @@ gulp.task('styles', function () {
browsers: ['last 2 versions'],
cascade: false
})).on('error', handleError)
// .pipe(config.production ? cssmin() : util.noop())
.pipe(cssmin())
// .pipe(prod ? cssmin() : util.noop())
.pipe(gulpif(prod, cssmin()))
// .pipe(cssmin())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./assets/dist/styles/'));
});
@@ -11,16 +11,18 @@
"gulp-autoprefixer": "latest",
"gulp-concat": "latest",
"gulp-cssmin": "latest",
"gulp-if": "^2.0.2",
"gulp-jsmin": "latest",
"gulp-json-to-sass": "latest",
"gulp-json2js": "latest",
"gulp-rename": "latest",
"gulp-sass": "latest",
"gulp-strip-debug": "latest",
"gulp-svgmin": "latest",
"gulp-svgmin": "^1.2.4",
"gulp-util": "latest",
"gulp-watch": "latest",
"main-bower-files": "latest"
"main-bower-files": "latest",
"minimist": "^1.2.0"
},
"dependencies": {}
}