mirror of
https://bitbucket.org/bellord13/kit.git
synced 2026-11-13 19:06:11 +03:00
fix
This commit is contained in:
+45
-1
@@ -467,14 +467,31 @@ kit.PluginManager.register('align',function(module, exports, require) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @class AlignDefault
|
||||
*/
|
||||
const Default = {
|
||||
hAlign: 'center',
|
||||
vAlign: 'top',
|
||||
hDirection: 'center',
|
||||
vDirection: 'top',
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param node {HTMLElement|String}
|
||||
* @param parentNode {HTMLElement|String}
|
||||
* @param limiterNode {HTMLElement|String}
|
||||
* @param options {AlignDefault}
|
||||
* @constructor
|
||||
*/
|
||||
var AlignClass = function(node, parentNode, limiterNode = window)
|
||||
var AlignClass = function(node, parentNode, limiterNode = window, options = {})
|
||||
{
|
||||
/**
|
||||
* @type {AlignDefault}
|
||||
*/
|
||||
this.options = Object.assign({}, Default, options);
|
||||
|
||||
this.changeOfDirection = true;
|
||||
this.withinTheScreen = true;
|
||||
this.offset = [0, 0];
|
||||
@@ -495,6 +512,9 @@ kit.PluginManager.register('align',function(module, exports, require) {
|
||||
AlignClass.prototype.setNode = function(node){
|
||||
this.unset();
|
||||
this.node = support.getNode(node);
|
||||
if(!support.isElement(this.node)){
|
||||
console.warn('Align: node is not valid');
|
||||
}
|
||||
this.reset();
|
||||
if(this.node instanceof HTMLElement) {
|
||||
this.node.kit = this.node.kit || {};
|
||||
@@ -512,6 +532,9 @@ kit.PluginManager.register('align',function(module, exports, require) {
|
||||
*/
|
||||
AlignClass.prototype.setParentNode = function(node){
|
||||
this.parentNode = support.getNode(node);
|
||||
if(!support.isElement(this.parentNode)){
|
||||
console.warn('Align: parentNode is not valid');
|
||||
}
|
||||
if(this.__calc) {
|
||||
this.__calc.setParentNode(this.parentNode);
|
||||
}
|
||||
@@ -520,6 +543,9 @@ kit.PluginManager.register('align',function(module, exports, require) {
|
||||
|
||||
AlignClass.prototype.setLimiterNode = function(node){
|
||||
this.limiterNode = support.getNode(node) || window;
|
||||
if(!support.isElement(this.limiterNode) && this.limiterNode !== window){
|
||||
console.warn('Align: limiterNode is not valid');
|
||||
}
|
||||
if(this.__calc) {
|
||||
this.__calc.setLimiterNode(this.limiterNode);
|
||||
}
|
||||
@@ -569,17 +595,35 @@ kit.PluginManager.register('align',function(module, exports, require) {
|
||||
* @return {AlignClass}
|
||||
*/
|
||||
AlignClass.prototype.set = function(hAlign, vAlign, hDirection, vDirection){
|
||||
|
||||
this.options.hAlign = hAlign;
|
||||
this.options.vAlign = vAlign;
|
||||
this.options.hDirection = hDirection;
|
||||
this.options.vDirection = vDirection;
|
||||
|
||||
this.setEx('vertical', vAlign, vDirection);
|
||||
this.setEx('horizontal', hAlign, hDirection);
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
AlignClass.prototype.setOptions = function(options){
|
||||
Object.assign(this.options, options);
|
||||
this.setEx('vertical', this.options.vAlign, this.options.vDirection);
|
||||
this.setEx('horizontal', this.options.hAlign, this.options.hDirection);
|
||||
return this;
|
||||
};
|
||||
|
||||
AlignClass.prototype.setVertical = function(align, direction){
|
||||
this.options.vAlign = align;
|
||||
this.options.vDirection = direction;
|
||||
this.setEx('vertical', align, direction);
|
||||
return this;
|
||||
};
|
||||
|
||||
AlignClass.prototype.setHorizontal = function(align, direction){
|
||||
this.options.hAlign = align;
|
||||
this.options.hDirection = direction;
|
||||
this.setEx('horizontal', align, direction);
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -137,7 +137,7 @@ __PluginManager__.register('support', function(module, exports, require, global)
|
||||
var nodeWrap = document.createElement('div');
|
||||
nodeWrap.innerHTML = html;
|
||||
var r = nodeWrap.firstChild;
|
||||
r.remove();
|
||||
r && r.remove();
|
||||
return r;
|
||||
}
|
||||
function makeNodeList(html = '') {
|
||||
|
||||
@@ -3,6 +3,7 @@ kit.PluginManager.register('Tooltip2',function(module, exports, require, global)
|
||||
|
||||
var Viewer = require('Viewer');
|
||||
var support = require('support');
|
||||
var Collection = require('Collection');
|
||||
var ActionCollection = require('ActionCollection');
|
||||
var Action = require('Action');
|
||||
var userAction = require('userAction');
|
||||
@@ -11,7 +12,15 @@ kit.PluginManager.register('Tooltip2',function(module, exports, require, global)
|
||||
|
||||
const PLUGIN_NAME = 'tooltip2';
|
||||
|
||||
/**
|
||||
* @class Tooltip2Default
|
||||
*/
|
||||
const Default = {
|
||||
hAlign: 'center',
|
||||
vAlign: 'top',
|
||||
hDirection: 'center',
|
||||
vDirection: 'top',
|
||||
offset: 10,
|
||||
template: '<div class="tooltip" role="tooltip" style="display: none">' +
|
||||
//'<div class="tooltip-arrow" data-popper-arrow="true"></div>' +
|
||||
'<div class="tooltip-inner"></div>' +
|
||||
@@ -23,21 +32,32 @@ kit.PluginManager.register('Tooltip2',function(module, exports, require, global)
|
||||
* @memberOf kit
|
||||
* @param masterNode
|
||||
* @param hintNode
|
||||
* @param options
|
||||
* @constructor
|
||||
*/
|
||||
var Tooltip2 = function(masterNode, hintNode) {
|
||||
var Tooltip2 = function(masterNode, hintNode, options = {}) {
|
||||
var self = this;
|
||||
var masterOptions = {};
|
||||
/**
|
||||
* @type {Tooltip2Default}
|
||||
*/
|
||||
this.options = Object.assign({}, Default, masterOptions, options);
|
||||
this.masterNode = support.getNode(masterNode);
|
||||
if(!support.isElement(this.masterNode)){
|
||||
console.warn('Tooltip2: masterNode not valid', this.masterNode);
|
||||
}
|
||||
this.hintNode = support.getNode(hintNode);
|
||||
if(!this.hintNode) {
|
||||
this.hintNode = support.makeNode(Default.template);
|
||||
this.hintNode = support.makeNode(this.options.template);
|
||||
}
|
||||
if(!support.isElement(this.hintNode)){
|
||||
console.warn('Tooltip2: masterNode not valid', this.hintNode);
|
||||
}
|
||||
this.hintNode.remove();
|
||||
this.masterNode.appendChild(this.hintNode);
|
||||
support.setNodeData(this.masterNode, PLUGIN_NAME, this);
|
||||
//support.setNodeData(this.masterNode, PLUGIN_NAME, this);
|
||||
|
||||
this.align = new align.Class(this.hintNode, this.masterNode);
|
||||
this.align.offset = [0, 10];
|
||||
var hint = new userAction.Hint(this.masterNode, this.hintNode);
|
||||
this.viewer = hint.viewer;
|
||||
this.viewer.delayHide = 400;
|
||||
@@ -53,6 +73,19 @@ kit.PluginManager.register('Tooltip2',function(module, exports, require, global)
|
||||
|
||||
var __proto = Tooltip2.prototype;
|
||||
|
||||
var vDirection = new Collection(['top', 'bottom']);
|
||||
var hDirection = new Collection(['left', 'right']);
|
||||
|
||||
__proto.__setOffset = function(){
|
||||
var offset = this.options.offset;
|
||||
this.align.offset = [0, 0];
|
||||
var directions = new Collection([this.options.hDirection, this.options.vDirection]);
|
||||
if(hDirection.includes(this.options.hDirection) || directions.includes('start'))
|
||||
this.align.offset[0] = offset;
|
||||
if(vDirection.includes(this.options.vDirection) || directions.includes('end'))
|
||||
this.align.offset[1] = offset;
|
||||
};
|
||||
|
||||
__proto.setContent = function(html = ''){
|
||||
var titleNode = this.hintNode.querySelector('.tooltip-inner');
|
||||
support.innerHtml(titleNode, html);
|
||||
@@ -70,7 +103,17 @@ kit.PluginManager.register('Tooltip2',function(module, exports, require, global)
|
||||
support.setNodeData(this.masterNode, PLUGIN_NAME, null);
|
||||
};
|
||||
__proto.render = function(){
|
||||
this.align.set('center', 'top', 'center', 'top');
|
||||
if(this.viewer.isShown()) {
|
||||
this.__setOffset();
|
||||
this.align.set(this.options.hAlign, this.options.vAlign, this.options.hDirection, this.options.vDirection);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @param options {Tooltip2Default}
|
||||
*/
|
||||
__proto.setOptions = function(options){
|
||||
Object.assign(this.options, options);
|
||||
this.render();
|
||||
};
|
||||
|
||||
module.exports = Tooltip2;
|
||||
|
||||
Reference in New Issue
Block a user