/** * Catlair JS Copyright (C) 2019 a@itserv.ru * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Debug system * http://catlair.net/?template=clDebug.js * * still@itserv.ru * * Use SCC styles: * .Log for log window; * .PostIndicator for job indicator with loader or other. */ const HIDE_TIMEOUT_SECOND = 4; class TLog { CountJob = 0; constructor() { var that = this; /* Create job indicator */ this.Indicator=document.createElement('div'); this.Indicator.className='PostIndicator'; this.Indicator.style.display = 'none'; this.Indicator.style.opacity = '0'; document.body.append(this.Indicator); /* Create board for log */ this.LogElement = document.createElement('div'); this.LogElement.style.display='none'; this.LogElement.id="clLogElement"; this.LogElement.className='MenuPopup Log'; this.LogElement.onclick=function() { that.LogElement.style.display="none"; }; document.body.append(this.LogElement); } /* Show log */ Show() { this.LogElement.style.display = null; return this; } /* Hide log */ Hide() { this.LogElement.style.display = 'none'; return this; } /* Add horizontal line to log */ Line() { this.LogElement.innerHTML='
' + this.LogElement.innerHTML; return this; } /* Begin job is named AMassage:string */ Beg(AMessage, AShow) { this.Msg('Beg', AMessage, AShow); return this; } /* End job AMessage:string */ End (AMessage, AShow) { this.Msg('End', AMessage, AShow); return this; } /* Debug message AMessage:string */ Deb (AMessage, AShow) { this.Msg('Deb', AMessage, AShow); return this; } /* Information message AMessage:string */ Inf (AMessage, AShow) { this.Msg('Inf', AMessage, AShow); return this; } /* Warning message AMessage:string */ War (AMessage, AShow) { this.Msg('War', AMessage, AShow); console.warn(AMessage); } /* вывод сообщения об ошибке */ Err (AMessage, AShow) { this.Msg('Err', AMessage, AShow); console.error(AMessage); } /* * Write to log * AClass: type of message Inf, War, Deb, Err, Beg, End. * AMessage: string - текст сообщения * AShow - true показать окно лога, false - не показывать окно лога. */ Msg (AClass, AMessage, AShow) { var that = this; if (AMessage) { var lLine=document.createElement('div'); lLine.className='LogLine Log'+AClass; lLine.innerHTML='
'+AMessage+'
'+'
'+clMomentToStr(clNow())+''; /* start timer for hiding message */ lLine.Timer = setTimeout ( function() { lLine.IntervalCount = 0; /*запуск таймера гасящего сообщение*/ lLine.Timer = setInterval ( function() { lLine.IntervalCount ++; lLine.style.opacity = 1 - lLine.IntervalCount / 10; if (lLine.IntervalCount == 10) { clearInterval(lLine.Timer); lLine.Timer = null; lLine.className = ''; lLine.parentNode.removeChild(lLine); if ( that.LogElement.childNodes.length == 0 ) that.Hide(); } }, 10 ) }, clSec * HIDE_TIMEOUT_SECOND ); this.LogElement.insertBefore(lLine, this.LogElement.firstChild); if (AShow) this.LogElement.style.display=null; } } /** Begin job. Start new job and enable indicator. */ JobBegin() { if (document.body) { this.CountJob++; if (this.CountJob>0) { this.Indicator.style.display = null; this.Indicator.style.opacity = '1'; } this.Indicator.innerHTML=this.CountJob; } return this; } /** Job end. End currentn job and dec indicator. */ JobEnd() { this.CountJob--; if (this.Indicator) { this.Indicator.innerHTML = this.CountJob; if (this.CountJob < 1) { /* Hide indicator*/ this.Indicator.style.display = 'none'; this.Indicator.style.opacity = '0'; this.CountJob = 0; } } return this; } } /******************************************************************************************* * Catlair JS Copyright (C) 2019 a@itserv.ru * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . ******************************************************************************************* * CatlairPHP * 12.04.2016 * still@itserv.ru * Loader library ******************************************************************************************* */ /* * AParams.ID:string - идентификатор скрипта, по нему определяется надо ли загружать скрипт заново * AParams.Type - источник, ссылка или сам кантнет * AParams.OnAfterLoad:function(AParams) - вызов функции в которую передаюется PAarams */ function clScriptLoad(AParams) { var that = this; /*Заполнение параметров умолчальными значениями*/ if (!AParams.URL) var URL = '?template=' + AParams.ID; else var URL=AParams.URL; /* Отметка о начале работы */ if (AParams.Log) AParams.Log.JobBegin(); /* Поиск идентификатора который возможно ранее был загружен */ var Script = document.scripts[AParams.ID]; if (!Script) { /* Добавление раздела Script */ Script = document.createElement('script'); AParams.Script = Script; var Head = document.getElementsByTagName('head')[0]; Head.appendChild(Script); Script.id = AParams.ID; Script.type = 'text/javascript'; Script.onload = function(){OnLoad(AParams)}; Script.src = URL; console.log('Begin to load dynamic script ' + Script.src); } else { /* Выполняем пользовательскую функцию, если скрипт уже загружен */ AParams.Script = Script; OnLoad(AParams); } function OnLoad(p) { console.log('Loaded dynamic script '+p.Script.src); if (p.Log) p.Log.JobEnd(); p.Script.Loaded=true; if (p.OnAfterLoad) p.OnAfterLoad(p); } return this; } /* Ожидание завершения загрузки скриптов AList:array - aray of strings with scriptname ACall:function() - for user function */ function clScriptWait (AList, ACall) { var that = this; var c=0; for (var i=0; i. * * Main library * - динамическая работа со скриптом * - ожидание загрузки скриптов * - динамическая работа со стилями * - управленеи индиактором загрузки * * Библиотеки расширения загружаемые отдельно программистом * - clAuth.php * - clPopup.php */ class TCatlair { Log = null; constructor(ADatabase) { this.Log = new TLog(); /*счетчик количества запросов используется в clPost*/ this.FrameCount = 0; /* настройки DB */ this.Database = ADatabase; this.DatabaseDomain = 'dbcatlair'; } get Log() { return this.Log; } /* Динамическая загрузка скрипта ID - идентификатор скрипта, по нему определяется надо ли загружать скрипт заново Type - источник, ссылка или сам кантнет */ ScriptLoad(AParams) { clScriptLoad(AParams); return this; } /* выгрузка скрипта */ ScriptUnload(AID) { var Head=document.getElementsByTagName('head')[0]; var Script=Head.ChildByID(AParams.ID); if (Script) Script.parentNode.removeChild(Script); return this; } /* Ожидание завершения загрузки скриптов */ ScriptWait(AList, ACall) { var that = this; var c=0; for (var i=0; i