mirror of
https://bitbucket.org/bellord13/kit.git
synced 2026-11-13 19:06:11 +03:00
fix
This commit is contained in:
@@ -5,8 +5,9 @@
|
||||
kit.PluginManager.register('UserActionManager',function(module, exports, require, global) {
|
||||
|
||||
var Collection = require('collection');
|
||||
var support = require('support');
|
||||
|
||||
var actionList = ['click', 'hover'];
|
||||
var actionList = ['popover', 'hint'];
|
||||
|
||||
var UserAction = function () {
|
||||
|
||||
@@ -157,11 +158,32 @@ kit.PluginManager.register('UserActionManager',function(module, exports, require
|
||||
|
||||
|
||||
/**
|
||||
* @memberof kitCore
|
||||
* @instance
|
||||
* @class UserActionManager
|
||||
* @memberOf kit
|
||||
*/
|
||||
var UserActionManager = function () {
|
||||
var UserActionManager = function (actions = []) {
|
||||
|
||||
this.test = new Collection([]);
|
||||
this.collection = new Collection([]);
|
||||
if(!Array.isArray(actions)) {
|
||||
actions = [actions];
|
||||
}
|
||||
actions.forEach(function (act) {
|
||||
|
||||
}.bind(this));
|
||||
/**
|
||||
* @static
|
||||
*/
|
||||
this.actions = {
|
||||
popover: 'popover',
|
||||
hint: 'hint',
|
||||
};
|
||||
return this;
|
||||
};
|
||||
|
||||
UserActionManager.prototype.setAction = function(action){
|
||||
this.action = action;
|
||||
this.collection.put();
|
||||
};
|
||||
|
||||
return module.exports = UserActionManager;
|
||||
|
||||
@@ -565,8 +565,7 @@ kit.PluginManager.register('align',function(module, exports, require) {
|
||||
|
||||
|
||||
/**
|
||||
* @memberof kitCore
|
||||
* @instance
|
||||
* @memberOf kit
|
||||
*/
|
||||
var align = {
|
||||
Class: AlignClass,
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
kit.PluginManager.register('animations',function(module, exports, require, global) {
|
||||
|
||||
/**
|
||||
* @memberof kitCore
|
||||
* @instance
|
||||
* @memberOf kit
|
||||
*/
|
||||
var animations = {
|
||||
scaleIn: 'anim-scale-in',
|
||||
|
||||
@@ -1,35 +1,11 @@
|
||||
/** @module collection */
|
||||
kit.PluginManager.register('collection',function(module, exports, require, global) {
|
||||
kit.PluginManager.register('Collection',function(module, exports, require, global) {
|
||||
|
||||
var support = require('support');
|
||||
var valueEx = support.valueEx;
|
||||
|
||||
function valueEx(value, item, key, arr) {
|
||||
if(typeof value === 'function') {
|
||||
return value(item, key, arr);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
function uniqueId (length = 32, firstLetter = true) {
|
||||
var idStr = '';
|
||||
if(length < 1) return idStr;
|
||||
if(firstLetter) {
|
||||
length && (idStr = (Math.floor((Math.random() * 25)) + 10).toString(36));
|
||||
if (length === 1) return idStr;
|
||||
}
|
||||
do {
|
||||
idStr += (Math.floor((Math.random() * 35))).toString(36);
|
||||
} while (idStr.length < length);
|
||||
return (idStr);
|
||||
}
|
||||
function empty(val){
|
||||
return arguments.length === 0 ||
|
||||
val === undefined ||
|
||||
val === null ||
|
||||
Number.isNaN(val) === true ||
|
||||
val === '' ||
|
||||
val === 0 ||
|
||||
val === false;
|
||||
}
|
||||
function filter(value, key, arr) {
|
||||
return !empty(value);
|
||||
return !support.empty(value);
|
||||
}
|
||||
function getSimilarInstance(type) {
|
||||
if(type === 'object') {
|
||||
@@ -38,10 +14,10 @@ kit.PluginManager.register('collection',function(module, exports, require, globa
|
||||
return new Collection([]);
|
||||
}
|
||||
/**
|
||||
* @memberof kitCore
|
||||
* @instance
|
||||
* @class Collection
|
||||
* @memberOf kit
|
||||
*/
|
||||
var Collection = function (data) {
|
||||
var Collection = function (data = []) {
|
||||
this.data = data;
|
||||
if(data instanceof NodeList) {
|
||||
this.type = 'NodeList';
|
||||
@@ -81,14 +57,14 @@ kit.PluginManager.register('collection',function(module, exports, require, globa
|
||||
this.data.push(value);
|
||||
return this;
|
||||
}
|
||||
this.data[uniqueId(8)] = value;
|
||||
this.data[support.uniqueId(8)] = value;
|
||||
return this;
|
||||
};
|
||||
Collection.prototype.get = function (key, defValue = undefined) {
|
||||
if(this.data.hasOwnProperty(key)) {
|
||||
return this.data[key];
|
||||
}
|
||||
return valueEx(defValue, this.data[key], key);
|
||||
return defValue;
|
||||
};
|
||||
Collection.prototype.has = function (key) {
|
||||
return this.data.hasOwnProperty(key);
|
||||
@@ -180,6 +156,16 @@ kit.PluginManager.register('collection',function(module, exports, require, globa
|
||||
});
|
||||
return res;
|
||||
};
|
||||
Collection.prototype.firstKey = function (callback = true) {
|
||||
var res = undefined;
|
||||
this.each(function (value, key, arr) {
|
||||
if(valueEx(callback, value, key, arr)) {
|
||||
res = key;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return res;
|
||||
};
|
||||
Collection.prototype.last = function (callback = true) {
|
||||
var res = undefined;
|
||||
this.eachReverse(function (value, key, arr) {
|
||||
@@ -190,6 +176,16 @@ kit.PluginManager.register('collection',function(module, exports, require, globa
|
||||
});
|
||||
return res;
|
||||
};
|
||||
Collection.prototype.lastKey = function (callback = true) {
|
||||
var res = undefined;
|
||||
this.eachReverse(function (value, key, arr) {
|
||||
if(valueEx(callback, value, key, arr)) {
|
||||
res = key;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return res;
|
||||
};
|
||||
/**
|
||||
* @return {kitCore.Collection}
|
||||
*/
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ window.kit = window.kit || {};
|
||||
* @class PluginManager
|
||||
* @param global
|
||||
* @param plugins
|
||||
* @constructor
|
||||
* @memberOf kit
|
||||
*/
|
||||
var PluginManager = function(global, plugins = {}){
|
||||
this.plugins = {};
|
||||
@@ -631,7 +631,7 @@ window.kit = window.kit || {};
|
||||
});
|
||||
manager.install('config');
|
||||
|
||||
window.__PluginManager__ = global.PluginManager = global.pm = manager;
|
||||
window.__PluginManager__ = manager;
|
||||
global.ready = manager.ready.bind(manager);
|
||||
global.exec = manager.exec.bind(manager);
|
||||
global.require = manager.require.bind(manager);
|
||||
|
||||
@@ -151,6 +151,7 @@ __PluginManager__.registerPlugins({
|
||||
path: __pmConfig__.assetsPath + '/collection',
|
||||
module: '/collection.js',
|
||||
type: 'loader',
|
||||
deps: ['support'],
|
||||
},
|
||||
dataStructures: {
|
||||
path: __pmConfig__.assetsPath + '/dataStructures',
|
||||
@@ -161,6 +162,7 @@ __PluginManager__.registerPlugins({
|
||||
path: __pmConfig__.assetsPath + '/UserActionManager',
|
||||
module: '/UserActionManager.js',
|
||||
type: 'loader',
|
||||
deps: ['Collection'],
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
/**
|
||||
* @typedef {Object} kitCorePlugins
|
||||
* @property {PluginManager} pm
|
||||
* @property {kitPluginManagerRequire} require
|
||||
* @property {kitBsCore} bsCore
|
||||
* @property {kitToolkit} toolkit
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
/** @module dataStructures */
|
||||
__PluginManager__.register('dataStructures', function(module, exports, require, global){
|
||||
/**
|
||||
* @memberof kitCore
|
||||
* @instance
|
||||
* @memberOf kit
|
||||
*/
|
||||
var dataStructures = {
|
||||
StackExecutionLimiter: (function () {
|
||||
|
||||
+1
-2
@@ -2,8 +2,7 @@
|
||||
kit.PluginManager.register('lib',function(module, exports, require, global) {
|
||||
|
||||
/**
|
||||
* @memberof kitCore
|
||||
* @instance
|
||||
* @memberOf kitCore
|
||||
*/
|
||||
var lib = {
|
||||
svg: {
|
||||
|
||||
+1
-2
@@ -931,8 +931,7 @@ __PluginManager__.register('menu',function(module, exports, require) {
|
||||
window.addEventListener('resize', globalHandlers.resize);
|
||||
|
||||
/**
|
||||
* @memberof kitCore
|
||||
* @instance
|
||||
* @memberOf kit
|
||||
*/
|
||||
var menu = {
|
||||
Class: MenuClass,
|
||||
|
||||
@@ -7,13 +7,46 @@ __PluginManager__.register('support', function(module, exports, require, global)
|
||||
return str[0].toUpperCase() + str.slice(1);
|
||||
}
|
||||
};
|
||||
|
||||
function uniqueId (length = 32, firstLetter = true) {
|
||||
var idStr = '';
|
||||
if(length < 1) return idStr;
|
||||
if(firstLetter) {
|
||||
length && (idStr = (Math.floor((Math.random() * 25)) + 10).toString(36));
|
||||
if (length === 1) return idStr;
|
||||
}
|
||||
do {
|
||||
idStr += (Math.floor((Math.random() * 35))).toString(36);
|
||||
} while (idStr.length < length);
|
||||
return (idStr);
|
||||
}
|
||||
function valueEx(value) {
|
||||
var arg = [];
|
||||
if(arguments.length > 1)
|
||||
for(var i = 1; arguments.length - 1 >= i;i++) {
|
||||
arg.push(arguments[i]);
|
||||
}
|
||||
if(typeof value === 'function') {
|
||||
return value.apply(this, arg);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
function empty(val){
|
||||
return arguments.length === 0 ||
|
||||
val === undefined ||
|
||||
val === null ||
|
||||
Number.isNaN(val) === true ||
|
||||
val === '' ||
|
||||
val === 0 ||
|
||||
val === false;
|
||||
}
|
||||
/**
|
||||
* @memberof kitCore
|
||||
* @instance
|
||||
* @memberOf kit
|
||||
*/
|
||||
var support = {
|
||||
str: str,
|
||||
uniqueId,
|
||||
valueEx,
|
||||
empty
|
||||
};
|
||||
|
||||
return module.exports = support;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");?>
|
||||
<?
|
||||
if(\Bitrix\Main\Loader::includeModule('wt.core')) {
|
||||
app()->service()->assets()->setPlugins([
|
||||
'kit:config',
|
||||
'kit:flex-kit',
|
||||
'kit:core',
|
||||
'kit:bsCore',
|
||||
'kit:collapse',
|
||||
'kit:site',
|
||||
'kit:toolkit',
|
||||
'kit:theme',
|
||||
])->render();
|
||||
}
|
||||
$APPLICATION->ShowHead();
|
||||
|
||||
?>
|
||||
<script>
|
||||
kit.ready(['UserActionManager'], function () {
|
||||
var m1 = new kit.UserActionManager();
|
||||
m1.setAction('popover');
|
||||
|
||||
});
|
||||
</script>
|
||||
<style>
|
||||
.hide {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
<div class="kit-wrapper">
|
||||
|
||||
|
||||
<div id="object1" style="width: 300px; height: 50px; background-color: #eaeaea; border: 1px solid;">1</div>
|
||||
|
||||
<div id="object2" style="width: 300px; height: 50px; background-color: #3860ff; border: 1px solid; display: none" class="hide">2</div>
|
||||
|
||||
<div id="object3" style="width: 300px; height: 50px; background-color: #ff1d34; border: 1px solid; display: none" class="hide">3</div>
|
||||
|
||||
</div>
|
||||
<?
|
||||
?>
|
||||
@@ -6,5 +6,6 @@
|
||||
<a href="cheatsheet.php">cheatsheet</a>
|
||||
<a href="card/block.php">card/block</a>
|
||||
<a href="kit.Collection.php">kit.Collection</a>
|
||||
<a href="UserActionManager.php">UserActionManager</a>
|
||||
|
||||
</div>
|
||||
@@ -107,6 +107,26 @@ kit.ready(['collection'], function () {
|
||||
}), undefined, 'first');
|
||||
|
||||
assertSame(collection.keys().count(), 3, 'keys');
|
||||
|
||||
|
||||
x = new kit.Collection({1: 1, 100: 100});
|
||||
x.push(200);
|
||||
assertSame(x.last(), 200, 'object push last');
|
||||
x.push(0);
|
||||
assertSame(x.last(), 0, 'object push last');
|
||||
x.push(undefined);
|
||||
assertSame(x.last(), undefined, 'object push last');
|
||||
x.push('window');
|
||||
assertSame(x.last(), 'window', 'object push last');
|
||||
assertSame(x.get(x.lastKey()), 'window', 'get lastKey');
|
||||
|
||||
x = new kit.Collection([1, 100]);
|
||||
x.push(200);
|
||||
assertSame(x.last(), 200, 'array push last');
|
||||
x.push(0);
|
||||
assertSame(x.last(), 0, 'array push last');
|
||||
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user