File: /home/confeduphaar/backip-old-files/libraries/syw/libraries.php
<?php
/**
* @copyright Copyright (C) 2011 Simplify Your Web, Inc. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE.txt
*/
// no direct access
defined('_JEXEC') or die;
class SYWLibraries
{
static $purePajinateLoaded = false;
static $lazysizesLoaded = false;
static $tinySliderLoaded = false;
static $tingleLoaded = false;
static $jq_pajinateLoaded = false;
static $jq_owlLoaded = false;
static $jqcLoaded = false;
static $jqcMultipackLoaded = false;
static $jqcthrottleLoaded = false;
static $jqctouchLoaded = false;
static $jqcmousewheelLoaded = false;
static $jqctransitLoaded = false;
static $highresLoaded = array();
static $instantiatePureModalLoaded = array();
static $compareLoaded = false;
/**
* Load purePajinate (pure javascript)
* v1.0.0
* https://github.com/obuisard/purePajinate
* IE10+ compatible
*/
static function loadPurePajinate($remote = false, $defer = false, $async = false)
{
if (self::$purePajinateLoaded) {
return;
}
$minified = (JDEBUG) ? '' : '.min';
$doc = JFactory::getDocument();
if (version_compare(JVERSION, '3.2.0', 'ge')) {
$doc->addScriptVersion(JURI::root(true).'/media/syw/js/purepajinate/purePajinate' . $minified . '.js', null, "text/javascript", $defer, $async);
} else {
$doc->addScript(JURI::root(true).'/media/syw/js/purepajinate/purePajinate' . $minified . '.js', "text/javascript", $defer, $async);
}
self::$purePajinateLoaded = true;
}
/*
* function that makes it easier to switch between libraries that handle pagination written in pure Javascript
*/
static function loadPurePagination($remote = false, $defer = false, $async = false)
{
self::loadPurePajinate($remote, $defer, $async);
}
/**
* Load Tiny Slider (pure javascript)
* v2.9.2
* https://github.com/ganlanyuan/tiny-slider
* IE8+ compatible
* the CSS file has been modified to add styling of the dots
* the JS file has been modified to add RTL support
*/
static function loadTinySlider($remote = false, $defer = false, $async = false)
{
if (self::$tinySliderLoaded) {
return;
}
$minified = (JDEBUG) ? '' : '.min';
$doc = JFactory::getDocument();
// WARNING loading the library remotely won't have the RTL fix
$remote = false;
if ($remote) {
$doc->addStyleSheet('https://cdnjs.cloudflare.com/ajax/libs/tiny-slider/2.9.3/tiny-slider' . $minified . '.css');
// style additions
$doc->addStyleDeclaration('.tns-slider{-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;}.tns-nav{text-align:center;margin:10px 0}.tns-nav>[aria-controls]{width:9px;height:9px;padding:0;margin:0 5px;border-radius:50%;background:#ddd;border:0}.tns-nav>.tns-nav-active{background:#999}');
$doc->addScript('https://cdnjs.cloudflare.com/ajax/libs/tiny-slider/2.9.3/tiny-slider' . $minified . '.js');
} else {
if (version_compare(JVERSION, '3.2.0', 'ge')) {
$doc->addStyleSheetVersion(JURI::root(true).'/media/syw/css/tinyslider/tiny-slider' . $minified . '.css');
$doc->addScriptVersion(JURI::root(true).'/media/syw/js/tinyslider/tiny-slider' . $minified . '.js', null, "text/javascript", $defer, $async);
} else {
$doc->addStyleSheet(JURI::root(true).'/media/syw/css/tinyslider/tiny-slider' . $minified . '.css');
$doc->addScript(JURI::root(true).'/media/syw/js/tinyslider/tiny-slider' . $minified . '.js', "text/javascript", $defer, $async);
}
}
self::$tinySliderLoaded = true;
}
/**
* Load Tingle (pure javascript)
* v0.15.2
* https://github.com/robinparisi/tingle
* ? compatible
*/
static function loadTingle($remote = false, $defer = false, $async = false)
{
if (self::$tingleLoaded) {
return;
}
$minified = (JDEBUG) ? '' : '.min';
$doc = JFactory::getDocument();
if ($remote) {
$doc->addStyleSheet('https://cdnjs.cloudflare.com/ajax/libs/tingle/0.15.2/tingle' . $minified . '.css');
$doc->addScript('https://cdnjs.cloudflare.com/ajax/libs/tingle/0.15.2/tingle' . $minified . '.js');
} else {
if (version_compare(JVERSION, '3.2.0', 'ge')) {
$doc->addStyleSheetVersion(JURI::root(true).'/media/syw/css/tingle/tingle' . $minified . '.css');
$doc->addScriptVersion(JURI::root(true).'/media/syw/js/tingle/tingle' . $minified . '.js', null, "text/javascript", $defer, $async);
} else {
$doc->addStyleSheet(JURI::root(true).'/media/syw/css/tingle/tingle' . $minified . '.css');
$doc->addScript(JURI::root(true).'/media/syw/js/tingle/tingle' . $minified . '.js', "text/javascript", $defer, $async);
}
}
self::$tingleLoaded = true;
}
/*
* function that makes it easier to switch between libraries that handle modals written in pure Javascript
*/
static function loadPureModal($remote = false, $defer = false, $async = false)
{
self::loadTingle($remote, $defer, $async);
}
/*
* loads the code that instantiates and sets up the modals written in pure Javascript
*/
static function instantiatePureModal($selector = 'modal')
{
if (in_array($selector, self::$instantiatePureModalLoaded)) {
return;
}
$lang = JFactory::getLanguage();
$lang->load('lib_syw.sys', JPATH_SITE);
$close_label = JText::_('LIB_SYW_MODAL_CLOSE');
$selector_variable = str_replace('-', '_', $selector); // javascript does not like - in the name
$inline_js = <<< JS
document.addEventListener("readystatechange", function(event) {
if (event.target.readyState === "complete") {
var {$selector_variable} = new tingle.modal({
stickyFooter: true,
closeLabel: "{$close_label}",
onOpen: function() {
document.querySelector(".tingle-modal .puremodal-close").addEventListener("click", function() { {$selector_variable}.close(); });
document.querySelector("body").classList.add('modal-open');
var event = document.createEvent('Event');
event.initEvent('modalopen', true, true);
document.dispatchEvent(event);
},
onClose: function() {
this.setContent("");
document.querySelector("#{$selector}Label").textContent = "";
document.querySelector("#{$selector} .iframe").setAttribute("src", "about:blank");
document.querySelector("body").classList.remove('modal-open');
var event = document.createEvent('Event');
event.initEvent('modalclose', true, true);
document.dispatchEvent(event);
}
});
var clickable = document.querySelectorAll(".{$selector}");
for (var i = 0; i < clickable.length; i++) {
clickable[i].addEventListener("click", function() {
var dataTitle = this.getAttribute("data-modaltitle");
if (typeof (dataTitle) !== "undefined" && dataTitle !== null) {
document.querySelector("#{$selector}Label").textContent = dataTitle;
}
var dataURL = this.getAttribute("href");
document.querySelector("#{$selector} .iframe").setAttribute("src", dataURL);
{$selector_variable}.setContent(document.querySelector("#{$selector}").innerHTML);
{$selector_variable}.open();
});
}
}
});
JS;
JFactory::getDocument()->addScriptDeclaration(self::compress($inline_js));
self::$instantiatePureModalLoaded[] = $selector;
}
/**
* Load Owl Carousel (jQuery plugin)
* v2.3.4
* https://github.com/OwlCarousel2/OwlCarousel2
*/
static function loadOwlCarousel($remote = false, $defer = false, $async = false)
{
if (self::$jq_owlLoaded) {
return;
}
$minified = (JDEBUG) ? '' : '.min';
$doc = JFactory::getDocument();
if ($remote) {
$doc->addStyleSheet('https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel' . $minified . '.css');
$doc->addScript('https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel' . $minified . '.js');
} else {
if (version_compare(JVERSION, '3.2.0', 'ge')) {
$doc->addStyleSheetVersion(JURI::root(true).'/media/syw/css/owlcarousel/owl.carousel' . $minified . '.css');
$doc->addScriptVersion(JURI::root(true).'/media/syw/js/owlcarousel/owl.carousel' . $minified . '.js', null, "text/javascript", $defer, $async);
} else {
$doc->addStyleSheet(JURI::root(true).'/media/syw/css/owlcarousel/owl.carousel' . $minified . '.css');
$doc->addScript(JURI::root(true).'/media/syw/js/owlcarousel/owl.carousel' . $minified . '.js', "text/javascript", $defer, $async);
}
}
self::$jq_owlLoaded = true;
}
/**
* Load Lazysizes (pure javascript)
* v5.2.0
* https://github.com/aFarkas/lazysizes
*/
static function loadLazysizes($remote = false, $defer = false, $async = false)
{
if (self::$lazysizesLoaded) {
return;
}
$minified = (JDEBUG) ? '' : '.min';
$doc = JFactory::getDocument();
if ($remote) {
$doc->addScript('https://cdnjs.cloudflare.com/ajax/libs/lazysizes/5.2.0/lazysizes.min.js'); // only minified version
} else {
if (version_compare(JVERSION, '3.2.0', 'ge')) {
$doc->addScriptVersion(JURI::root(true).'/media/syw/js/lazysizes/lazysizes' . $minified . '.js', null, "text/javascript", $defer, $async);
} else {
$doc->addScript(JURI::root(true).'/media/syw/js/lazysizes/lazysizes' . $minified . '.js', "text/javascript", $defer, $async);
}
}
self::$lazysizesLoaded = true;
}
/**
* Load Pajinate (jQuery plugin)
* v0.4 modified
* https://github.com/wesnolte/Pajinate
*/
static function loadPagination($defer = false, $async = false, $remote = false)
{
if (self::$jq_pajinateLoaded) {
return;
}
$minified = (JDEBUG) ? '' : '.min';
$doc = JFactory::getDocument();
if (version_compare(JVERSION, '3.2.0', 'ge')) {
$doc->addScriptVersion(JURI::root(true).'/media/syw/js/pagination/jquery.pajinate' . $minified . '.js', null, "text/javascript", $defer, $async);
} else {
$doc->addScript(JURI::root(true).'/media/syw/js/pagination/jquery.pajinate' . $minified . '.js', "text/javascript", $defer, $async);
}
self::$jq_pajinateLoaded = true;
}
/**
* Load the carousel carouFredSel library (jQuery plugins)
* v6.2.1
*/
static function loadCarousel($throttle = true, $touch = true, $mousewheel = false, $transit = false, $defer = false, $async = false, $remote = false)
{
if (self::$jqcMultipackLoaded && !$mousewheel && !$transit) {
return;
}
$will_use_multipack = false;
if (!self::$jqcLoaded && $throttle && $touch && !$mousewheel && !$transit && !JDEBUG && !$remote) {
$will_use_multipack = true;
}
if ($throttle && !self::$jqcMultipackLoaded && !$will_use_multipack) {
self::loadCarousel_throttle($defer, $async, $remote);
}
if ($touch && !self::$jqcMultipackLoaded && !$will_use_multipack) {
self::loadCarousel_touch($defer, $async, $remote);
}
if ($mousewheel) {
self::loadCarousel_mousewheel($defer, $async, $remote);
}
if ($transit) {
self::loadCarousel_transit($defer, $async, $remote);
}
$doc = JFactory::getDocument();
if (!self::$jqcMultipackLoaded && $will_use_multipack) { // multi-pack is not used when debug or when remote
if (version_compare(JVERSION, '3.2.0', 'ge')) {
$doc->addScriptVersion(JURI::root(true).'/media/syw/js/carousel/jquery.carouFredSel.min.js', null, "text/javascript", $defer, $async);
} else {
$doc->addScript(JURI::root(true).'/media/syw/js/carousel/jquery.carouFredSel.min.js', "text/javascript", $defer, $async);
}
self::$jqcMultipackLoaded = true;
} else {
if (self::$jqcLoaded) {
return;
}
if ($remote) {
$doc->addScript('https://cdnjs.cloudflare.com/ajax/libs/jquery.caroufredsel/6.2.1/jquery.carouFredSel.packed.js'); // only minified version
} else {
if (version_compare(JVERSION, '3.2.0', 'ge')) {
$doc->addScriptVersion(JURI::root(true).'/media/syw/js/carousel/jquery.carouFredSel-6.2.1' . ((JDEBUG) ? '' : '-packed') . '.js', null, "text/javascript", $defer, $async);
} else {
$doc->addScript(JURI::root(true).'/media/syw/js/carousel/jquery.carouFredSel-6.2.1' . ((JDEBUG) ? '' : '-packed') . '.js', "text/javascript", $defer, $async);
}
}
self::$jqcLoaded = true;
}
}
/**
* jquery.ba-throttle-debounce
* v1.1
*/
static function loadCarousel_throttle($defer = false, $async = false, $remote = false)
{
if (self::$jqcthrottleLoaded) {
return;
}
$doc = JFactory::getDocument();
if ($remote) {
$doc->addScript('https://cdnjs.cloudflare.com/ajax/libs/jquery-throttle-debounce/1.1/jquery.ba-throttle-debounce' . ((JDEBUG) ? '' : '.min') . '.js');
} else {
if (version_compare(JVERSION, '3.2.0', 'ge')) {
$doc->addScriptVersion(JURI::root(true).'/media/syw/js/carousel/jquery.ba-throttle-debounce.min.js', null, "text/javascript", $defer, $async);
} else {
$doc->addScript(JURI::root(true).'/media/syw/js/carousel/jquery.ba-throttle-debounce.min.js', "text/javascript", $defer, $async);
}
}
self::$jqcthrottleLoaded = true;
}
/**
* jquery.touchSwipe
* v1.6.18
*/
static function loadCarousel_touch($defer = false, $async = false, $remote = false)
{
if (self::$jqctouchLoaded) {
return;
}
$doc = JFactory::getDocument();
if ($remote) {
$doc->addScript('https://cdnjs.cloudflare.com/ajax/libs/jquery.touchswipe/1.6.18/jquery.touchSwipe' . ((JDEBUG) ? '' : '.min') . '.js');
} else {
if (version_compare(JVERSION, '3.2.0', 'ge')) {
$doc->addScriptVersion(JURI::root(true).'/media/syw/js/carousel/jquery.touchSwipe.min.js', null, "text/javascript", $defer, $async);
} else {
$doc->addScript(JURI::root(true).'/media/syw/js/carousel/jquery.touchSwipe.min.js', "text/javascript", $defer, $async);
}
}
self::$jqctouchLoaded = true;
}
/**
* jquery.mousewheel
* v3.0.6
*/
static function loadCarousel_mousewheel($defer = false, $async = false, $remote = false)
{
if (self::$jqcmousewheelLoaded) {
return;
}
$doc = JFactory::getDocument();
if (version_compare(JVERSION, '3.2.0', 'ge')) {
$doc->addScriptVersion(JURI::root(true).'/media/syw/js/carousel/jquery.mousewheel.min.js', null, "text/javascript", $defer, $async);
} else {
$doc->addScript(JURI::root(true).'/media/syw/js/carousel/jquery.mousewheel.min.js', "text/javascript", $defer, $async);
}
self::$jqcmousewheelLoaded = true;
}
/**
* jquery.transit
* v?
*/
static function loadCarousel_transit($defer = false, $async = false, $remote = false)
{
if (self::$jqctransitLoaded) {
return;
}
$doc = JFactory::getDocument();
if (version_compare(JVERSION, '3.2.0', 'ge')) {
$doc->addScriptVersion(JURI::root(true).'/media/syw/js/carousel/jquery.transit.min.js', null, "text/javascript", $defer, $async);
} else {
$doc->addScript(JURI::root(true).'/media/syw/js/carousel/jquery.transit.min.js', "text/javascript", $defer, $async);
}
self::$jqctransitLoaded = true;
}
/**
* add lazyload class when on high resolution devices only
* @param string $selector
* @param boolean $lazyload
* @param string $lazyload_image
*/
static function triggerLazysizes($selector = 'img', $lazyload = false, $lazyload_image = '')
{
if (in_array($selector, self::$highresLoaded)) {
return;
}
$javascript = array();
//$javascript[] = 'jQuery(document).ready(function() { ';
//$javascript[] = 'document.addEventListener("DOMContentLoaded", function() { ';
$javascript[] = 'document.addEventListener("readystatechange", function(event) { ';
$javascript[] = 'if (event.target.readyState == "complete") { ';
$javascript[] = 'var elements = document.querySelectorAll("' . $selector . '[data-src]"); ';
$javascript[] = 'if (window.devicePixelRatio > 1) { '; // undefined > 1 results in false (IE < 11 do not support the property)
//$javascript[] = 'elements.forEach(function (el) { ';
$javascript[] = 'for (var i = 0; i < elements.length; i++) { ';
$javascript[] = 'el = elements[i]; ';
$javascript[] = 'if (el.classList) { el.classList.add("lazyload"); } else { el.className += " lazyload" } ';
if ($lazyload && $lazyload_image) {
$javascript[] = 'el.setAttribute("src", "' . $lazyload_image . '"); ';
}
$javascript[] = '} ';
// $javascript[] = 'jQuery("'.$selector.'[data-src]").each(function() { ';
// $javascript[] = 'jQuery(this).addClass("lazyload"); ';
// if ($lazyload && $lazyload_image) {
// $javascript[] = 'jQuery(this).attr("src", "'.$lazyload_image.'"); ';
// }
// $javascript[] = '});';
$javascript[] = '}';
if ($lazyload && $lazyload_image) {
$javascript[] = ' else {';
//$javascript[] = 'elements.forEach(function (el) { ';
$javascript[] = 'for (var i = 0; i < elements.length; i++) { ';
$javascript[] = 'el = elements[i]; ';
$javascript[] = 'if (el.classList) { el.classList.add("lazyload"); } else { el.className += " lazyload" } ';
$javascript[] = 'el.setAttribute("data-src", el.getAttribute("src")); ';
$javascript[] = 'el.setAttribute("src", "' . $lazyload_image . '"); ';
$javascript[] = '} ';
// $javascript[] = 'jQuery("'.$selector.'[data-src]").each(function() { ';
// $javascript[] = 'jQuery(this).addClass("lazyload"); ';
// $javascript[] = 'jQuery(this).attr("data-src", jQuery(this).attr("src")); ';
// $javascript[] = 'jQuery(this).attr("src", "'.$lazyload_image.'"); ';
// $javascript[] = '});';
$javascript[] = '}';
}
$javascript[] = '} ';
$javascript[] = '}); ';
JFactory::getDocument()->addScriptDeclaration(implode($javascript));
self::$highresLoaded[] = $selector;
}
/**
* Load the comparison version function if needed
*/
static function loadCompareVersions()
{
if (self::$compareLoaded) {
return;
}
$doc = JFactory::getDocument();
// returns false if version e > t (version is 1.3.2 for example)
$compareScript = 'function SYWCompareVersions(e,t){var r=!1;if(e==t)return!0;"object"!=typeof e&&(e=e.toString().split(".")),"object"!=typeof t&&(t=t.toString().split("."));for(var o=0;o<Math.max(e.length,t.length);o++){if(void 0==e[o]&&(e[o]=0),void 0==t[o]&&(t[o]=0),Number(e[o])<Number(t[o])){r=!0;break}if(e[o]!=t[o])break}return r};';
$doc->addScriptDeclaration($compareScript);
self::$compareLoaded = true;
}
/**
* Compress inline JS
* @param string $inlineJS
* @return string
*/
static function compress($inlineJS = '', $remove_comments = false)
{
if ($remove_comments) {
$inlineJS = preg_replace('!\/\*[\s\S]*?\*\/|\/\/.*!', '', $inlineJS);
}
return str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $inlineJS);
}
}
?>