src/js/sow_core/sow.js
Everything related to javascript is starting with this single file! Is just an object! Just one! But this is the root of all evil goodness!
At the very end of this page you can find the structure! Core sructure where everything is happening inside Smarty!
Despite the fact than right now, Smarty Core has over 25 plugins written from scratch, is incredibily lightweight: under 130Kb minified, all plugins together. 223Kb including jQuery! ~60Kb gzipped!
Smarty is working like a framework. All core plugins (SOW) are linked together, so all of them are working together. You can remove any plugin but is highly recommended to keep the most used ones: toast, bootstrap validation, dropdowns + deep navigation (required by header main navigation), scroll to, button toggle. Of course, because the total size is so small, you can keep all of them! Vendors are the only issue BUT solved by Smarty in an elegant way. Picture this: only, and only datatable PDF export function is using a plugin that is OVER 1Mb in size, MINIFIED! Can you imagine? 10 times larger than entire Smarty Core and is just one single little option! So how Smarty solved these kind of issues without you writing a single line of javascript code?
gulp.config__core.js
gulp.config__vendors.js
Vendors are actually plugins, but we call them "vendors" because are third party files, and are not part of Smarty Core. Each vendor has it's own controller written from scratch for Smarty - that's why there is no need for 95% of plugins to write a single line of javascript code. Everything works in seconds!
Vendor controllers are working like this:
1. Check if there is a need for the plugin on that specific page
2. If the plugin is needed, load it! Load also the CSS if there is any asociated with the plugin!
3. Initialize the plugin!
4. Done!
Did you catch the trick? Instead of loading over 5Mb of vendor javascript files, is loaded only and only the vendor is needed for that specific page! Is like you add manually on each page, only the javascript you need! So that's why Smarty is fast and lightweight! Oh, and unique - no other template in any marketplace has this feature (not yet, but is never too late ).
Smarty has many plugins you can use but of course, you might want to add a new plugin.
You can do it in 2 ways:
1. Creating a Smarty Controller for that plugin - there is a boilerplate or you can inspire from all others.
2. Using it like you always did. That was easy, isn't it?
Smarty is adding new features on each update but any feature request is more than welcome! Oh, not only requests, also suggestions and/or bad things are welcome! We all know that there is no such thing "perfect" but I am willing to fix and improve my work!
Down below is the Smarty Core Structure I promised in the beggining.
/**
src/js/sow_core/sow.js
**/
;(function ($) {
'use strict';
$.SOW = {
/**
*
* @init
*
*
**/
init: function () {}
/**
*
* @globals
* SOW Config
*
**/
globals: {
direction : $('body').css('direction'), /* rtl | ltr */
width : $(window).width(), /* window width, updated on resize */
height : $(window).height(), /* window height, updated on resize */
is_modern_browser : ('querySelector' in document && 'localStorage' in window && 'addEventListener' in window), /* `true` if modern */
is_mobile : ($(window).width() < 993) ? true : false,
is_admin : $('body').hasClass('layout-admin') ? true : false,
}
/**
*
* @core
* SOW Core Plugins
*
**/
core: {},
/**
*
* @vendor
* Vendor Plugins [separated by SOW]
*
**/
vendor: {},
/**
*
* @helper
* SOW Helpers
*
**/
helper: {},
/**
*
* @custom
* My Custom [optional]
*
**/
custom: {},
/**
*
* @reinit
* Ajax Callable
*
**/
reinit: function(ajax_container) {}
/**
*
* Init this
*
*
**/
$.SOW.init();
})(jQuery);
/*
Globals you can get
if you need in your js code
*/
@globals
$.SOW.globals.direction 'ltr|rtl'
$.SOW.globals.width actual width (updated on resize)
$.SOW.globals.height actual height (updated on resize)
$.SOW.globals.is_mobile true|false
$.SOW.globals.is_modern_browser true if modern
$.SOW.globals.is_admin true|false (admin layout)
$.SOW.globals.breakpoints.[sm|ms|lg|xl] bootstrap default breakpoints
$.SOW.globals.elBody body element
$.SOW.globals.elHeader header element
$.SOW.globals.elAside main sidebar element
@functions
$.SOW.reinit('#container') reinit plugins for a specific ajax container; see also:
/**
HELPERS YOU CAN USE IN YOUR JS CODE
src/js/sow_core/helpers.js
Please do not modify them, SOW plugins are using them!
**/
@loadScript
$.SOW.helper.loadScript(script_arr, async[true|false], cache[true|false]).done(function() {
// all scripts loaded... do something
// * async = false by default (scripts are loaded in order)
// * cache = true by default
});
*
@loadCSS
$.SOW.helper.loadCSS("/path/to/file.css", "append|prepend|remove"); "append" is default, if no option passed
*
@loadingSpinner
$.SOW.helper.loadingSpinner('show|hide', "#mycontainer", 'overlay|icon');
*
@overlay
$.SOW.helper.overlay('show|hide|toggle');
*
@randomStr
$.SOW.helper.randomStr(8, 'empty|L|N');
*
@byte2size
$.SOW.helper.byte2size(bytes, precision=2, int_only=false);
$.SOW.helper.byte2kb(bytes);
*
@scrollAnimate
$.SOW.helper.scrollAnimate(_el, _offset, _hash_change, _speed);
_el = element to scroll to. #top = page top
_offset = top offset (0 default)
_hash_change = update url hash on click
_speed = scroll speed (400 default)
$.SOW.helper.scrollAnimate('#top', 0, false, 400);
*
@removeUrlHash
$.SOW.helper.removeUrlHash('https://domain.com/url#hash');
*
@playSound
$.SOW.helper.playSound('path/to/audio.mp3');
*
@time_from_ms
$.SOW.helper.time_from_ms(miliseconds, 's|m|h|d|empty for all');
*
@get_browser (unfinished, need improvement, do not use)
$.SOW.helper.get_browser();
*
@params_parse
var params = $.SOW.helper.params_parse(params_from_post); // return: array
var ajax_params_arr = $.SOW.helper.params_parse(ajax_params);
for (var i = 0; i < ajax_params_arr.length; ++i) {
formDataDel.append(ajax_params_arr[i][0], ajax_params_arr[i][1]);
}
*
@indexedDB (local database)
$.SOW.helper.indexedDB(.. see function ..);
*
@currencyFormat
$.SOW.helper.currencyFormat(1000000); // output: 1,234,567.89
// 1,234,567.89
$.SOW.helper.currencyFormat(1000000, [
2, ',', '.' // en
// 2, '.', ',' // de
// 2, ' ', ',' // fr
]);
*
@consoleLog (output - only if debug is enabled!)
$.SOW.helper.consoleLog('Lorem Ipsum', 'color: #ff0000;');
<!-- Classic Smarty Preloader
Smarty Reborn is not using it anymore but you can, if you want to ;)
-->
<!-- preloader -->
<div id="page_preload" class="d-middle fixed-full z-index-9999 bg-white">
<span class="p-3 shadow-xs rounded">
<i class="fi fi-circle-spin fi-spin text-muted float-start"></i>
loading...
</span>
</div>
<!-- /preloader -->