mirror of
https://github.com/locomotivemtl/locomotive-boilerplate.git
synced 2026-01-15 00:55:08 +08:00
Reorganization of globals
- Simplified globals usage in App - Removed global App
This commit is contained in:
@@ -3,7 +3,7 @@ import { $document } from './utils/environment';
|
||||
import { getNodeData } from './utils/html';
|
||||
|
||||
// Global functions and tools
|
||||
import globals from './utils/globals';
|
||||
import globals from './globals';
|
||||
import { isFunction } from './utils/is';
|
||||
|
||||
// Basic modules
|
||||
@@ -17,7 +17,7 @@ class App {
|
||||
$document.on('initModules.App', (event) => {
|
||||
this.initGlobals(event.firstBlood)
|
||||
.deleteModules()
|
||||
.initModules();
|
||||
.initModules(event);
|
||||
});
|
||||
|
||||
$document.on('initScopedModules.App', (event) => {
|
||||
@@ -55,10 +55,10 @@ class App {
|
||||
|
||||
/**
|
||||
* Find modules and initialize them
|
||||
* @param {object} event The event being triggered.
|
||||
* @return {object} Self (allows chaining)
|
||||
* @param {Object} event The event being triggered.
|
||||
* @return {Object} Self (allows chaining)
|
||||
*/
|
||||
initModules() {
|
||||
initModules(event) {
|
||||
// Elements with module
|
||||
let moduleEls;
|
||||
|
||||
@@ -116,8 +116,8 @@ class App {
|
||||
// IIFE for loading the application
|
||||
// ==========================================================================
|
||||
(function() {
|
||||
window.App = new App();
|
||||
$document.trigger({
|
||||
new App();
|
||||
$document.triggerHandler({
|
||||
type: 'initModules.App',
|
||||
firstBlood: true
|
||||
});
|
||||
|
||||
10
assets/scripts/globals.js
Normal file
10
assets/scripts/globals.js
Normal file
@@ -0,0 +1,10 @@
|
||||
/* jshint esnext: true */
|
||||
import TransitionManager from './transitions/TransitionManager';
|
||||
|
||||
export default function(firstBlood) {
|
||||
svg4everybody();
|
||||
|
||||
if (firstBlood) {
|
||||
const transitionManager = new TransitionManager();
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,6 @@ const $window = $(window);
|
||||
const $html = $(document.documentElement);
|
||||
const $body = $(document.body);
|
||||
|
||||
export { $document, $window, $html, $body, APP_NAME, DATA_API_KEY };
|
||||
const isDebug = !!$html.data('debug');
|
||||
|
||||
export { APP_NAME, DATA_API_KEY, $document, $window, $html, $body, isDebug };
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
/* jshint esnext: true */
|
||||
|
||||
export default function() {
|
||||
svg4everybody();
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
/* jshint esnext: true */
|
||||
var isAnimating = false;
|
||||
import { isNumeric } from './is'
|
||||
|
||||
var defaults = {
|
||||
let isAnimating = false;
|
||||
|
||||
const defaults = {
|
||||
easing: 'swing',
|
||||
headerOffset: 60,
|
||||
speed: 300
|
||||
@@ -14,7 +16,7 @@ var defaults = {
|
||||
* @param {object} options
|
||||
*/
|
||||
export function scrollTo($element, options) {
|
||||
var deferred = $.Deferred();
|
||||
const deferred = $.Deferred();
|
||||
|
||||
// Drop everything if this ain't a jQuery object
|
||||
if ($element instanceof jQuery && $element.length > 0) {
|
||||
@@ -27,21 +29,30 @@ export function scrollTo($element, options) {
|
||||
isAnimating = true;
|
||||
|
||||
// Default container that we'll be scrolling
|
||||
var $container = $('html, body');
|
||||
var elementOffset = 0;
|
||||
let $container = $('html, body');
|
||||
let elementOffset = 0;
|
||||
|
||||
// Testing container in options for jQuery-ness
|
||||
// If we're not using a custom container, we take the top document offset
|
||||
// If we are, we use the elements position relative to the container
|
||||
if (typeof options.$container !== 'undefined' && options.$container instanceof jQuery && options.$container.length > 0) {
|
||||
$container = options.$container;
|
||||
elementOffset = $element.position().top
|
||||
|
||||
if (typeof options.scrollTop !== 'undefined' && isNumeric(options.scrollTop) && options.scrollTop !== 0) {
|
||||
scrollTop = options.scrollTop;
|
||||
} else {
|
||||
scrollTop = $element.position().top - options.headerOffset;
|
||||
}
|
||||
} else {
|
||||
elementOffset = $element.offset().top
|
||||
if (typeof options.scrollTop !== 'undefined' && isNumeric(options.scrollTop) && options.scrollTop !== 0) {
|
||||
scrollTop = options.scrollTop;
|
||||
} else {
|
||||
scrollTop = $element.offset().top - options.headerOffset;
|
||||
}
|
||||
}
|
||||
|
||||
$container.animate({
|
||||
scrollTop: elementOffset - options.headerOffset
|
||||
scrollTop: scrollTop
|
||||
}, options.speed, options.easing, function() {
|
||||
isAnimating = false;
|
||||
deferred.resolve();
|
||||
Reference in New Issue
Block a user