1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*!
* @package yii2-widget-activeform
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright © Kartik Visweswaran, Krajee.com, 2015 - 2018
* @version 1.4.9
*
* Active Field Hints Display Module
*
* Author: Kartik Visweswaran
* Copyright: 2015, Kartik Visweswaran, Krajee.com
* For more JQuery plugins visit http://plugins.krajee.com
* For more Yii related demos visit http://demos.krajee.com
*/
(function ($) {
"use strict";
var isEmpty = function (value, trim) {
return value === null || value === undefined || value === [] || value === '' || trim && $.trim(value) === '';
},
NAMESPACE = '.kvActiveField',
ActiveFieldHint = function (element, options) {
var self = this;
self.$element = $(element);
$.each(options, function (key, val) {
self[key] = val;
});
self.init();
};
ActiveFieldHint.prototype = {
constructor: ActiveFieldHint,
init: function () {
var self = this, $el = self.$element, $block = $el.find('.kv-hint-block'), content = $block.html(),
$hints = $el.find('.kv-hintable'), $span;
$block.hide();
if (isEmpty(content)) {
return;
}
if (!isEmpty(self.contentCssClass)) {
$span = $(document.createElement('span')).addClass(self.contentCssClass).append(content);
$span = $(document.createElement('span')).append($span);
content = $span.html();
$span.remove();
}
$hints.each(function () {
var $src = $(this);
if ($src.hasClass('kv-type-label')) {
$src.removeClass(self.labelCssClass).addClass(self.labelCssClass);
} else {
$src.removeClass('hide ' + self.iconCssClass).addClass(self.iconCssClass);
}
if ($src.hasClass('kv-hint-click')) {
self.listen('click', $src, content);
}
if ($src.hasClass('kv-hint-hover')) {
self.listen('hover', $src, content);
}
});
if (self.hideOnEscape) {
$(document).on('keyup', function (e) {
$hints.each(function () {
var $src = $(this);
if (e.which === 27) {
$src.popover('hide');
}
});
});
}
if (self.hideOnClickOut) {
$('body').on('click', function (e) {
$hints.each(function () {
var $src = $(this);
if (!$src.is(e.target) && $src.has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
$src.popover('hide');
}
});
});
}
},
listen: function (event, $src, content) {
var self = this, opts = {
html: true,
trigger: 'manual',
content: content,
title: self.title,
placement: self.placement,
container: self.container || false,
animation: !!self.animation,
delay: self.delay,
selector: self.selector
};
if (!isEmpty(self.template)) {
opts.template = self.template;
}
if (!isEmpty(self.viewport)) {
opts.viewport = self.viewport;
}
$src.popover(opts);
if (event === 'click') {
self.raise($src, 'click', function (e) {
e.preventDefault();
$src.popover('toggle');
});
return;
}
self.raise($src, 'mouseenter', function () {
$src.popover('show');
});
self.raise($src, 'mouseleave', function () {
$src.popover('hide');
});
},
raise: function ($elem, event, callback) {
event = event + NAMESPACE;
$elem.off(event).on(event, callback);
}
};
//ActiveFieldHint plugin definition
$.fn.activeFieldHint = function (option) {
var args = Array.apply(null, arguments);
args.shift();
return this.each(function () {
var $this = $(this),
data = $this.data('activeFieldHint'),
options = typeof option === 'object' && option;
if (!data) {
$this.data('activeFieldHint',
(data = new ActiveFieldHint(this, $.extend({}, $.fn.activeFieldHint.defaults, options, $(this).data()))));
}
if (typeof option === 'string') {
data[option].apply(data, args);
}
});
};
$.fn.activeFieldHint.defaults = {
labelCssClass: 'kv-hint-label',
iconCssClass: 'kv-hint-icon',
contentCssClass: 'kv-hint-content',
hideOnEscape: false,
hideOnClickOut: false,
title: '',
placement: 'right',
container: 'form',
delay: 0,
animation: true,
selector: false,
template: '',
viewport: ''
};
})(window.jQuery);