CNVS.Tips = function() {
var __core = SEMICOLON.Core;
var __modules = SEMICOLON.Modules;
return {
init: function(selector) {
__core.loadJS({ file: 'plugins.bootstrap.js', id: 'canvas-bootstrap-js', jsFolder: true });
__core.isFuncTrue( function() {
return typeof bootstrap !== 'undefined';
}).then( function(cond) {
if( !cond ) {
return false;
}
if( typeof cnvsTips === "undefined" || cnvsTips.length < 1 ) {
return false;
}
__core.initFunction({ class: 'has-plugin-tips', event: 'pluginTipsReady' });
var randomIndex = Math.floor(Math.random() * cnvsTips.length);
var randomTip = cnvsTips[randomIndex];
var tipsEl = document.getElementById('cnvs-tips-element');
if( !tipsEl ) {
var tipsHTML = '
';
__core.getVars.elWrapper.insertAdjacentHTML('beforeend', tipsHTML);
tipsEl = document.getElementById('cnvs-tips-element');
}
var tipsTitle = document.getElementById('cnvs-tips-element-title');
var tipsContent = document.getElementById('cnvs-tips-element-content');
var tipsDisable = document.getElementById('cnvs-tips-element-disable');
var tipsEnable = document.getElementById('cnvs-tips-element-enable');
tipsTitle.innerHTML = randomTip.title;
tipsContent.innerHTML = randomTip.content;
if( tipsDisable ) {
tipsDisable.onclick = function(e) {
e.preventDefault();
var tipsToast = bootstrap.Toast.getOrCreateInstance(document.getElementById('cnvs-tips-element'));
tipsToast.hide();
__core.cookie.set('__cnvs_tips_cookies', 'hide', 1);
};
}
if( tipsEnable ) {
tipsEnable.onclick = function(e) {
e.preventDefault();
__core.cookie.remove('__cnvs_tips_cookies');
window.location.reload();
};
}
(function(){
var enabled = true;
if( __core.cookie.get('__cnvs_tips_cookies' ) == 'hide' ) {
enabled = false;
}
if( enabled ) {
setTimeout(function(){
__modules.notifications(tipsEl);
}, Math.floor(Math.random() * 5000));
}
})();
});
}
};
}();