From a44faad823cf8d5cb133f62215ece9dafb3ab813 Mon Sep 17 00:00:00 2001 From: bellord13 Date: Mon, 30 May 2022 17:50:04 +0300 Subject: [PATCH] fix --- assets/ActionCollection/ActionCollection.js | 2 +- assets/align/align.js | 8 +- assets/bsToastService/bsToastService.js | 3 +- assets/collection/collection.js | 34 +- assets/config/config.js | 13 +- assets/core/core.js | 11 +- assets/core/core.register.js | 42 ++- assets/core/doc.js | 22 -- assets/dataStructures/dataStructures.js | 43 ++- assets/date/date.js | 15 + assets/flex-kit/flex-kit.css | 96 +++--- .../loggerService.css => log/log.css} | 22 +- assets/log/log.js | 296 ++++++++++++++++++ assets/logger/logger.js | 73 ----- assets/loggerService/loggerService.js | 165 ---------- assets/menu/menu.js | 3 +- assets/support/support.js | 84 ++++- assets/testing/testing.js | 4 +- assets/tooltip2/tooltip2.js | 32 +- assets/userAction/userAction.js | 12 +- templates/elementproperty/s/field.php | 72 +++++ templates/elementproperty/s/view.php | 16 + tests/dateTest.php | 2 +- tests/index.php | 2 +- tests/logger-system/index.php | 70 +++++ tests/logger-system/script.js | 23 ++ 26 files changed, 772 insertions(+), 393 deletions(-) rename assets/{loggerService/loggerService.css => log/log.css} (90%) create mode 100644 assets/log/log.js delete mode 100644 assets/logger/logger.js delete mode 100644 assets/loggerService/loggerService.js create mode 100644 templates/elementproperty/s/field.php create mode 100644 templates/elementproperty/s/view.php create mode 100644 tests/logger-system/index.php create mode 100644 tests/logger-system/script.js diff --git a/assets/ActionCollection/ActionCollection.js b/assets/ActionCollection/ActionCollection.js index 45fdbd0..bd79b56 100644 --- a/assets/ActionCollection/ActionCollection.js +++ b/assets/ActionCollection/ActionCollection.js @@ -6,7 +6,7 @@ kit.PluginManager.register('ActionCollection', function(module, exports, require /** * @class ActionCollection - * @extends {kit.Collection} + * @extends {Collection} * @memberOf kit */ var ActionCollection = function (list = []) { diff --git a/assets/align/align.js b/assets/align/align.js index 12d3c38..6da0465 100644 --- a/assets/align/align.js +++ b/assets/align/align.js @@ -294,16 +294,16 @@ kit.PluginManager.register('align',function(module, exports, require) { return - this.nodeMetricsLine.offset / 2 + this.offset[this.map.axisNumber()]; }.bind(this), applicability: function () { - return this.limiterMetricsLine.end - (this.parentMetricsLine.start + this.nodeMetricsLine.length + this.shift); + return this.limiterMetricsLine.end - this.limiterMetricsLine.clientEnd - (this.parentMetricsLine.start + this.nodeMetricsLine.length + this.shift); }.bind(this), valid: function () { - return this.limiterMetricsLine.end >= (this.parentMetricsLine.start + this.nodeMetricsLine.length + this.shift); + return this.limiterMetricsLine.end - this.limiterMetricsLine.clientEnd >= (this.parentMetricsLine.start + this.nodeMetricsLine.length + this.shift); }.bind(this), shiftExtra: function () { var shift = getShiftWhenHidingNodeUnderLimiterStart(this.shift); var applicability = 0; if(!this.valid) { - applicability = this.limiterMetricsLine.end - (this.parentMetricsLine.start + this.nodeMetricsLine.length + shift); + applicability = this.limiterMetricsLine.end - this.limiterMetricsLine.clientEnd - (this.parentMetricsLine.start + this.nodeMetricsLine.length + shift); shift = getShiftWhenHidingNodeUnderLimiterStart(shift + applicability); } return shift; @@ -481,7 +481,7 @@ kit.PluginManager.register('align',function(module, exports, require) { /** * @param node {HTMLElement|String} * @param parentNode {HTMLElement|String} - * @param limiterNode {HTMLElement|String} + * @param limiterNode {HTMLElement|String|Window} * @param options {AlignDefault} * @constructor */ diff --git a/assets/bsToastService/bsToastService.js b/assets/bsToastService/bsToastService.js index ddf2629..5fde465 100644 --- a/assets/bsToastService/bsToastService.js +++ b/assets/bsToastService/bsToastService.js @@ -64,9 +64,8 @@ kit.PluginManager.register('bsToastService', function(module, exports, require, this.onShow.eachCall(this, toast, toastNode); }; - /** - * @memberOf kit.service + * @namespace kit.service * @class toast **/ var toast = new Service(); diff --git a/assets/collection/collection.js b/assets/collection/collection.js index 33b384b..8e2e469 100644 --- a/assets/collection/collection.js +++ b/assets/collection/collection.js @@ -13,7 +13,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob } /** * @param type - * @return {kit.Collection} + * @return {Collection} */ function getSimilarInstance(type) { if(type === 'object') { @@ -25,7 +25,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob /** * @class Collection * @property length - * @memberOf kit + * @memberOf {kit} */ var Collection = function (data = []) { var self = this; @@ -114,7 +114,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob /** * @param key * @param value - * @return {kit.Collection} + * @return {Collection} */ Collection.prototype.add = Collection.prototype.set = Collection.prototype.put = function (key, value) { var index = -1; @@ -128,7 +128,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob }; /** * @param value - * @return {kit.Collection} + * @return {Collection} */ Collection.prototype.push = function (value) { this.set(this.__getLastIndex() + 1, value); @@ -151,7 +151,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob * возвращает новый экземпляр коллекции; не изменяет вызываемую коллекцию * * @param callback - * @return {kit.Collection} + * @return {Collection} */ Collection.prototype.map = function (callback) { var res = getSimilarInstance(this.__type); @@ -165,7 +165,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob }; /** * @param callback - * @return {kit.Collection} + * @return {Collection} */ Collection.prototype.each = function (callback = true) { var i; @@ -179,7 +179,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob }; /** * @param callback - * @return {kit.Collection} + * @return {Collection} */ Collection.prototype.eachReverse = function (callback = true) { var i; @@ -193,7 +193,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob }; /** * @param callback - * @return {kit.Collection} + * @return {Collection} */ Collection.prototype.filter = function (callback = filter) { var res = getSimilarInstance(this.__type); @@ -208,7 +208,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob /** * Метод возвращает все элементы коллекции, кроме тех у кого ключи соответствуют заданным * @param keys - * @return {kit.Collection} + * @return {Collection} */ Collection.prototype.except = function (keys) { var __keys = [], iKey; @@ -227,7 +227,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob /** * Метод возвращает элементы коллекции с заданными ключами * @param keys - * @return {kit.Collection} + * @return {Collection} */ Collection.prototype.only = function (keys) { var __keys = [], iKey; @@ -294,7 +294,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob /** * Method removes/delete an item from the collection by its key * @param key - * @return {kit.Collection} + * @return {Collection} */ Collection.prototype.forget = function (key) { key = valueEx(key); @@ -311,7 +311,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob * Method removes and returns an item from the collection by its key * @param key * @param defValue - * @return {kit.Collection} + * @return {Collection} */ Collection.prototype.pull = function (key, defValue = undefined) { key = valueEx(key); @@ -356,20 +356,20 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob return value; }; /** - * @return {kit.Collection} + * @return {Collection} */ Collection.prototype.keys = function () { return new Collection(Object.keys(this.data)); }; /** - * @return {kit.Collection} + * @return {Collection} */ Collection.prototype.dump = function () { console.log('Collection', this.data); return this; }; /** - * @return {kit.Collection} + * @return {Collection} */ Collection.prototype.dd = function () { this.dump(); @@ -377,7 +377,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob return this; }; /** - * @return {kit.Collection} + * @return {Collection} */ Collection.prototype.eachCall = function (context, args1, args2) { var args = [], i; @@ -446,7 +446,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob * Значения в коллекци должны быть массиво подобные * * @param key - * @return {kit.Collection} + * @return {Collection} */ Collection.prototype.pluck = function (key) { return this.map(function (value) { diff --git a/assets/config/config.js b/assets/config/config.js index 3e6cc2a..b4dab7a 100644 --- a/assets/config/config.js +++ b/assets/config/config.js @@ -1,10 +1,15 @@ /** - * @type {kitCore} + * @namespace kit + * @module kit */ -window.kit = window.kit || {}; +var kit; +kit = window.kit = window.kit || {}; /** - * @var kit.config - * @type {kitConfig} + * @typedef kit.service + */ +kit.service = kit.service || {}; +/** + * @typedef kit.config */ kit.config = kit.config || {}; diff --git a/assets/core/core.js b/assets/core/core.js index 887c57e..207ef93 100644 --- a/assets/core/core.js +++ b/assets/core/core.js @@ -1,9 +1,8 @@ -/** - * @class kitCore - * @extends kitCorePlugins - */ -window.kit = window.kit || {}; -window.kit.service = window.kit.service || {}; + +var kit; +kit = window.kit = window.kit || {}; +kit.service = kit.service || {}; +kit.config = kit.config || {}; (function(global){ var stateList = { undefined: 0, diff --git a/assets/core/core.register.js b/assets/core/core.register.js index 9ffd42a..124bb86 100644 --- a/assets/core/core.register.js +++ b/assets/core/core.register.js @@ -83,12 +83,28 @@ __PluginManager__.registerPlugins({ type: 'loader', css: '/tooltip2.css', onInstall: function(plugin){ - var elements = [].slice.call(document.querySelectorAll('[data-kit-tooltip2="autoload"]')); - elements.map(function (element) { - var tooltip = new __pmGlobal__.Tooltip2(element); + console.log('tt2 install'); + document.addEventListener('mouseover', function(event) { + // console.log(event); + // console.log(event.target); + if(!(event.target && event.target.dataset.kitTooltip2 === 'autoload')) { + return; + } + // console.log(1); + if(kit.support.getNodeData(event.target, 'tooltip2')){ + return; + } + // console.log(2); + var tooltip = new __pmGlobal__.Tooltip2(event.target); tooltip.run(); - console.log(tooltip); + tooltip.show(); }); + // var elements = [].slice.call(document.querySelectorAll('[data-kit-tooltip2="autoload"]')); + // elements.map(function (element) { + // var tooltip = new __pmGlobal__.Tooltip2(element); + // tooltip.run(); + // console.log(tooltip); + // }); }, deps: ['Viewer', 'support', 'ActionCollection', 'Action', 'userAction', 'align', 'Collection', 'animations'], }, @@ -227,20 +243,14 @@ __PluginManager__.registerPlugins({ path: __pmConfig__.assetsPath + '/testing', module: '/testing.js', type: 'loader', - deps: ['loggerService'], + deps: ['log'], }, - Logger: { - path: __pmConfig__.assetsPath + '/logger', - module: '/logger.js', + log: { + path: __pmConfig__.assetsPath + '/log', + module: '/log.js', + css: '/log.css', type: 'loader', - deps: ['support', 'Collection'] - }, - loggerService: { - path: __pmConfig__.assetsPath + '/loggerService', - module: '/loggerService.js', - css: '/loggerService.css', - type: 'loader', - deps: ['Logger', 'support', 'Collection'], + deps: ['support', 'Collection', 'lib'] }, fancybox: { path: __pmConfig__.assetsPath + '/fancybox', diff --git a/assets/core/doc.js b/assets/core/doc.js index e9ca16d..e69de29 100644 --- a/assets/core/doc.js +++ b/assets/core/doc.js @@ -1,22 +0,0 @@ -/** - * @typedef kitModuleTypeLoader - * @param module {{exports: Object}} - * @param exports {Object} - * @param require {kitPluginManagerRequire} - * @param global {kitCore} - */ - -/** - * @typedef {Object} kitCorePlugins - * @property {PluginManager} pm - * @property {kitPluginManagerRequire} require - * @property {kitToolkit} toolkit - * @property {kitModal} Modal - * @property {kitConfig} config - * @property {kitPopover} Popover - * @property {kitPopper} popper - */ - -/** - * @namespace kit - */ diff --git a/assets/dataStructures/dataStructures.js b/assets/dataStructures/dataStructures.js index 6fcac56..b4e281e 100644 --- a/assets/dataStructures/dataStructures.js +++ b/assets/dataStructures/dataStructures.js @@ -1,9 +1,46 @@ /** @module dataStructures */ __PluginManager__.register('dataStructures', function(module, exports, require, global){ + + /** + * + * @param context + * @param callback + * @param interval + * @constructor + */ + function Interval(context, callback, interval = 1000){ + /** @private */ + this.context = context || window; + /** @private */ + this.callback = callback; + /** @private */ + this.interval = interval; + + } + Interval.prototype.start = function () { + /** @private */ + this.intervalId = setInterval(function () { + this.callback.apply(this.context, arguments); + }.bind(this), this.interval) + }; + Interval.prototype.stop = function () { + if(this.intervalId){ + clearInterval(this.intervalId); + } + }; + + + + + /** + * Stack – LIFO + * Queue – FIFO + * @type dataStructures * @memberOf kit */ - var dataStructures = { + const dataStructures = { + StackExecutionLimiter: (function () { var stack = function (context, callback, timeout = 1000) { this.counter = 0; @@ -59,7 +96,9 @@ __PluginManager__.register('dataStructures', function(module, exports, require, this.counter = 0; }; return stack; - })() + })(), + + Interval, }; return module.exports = dataStructures; diff --git a/assets/date/date.js b/assets/date/date.js index 92f2cfa..1390d53 100644 --- a/assets/date/date.js +++ b/assets/date/date.js @@ -361,6 +361,21 @@ kit.PluginManager.register('date',function(module, exports, require, global) { date.countTime = countTime; + date.DATA_ATOM = "Y-m-d\TH:i:sP"; + date.DATA_COOKIE = "l, d-M-Y H:i:s T"; + date.DATA_ISO8601 = "Y-m-d\TH:i:sO"; + date.DATA_RFC822 = "D, d M y H:i:s O"; + date.DATA_RFC850 = "l, d-M-y H:i:s T"; + date.DATA_RFC1036 = "D, d M y H:i:s O"; + date.DATA_RFC1123 = "D, d M Y H:i:s O"; + date.DATA_RFC7231 = "D, d M Y H:i:s \G\M\T"; + date.DATA_RFC2822 = "D, d M Y H:i:s O"; + date.DATA_RFC3339 = "Y-m-d\TH:i:sP"; + date.DATA_RFC3339_EXTENDED = "Y-m-d\TH:i:s.vP"; + date.DATA_RSS = "D, d M Y H:i:s O"; + date.DATA_W3C = "Y-m-d\TH:i:sP"; + date.DATA_DB = "Y-m-d H:i:s"; + return date; })); diff --git a/assets/flex-kit/flex-kit.css b/assets/flex-kit/flex-kit.css index 9324521..3a1c0e2 100644 --- a/assets/flex-kit/flex-kit.css +++ b/assets/flex-kit/flex-kit.css @@ -10,7 +10,6 @@ --gap: 10px; --gap-section: 30px; --gap-wrapper: 30px; - --col-count: 4; --col-span: 1; --line-clamp: 3; --line-clamp-height: 1.3em; @@ -92,6 +91,8 @@ -webkit-align-items: stretch; -ms-flex-align: stretch; align-items: stretch; + --col-span: 1; + --col-count: 4; } .flex-list:not(.owl-loaded) { margin-left: calc(var(--gap) / -2) !important; @@ -110,12 +111,13 @@ .flex-list-item { --gap-row: var(--gap); --col-width: calc(100% / var(--col-count) * var(--col-span)); + --line-height: calc(100% / var(--line-count) * var(--line-span, 1)); box-sizing: border-box; } .flex-list > .flex-list-item { - width: var( --col-width) !important; - max-width: var( --col-width) !important; - flex-basis: var( --col-width) !important; + width: var(--col-width) !important; + max-width: var(--col-width) !important; + flex-basis: var(--col-width) !important; margin-bottom: var(--gap-row) !important; } .flex-list-item:before, @@ -149,8 +151,13 @@ -ms-flex-align: center; align-items: center; } - - +.flex-list--static { + --line-count: 1; +} +.flex-list--static .flex-list-item { + height: var(--line-height) !important; + max-height: var(--line-height) !important; +} script, style { display: none !important; @@ -388,35 +395,12 @@ script, style { -webkit-flex-basis: auto; flex-basis: auto; } -.flex-col.flex-cell, -.flex-col-wrap.flex-cell, -.flex-line.flex-cell, -.flex-line-wrap.flex-cell -{ - padding: var(--flex-padding) !important; -} - -.flex-direction-column { - -webkit-flex-direction: column; - -ms-flex-direction: column; - flex-direction: column; -} -.flex-direction-row { - -webkit-box-orient: horizontal; - -webkit-box-direction: normal; - -webkit-flex-direction: row; - -ms-flex-direction: row; - flex-direction: row; -} - - - /* применяем к таблице: ПРОДОЛЬНОЕ выравнивание элементов в строке или колонке */ .flex-align-start { -webkit-justify-content: flex-start !important; @@ -451,6 +435,24 @@ script, style { align-items: center; } +.flex-cells-v-align--start > *{ + justify-content: start; +} +.flex-cells-v-align--end > *{ + justify-content: end; +} +.flex-cells-v-align--stretch > *{ + justify-content: stretch; +} +.flex-cells-g-align--start > *{ + align-items: start; +} +.flex-cells-g-align--end > *{ + align-items: end; +} +.flex-cells-g-align--stretch > *{ + align-items: stretch; +} /* применяем к ячейкам: поперечное выравнивание */ .flex-cell-align--start { @@ -909,7 +911,22 @@ script, style { /* picture - icon */ - +.kit-icon picture, +.kit-icon img, +.kit-icon svg, +.kit-picture picture, +.kit-picture img, +.kit-picture svg { + width: 100%; + height: 100%; + max-width: 100%; + max-height: 100%; + display: block; + fill: currentColor; + transition: inherit; + object-fit: contain; + object-position: center; +} .kit-picture-line, .kit-icon-line { display: inline-block; margin-bottom: calc(-1em * var(--font-ratio-bottom, 0.2)); @@ -934,25 +951,6 @@ script, style { } -.kit-icon picture, -.kit-icon img, -.kit-icon svg, -.kit-picture picture, -.kit-picture img, -.kit-picture svg { - width: 100%; - height: 100%; - max-width: 100%; - max-height: 100%; - display: block; - fill: currentColor; - transition: inherit; - object-fit: contain; - object-position: center; -} - - - /* flex-kit.css end */ \ No newline at end of file diff --git a/assets/loggerService/loggerService.css b/assets/log/log.css similarity index 90% rename from assets/loggerService/loggerService.css rename to assets/log/log.css index 61a5c60..45b040f 100644 --- a/assets/loggerService/loggerService.css +++ b/assets/log/log.css @@ -1,8 +1,8 @@ :root { - --logger-color-emergency: hsl(0, 100%, 55%); - --logger-color-alert: hsl(0, 100%, 55%); - --logger-color-critical: hsl(0, 100%, 55%); - --logger-color-error: #f44336; + --logger-color-emergency: hsl(0, 100%, 25%); + --logger-color-alert: hsl(0, 100%, 45%); + --logger-color-critical: hsl(0, 100%, 40%); + --logger-color-error: hsl(0, 100%, 35%); --logger-color-warning: hsl(31, 100%, 55%); --logger-color-notice: #909090; --logger-color-info: hsl(205, 100%, 61%); @@ -14,7 +14,7 @@ margin: 0; padding: 5px; font-family: monospace; - background: hsla(0, 0%, 11%, 1); + background: hsl(0, 0%, 15%); color: #909090; overflow-y: scroll !important; word-break: break-all; @@ -69,14 +69,21 @@ logger-item { word-break: break-all; font-size: 1em !important; line-height: calc(1.1em) !important; + color: var(--logger-color-value, #c1c1c1); + background-color: var(--logger-color-content-value, transparent); +} +logger-item__options { + color: #606060; } logger-item__value * { color: inherit; } logger-item__value .logger-toggler { cursor: pointer; - color: #2698db !important; + color: hsl(0, 0%, 75%) !important; opacity: 0.6; + font-size: 0.8em !important; + padding-left: 0.5em; } logger-item__msg { @@ -84,7 +91,6 @@ logger-item__msg { logger-item__key { min-width: 2em; padding-right: 5px; - background-color: var(--logger-color-content-key, transparent); } logger-item__key, logger-item__key > * { color: var(--logger-color-key, #909090); @@ -94,8 +100,6 @@ logger-item__key:empty { } logger-item__value { flex: 1 0 0; - color: var(--logger-color-value, #c1c1c1); - background-color: var(--logger-color-content-value, transparent); } logger-item__value * { font-size: inherit !important; diff --git a/assets/log/log.js b/assets/log/log.js new file mode 100644 index 0000000..6417ea4 --- /dev/null +++ b/assets/log/log.js @@ -0,0 +1,296 @@ +/** @module log */ +__PluginManager__.register('log', function(module, exports, require, /** @param {kit}*/global){ + + var support = require('support'); + var Collection = require('Collection'); + var lib = require('lib'); + + var LogLevel = { + EMERGENCY: 'emergency', + ALERT: 'alert', + CRITICAL: 'critical', + ERROR: 'error', + WARNING: 'warning', + NOTICE: 'notice', + INFO: 'info', + DEBUG: 'debug', + SUCCESS: 'success', + }; + + /** + * @class Logger + */ + class Logger + { + constructor() { + this.collection = new Collection(); + this.onLog = new Collection(); + } + } + + + /** + * @param collection {kit.Collection} + */ + Logger.prototype.setCollection = function (collection) { + this.collection = collection; + }; + + Logger.prototype.emergency = function (message, context) { + this.log(LogLevel.EMERGENCY, message, context); + }; + Logger.prototype.alert = function (message, context) { + this.log(LogLevel.ALERT, message, context); + }; + Logger.prototype.critical = function (message, context) { + this.log(LogLevel.CRITICAL, message, context); + }; + Logger.prototype.error = function (message, context) { + this.log(LogLevel.ERROR, message, context); + }; + Logger.prototype.warning = function (message, context) { + this.log(LogLevel.WARNING, message, context); + }; + Logger.prototype.notice = function (message, context) { + this.log(LogLevel.NOTICE, message, context); + }; + Logger.prototype.info = function (message, context) { + this.log(LogLevel.INFO, message, context); + }; + Logger.prototype.debug = function (message, context) { + this.log(LogLevel.DEBUG, message, context); + }; + Logger.prototype.success = function (message, context) { + this.log(LogLevel.SUCCESS, message, context); + }; + Logger.prototype.log = function (level, message, context = []) { + var data = { + level: level, + message: message, + context: context, + }; + this.__logData(data); + }; + Logger.prototype.__logData = function (data) { + this.collection.push(data); + this.onLog.eachCall(this, data); + }; + + const HINT_DATA_KEY_LIST = ['id', 'createdAt', 'userId', 'ip']; + function getTooltipContent(data) { + var contentList = []; + HINT_DATA_KEY_LIST.map(function (item) { + if(data[item]){contentList.push(item+': ' + data[item]);} + }); + return contentList.join('
'); + } + function getOptionsTemplate(data) { + var optionsTemplate = ''; + var content = getTooltipContent(data); + if(content) { + optionsTemplate = ''+ + lib.svg.options+ + ''; + } + return optionsTemplate; + } + + function getRowNode(key, value, level = '', data = { + id: 0, + createdAt: '', + userId: '', + }){ + key = String(key); + value = String(value); + var result = '' + + ''+key+'' + + ''+value+'' + + getOptionsTemplate(data) + + ''; + + return support.makeNode(result); + } + + function getLoggerLogNode(id = ''){ + var entity = '', css = '', style = ''; + return support.makeNode(''); + } + function getLoggerPairNode(depth = 1){ + return support.makeNode(''); + } + + function getLoggerAdditionalHtml(html = ''){ + return ''+html+''; + } + + function getLoggerToggerHtml(id, html = ''){ + return ''; + } + + function getContextNode(id = ''){ + var entity = '', css = '', style = ''; + if(id) { + css = ''; + entity = ' data-entity-id="'+id+'"'; + style = ' style="display: none"' + } + return support.makeNode(''+css+''); + } + + /** + * @extends Logger + * @class LoggerVisual + * @param nodeOrSelector + * @param maxDepth + * @param openDepth + */ + class LoggerVisual extends Logger + { + constructor(nodeOrSelector = '', maxDepth = 3, openDepth = 1){ + super(); + /** + * @type {Element} + * @private + */ + this.__htmlCollection = support.getNode(nodeOrSelector); + if(this.__htmlCollection) { + support.data.set(this.__htmlCollection, 'log', this); + } + this.__maxDepth = support.toNumber(maxDepth, 3); + this.__openDepth = support.toNumber(openDepth, 1); + + this.onLog.push(this.__logHandler); + this.__htmlCollectionTemplater = '
'; + } + } + + + /** + * + * @return {HTMLElement} + */ + LoggerVisual.prototype.getHtmlCollection = function() { + if (!this.__htmlCollection) { + /** + * @type {HTMLElement} + */ + this.__htmlCollection = document.getElementById('kit-logger') || document.querySelector('.kit-logger') || support.makeNode(this.__htmlCollectionTemplater); + + if((this.__htmlCollection instanceof HTMLElement) && !this.__htmlCollection.parentElement) { + document.body.appendChild(this.__htmlCollection) + } + if(this.__htmlCollection) { + support.data.set(this.__htmlCollection, 'log', this); + } + } + + return this.__htmlCollection; + }; + + function getPairNode(depth, key, value, logLevel, maxDepth = 6, openDepth = 1, isRoot = true, data = {}) { + var pairNode = getLoggerPairNode(depth); + var contextNode, + isIterable = support.isIterable(value), + isEmptyValue = support.empty(value), + id = isIterable?support.uniqueId():'', + skipValue = value === window || value === document, + valueType = support.getType(value), + len = isIterable?Object.keys(value).length:0, + lenPrint = isIterable?' [' + Object.keys(value).length + ']':'', + val = value,inp, j; + + if(support.isIterable(value)){ + + if(value === window) { + val = 'window ' + getLoggerAdditionalHtml(valueType); + } else if(value === document) { + val = 'document ' + getLoggerAdditionalHtml(valueType); + } else { + if(isRoot && support.empty(value)){ + val = ''; + } else + if(len){ + if(maxDepth){ + val = getLoggerToggerHtml(id, valueType + lenPrint) + } else { + val = getLoggerAdditionalHtml(valueType + lenPrint); + } + } else { + val = getLoggerAdditionalHtml(valueType + ' empty'); + } + } + } + if(isIterable&&maxDepth&&!skipValue) { + pairNode.appendChild(inp = support.makeNode('')); + inp.checked = !!openDepth; + } + + if(support.isIterable(key)){ + pairNode.appendChild(x = getRowNode('', '' + val, logLevel)); + x.querySelector('logger-item__key').appendChild(getPairNode(depth, null, key, logLevel, 1, 1, isRoot)); + } else { + if(!(isRoot&&support.isUndefined(key))) { + pairNode.appendChild(getRowNode(key, '' + val, logLevel, data)); + } + } + + if(isIterable&&maxDepth&&!skipValue) { + if(!(isRoot&&support.isUndefined(key))) { + ++depth; + } + maxDepth = Math.max(0, maxDepth - 1); + openDepth = Math.max(0, openDepth - 1); + pairNode.appendChild(contextNode = getContextNode(id)); + for(j in value) { + if(value.hasOwnProperty(j)) { + contextNode.appendChild(getPairNode(depth, j, value[j], '', maxDepth, openDepth, false)); + } + } + } + return pairNode; + } + + LoggerVisual.prototype.__logHandler = function(data = { + level: '', + message: '', + context: [], + }){ + var logCollectionNode = this.getHtmlCollection(); + var loggerLogNode = getLoggerLogNode(); + loggerLogNode.appendChild(getPairNode(1, data.message, data.context, data.level, this.__maxDepth, this.__openDepth, true, data)); + logCollectionNode.appendChild(loggerLogNode); + logCollectionNode.scrollTop = logCollectionNode.scrollHeight; + }; + + LoggerVisual.prototype.logList = function (logList) { + var self = this; + logList = new Collection(logList); + logList.map(function (log) { + self.__logData(log); + }); + }; + + /** + * @var logger + * @memberOf {kit.service} + * @type LoggerVisual + */ + global.service.logger = new LoggerVisual(); + + /** + * @memberOf kit + */ + var log = { + Logger, + LogLevel, + LoggerVisual + }; + return module.exports = log; +}); diff --git a/assets/logger/logger.js b/assets/logger/logger.js deleted file mode 100644 index 69c339e..0000000 --- a/assets/logger/logger.js +++ /dev/null @@ -1,73 +0,0 @@ -/** @module Logger */ -__PluginManager__.register('Logger', function(module, exports, require, global){ - - var support = require('support'); - var Collection = require('Collection'); - - var LogLevel = { - EMERGENCY: 'emergency', - ALERT: 'alert', - CRITICAL: 'critical', - ERROR: 'error', - WARNING: 'warning', - NOTICE: 'notice', - INFO: 'info', - DEBUG: 'debug', - SUCCESS: 'success', - }; - - /** - * @class Logger - * @memberOf kit - */ - var Logger = function() { - this.collection = new Collection(); - this.onLog = new Collection(); - }; - - /** - * @param collection {kit.Collection} - */ - Logger.prototype.setCollection = function (collection) { - this.collection = collection; - }; - - Logger.prototype.emergency = function (message, context) { - this.log(LogLevel.EMERGENCY, message, context); - }; - Logger.prototype.alert = function (message, context) { - this.log(LogLevel.ALERT, message, context); - }; - Logger.prototype.critical = function (message, context) { - this.log(LogLevel.CRITICAL, message, context); - }; - Logger.prototype.error = function (message, context) { - this.log(LogLevel.ERROR, message, context); - }; - Logger.prototype.warning = function (message, context) { - this.log(LogLevel.WARNING, message, context); - }; - Logger.prototype.notice = function (message, context) { - this.log(LogLevel.NOTICE, message, context); - }; - Logger.prototype.info = function (message, context) { - this.log(LogLevel.INFO, message, context); - }; - Logger.prototype.debug = function (message, context) { - this.log(LogLevel.DEBUG, message, context); - }; - Logger.prototype.success = function (message, context) { - this.log(LogLevel.SUCCESS, message, context); - }; - Logger.prototype.log = function (level, message, context = []) { - var data = { - level: level, - message: message, - context: context, - }; - this.collection.push(data); - this.onLog.eachCall(this, data); - }; - - return module.exports = Logger; -}); diff --git a/assets/loggerService/loggerService.js b/assets/loggerService/loggerService.js deleted file mode 100644 index c59e63c..0000000 --- a/assets/loggerService/loggerService.js +++ /dev/null @@ -1,165 +0,0 @@ -/** @module loggerService */ -__PluginManager__.register('loggerService', function(module, exports, require, global){ - - var support = require('support'); - var Logger = require('Logger'); - var Collection = require('Collection'); - - function getRowNode(key, value, level = ''){ - key = String(key); - value = String(value); - var result = ''+key+''+value+''; - - return support.makeNode(result); - } - - function getLoggerLogNode(id = ''){ - var entity = '', css = '', style = ''; - return support.makeNode(''); - } - function getLoggerPairNode(depth = 1){ - return support.makeNode(''); - } - - function getLoggerAdditionalHtml(html = ''){ - return ''+html+''; - } - - function getLoggerToggerHtml(id, html = ''){ - return ''; - } - - function getContextNode(id = ''){ - var entity = '', css = '', style = ''; - if(id) { - css = ''; - entity = ' data-entity-id="'+id+'"'; - style = ' style="display: none"' - } - return support.makeNode(''+css+''); - } - - - - /** - * @extends kit.Logger - * @class LoggerService - * @memberOf kit - */ - var LoggerService = function() { - Logger.prototype.constructor.apply(this, arguments); - this.onLog.push(this.__logHandler); - this.__htmlCollectionTemplater = '
'; - }; - - support.extend(LoggerService.prototype, Logger.prototype); - - LoggerService.prototype.getHtmlCollection = function() { - var node; - if (!this.__htmlCollection) { - /** - * @type {HTMLElement} - */ - this.__htmlCollection = node || document.getElementById('kit-logger') || document.querySelector('.kit-logger') || support.makeNode(this.__htmlCollectionTemplater); - - if((this.__htmlCollection instanceof HTMLElement) && !this.__htmlCollection.parentElement) { - document.body.appendChild(this.__htmlCollection) - } - } - - return this.__htmlCollection; - }; - - function getPairNode(depth, key, value, logLevel, maxDepth = 3, openDepth = 1, isRoot = true) { - var pairNode = getLoggerPairNode(depth); - var contextNode, - isIterable = support.isIterable(value), - isEmptyValue = support.empty(value), - id = isIterable?support.uniqueId():'', - skipValue = value === window || value === document, - valueType = support.getType(value), - len = isIterable?Object.keys(value).length:0, - lenPrint = isIterable?' [' + Object.keys(value).length + ']':'', - val = value,inp, j; - - if(support.isIterable(value)){ - - if(value === window) { - val = 'window ' + getLoggerAdditionalHtml(valueType); - } else if(value === document) { - val = 'document ' + getLoggerAdditionalHtml(valueType); - } else { - if(isRoot && support.empty(value)){ - val = ''; - } else - if(len){ - if(maxDepth){ - val = getLoggerToggerHtml(id, valueType + lenPrint) - } else { - val = getLoggerAdditionalHtml(valueType + lenPrint); - } - } else { - val = getLoggerAdditionalHtml(valueType + ' empty'); - } - } - } - if(isIterable&&maxDepth&&!skipValue) { - pairNode.appendChild(inp = support.makeNode('')); - inp.checked = !!openDepth; - } - - if(support.isIterable(key)){ - pairNode.appendChild(x = getRowNode('', '' + val, logLevel)); - x.querySelector('logger-item__key').appendChild(getPairNode(depth, null, key, logLevel, 1, 1, isRoot)); - } else { - if(!(isRoot&&support.isUndefined(key))) { - pairNode.appendChild(getRowNode(key, '' + val, logLevel)); - } - } - - if(isIterable&&maxDepth&&!skipValue) { - if(!(isRoot&&support.isUndefined(key))) { - ++depth; - } - maxDepth = Math.max(0, maxDepth - 1); - openDepth = Math.max(0, openDepth - 1); - pairNode.appendChild(contextNode = getContextNode(id)); - for(j in value) { - if(value.hasOwnProperty(j)) { - contextNode.appendChild(getPairNode(depth, j, value[j], logLevel, maxDepth, openDepth, false)); - } - } - } - return pairNode; - } - - LoggerService.prototype.__logHandler = function(data = { - level: '', - message: '', - context: [], - }){ - var logCollectionNode = this.getHtmlCollection(); - var loggerLogNode = getLoggerLogNode(); - loggerLogNode.appendChild(getPairNode(1, data.message, data.context, data.level, 6, 3)); - logCollectionNode.appendChild(loggerLogNode); - logCollectionNode.scrollTop = logCollectionNode.scrollHeight; - }; - - LoggerService.prototype.logList = function (logList) { - var self = this; - logList = new Collection(logList); - logList.map(function (log) { - self.log(log.level, log.message, log.context); - }); - }; - - /** - * @memberOf kit.service - * @class logger - **/ - var logger = new LoggerService(); - - global.service.logger = logger; - - module.exports = logger; -}); diff --git a/assets/menu/menu.js b/assets/menu/menu.js index e486d2a..98669a1 100644 --- a/assets/menu/menu.js +++ b/assets/menu/menu.js @@ -95,8 +95,7 @@ __PluginManager__.register('menu',function(module, exports, require, global) { this.node.classList.add(MENU_CLASS); this.node.style.display = 'none'; this.node.setAttribute('data-menu-id', this.id); - this.node.kit = this.node.kit || {}; - this.node.kit[MENU_PLUGIN_NAME] = this; + support.setNodeData(this.node, MENU_PLUGIN_NAME, this); }; diff --git a/assets/support/support.js b/assets/support/support.js index 4e72e94..184a8e1 100644 --- a/assets/support/support.js +++ b/assets/support/support.js @@ -3,6 +3,7 @@ __PluginManager__.register('support', function(module, exports, require, global) window.pre = console.log; + const KIT_DATA_PREFIX = 'kit'; var data = function(){ function normalizeData(val) { @@ -30,6 +31,12 @@ __PluginManager__.register('support', function(module, exports, require, global) } const manipulator = { + /** + * @param element {HTMLElement} + * @param key + * @param value + * @param prefix + */ set(element, key, value, prefix = 'kit') { if(prefix !== '') { prefix = '-' + prefix; @@ -78,10 +85,71 @@ __PluginManager__.register('support', function(module, exports, require, global) }(); + var num = { + round, + ceil, + floor, + }; + function round(num, decimals = 0) { + num = toNumber(num); + decimals = toNumber(decimals); + var k = Math.pow(10, decimals); + num = Math.round(k * num) / k; + return num; + } + function ceil(num, decimals = 0) { + num = toNumber(num); + decimals = toNumber(decimals); + var k = Math.pow(10, decimals); + num = Math.ceil(k * num) / k; + return num; + } + function floor(num, decimals = 0) { + num = toNumber(num); + decimals = toNumber(decimals); + var k = Math.pow(10, decimals); + num = Math.floor(k * num) / k; + return num; + } + var node = { isRelate: function (node, container = document) { return node === container || container.contains(node); - } + }, + /** + * @param node {HTMLElement} + * @return {[]} + */ + getChainOfParents: function getChainOfParents(node) { + var chain = []; + if(!isNode(node)){ + return chain; + } + node = node.parentNode; + while(node){ + chain.push(node); + node = node.parentNode; + } + return chain; + }, + /** + * @param node {HTMLElement} + * @return {[]} + */ + getChainOfParentsWithNode: function getChainOfParentsWithNode(node) { + var chain = []; + if(!isNode(node)){ + return chain; + } + while(node){ + chain.push(node); + node = node.parentNode; + } + return chain; + }, + isInPage: function (node) { + return (node === document.body) ? false : document.body.contains(node); + }, }; var str = { ucFirst: function (str) { @@ -252,9 +320,7 @@ __PluginManager__.register('support', function(module, exports, require, global) return nodeWrap.childNodes; } function setNodeData(node, key, value) { - if(!isElement(node)) return false; - node.kit = node.kit || {}; - node.kit[key] = value; + return setObjProp(node, [KIT_DATA_PREFIX, key], value); } function setObjProp(object, branch, value) { if(!Array.isArray(branch)) { @@ -279,15 +345,10 @@ __PluginManager__.register('support', function(module, exports, require, global) return result; } function getNodeData(node, key, def = null) { - if(!Array.isArray(key)) { - key = [key]; - } - var branch = ['kit'].concat(key); - return getObjProp(node, branch, def); + return getObjProp(node, [KIT_DATA_PREFIX, key], def); } - function getObjProp(object, branch, def = null) { - if(!Array.isArray(branch)) { + if(!isArray(branch)) { branch = [branch]; } if(!isObject(object)) return def; @@ -387,6 +448,7 @@ __PluginManager__.register('support', function(module, exports, require, global) node: node, str: str, arr: arr, + num: num, uniqueId, valueEx, empty, diff --git a/assets/testing/testing.js b/assets/testing/testing.js index e7f60ca..690e3a6 100644 --- a/assets/testing/testing.js +++ b/assets/testing/testing.js @@ -1,13 +1,13 @@ /** @module testing */ __PluginManager__.register('testing', function(module, exports, require, global){ - var loggerService = require('loggerService'); + // var loggerService = require('loggerService'); /** * @constructor */ function Unit() { - this.logger = loggerService; + this.logger = kit.service.logger; } /** diff --git a/assets/tooltip2/tooltip2.js b/assets/tooltip2/tooltip2.js index 756e8ad..34f7697 100644 --- a/assets/tooltip2/tooltip2.js +++ b/assets/tooltip2/tooltip2.js @@ -59,6 +59,12 @@ kit.PluginManager.register('Tooltip2',function(module, exports, require, global) if(!support.isElement(this.hintNode)){ console.warn('Tooltip2: masterNode not valid', this.hintNode); } + + if(!support.getNodeData(this.masterNode, PLUGIN_NAME)){ + support.setNodeData(this.masterNode, PLUGIN_NAME, this); + support.data.set(this.masterNode, PLUGIN_NAME, 'loaded'); + } + this.hintNode.remove(); this.masterNode.appendChild(this.hintNode); //support.setNodeData(this.masterNode, PLUGIN_NAME, this); @@ -67,7 +73,25 @@ kit.PluginManager.register('Tooltip2',function(module, exports, require, global) this.setContent(this.options.content); } - this.align = new align.Class(this.hintNode, this.masterNode); + var limiter = window; + var chain = support.node.getChainOfParentsWithNode(this.masterNode); + + chain.every(function(node, i){ + if(node === document.body || node.tagName === 'HTML' || node === document){ + limiter = window; + return false; + } + limiter = node; + var style = getComputedStyle(node); + var overflowX = style.overflowX; + var overflowY = style.overflowY; + if(!(overflowX === 'visible' || overflowX === 'auto') || !(overflowY === 'visible' || overflowY === 'auto')){ + return false; + } + return true; + }); + + this.align = new align.Class(this.hintNode, this.masterNode, limiter); var hint = new userAction.Hint(this.masterNode, this.hintNode); this.viewer = hint.viewer; this.viewer.delayHide = 400; @@ -117,6 +141,12 @@ kit.PluginManager.register('Tooltip2',function(module, exports, require, global) this.__setOffset(); this.align.set(this.options.hAlign, this.options.vAlign, this.options.hDirection, this.options.vDirection); } + }; + __proto.show = function(){ + this.viewer.show(); + }; + __proto.hide = function(){ + }; /** * @param options {Tooltip2Default} diff --git a/assets/userAction/userAction.js b/assets/userAction/userAction.js index 93b6d6f..ce00eb7 100644 --- a/assets/userAction/userAction.js +++ b/assets/userAction/userAction.js @@ -63,13 +63,12 @@ kit.PluginManager.register('userAction', function(module, exports, require, glob /** - * + * @class * @param masterNode * @param slaveNode - * @return {Hint} * @constructor */ - var Hint = function (masterNode, slaveNode) { + function Hint (masterNode, slaveNode) { this.__setMasterNode(masterNode); this.__setSlaveNode(slaveNode); this.viewer = new Viewer(this.__slaveNode, this.__masterNode); @@ -156,8 +155,11 @@ kit.PluginManager.register('userAction', function(module, exports, require, glob * @memberOf kit */ var userAction = { - Popover: Popover, - Hint: Hint, + Popover, + /** + * @type {Hint} + */ + Hint, }; return module.exports = userAction; diff --git a/templates/elementproperty/s/field.php b/templates/elementproperty/s/field.php new file mode 100644 index 0000000..777a473 --- /dev/null +++ b/templates/elementproperty/s/field.php @@ -0,0 +1,72 @@ +getContext(); +$blockId = $elementPropertyEntity->getFactory()->getIBlockId(); +$code = $elementPropertyEntity->getCode(); +$fieldId = 'iblock_' . $blockId . '_prop_' . $code; +/** + * @var array $arParams + */ + +use Wt\Core\Templater\Tools as TemplaterTools; +use Wt\Core\Tools; + + +$arParams['TYPE'] = $arParams['TYPE'] ?: 'hidden'; +$isReadonly = Tools::isTrue($arParams['READONLY']); +$isRequired = $elementPropertyEntity->isRequired(); +$hidden = Tools::isTrue($arParams['HIDDEN']); +$isHint = $elementPropertyEntity->getHint() !== ''; +$dirty = $arParams['PLACEHOLDER'] || mb_strlen($code); +$name = "FORM[iblock][$blockId]{$elementPropertyEntity->getCode()}]"; + + +?> + +
+ readonly required id="" + data-dirty="" + type="text" + name="" + class="kit-field__input kit-field--success kit-field--error" + value="getValue()) ?>" + maxlength="255" + placeholder="" + + autocomplete="off">service()->templater()->render('kit:field/hint', ['TITLE' => $elementPropertyEntity->getHint()]); + } + ?> + +
+
+
+getContext(); +if(!$elementPropertyEntity->isMultiple()){ + echo $elementPropertyEntity->getDisplayValue(); +} else { + echo implode(', ', $elementPropertyEntity->getDisplayValue()); +} \ No newline at end of file diff --git a/tests/dateTest.php b/tests/dateTest.php index 1e7acbd..c71a751 100644 --- a/tests/dateTest.php +++ b/tests/dateTest.php @@ -28,7 +28,7 @@ $APPLICATION->ShowHead(); x = setInterval(function() { for(let i=0; i + + + + + +
+
+
+
+
+
+
+
+ + +
+
+
+
+ +
+
+
+ + + diff --git a/tests/logger-system/script.js b/tests/logger-system/script.js new file mode 100644 index 0000000..65be14d --- /dev/null +++ b/tests/logger-system/script.js @@ -0,0 +1,23 @@ +kit.ready(['flexKit', 'log', 'dataStructures', 'jQuery', 'date'], function () { + + window.loggerList = window.loggerList || {}; + window.loggerList.full = new kit.log.LoggerVisual('.kit-logger--full', 3, 0); + window.loggerList.full.notice(kit.date(kit.date.DATA_DB)); + var lastId = 0; + + var interval = new kit.dataStructures.Interval(null, function () { + kit.jQuery + .ajax('/ajax/LoggerSystemAjax/filter?>id=' + lastId) + .done(function(response){ + var data = response.data || {}; + var logs = new kit.Collection(data); + logs.map(function (data) { + console.log(data); + lastId = Math.max(lastId, data['id']); + window.loggerList[data.level].__logData(data); + }); + window.loggerList.full.logList(data); + }); + }, 5000); + interval.start(); +}); \ No newline at end of file