update 2023-04-10

This commit is contained in:
2023-04-10 11:25:34 +07:00
parent 9e890303ba
commit b64325d3c6
12 changed files with 1703 additions and 592 deletions
+532 -445
View File
@@ -1,450 +1,537 @@
!(function (t) {
var e = {};
function s(i) {
if (e[i]) return e[i].exports;
var o = (e[i] = { i: i, l: !1, exports: {} });
return t[i].call(o.exports, o, o.exports, s), (o.l = !0), o.exports;
var __extends = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var BaseResolver = (function () {
function BaseResolver(options) {
this._settings = $.extend(true, {}, this.getDefaults(), options);
}
(s.m = t),
(s.c = e),
(s.d = function (t, e, i) {
s.o(t, e) || Object.defineProperty(t, e, { enumerable: !0, get: i });
}),
(s.r = function (t) {
"undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(t, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(t, "__esModule", { value: !0 });
}),
(s.t = function (t, e) {
if ((1 & e && (t = s(t)), 8 & e)) return t;
if (4 & e && "object" == typeof t && t && t.__esModule) return t;
var i = Object.create(null);
if ((s.r(i), Object.defineProperty(i, "default", { enumerable: !0, value: t }), 2 & e && "string" != typeof t))
for (var o in t)
s.d(i,
o,
function (e) {
return t[e];
}.bind(null, o)
);
return i;
}),
(s.n = function (t) {
var e = t && t.__esModule
? function () {
return t.default;
}
: function () {
return t;
};
return s.d(e, "a", e), e;
}),
(s.o = function (t, e) {
return Object.prototype.hasOwnProperty.call(t, e);
}),
(s.p = ""), s((s.s = 0));
})([
function (t, e, s) {
"use strict";
s.r(e),
s.d(e, "AutoComplete", function () {
return a;
BaseResolver.prototype.getDefaults = function () {
return {};
};
BaseResolver.prototype.getResults = function (limit, start, end) {
return this.results;
};
BaseResolver.prototype.search = function (q, cbk) {
cbk(this.getResults());
};
return BaseResolver;
}());
var AjaxResolver = (function (_super) {
__extends(AjaxResolver, _super);
function AjaxResolver(options) {
return _super.call(this, options) || this;
}
AjaxResolver.prototype.getDefaults = function () {
return {
url: '',
method: 'post',
queryKey: 'Auto_Query',
extraData: {},
timeout: 0,
requestThrottling: 500
};
};
AjaxResolver.prototype.search = function (q, cbk) {
var _this = this;
if (this.jqXHR != null) {
this.jqXHR.abort();
}
var data = {};
data[this._settings.queryKey] = q;
$.extend(data, this._settings.extraData);
if (this.requestTID) {
window.clearTimeout(this.requestTID);
}
this.requestTID = window.setTimeout(function () {
_this.jqXHR = $.ajax(_this._settings.url, {
method: _this._settings.method,
data: data,
timeout: _this._settings.timeout
});
_this.jqXHR.done(function (result) {
//gnips: result in object
cbk((undefined !== result.autodata) ? result.autodata : result);
});
_this.jqXHR.fail(function (err) {
var _a;
(_a = _this._settings) === null || _a === void 0 ? void 0 : _a.fail(err);
});
_this.jqXHR.always(function () {
_this.jqXHR = null;
});
}, this._settings.requestThrottling);
};
return AjaxResolver;
}(BaseResolver));
var DropdownV5 = (function () {
function DropdownV5(e, formatItemCbk, autoSelect, noResultsText) {
this.initialized = false;
this.shown = false;
this.items = [];
this.ddMouseover = false;
this._$el = e;
this.formatItem = formatItemCbk;
this.autoSelect = autoSelect;
this.noResultsText = noResultsText;
}
DropdownV5.prototype.getElPos = function () {
var pos = $.extend({}, this._$el.position(), {
height: this._$el[0].offsetHeight
});
var i,
o = ((i = function (t, e) {
return (i =
Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array &&
function (t, e) {
t.__proto__ = e;
}) ||
function (t, e) {
for (var s in e) e.hasOwnProperty(s) && (t[s] = e[s]);
})(t, e);
}),
function (t, e) {
function s() {
this.constructor = t;
return pos;
};
DropdownV5.prototype.init = function () {
var _this = this;
var pos = this.getElPos();
this._dd = $('<div />');
this._dd.addClass('bootstrap-autocomplete dropdown-menu');
this._dd.insertAfter(this._$el);
this._dd.css({ top: pos.top + this._$el.outerHeight(), left: pos.left, width: this._$el.outerWidth() });
this._dd.on('click', '.dropdown-item', function (evt) {
//console.log('clicked', evt.currentTarget);
//console.log($(evt.currentTarget));
var item = $(evt.currentTarget).data('item');
_this.itemSelectedLaunchEvent(item);
evt.preventDefault();
});
this._dd.on('keyup', function (evt) {
if (_this.shown) {
switch (evt.which) {
case 27:
_this.hide();
_this._$el.focus();
break;
}
return false;
}
});
this._dd.on('mouseenter', function (evt) {
_this.ddMouseover = true;
});
this._dd.on('mouseleave', function (evt) {
_this.ddMouseover = false;
});
this._dd.on('mouseenter', '.dropdown-item', function (evt) {
if (_this.haveResults) {
$(evt.currentTarget).closest('div').find('.dropdown-item.active').removeClass('active');
$(evt.currentTarget).addClass('active');
_this.mouseover = true;
}
});
this._dd.on('mouseleave', '.dropdown-item', function (evt) {
_this.mouseover = false;
});
this.initialized = true;
};
DropdownV5.prototype.checkInitialized = function () {
if (!this.initialized) {
this.init();
}
};
Object.defineProperty(DropdownV5.prototype, "isMouseOver", {
get: function () {
return this.mouseover;
},
enumerable: false,
configurable: true
});
Object.defineProperty(DropdownV5.prototype, "isDdMouseOver", {
get: function () {
return this.ddMouseover;
},
enumerable: false,
configurable: true
});
Object.defineProperty(DropdownV5.prototype, "haveResults", {
get: function () {
return (this.items.length > 0);
},
enumerable: false,
configurable: true
});
DropdownV5.prototype.focusNextItem = function (reversed) {
if (this.haveResults) {
var currElem = this._dd.find('.dropdown-item.active');
var nextElem = reversed ? currElem.prev() : currElem.next();
if (nextElem.length === 0) {
nextElem = reversed ? this._dd.find('.dropdown-item').last() : this._dd.find('.dropdown-item').first();
}
currElem.removeClass('active');
nextElem.addClass('active');
this.scrollTo(nextElem);
}
};
DropdownV5.prototype.focusPreviousItem = function () {
this.focusNextItem(true);
};
DropdownV5.prototype.selectFocusItem = function () {
this._dd.find('.dropdown-item.active').trigger('click');
};
Object.defineProperty(DropdownV5.prototype, "isItemFocused", {
get: function () {
if (this._dd && this.isShown() && (this._dd.find('.dropdown-item.active').length > 0)) {
return true;
}
return false;
},
enumerable: false,
configurable: true
});
DropdownV5.prototype.show = function () {
if (!this.shown) {
this._dd.addClass('show');
this.shown = true;
this._$el.trigger('autocomplete.dd.shown');
}
};
DropdownV5.prototype.isShown = function () {
return this.shown;
};
DropdownV5.prototype.hide = function () {
if (this.shown) {
this._dd.removeClass('show');
this.shown = false;
this._$el.trigger('autocomplete.dd.hidden');
}
};
DropdownV5.prototype.updateItems = function (items, searchText) {
this.items = items;
this.searchText = searchText;
this.refreshItemList();
};
DropdownV5.prototype.showMatchedText = function (text, qry) {
var startIndex = text.toLowerCase().indexOf(qry.toLowerCase());
if (startIndex > -1) {
var endIndex = startIndex + qry.length;
return text.slice(0, startIndex) + '<b>'
+ text.slice(startIndex, endIndex) + '</b>'
+ text.slice(endIndex);
}
return text;
};
DropdownV5.prototype.refreshItemList = function () {
var _this = this;
this.checkInitialized();
this._dd.empty();
var liList = [];
if (this.items.length > 0) {
this.items.forEach(function (item) {
var itemFormatted = _this.formatItem(item);
if (typeof itemFormatted === 'string') {
itemFormatted = { text: itemFormatted };
}
var itemText;
var itemHtml;
itemText = _this.showMatchedText(itemFormatted.text, _this.searchText);
if (itemFormatted.html !== undefined) {
itemHtml = itemFormatted.html;
}
else {
itemHtml = itemText;
}
var disabledItem = itemFormatted.disabled;
var li = $('<a >');
li.addClass('dropdown-item')
//css bisa dimasukkan ke style default + cursor select
//.css({ 'overflow': 'hidden', 'text-overflow': 'ellipsis' })
.html(itemHtml)
.data('item', item);
if (disabledItem) {
li.addClass('disabled');
}
liList.push(li);
});
this._dd.append(liList);
this.show();
}
else {
if (this.noResultsText === '') {
this.hide();
}
else {
var li = $('<a >');
li.addClass('dropdown-item disabled')
.html(this.noResultsText);
liList.push(li);
this._dd.append(liList);
this.show();
}
}
};
DropdownV5.prototype.itemSelectedLaunchEvent = function (item) {
this._$el.trigger('autocomplete.select', item);
};
DropdownV5.prototype.scrollTo = function (el) {
var _he = this._dd.height(), _to = this._dd.scrollTop(), _ito = el.position().top, _ihe = el.outerHeight(),
_nto = _to, _wra = false;
if (_ito < 0){
_wra = el.is(':first-child');
_nto = _wra ? 0 : _to - _he / 2;
} else if (_ito > _he - _ihe) {
_wra = el.is(':last-child') && _ito > _he;
_nto = _wra ? (_ito + _ihe - _he) : _to + _he / 2;
}
this._dd.scrollTop(_nto);
};
return DropdownV5;
}());
var AutoComplete = (function () {
function AutoComplete(element, options) {
this._selectedItem = null;
this._defaultValue = null;
this._defaultText = null;
this._settings = {
resolver: 'ajax',
resolverSettings: {},
minLength: 3,
valueKey: 'value',
formatResult: this.defaultFormatResult,
autoSelect: true,
noResultsText: 'Pencarian Tidak Ketemu',
preventEnter: false,
events: {
typed: null,
searchPre: null,
search: null,
searchPost: null,
select: null,
focus: null,
},
//gnips: adding callback and keydown function
selectFunc: function(){},
keydownFunc: function(){}
};
this._el = element;
this._$el = $(this._el);
this.manageInlineDataAttributes();
if (typeof options === 'object') {
this._settings = $.extend(true, {}, this.getSettings(), options);
}
this.init();
}
AutoComplete.prototype.manageInlineDataAttributes = function () {
var s = this.getSettings();
if (this._$el.data('url')) {
s.resolverSettings.url = this._$el.data('url');
}
if (this._$el.data('default-value')) {
this._defaultValue = this._$el.data('default-value');
}
if (this._$el.data('default-text')) {
this._defaultText = this._$el.data('default-text');
}
if (this._$el.data('noresults-text') !== undefined) {
s.noResultsText = this._$el.data('noresults-text');
}
};
AutoComplete.prototype.getSettings = function () {
return this._settings;
};
AutoComplete.prototype.init = function () {
this.bindDefaultEventListeners();
if (this._settings.resolver === 'ajax') {
this.resolver = new AjaxResolver(this._settings.resolverSettings);
}
this._dd = new DropdownV5(this._$el, this._settings.formatResult, this._settings.autoSelect, this._settings.noResultsText);
};
AutoComplete.prototype.bindDefaultEventListeners = function () {
var _this = this;
this._$el.on('keydown', function (evt) {
//gnips: call keydown function
('' == _this._$el.val() && _this._settings.keydownFunc(evt.which));
switch (evt.which) {
case 9:
if (_this._dd.isItemFocused) {
_this._dd.selectFocusItem();
}
i(t, e), (t.prototype = null === e ? Object.create(e) : ((s.prototype = e.prototype), new s()));
}),
n = (function (t) {
function e(e) {
return t.call(this, e) || this;
}
return (
o(e, t),
(e.prototype.getDefaults = function () {
return { url: "", method: "post", queryKey: "Auto_Query", extraData: {}, timeout: void 0, requestThrottling: 500 };
}),
(e.prototype.search = function (t, e) {
var s = this;
null != this.jqXHR && this.jqXHR.abort();
var i = {};
(i[this._settings.queryKey] = t),
$.extend(i, this._settings.extraData),
this.requestTID && window.clearTimeout(this.requestTID),
(this.requestTID = window.setTimeout(function () {
(s.jqXHR = $.ajax(s._settings.url, { method: s._settings.method, data: i, timeout: s._settings.timeout })),
s.jqXHR.done(function (t) {
var v;
(v = void 0 !== t.autodata ? t.autodata : t), e(v);
}),
s.jqXHR.fail(function (t) {
var e;
null === (e = s._settings) || void 0 === e || e.fail(t);
}),
s.jqXHR.always(function () {
s.jqXHR = null;
});
}, this._settings.requestThrottling));
}),
e
);
})(
(function () {
function t(t) {
this._settings = $.extend(!0, {}, this.getDefaults(), t);
_this._dd.hide();
break;
case 13:
if (_this._dd.isItemFocused) {
_this._dd.selectFocusItem();
}
return (
(t.prototype.getDefaults = function () {
return {};
}),
(t.prototype.getResults = function (t, e, s) {
return this.results;
}),
(t.prototype.search = function (t, e) {
e(this.getResults());
}),
t
);
})()
),
l = (function () {
function t(t, e, s, i) {
(this.initialized = !1), (this.shown = !1), (this.items = []), (this.ddMouseover = !1), (this._$el = t), (this.formatItem = e), (this.autoSelect = s), (this.noResultsText = i);
}
return (
(t.prototype.getElPos = function () {
return $.extend({}, this._$el.position(), { height: this._$el[0].offsetHeight });
}),
(t.prototype.init = function () {
var t = this, e = this.getElPos();
(this._dd = $("<div />")),
this._dd.addClass("bs-fonac dropdown-menu"),
this._dd.insertAfter(this._$el),
this._dd.css({ cssText: 'width: '+this._$el.outerWidth()+'px !important', top: e.top + this._$el.outerHeight(), left: e.left }),
this._dd.on("click", ".dropdown-item", function (e) {
var s = $(e.currentTarget).data("item");
t.itemSelectedLaunchEvent(s), e.preventDefault();
}),
this._dd.on("keyup", function (e) {
if (t.shown) {
switch (e.which) {
case 27:
t.hide(), t._$el.focus();
}
return !1;
}
}),
this._dd.on("mouseenter", function (e) {
t.ddMouseover = !0;
}),
this._dd.on("mouseleave", function (e) {
t.ddMouseover = !1;
}),
this._dd.on("mouseenter", ".dropdown-item", function (e) {
t.haveResults && ($(e.currentTarget).closest("div").find(".dropdown-item.active").removeClass("active"), $(e.currentTarget).addClass("active"), (t.mouseover = !0));
}),
this._dd.on("mouseleave", ".dropdown-item", function (e) {
t.mouseover = !1;
}),
(this.initialized = !0);
}),
(t.prototype.checkInitialized = function () {
this.initialized || this.init();
}),
Object.defineProperty(t.prototype, "isMouseOver", {
get: function () {
return this.mouseover;
},
enumerable: !1,
configurable: !0,
}),
Object.defineProperty(t.prototype, "isDdMouseOver", {
get: function () {
return this.ddMouseover;
},
enumerable: !1,
configurable: !0,
}),
Object.defineProperty(t.prototype, "haveResults", {
get: function () {
return this.items.length > 0;
},
enumerable: !1,
configurable: !0,
}),
(t.prototype.focusNextItem = function (t) {
if (this.haveResults) {
var e = this._dd.find(".dropdown-item.active"),
s = t ? e.prev() : e.next();
0 === s.length && (s = t ? this._dd.find(".dropdown-item").last() : this._dd.find(".dropdown-item").first()), e.removeClass("active"), s.addClass("active");
}
}),
(t.prototype.focusPreviousItem = function () {
this.focusNextItem(!0);
}),
(t.prototype.selectFocusItem = function () {
this._dd.find(".dropdown-item.active").trigger("click");
}),
Object.defineProperty(t.prototype, "isItemFocused", {
get: function () {
return !!(this._dd && this.isShown() && this._dd.find(".dropdown-item.active").length > 0);
},
enumerable: !1,
configurable: !0,
}),
(t.prototype.show = function () {
if (!this.shown) {
this.getElPos();
this._dd.addClass("show"), (this.shown = !0), this._$el.trigger("autocomplete.dd.shown");
}
}),
(t.prototype.isShown = function () {
return this.shown;
}),
(t.prototype.hide = function () {
this.shown && (this._dd.removeClass("show"), (this.shown = !1), this._$el.trigger("autocomplete.dd.hidden"));
}),
(t.prototype.updateItems = function (t, e) {
(this.items = t), (this.searchText = e), this.refreshItemList();
}),
(t.prototype.showMatchedText = function (t, e) {
var s = t.toLowerCase().indexOf(e.toLowerCase());
if (s > -1) {
var i = s + e.length;
return t.slice(0, s) + "<b>" + t.slice(s, i) + "</b>" + t.slice(i);
}
return t;
}),
(t.prototype.refreshItemList = function () {
var t = this;
this.checkInitialized(), this._dd.empty();
var e = [];
if (this.items.length > 0)
this.items.forEach(function (s) {
var i, o, n = t.formatItem(s);
"string" == typeof n && (n = { text: n }),
(i = void 0 !== n.html ? n.html : n.text),
(o = t.showMatchedText(i, t.searchText));
var r = n.disabled, l = $("<a >");
l.addClass("dropdown-item").css({ overflow: "hidden", "text-overflow": "ellipsis" }).html(o).data("item", s), r && l.addClass("disabled"), e.push(l);
}),
this._dd.append(e),
this.show();
else if ("" === this.noResultsText) this.hide();
else {
var s = $("<a >");
s.addClass("dropdown-item disabled").html(this.noResultsText), e.push(s), this._dd.append(e), this.show();
}
}),
(t.prototype.itemSelectedLaunchEvent = function (t) {
this._$el.trigger("autocomplete.select", t);
}),
t
);
})(),
a = (function () {
function t(t, e) {
(this._selectedItem = null),
(this._defaultValue = null),
(this._defaultText = null),
(this._isSelectElement = !1),
(this._settings = {
resolver: "ajax",
resolverSettings: {},
minLength: 3,
valueKey: "value",
formatResult: this.defaultFormatResult,
autoSelect: !0,
noResultsText: "Tidak ditemukan data",
bootstrapVersion: "4",
preventEnter: !1,
events: { typed: null, searchPre: null, search: null, searchPost: null, select: null, focus: null },
keydownFunc: function(){},//gnips
}),
(this._el = t),
(this._$el = $(this._el)),
this._$el.is("select") && (this._isSelectElement = !0),
this.manageInlineDataAttributes(),
"object" == typeof e && (this._settings = $.extend(!0, {}, this.getSettings(), e)),
this._isSelectElement && this.convertSelectToText(),
this.init();
}
return (
(t.prototype.manageInlineDataAttributes = function () {
var t = this.getSettings();
this._$el.data("url") && (t.resolverSettings.url = this._$el.data("url")),
this._$el.data("default-value") && (this._defaultValue = this._$el.data("default-value")),
this._$el.data("default-text") && (this._defaultText = this._$el.data("default-text")),
void 0 !== this._$el.data("noresults-text") && (t.noResultsText = this._$el.data("noresults-text"));
}),
(t.prototype.getSettings = function () {
return this._settings;
}),
(t.prototype.getBootstrapVersion = function () {
var t;
"4" === this._settings.bootstrapVersion ? (t = [4])
: (console.error("INVALID value for 'bootstrapVersion' settings property: " + this._settings.bootstrapVersion + " defaulting to 4"), (t = [4]));
return t;
}),
(t.prototype.convertSelectToText = function () {
var e = $("<input>");
e.attr("type", "hidden"), e.attr("id", this._$el.attr("id")+'_AutoVal'), this._defaultValue && e.val(this._defaultValue), (this._selectHiddenField = e), e.insertAfter(this._$el);
var s = $("<input>");
s.attr("type", "search"),
s.attr("id", this._$el.attr("id")),
s.attr("disabled", this._$el.attr("disabled")),
s.attr("placeholder", this._$el.attr("placeholder")),
s.attr("autocomplete", "off"),
s.addClass(this._$el.attr("class")),
this._defaultText && s.val(this._defaultText);
var i = this._$el.attr("required");
i && s.attr("required", i), s.data(t.NAME, this), this._$el.replaceWith(s), (this._$el = s), (this._el = s.get(0));
}),
(t.prototype.init = function () {
this.bindDefaultEventListeners(),
"ajax" === this._settings.resolver && (this.resolver = new n(this._settings.resolverSettings)),
(this._dd = new l(this._$el, this._settings.formatResult, this._settings.autoSelect, this._settings.noResultsText));
}),
(t.prototype.bindDefaultEventListeners = function () {
var t = this;
this._$el.on("keydown", function (e) {
("" == t._$el.val() && t._settings.keydownFunc(e.which));//gnips
switch (e.which) {
case 9:
t._dd.isItemFocused ? t._dd.selectFocusItem() : t._selectedItem || ("" !== t._$el.val() && t._$el.trigger("autocomplete.freevalue", t._$el.val())), t._dd.hide();
break;
case 13:
t._dd.isItemFocused ? t._dd.selectFocusItem() : t._selectedItem || ("" !== t._$el.val() && t._$el.trigger("autocomplete.freevalue", t._$el.val())),
t._dd.hide(),
t._settings.preventEnter && e.preventDefault();
break;
case 40:
t._dd.focusNextItem();
break;
case 38:
t._dd.focusPreviousItem();
}
}),
this._$el.on("keyup", function (e) {
switch (e.which) {
case 16:
case 17:
case 18:
case 39:
case 37:
case 36:
case 35:
break;
case 13:
case 27:
t._dd.hide();
break;
case 40:
case 38:
break;
default:
t._selectedItem = null;
var s = t._$el.val();
t.handlerTyped(s);
}
}),
this._$el.on("blur", function (e) {
!t._dd.isMouseOver && t._dd.isDdMouseOver && t._dd.isShown()
? (setTimeout(function () {
t._$el.focus();
}),
t._$el.focus())
: t._dd.isMouseOver ||
/*(t._isSelectElement
? t._dd.isItemFocused
? t._dd.selectFocusItem()
: null !== t._selectedItem && "" !== t._$el.val()
? t._$el.trigger("autocomplete.select", t._selectedItem)
: "" !== t._$el.val() && null !== t._defaultValue
? (t._$el.val(t._defaultText), t._selectHiddenField.val(t._defaultValue), (t._selectedItem = null), t._$el.trigger("autocomplete.select", t._selectedItem))
: (t._$el.val(""), t._selectHiddenField.val(""), (t._selectedItem = null), t._$el.trigger("autocomplete.select", t._selectedItem))
: null === t._selectedItem && t._$el.trigger("autocomplete.freevalue", t._$el.val()),
t._dd.hide());*/ t._dd.hide();
}),
this._$el.on("autocomplete.select", function (e, s) {
(t._selectedItem = s), t.itemSelectedDefaultHandler(s);
}),
this._$el.on("paste", function (e) {
setTimeout(function () {
t._$el.trigger("keyup", e);
}, 0);
});
}),
(t.prototype.handlerTyped = function (t) {
(null === this._settings.events.typed || (t = this._settings.events.typed(t, this._$el))) && (t.length >= this._settings.minLength ? ((this._searchText = t), this.handlerPreSearch()) : this._dd.hide());
}),
(t.prototype.handlerPreSearch = function () {
if (null !== this._settings.events.searchPre) {
var t = this._settings.events.searchPre(this._searchText, this._$el);
if (!t) return;
this._searchText = t;
}
this.handlerDoSearch();
}),
(t.prototype.handlerDoSearch = function () {
var t = this;
null !== this._settings.events.search
? this._settings.events.search(
this._searchText,
function (e) {
t.postSearchCallback(e);
},
this._$el
)
: this.resolver &&
this.resolver.search(this._searchText, function (e) {
t.postSearchCallback(e);
});
}),
(t.prototype.postSearchCallback = function (t) {
(this._settings.events.searchPost && "boolean" == typeof (t = this._settings.events.searchPost(t, this._$el)) && !t) || this.handlerStartShow(t);
}),
(t.prototype.handlerStartShow = function (t) {
if (1 == t.length && 1 == (void 0 !== t[0].bc ? t[0].bc : 0)) {
this._$el.trigger("autocomplete.select", t[0]),
this._dd.hide();
} else this._dd.updateItems(t, this._searchText);
}),
(t.prototype.itemSelectedDefaultHandler = function (t) {
if (null != t) {
var e = this._settings.formatResult(t);
"string" == typeof e && (e = { text: e }), this._$el.val(e.text), this._isSelectElement && this._selectHiddenField.val(e.value);
} else this._$el.val(""), this._isSelectElement && this._selectHiddenField.val("");
(this._selectedItem = t), this._dd.hide();
}),
(t.prototype.defaultFormatResult = function (t) {
return "string" == typeof t ? { text: t } : t.text ? t : { text: t.toString() };
}),
(t.prototype.manageAPI = function (t, e) {
"set" === t ? this.itemSelectedDefaultHandler(e) : "clear" === t ? this.itemSelectedDefaultHandler(null) : "show" === t ? this._$el.trigger("keyup") : "updateResolver" === t && (this.resolver = new n(e));
}),
(t.NAME = "autoComplete"),
t
);
})();
!(function (t, e, s) {
t.fn[a.NAME] = function (e, s) {
return this.each(function () {
var i;
(i = t(this).data(a.NAME)) || ((i = new a(this, e)), t(this).data(a.NAME, i)), i.manageAPI(e, s);
_this._dd.hide();
if (_this._settings.preventEnter) {
evt.preventDefault();
}
break;
case 40:
_this._dd.focusNextItem();
break;
case 38:
_this._dd.focusPreviousItem();
break;
}
});
this._$el.on('keyup', function (evt) {
switch (evt.which) {
case 16:
case 17:
case 18:
case 39:
case 37:
case 36:
case 35:
break;
case 13:
_this._dd.hide();
break;
case 27:
_this._dd.hide();
break;
case 40:
break;
case 38:
break;
default:
_this._selectedItem = null;
var newValue = _this._$el.val();
_this.handlerTyped(newValue);
}
});
this._$el.on('blur', function (evt) {
if (!_this._dd.isMouseOver && _this._dd.isDdMouseOver && _this._dd.isShown()) {
setTimeout(function () { _this._$el.focus(); });
_this._$el.focus();
}
else if (!_this._dd.isMouseOver) {
_this._dd.hide();
}
});
this._$el.on('autocomplete.select', function (evt, item) {
_this._selectedItem = item;
_this.itemSelectedDefaultHandler(item);
});
this._$el.on('paste', function (evt) {
setTimeout(function () {
_this._$el.trigger('keyup', evt);
}, 0);
});
};
AutoComplete.prototype.handlerTyped = function (newValue) {
if (this._settings.events.typed !== null) {
newValue = this._settings.events.typed(newValue, this._$el);
if (!newValue) {
return;
}
}
if (newValue.length >= this._settings.minLength) {
this._searchText = newValue;
this.handlerPreSearch();
}
else {
this._dd.hide();
}
};
AutoComplete.prototype.handlerPreSearch = function () {
if (this._settings.events.searchPre !== null) {
var newValue = this._settings.events.searchPre(this._searchText, this._$el);
if (!newValue)
return;
this._searchText = newValue;
}
this.handlerDoSearch();
};
AutoComplete.prototype.handlerDoSearch = function () {
var _this = this;
if (this._settings.events.search !== null) {
this._settings.events.search(this._searchText, function (results) {
_this.postSearchCallback(results);
}, this._$el);
}
else {
if (this.resolver) {
this.resolver.search(this._searchText, function (results) {
_this.postSearchCallback(results);
});
};
})(jQuery, window, document);
},
]);
}
}
};
AutoComplete.prototype.postSearchCallback = function (results) {
if (this._settings.events.searchPost) {
results = this._settings.events.searchPost(results, this._$el);
if ((typeof results === 'boolean') && !results)
return;
}
this.handlerStartShow(results);
};
AutoComplete.prototype.handlerStartShow = function (results) {
//gnips: adding auto select when barcode result of 1 item only
if (1 == results.length && 1 == (void 0 !== results[0].bc ? results[0].bc : 0)) {
this._$el.trigger('autocomplete.select', results[0]),
this._dd.hide();
} else this._dd.updateItems(results, this._searchText);
};
AutoComplete.prototype.itemSelectedDefaultHandler = function (item) {
if (item != null) {
var itemFormatted = this._settings.formatResult(item);
if (typeof itemFormatted === 'string') {
itemFormatted = { text: itemFormatted };
}
this._$el.val(itemFormatted.text);
}
else {
this._$el.val('');
}
this._selectedItem = item;
//gnips: callback with selected item
this._settings.selectFunc(item);
this._dd.hide();
};
AutoComplete.prototype.defaultFormatResult = function (item) {
if (typeof item === 'string') {
return { text: item };
}
else if (item.text) {
return item;
}
else {
return { text: item.toString() };
}
};
AutoComplete.prototype.manageAPI = function (APICmd, params) {
if (APICmd === 'set') {
this.itemSelectedDefaultHandler(params);
}
else if (APICmd === 'clear') {
this.itemSelectedDefaultHandler(null);
}
else if (APICmd === 'show') {
this._$el.trigger('keyup');
}
else if (APICmd === 'updateResolver') {
this.resolver = new AjaxResolver(params);
}
};
AutoComplete.NAME = 'autoComplete';
return AutoComplete;
}());
(function ($, window, document) {
$.fn[AutoComplete.NAME] = function (optionsOrAPI, optionalParams) {
return this.each(function () {
var pluginClass;
pluginClass = $(this).data(AutoComplete.NAME);
if (!pluginClass) {
pluginClass = new AutoComplete(this, optionsOrAPI);
$(this).data(AutoComplete.NAME, pluginClass);
}
pluginClass.manageAPI(optionsOrAPI, optionalParams);
});
};
})(jQuery, window, document);
+34 -72
View File
@@ -4,9 +4,9 @@
Desc. : JS - Fonia Custom Class v3
Created By : Siau Pheng ([email protected]).
Created Date : June 19th, 2009.
Last Modified : May 3rd, 2022.
Last Modified : March 24th, 2023.
(c) 2009 - 2022, 3FONIA Software; WWW.3FONIA.COM.
(c) 2009 - 2023, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
@@ -105,7 +105,7 @@ var FoniaJS = {
url: this.WEB_PATH + "apps/php/" + apop.php,
sendParam: ["data=default"],
onSuccess: function(txt) {
this.showWindowDetail(apop.kode, apop.title, txt, apop.width, apop.button, 'static', function(){
this.showWindow(apop.kode, apop.title, txt, apop.width, apop.button, function(){
if (typeof window[apop.func]['loading'] === 'function') window[apop.func]['loading'](q);
});
}.bind(this)
@@ -341,21 +341,19 @@ var FoniaJS = {
}
return smenu;
},
FormDecorated: function() {
$("input").each(function() {
if ($(this).hasClass("integer") || $(this).hasClass("angka")) {
FormDecorated: function() {//oke
$('input').each(function() {
// 16:shift 17:ctrl 18:alt 35:end 36:home 37:left 38:up 39:right 40:down 9:tab 13:enter 27:esc
// 8:backspace 46:delete 45:delete 48-57/96-105:num 110/190:dot 109/189/173:minus 107/187/61:plus
if ($(this).hasClass('integer') || $(this).hasClass('angka')) {
$(this).keydown(function(e) {
var key = e.charCode || e.keyCode || 0;
return (key==8 || key==9 || key==13 || key==46 || key==110 || key==190 || (key>=35 && key<=40) || (key>=48 && key<=57) || (key>=96 && key<=105));
// allow backspace, tab, delete, enter, arrows, numbers and keypad numbers ONLY
// home, end, period, and numpad decimal
var key = e.keyCode ?? e.which;
return (jQuery.inArray(key,[8,9,13,46,110,190])!==-1 || (key>=16 && key<=18) || (key>=35 && key<=40) || (key>=48 && key<=57) || (key>=96 && key<=105));
});
} else if ($(this).hasClass("number")) {
} else if ($(this).hasClass('number')) {
$(this).keydown(function(e) {
var key = e.charCode || e.keyCode || 0;
return (key==8 || key==9 || key==13 || key==46 || key==110 || key==190 || (key>=35 && key<=40) || (key>=48 && key<=57) || (key>=96 && key<=105) || key==109 || key==173);
// allow backspace, tab, delete, enter, arrows, numbers and keypad numbers ONLY
// home, end, period, numpad decimal, minus, minus-ff
var key = e.keyCode ?? e.which;
return (jQuery.inArray(key,[8,9,13,46,110,190,109,189,173])!==-1 || (key>=16 && key<=18) || (key>=35 && key<=40) || (key>=48 && key<=57) || (key>=96 && key<=105));
});
$(this).focus(function() {
$(this).val( FoniaJS.StrToFloat($(this).val()) );
@@ -363,36 +361,10 @@ var FoniaJS = {
$(this).blur(function() {
$(this).val( FoniaJS.FloatToStr($(this).val(), 0) );
});
} else if ($(this).hasClass("double")) {
} else if ($(this).hasClass('double')) {
$(this).keydown(function(e) {
var key = e.charCode || e.keyCode || 0;
return (key==8 || key==9 || key==13 || key==46 || key==110 || key==190 || (key>=35 && key<=40) || (key>=48 && key<=57) || (key>=96 && key<=105) || key==109 || key==173);
// allow backspace, tab, delete, enter, arrows, numbers and keypad numbers ONLY
// home, end, period, numpad decimal, minus, minus-ff
/*var ctrlDown = false;
var ctrlKey = 17, vKey = 86, cKey = 67;
if (e.keyCode === ctrlKey){
ctrlDown = true;
}
// Allow: backspace, delete, tab, escape, enter and .
if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110]) !== -1 ||
// Allow: Ctrl
(e.keyCode === ctrlKey) ||
// Allow: Ctrl+A
(e.keyCode === 65 && e.ctrlKey === true) ||
// Allow: Ctrl+v
(e.keyCode === vKey && ctrlDown) ||
// Allow: Ctrl+c
(e.keyCode === cKey && ctrlDown) ||
// Allow: home, end, left, right, down, up
(e.keyCode >= 35 && e.keyCode <= 40)) {
// let it happen, don't do anything
return;
}
// Ensure that it is a number and stop the keypress
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
e.preventDefault();
}*/
var key = e.keyCode ?? e.which;
return (jQuery.inArray(key,[8,9,13,46,110,190,109,189,173])!==-1 || (key>=16 && key<=18) || (key>=35 && key<=40) || (key>=48 && key<=57) || (key>=96 && key<=105));
});
$(this).focus(function() {
$(this).val( FoniaJS.StrToFloat($(this).val()) );
@@ -401,14 +373,12 @@ var FoniaJS = {
$(this).blur(function() {
$(this).val( FoniaJS.FloatToStr($(this).val(), 2) );
});
} else if ($(this).hasClass("phone")) {
} else if ($(this).hasClass('phone')) {
$(this).keyup(function() {
var key = e.charCode || e.keyCode || 0;
return (key==8 || key==9 || key==13 || key==46 || key==110 || key==190 || (key>=35 && key<=40) || (key>=48 && key<=57) || (key>=96 && key<=105) || key==109 || key==173 || key==107);
// allow backspace, tab, delete, enter, arrows, numbers and keypad numbers ONLY
// home, end, period, numpad decimal, minus, minus-ff, add
var key = e.keyCode ?? e.which;
return (jQuery.inArray(key,[8,9,13,46,110,190,109,189,173,107,187,61])!==-1 || (key>=16 && key<=18) || (key>=35 && key<=40) || (key>=48 && key<=57) || (key>=96 && key<=105));
});
} else if ($(this).hasClass("error") && $(this).val()) {
} else if ($(this).hasClass('error') && $(this).val()) {
var tmp_str = $(this).val();
$(this).val('');
FoniaJS.showError(tmp_str);
@@ -418,20 +388,22 @@ var FoniaJS = {
var _opts = {tags: false, theme: 'bootstrap-5'};
var _dmodal = $(this).closest('div.modal');
if ($(_dmodal).hasClass('modal')) _opts.dropdownParent = _dmodal;
$(this).select2(_opts).on('select2:close', function(e){ $(this).valid(); });
var _sel2 = $(this).select2(_opts);
if ($(this).prop('required')) _sel2.on('select2:close', function(e){ $(this).valid(); });
});
$('[data-toggle="tooltip"]').tooltip();
$(".colorpic").each(function() {
$('.colorpic').each(function() {
$(this).prop('background-color', $(this).val());
});
if('function' == typeof jQuery.fn.datepicker){
$(".pickdate").datepicker({
$('.pickdate').datepicker({
format: 'dd-mm-yyyy',
weekStart: 1,
language: 'id',
autoclose: true,
todayHighlight: true
todayHighlight: true,
enableOnReadonly: false
});
}
if ('function' == typeof autosize) autosize($('textarea'));
@@ -562,12 +534,9 @@ var FoniaJS = {
});
}).modal('show');
},
showWindow: function(id_wind, s_judul, s_isi, i_width, s_toolb, f_onload) {//oke
return this.showWindowDetail(id_wind, s_judul, s_isi, i_width, s_toolb, 'static', f_onload);
},
showWindowDetail: function(id_wind, s_judul, s_isi, i_width, s_toolb, s_block, f_onload) {//oke
var t_width = '', t_toolb = '';
var f_oncall = (typeof f_onload == "function") ? f_onload : function() {};
showWindow: function(id_wind, s_judul, s_isi, i_width, s_toolb, f_onload, b_scroll) {//oke
var t_width = '', t_toolb = '', t_scroll = (typeof b_scroll == 'boolean' && b_scroll == false) ? '' : 'modal-dialog-scrollable';
var f_oncall = (typeof f_onload == "function") ? f_onload : function(){};
if (i_width <= 300) { t_width = 'modal-sm'; } else
if (i_width <= 400) { t_width = 'modal-400'; } else
if (i_width <= 500) { t_width = 'modal-500'; } else
@@ -580,8 +549,8 @@ var FoniaJS = {
t_toolb += '</div>';
}
var _wtxt =
'<div class="modal fade" id="win'+id_wind+'" tabindex="-1" data-bs-keyboard="false"'+(s_block==''?'':' data-bs-backdrop="'+s_block+'"')+' aria-labelledby="win'+id_wind+'Label" aria-hidden="true">'+
'<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable '+t_width+'">'+
'<div class="modal fade" id="win'+id_wind+'" tabindex="-1" data-bs-keyboard="false" data-bs-backdrop="static" aria-labelledby="win'+id_wind+'Label" aria-hidden="true">'+
'<div class="modal-dialog modal-dialog-centered '+t_scroll+' '+t_width+'">'+
'<div class="modal-content">'+
'<div class="modal-header"><h5 class="modal-title" id="win'+id_wind+'Label">'+s_judul+'</h5><button class="btn-close" type="button" data-bs-dismiss="modal" aria-label="Close"></button></div>'+
'<div class="modal-body">'+s_isi+'</div>'+ t_toolb +
@@ -650,26 +619,19 @@ var FoniaJS = {
}, this.locales[this.deflocal]);
}
},
Text_Auto: function(elm, turl, aparam, func_comp, func_key){
AutoComplete: function(elm, turl, aparam, func_comp, func_key){//oke
var arrData = [], objComp = {};
if ('string' !== typeof aparam) arrData = this.RequestParam(aparam);
objComp = {
//preventEnter: false,
resolverSettings: {
url: turl,
extraData: arrData.reduce(function(o, val) { var t = val.split('='); o[t[0]] = t[1]; return o; }, {})
}
};
if ('function' === typeof func_key) objComp.keydownFunc = func_key;
if ('function' === typeof func_comp) objComp.selectFunc = func_comp;
$(elm).autoComplete(objComp);
if ('function' === typeof func_comp) {
$(elm).unbind('autocomplete.select');
$(elm).on('autocomplete.select', function (evt, item) {
('object' == typeof item) && func_comp(item);
});
$(elm).on('keydown', function(e){
if (13 === e.keyCode) return false;
});
}
},
getAppID: function() {
return this.APP_ID;
+2 -2
View File
File diff suppressed because one or more lines are too long