How to use isDomNode method in Jest

Best JavaScript code snippet using jest

script.js

Source:script.js Github

copy

Full Screen

...127 if (!('containerId' in params) || !BX.type.isNotEmptyString(params.containerId))128 {129 throw 'BX.MainButtons: containerId not set in params';130 }131 if (!BX.type.isDomNode(this.listContainer))132 {133 throw 'BX.MainButtons: #' + params.containerId + ' is not dom node';134 }135 if (('classes' in params) && BX.type.isPlainObject(params.classes)) 136 {137 this.setCustomClasses(params.classes);138 }139 if (('messages' in params) && BX.type.isPlainObject(params.messages))140 {141 this.setMessages(params.messages);142 }143 if (('licenseWindow' in params) && BX.type.isPlainObject(params.licenseWindow))144 {145 this.setLicenseWindowParams(params.licenseWindow);146 }147 this.moreButton = this.getMoreButton();148 this.visibleControllMoreButton();149 this.dragAndDropInit();150 this.adjustMoreButtonPosition();151 this.bindOnClickOnMoreButton();152 this.createFrame();153 this.bindOnResizeFrame();154 this.bindOnScrollWindow();155 this.bindOnClick();156 this.createSubmenu();157 this.setSubmenuContainer(this.getSubmenuContainer());158 this.setContainerHeight();159 this.setParentPinContainer();160 },161 bindOnScrollWindow: function()162 {163 BX.bind(window, 'scroll', BX.delegate(this._onScroll, this));164 },165 setParentPinContainer: function()166 {167 this.pinContainer = this.findParentByClassName(this.moreButton, 'bx-pin');168 },169 /**170 * Calculate container heigth171 * @return {integer|float} Container height in pixels172 */173 getContainerHeight: function() 174 {175 var allItems = this.getAllItems();176 var heights, currentStyle;177 heights = [].map.call(allItems, function(current) {178 currentStyle = getComputedStyle(current);179 return (180 BX.height(current) + 181 parseInt(currentStyle.marginTop) + 182 parseInt(currentStyle.marginBottom)183 );184 });185 return Math.max.apply(Math, heights);186 },187 /**188 * Sets container heigth189 */190 setContainerHeight: function() 191 {192 var containerHeight = this.getContainerHeight();193 BX.height(this.listContainer, containerHeight);194 },195 /**196 * Sets license window params in this.licenseParams197 * @param {object} params Params object198 */199 setLicenseWindowParams: function(params)200 {201 this.licenseParams = params || {};202 },203 /**204 * Gets message by id205 * @method message206 * @private207 * @param {string} messageId208 * @return {string}209 */210 message: function(messageId) 211 {212 var result;213 try 214 {215 result = this.messages[messageId];216 } 217 catch (error) 218 {219 result = '';220 }221 return result;222 },223 /**224 * Sets custom classes225 * @param {object} classes226 * @return {undefined}227 */228 setCustomClasses: function(classes) 229 {230 if (!BX.type.isPlainObject(classes)) 231 {232 return;233 }234 this.classItem = (classes.item || this.classItem);235 this.classItemSublink = (classes.itemSublink || this.classItemSublink);236 this.classItemText = (classes.itemText || this.classItemText);237 this.classItemCounter = (classes.itemCounter || this.classItemCounter);238 this.classItemIcon = (classes.itemIcon || this.classItemIcon);239 this.classItemMore = (classes.itemMore || this.classItemMore);240 this.classItemOver = (classes.itemOver || this.classItemOver);241 this.classItemActive = (classes.itemActive || this.classItemActive);242 this.classItemDisabled = (classes.itemDisabled || this.classItemDisabled);243 this.classOnDrag = (classes.onDrag || this.classOnDrag);244 this.classDropzone = (classes.dropzone || this.classDropzone);245 this.classSeporator = (classes.seporator || this.classSeporator);246 this.classSubmenuItem = (classes.submenuItem || this.classSubmenuItem);247 this.classSubmenu = (classes.submenu || this.classSubmenu);248 this.classSecret = (classes.secret || this.classSecret);249 this.classItemLocked = (classes.itemLocked || this.classItemLocked);250 },251 /**252 * Sets list container 253 * @param {string} id container id254 */255 setListContainer: function(container)256 {257 if (BX.type.isDomNode(container)) 258 {259 this.listContainer = container;260 }261 },262 /**263 * Sets messages264 * @param {object} messages Messages object265 */266 setMessages: function(messages) 267 {268 if (!BX.type.isPlainObject(messages))269 {270 return;271 }272 this.messages = messages;273 },274 /**275 * Makes full item id276 * @private277 * @method makeFullItemId278 * @param {string} itemId279 * @return {string} 280 */281 makeFullItemId: function(itemId)282 {283 if (!BX.type.isNotEmptyString(itemId))284 {285 return;286 }287 return [this.listContainer.id, itemId.replace('-', '_')].join('_');288 },289 /**290 * Gets listContainer child by id291 * @public292 * @method getItemById293 * @param {string} itemId294 * @return {object} dom node295 */296 getItemById: function(itemId)297 { 298 var resultItem = null;299 var realId;300 if (BX.type.isNotEmptyString(itemId))301 {302 realId = this.makeFullItemId(itemId);303 resultItem = BX.findChild(this.listContainer, {attribute: {id: realId}}, true, false);304 }305 return resultItem;306 },307 /**308 * Finds counter object309 * @private310 * @method getItemCounterObject311 * @param {object} item312 * @return {object} Counter dom node313 */314 getItemCounterObject: function(item)315 {316 var result = null;317 if (BX.type.isDomNode(item))318 {319 result = BX.findChild(item, {class: this.classItemCounter}, true, false);320 }321 return result;322 },323 /**324 * Sets item counter value325 * @private326 * @method setCounterValue327 * @param {object} item328 * @param {integer|float|string} value329 */330 setCounterValue: function(item, value)331 {332 var counter = this.getItemCounterObject(item);333 if (BX.type.isDomNode(counter))334 {335 counter.innerText = value > 99 ? '99+' : value;336 item.dataset.counter = value;337 }338 },339 /**340 * Sets counter value by item id341 * @public342 * @method setCounterValueByItemId343 * @param {string} itemId 344 * @param {integer|Float} counterValue 345 */346 setCounterValueByItemId: function(itemId, counterValue)347 {348 var currentValue = counterValue !== null ? parseFloat(counterValue) : null;349 var currentItem, aliasItem;350 if (!BX.type.isNotEmptyString(itemId))351 {352 throw 'Bad first arg. Need string as item id';353 }354 if (currentValue !== null && !BX.type.isNumber(currentValue))355 {356 throw 'Bad two arg. Need number counter value - Integer, Float or string with number';357 }358 currentItem = this.getItemById(itemId);359 if (!BX.type.isDomNode(currentItem))360 {361 console.info('Not found node with id #' + itemId);362 return;363 }364 aliasItem = this.getItemAlias(currentItem);365 this.setCounterValue(currentItem, currentValue);366 this.setCounterValue(aliasItem, currentValue);367 },368 /**369 * Gets counter value by item id370 * @param {string} itemId 371 * @return {number}372 */373 getCounterValueByItemId: function(itemId)374 { 375 var item, counter;376 var counterValue = NaN;377 if (!BX.type.isNotEmptyString(itemId))378 {379 throw 'Bad first arg. Need string item id'; 380 }381 else382 {383 item = this.getItemById(itemId);384 counterValue = this.dataValue(item, 'counter');385 counterValue = parseFloat(counterValue);386 if (!BX.type.isNumber(counterValue))387 {388 counter = this.getItemCounterObject(item);389 counterValue = parseFloat(counter.innerText);390 }391 }392 return counterValue;393 },394 /**395 * Binds on click on more button396 * @method bindOnClickOnMoreButton397 * @private398 * @return {undefined}399 */400 bindOnClickOnMoreButton: function()401 {402 BX.bind(403 this.moreButton,404 'click',405 BX.delegate(this._onClickMoreButton, this)406 );407 },408 /**409 * Binds on tmp frame resize410 * @method bindOnResizeFrame411 * @private412 * @return {undefined}413 */414 bindOnResizeFrame: function()415 {416 maininterfacebuttonstmpframe.onresize = BX.throttle(this._onResizeHandler, 20, this); 417 },418 /**419 * Binds on click event420 * @method bindOnClick421 * @private422 * @return {undefined}423 */424 bindOnClick: function()425 {426 var allItems = this.getAllItems();427 var self = this;428 if (!allItems || !allItems.length)429 {430 return;431 }432 [].forEach.call(allItems, function(current)433 {434 BX.bind(435 current,436 'click',437 BX.delegate(self._onClick, self)438 );439 });440 },441 createFrame: function()442 {443 this.tmp.frame = BX.create('iframe', {444 props: {445 height: '100%',446 width: '100%',447 id: 'maininterfacebuttons-tmp-frame',448 name: 'maininterfacebuttonstmpframe'449 },450 style: {451 position: 'absolute',452 'z-index': '-1',453 opacity: 0454 }455 });456 this.listContainer.parentNode.appendChild(this.tmp.frame);457 },458 /**459 * Gets all items460 * @public461 * @method getAllItems462 * @return {array} html collection463 */464 getAllItems: function()465 {466 return this.listContainer.children;467 },468 /**469 * Gets only visible items470 * @public471 * @method getVisibleItems472 * @return {array} html collection473 */474 getVisibleItems: function()475 {476 var allItems = this.getAllItems();477 var self = this;478 var visibleItems = [];479 if (allItems && allItems.length)480 {481 visibleItems = [].filter.call(allItems, function(current)482 {483 return self.isVisibleItem(current) && !self.isDisabled(current);484 });485 }486 return visibleItems;487 },488 /**489 * Gets only hidden items490 * @public491 * @method getHiddenItems492 * @return {array} html collection493 */494 getHiddenItems: function()495 {496 var allItems = this.getAllItems();497 var hiddenItems = [];498 var self = this;499 if (allItems && allItems.length)500 {501 hiddenItems = [].filter.call(allItems, function(current)502 {503 return !self.isVisibleItem(current) && !self.isDisabled(current);504 });505 }506 return hiddenItems;507 },508 /**509 * Gets only disabled items, 510 * as showed after seporator in popup menu511 * @public512 * @method getDisabledItems513 * @return {array} html collection514 */515 getDisabledItems: function()516 {517 var allItems = this.getAllItems();518 var disabledItems = [];519 var self = this;520 if (allItems && allItems.length)521 {522 disabledItems = [].filter.call(allItems, function(current)523 {524 return self.isDisabled(current);525 });526 }527 return disabledItems;528 },529 /**530 * Gets more button item531 * @public532 * @getMoreButton533 * @return {object||null} more button object or null534 */535 getMoreButton: function()536 {537 var allItems = this.getAllItems();538 var moreButton = null;539 var self = this;540 if (allItems && allItems.length)541 {542 [].map.call(allItems, function(current)543 {544 if (BX.hasClass(current, self.classItemMore))545 {546 moreButton = current;547 return;548 }549 });550 }551 return moreButton;552 },553 /**554 * Gets last visible item555 * @private556 * @method getLastVisibleItem557 * @return {object} last visible item object 558 */559 getLastVisibleItem: function()560 {561 var visibleItems = this.getVisibleItems();562 var lastVisibleItem = null;563 if (BX.type.isArray(visibleItems) && visibleItems.length)564 {565 lastVisibleItem = visibleItems[visibleItems.length - 1];566 }567 if (!BX.type.isDomNode(lastVisibleItem))568 {569 lastVisibleItem = null;570 }571 return lastVisibleItem;572 },573 /**574 * Moves "more button" in the end of the list575 * @public576 * @method adjustMoreButtonPosition577 * @return {undefined}578 */579 adjustMoreButtonPosition: function()580 {581 var lastVisibleItem = this.getLastVisibleItem();582 var isLast = this.isMoreButton(lastVisibleItem);583 var isNext = (!isLast && !this.moreButton.offsetTop);584 var nextSiblingItem = null;585 if (isLast)586 {587 return;588 }589 if (isNext)590 {591 nextSiblingItem = this.findNextSiblingByClass(lastVisibleItem, this.classItem);592 if (BX.type.isDomNode(nextSiblingItem))593 {594 this.listContainer.insertBefore(this.moreButton, nextSiblingItem);595 }596 else597 {598 this.listContainer.appendChild(this.moreButton);599 }600 }601 else602 {603 this.listContainer.insertBefore(this.moreButton, lastVisibleItem);604 }605 this.adjustMoreButtonPosition();606 },607 /**608 * Gets submenu id609 * @private610 * @method getSubmenuId611 * @param {boolean} isFull Set true if your need to get id for popup window612 * @return {string} id613 */614 getSubmenuId: function(isFull)615 {616 var id = '';617 if (BX.type.isDomNode(this.listContainer) &&618 BX.type.isNotEmptyString(this.listContainer.id))619 {620 id = this.submenuIdPrefix + this.listContainer.id;621 }622 if (isFull)623 {624 id = this.submenuWindowIdPrefix + id;625 }626 return id;627 },628 /**629 * Gets submenu item content630 * @private631 * @method getSubmenuItemText632 * @param {object} item633 * @return {string}634 */635 getSubmenuItemText: function(item)636 {637 var text, counter, result;638 if (!BX.type.isDomNode(item))639 {640 return;641 }642 text = this.findChildrenByClassName(item, this.classItemText);643 counter = this.findChildrenByClassName(item, this.classItemCounter);644 if (BX.type.isDomNode(counter) && BX.type.isDomNode(text))645 {646 result = text.outerHTML + counter.outerHTML;647 }648 else649 {650 text = this.dataValue(item, 'text');651 counter = this.dataValue(item, 'counter');652 result = text;653 }654 return result;655 },656 /**657 * Updates submenu position relative to more button658 * @return {undefind}659 */660 adjustSubmenuPosition: function()661 {662 var submenu, submenuWindow, bindElement, bindElementPosition;663 if (!this.isSubmenuShown)664 {665 return;666 }667 submenu = this.getSubmenu();668 if (submenu === null)669 {670 return;671 }672 submenuWindow = submenu.popupWindow;673 bindElement = document.getElementById('morebutton');674 bindElementPosition = submenuWindow.getBindElementPos(bindElement);675 submenuWindow.adjustPosition(bindElementPosition);676 },677 getLockedClass: function(item)678 {679 var result = '';680 if (BX.type.isDomNode(item) && this.isLocked(item))681 {682 result = this.classItemLocked;683 }684 return result;685 },686 /**687 * Gets submenu items688 * @private689 * @method getSubmenuItems690 * @return {array} 691 */692 getSubmenuItems: function()693 {694 var allItems = this.getAllItems();695 var hiddenItems = this.getHiddenItems();696 var disabledItems = this.getDisabledItems();697 var result = [];698 var self = this;699 if (allItems.length)700 {701 [].map.call(allItems, function(current)702 {703 if (hiddenItems.indexOf(current) === -1 &&704 disabledItems.indexOf(current) === -1)705 {706 result.push({707 text: self.getSubmenuItemText(current),708 href: self.dataValue(current, 'url'),709 className: [710 self.classSubmenuItem,711 self.getIconClass(current),712 self.classSecret,713 self.getAliasLink(current),714 self.getLockedClass(current)715 ].join(' ')716 });717 }718 });719 }720 if (hiddenItems.length)721 {722 [].map.call(hiddenItems, function(current)723 {724 result.push({725 text: self.getSubmenuItemText(current),726 href: self.dataValue(current, 'url'),727 className: [728 self.classSubmenuItem,729 self.getIconClass(current),730 self.getAliasLink(current),731 self.getLockedClass(current)732 ].join(' ')733 });734 });735 }736 if (disabledItems.length)737 {738 result.push({739 text: '&nbsp;',740 className: [741 this.classSeporator,742 this.classSubmenuItem743 ].join(' ')744 });745 [].map.call(disabledItems, function(current)746 {747 result.push({748 text: self.getSubmenuItemText(current),749 href: self.dataValue(current, 'url'),750 className: [751 self.classSubmenuItem,752 self.classItemDisabled,753 self.getIconClass(current),754 self.getAliasLink(current),755 self.getLockedClass(current)756 ].join(' ')757 });758 });759 }760 result.push({761 text: this.message('MIB_DROPZONE_TEXT'),762 className: [763 this.classDropzone,764 this.classSubmenuItem765 ].join(' ')766 });767 return result;768 },769 /** 770 * Gets BX.PopupMenu.show arguments771 * @private772 * @method getSubmenuArgs773 * @return {array} Arguments774 */775 getSubmenuArgs: function()776 {777 var menuId = this.getSubmenuId();778 var anchor = this.moreButton;779 var anchorPosition = BX.pos(anchor);780 var menuItems = this.getSubmenuItems();781 var params = {782 'autoHide': true,783 'offsetLeft': (anchorPosition.width / 2) - 18,784 'angle':785 {786 'position': 'top',787 'offset': (anchorPosition.width / 2) - 8788 },789 'events':790 {791 'onPopupClose': BX.delegate(this._onSubmenuClose, this),792 'onPopupShow': BX.delegate(this.dragAndDropInitInSubmenu, this)793 }794 };795 return [menuId, anchor, menuItems, params];796 },797 /**798 * Controls the visibility of more button799 * @return {undefined}800 */801 visibleControllMoreButton: function()802 {803 var hiddenItems = this.getHiddenItems();804 var disabledItems = this.getDisabledItems();805 if (!hiddenItems.length && !disabledItems.length && this.dragItem === null) 806 {807 this.closeSubmenu();808 BX.hide(this.moreButton);809 return;810 } else {811 BX.show(this.moreButton);812 }813 },814 /**815 * Creates submenu816 * @return {undefined}817 */818 createSubmenu: function() 819 {820 var args = this.getSubmenuArgs();821 if (BX.type.isArray(args))822 {823 BX.PopupMenu.create.apply(BX.PopupMenu, args);824 }825 },826 /**827 * Shows submenu828 * @public829 * @method showSubmenu830 * @return {undefined}831 */832 showSubmenu: function()833 {834 var submenu = this.getSubmenu();835 if (submenu !== null) 836 {837 submenu.popupWindow.show();838 }839 else840 {841 this.createSubmenu();842 submenu = this.getSubmenu();843 submenu.popupWindow.show();844 }845 this.setSubmenuShown(true);846 this.activateItem(this.moreButton);847 },848 /**849 * Closes submenu850 * @public851 * @method closeSubmenu852 * @return {undefined}853 */854 closeSubmenu: function()855 {856 var submenu = this.getSubmenu();857 if (submenu === null) 858 {859 return;860 }861 submenu.popupWindow.close();862 this.deactivateItem(this.moreButton);863 this.setSubmenuShown(false);864 },865 /**866 * Gets current submenu867 * @public868 * @method getSubmenu869 * @return {object}870 */871 getSubmenu: function()872 {873 return BX.PopupMenu.getMenuById(this.getSubmenuId());874 },875 /**876 * Destroys submenu877 * @private878 * @method destroySubmenu879 * @return {undefined}880 */881 destroySubmenu: function()882 {883 BX.PopupMenu.destroy(this.getSubmenuId());884 },885 /**886 * Refreshes submenu887 * @public888 * @method refreshSubmenu889 * @return {undefined}890 */891 refreshSubmenu: function()892 {893 var submenu = this.getSubmenu();894 var args;895 if (submenu === null)896 {897 return;898 }899 args = this.getSubmenuArgs();900 if (BX.type.isArray(args))901 {902 this.destroySubmenu();903 BX.PopupMenu.show.apply(BX.PopupMenu, args);904 }905 },906 /**907 * Sets value this.isSubmenuShown908 * @private909 * @method setSubmenuShown910 * @param {boolean} value911 */912 setSubmenuShown: function(value)913 {914 this.isSubmenuShown = false;915 if (BX.type.isBoolean(value))916 {917 this.isSubmenuShown = value;918 }919 },920 /**921 * Adds class active for item922 * @private923 * @method activateItem924 * @param {object} item925 * @return {undefined}926 */927 activateItem: function(item)928 {929 if (!BX.type.isDomNode(item))930 {931 return;932 }933 if (!BX.hasClass(item, this.classItemActive))934 {935 BX.addClass(item, this.classItemActive);936 }937 },938 /**939 * Removes class active for item940 * @private941 * @method deactivateItem942 * @param {object} item943 * @return {undefined}944 */945 deactivateItem: function(item)946 {947 if (!BX.type.isDomNode(item))948 {949 return;950 }951 if (BX.hasClass(item, this.classItemActive))952 {953 BX.removeClass(item, this.classItemActive);954 }955 },956 /**957 * Gets current component settings958 * @public959 * @method getCurrentSettings960 * @return {object}961 */962 getCurrentSettings: function()963 {964 var allItems = this.getAllItems();965 var settings = {};966 var self = this;967 if (allItems && allItems.length)968 {969 [].map.call(allItems, function(current, index)970 {971 settings[current.id] = {972 sort: index,973 isDisabled: self.isDisabled(current)974 };975 });976 }977 return settings;978 },979 /**980 * Saves current component settings981 * @public982 * @method saveSettings983 * @return {undefined}984 */985 saveSettings: function()986 {987 var settings = this.getCurrentSettings();988 var paramName = 'settings';989 var containerId;990 if (!BX.type.isPlainObject(settings))991 {992 return;993 }994 if (BX.type.isDomNode(this.listContainer) && ('id' in this.listContainer))995 {996 containerId = this.listContainer.id;997 }998 settings = JSON.stringify(settings);999 BX.userOptions.save('UI', containerId, paramName, settings, true);1000 },1001 /**1002 * Moves alias buttons1003 * @private1004 * @method moveButtonAlias1005 * @param {object} item1006 * @return {undefined}1007 */1008 moveButtonAlias: function(item)1009 {1010 var aliasDragItem, aliasItem;1011 if (!item || !this.dragItem)1012 {1013 return;1014 }1015 aliasDragItem = this.getItemAlias(this.dragItem);1016 aliasItem = this.getItemAlias(item);1017 if (this.isListItem(aliasDragItem))1018 {1019 if (!aliasItem)1020 {1021 this.listContainer.appendChild(aliasDragItem);1022 }1023 else1024 {1025 this.listContainer.insertBefore(aliasDragItem, aliasItem);1026 }1027 }1028 },1029 /**1030 * Moves drag item before item, or appendChild to container1031 * @private1032 * @method moveButton1033 * @param {object} item1034 * @return {undefined}1035 */1036 moveButton: function(item)1037 {1038 var submenuContainer;1039 if (!BX.type.isDomNode(item) || !BX.type.isDomNode(this.dragItem))1040 {1041 return;1042 }1043 if (this.isListItem(item))1044 {1045 if (this.isDisabled(this.dragItem))1046 {1047 this.dragItem.dataset.disabled = 'false';1048 }1049 if (BX.type.isDomNode(item))1050 { 1051 this.listContainer.insertBefore(this.dragItem, item);1052 }1053 else1054 {1055 this.listContainer.appendChild(this.dragItem);1056 }1057 }1058 if (this.isSubmenuItem(item))1059 {1060 if (this.isDisabled(this.dragItem) && !this.isDisabled(item))1061 {1062 this.enableItem(this.dragItem);1063 }1064 submenuContainer = this.getSubmenuContainer();1065 submenuContainer.insertBefore(this.dragItem, item);1066 }1067 },1068 /**1069 * Gets submenu container1070 * @private1071 * @method getSubmenuContainer1072 * @return {object}1073 */1074 getSubmenuContainer: function()1075 {1076 var submenu = this.getSubmenu();1077 var result = null;1078 if (submenu !== null)1079 {1080 result = submenu.itemsContainer;1081 }1082 return result;1083 },1084 /**1085 * Finds nextElementSibling for item by className1086 * @private1087 * @method findNextSiblingByClass1088 * @param {object} item1089 * @param {string} className1090 * @return {object}1091 */1092 findNextSiblingByClass: function(item, className)1093 {1094 var sourceItem = item;1095 for (; item && item !== document; item = item.nextSibling)1096 {1097 if (className)1098 {1099 if (BX.hasClass(item, className) &&1100 item !== sourceItem)1101 {1102 return item;1103 }1104 }1105 else1106 {1107 return null;1108 }1109 }1110 },1111 /**1112 * Finds parent node for item by className1113 * @private1114 * @method findParentByClassName1115 * @param {object} item1116 * @param {string} className1117 * @return {object}1118 */1119 findParentByClassName: function(item, className)1120 {1121 for (; item && item !== document; item = item.parentNode)1122 {1123 if (className)1124 {1125 if (BX.hasClass(item, className))1126 {1127 return item;1128 }1129 }1130 else1131 {1132 return null;1133 }1134 }1135 },1136 /**1137 * Finds children item by className1138 * @private1139 * @method findChildrenByClassName1140 * @param {object} item1141 * @param {string} className1142 * @return {object} 1143 */1144 findChildrenByClassName: function(item, className)1145 {1146 var result = null;1147 if (BX.type.isDomNode(item) && BX.type.isNotEmptyString(className))1148 {1149 result = BX.findChildren(item,1150 {1151 className: className1152 }, true);1153 if (BX.type.isArray(result) && result.length)1154 {1155 result = result[0];1156 }1157 }1158 return result;1159 },1160 /**1161 * Initialisere Drag And Drop1162 * @private1163 * @method dragAndDropInit1164 * @return {undefined}1165 */1166 dragAndDropInit: function()1167 {1168 var allItems = this.getAllItems();1169 var self = this;1170 [].forEach.call(allItems, function(current, index)1171 {1172 current.draggable = true;1173 current.tabindex = -1;1174 current.dataset.link = 'item' + index;1175 BX.bind(current, 'mouseover', BX.delegate(self._onMouse, self));1176 BX.bind(current, 'mouseout', BX.delegate(self._onMouse, self));1177 BX.bind(current, 'dragstart', BX.delegate(self._onDragStart, self));1178 BX.bind(current, 'dragend', BX.delegate(self._onDragEnd, self));1179 BX.bind(current, 'dragenter', BX.delegate(self._onDragEnter, self));1180 BX.bind(current, 'dragover', BX.delegate(self._onDragOver, self));1181 BX.bind(current, 'dragleave', BX.delegate(self._onDragLeave, self));1182 });1183 },1184 /**1185 * Initialisere Drag And Drop for submenu items1186 * @private1187 * @method dragAndDropInitInSubmenu1188 * @return {undefined}1189 */1190 dragAndDropInitInSubmenu: function()1191 {1192 var submenu = this.getSubmenu();1193 var submenuItems = submenu.menuItems;1194 var self = this;1195 [].forEach.call(submenuItems, function(current)1196 {1197 current.layout.item.draggable = true;1198 current.layout.item.dataset.sortable = true;1199 BX.bind(current.layout.item, 'dragstart', BX.delegate(self._onDragStart, self));1200 BX.bind(current.layout.item, 'dragenter', BX.delegate(self._onDragEnter, self));1201 BX.bind(current.layout.item, 'dragover', BX.delegate(self._onDragOver, self));1202 BX.bind(current.layout.item, 'dragleave', BX.delegate(self._onDragLeave, self));1203 BX.bind(current.layout.item, 'dragend', BX.delegate(self._onDragEnd, self));1204 if (self.isDropzone(current.layout.item))1205 {1206 BX.bind(current.layout.item, 'drop', BX.delegate(self._onDrop, self));1207 }1208 BX.bind(current.layout.item, 'click', BX.delegate(self._onClick, self));1209 });1210 },1211 /**1212 * Gets drag and drop event target element1213 * @private1214 * @method getItem1215 * @param {object} event1216 * @return {object}1217 */1218 getItem: function(event)1219 {1220 var item = null;1221 if (!event || !BX.type.isDomNode(event.target))1222 {1223 return;1224 }1225 item = this.findParentByClassName(event.target, this.classItem);1226 if (!BX.type.isDomNode(item))1227 {1228 item = this.findParentByClassName(event.target, this.classSubmenuItem);1229 }1230 return item;1231 },1232 /**1233 * Sets default opacity style1234 * @private1235 * @method setOpacity1236 * @param {object} item1237 */1238 setOpacity: function(item)1239 {1240 if (!BX.type.isDomNode(item))1241 {1242 return;1243 }1244 BX.style(item, 'opacity', '.6');1245 },1246 /**1247 * Unsets opacity style1248 * @private1249 * @method unsetOpacity1250 * @param {object} item1251 * @return {undefined}1252 */1253 unsetOpacity: function(item)1254 {1255 if (!BX.type.isDomNode(item))1256 {1257 return;1258 }1259 BX.style(item, 'opacity', '1');1260 },1261 /**1262 * Updates link to submenu container object1263 * @private1264 * @method updateSubmenuContainer1265 * @return {undefined}1266 */1267 setSubmenuContainer: function(container)1268 {1269 this.submenuContainer = container;1270 },1271 /**1272 * Sets drag styles1273 * @private1274 * @method setDragStyles1275 */1276 setDragStyles: function()1277 {1278 BX.addClass(this.listContainer, this.classOnDrag);1279 BX.addClass(BX(this.getSubmenuId(true)), this.classOnDrag);1280 this.setOpacity(this.dragItem);1281 this.setOpacity(this.moreButton);1282 },1283 /**1284 * Unsets drag styles1285 * @private1286 * @method unsetDragStyles1287 * @return {undefined}1288 */1289 unsetDragStyles: function()1290 {1291 var items = this.getAllItems();1292 var submenu = this.getSubmenu();1293 var self = this;1294 if (items && items.length) 1295 {1296 [].forEach.call(items, function(current)1297 {1298 self.unsetOpacity(current);1299 BX.removeClass(current, 'over');1300 }); 1301 }1302 if (submenu && ('menuItems' in submenu) && 1303 BX.type.isArray(submenu.menuItems) && 1304 submenu.menuItems.length)1305 {1306 [].forEach.call(submenu.menuItems, function(current)1307 {1308 self.unsetOpacity(current);1309 BX.removeClass(current.layout.item, 'over');1310 }); 1311 }1312 BX.removeClass(this.listContainer, this.classOnDrag);1313 BX.removeClass(BX(this.getSubmenuId(true)), this.classOnDrag);1314 },1315 /**1316 * Gets icon class1317 * @private1318 * @method getIconClass1319 * @param {object} item1320 * @return {string} className1321 */1322 getIconClass: function(item)1323 {1324 var result = '';1325 if (BX.type.isDomNode(item) &&1326 ('dataset' in item) &&1327 ('class' in item.dataset) &&1328 (BX.type.isNotEmptyString(item.dataset.class)))1329 {1330 result = item.dataset.class;1331 }1332 return result;1333 },1334 /**1335 * Disables the element1336 * @private1337 * @method disableItem1338 * @param {object} item1339 * @return {undefined}1340 */1341 disableItem: function(item)1342 {1343 var alias = this.getItemAlias(item);1344 if (item && ('dataset' in item))1345 {1346 item.dataset.disabled = 'true';1347 if (alias)1348 {1349 alias.dataset.disabled = 'true';1350 }1351 }1352 },1353 /**1354 * Disables the element1355 * @private1356 * @method enableItem1357 * @param {object} item1358 * @return {undefined}1359 */1360 enableItem: function(item)1361 {1362 var alias;1363 if (!BX.type.isDomNode(item))1364 {1365 return;1366 }1367 if (this.isSubmenuItem(item))1368 {1369 BX.removeClass(item, this.classItemDisabled);1370 alias = this.getItemAlias(item);1371 if (BX.type.isDomNode(alias))1372 {1373 alias.dataset.disabled = 'false';1374 }1375 }1376 },1377 /**1378 * Gets alias link1379 * @private1380 * @method getAliasLink1381 * @param {object} item1382 * @return {string}1383 */1384 getAliasLink: function(item)1385 {1386 return this.dataValue(item, 'link') || '';1387 },1388 /**1389 * Gets item alias1390 * @private1391 * @method getItemAlias1392 * @param {object} item1393 * @return {object}1394 */1395 getItemAlias: function(item)1396 {1397 var result = null;1398 var self = this;1399 var isSubmenuItem, isListItem, allItems;1400 if (!BX.type.isDomNode(item))1401 {1402 return result;1403 }1404 allItems = this.getAllItems();1405 isSubmenuItem = this.isSubmenuItem(item);1406 isListItem = this.isListItem(item);1407 if (!isSubmenuItem && !isListItem)1408 {1409 return result;1410 }1411 if (isSubmenuItem)1412 {1413 [].forEach.call(allItems, function(current)1414 {1415 if (BX.hasClass(item, self.getAliasLink(current)))1416 {1417 result = current;1418 }1419 });1420 }1421 if (isListItem)1422 {1423 result = BX.findChildren(document,1424 {1425 class: this.getAliasLink(item)1426 }, true);1427 if (BX.type.isArray(result) && result.length)1428 {1429 result = result[0];1430 }1431 }1432 return result;1433 },1434 /**1435 * Hides item1436 * @private1437 * @method hideItem1438 * @param {object} item1439 * @return {undefined}1440 */1441 hideItem: function(item)1442 {1443 if (BX.type.isDomNode)1444 {1445 BX.addClass(item, this.classSecret);1446 }1447 },1448 /**1449 * Shows item1450 * @private1451 * @method showItem1452 * @param {object} item1453 * @return {undefined}1454 */1455 showItem: function(item)1456 {1457 if (BX.type.isDomNode)1458 {1459 BX.removeClass(item, this.classSecret);1460 }1461 },1462 /**1463 * Replaces drag item1464 * @private1465 * @method fakeDragItem1466 * @return {undefined}1467 */1468 fakeDragItem: function()1469 {1470 var fakeDragItem = null;1471 if (!BX.type.isDomNode(this.dragItem) || !BX.type.isDomNode(this.overItem))1472 {1473 return;1474 }1475 if (this.isDragToSubmenu())1476 {1477 fakeDragItem = this.getItemAlias(this.dragItem);1478 if (fakeDragItem !== this.dragItem)1479 {1480 this.listContainer.appendChild(this.dragItem);1481 this.dragItem = fakeDragItem;1482 this.showItem(this.dragItem);1483 this.adjustMoreButtonPosition();1484 this.updateSubmenuItems();1485 this.tmp.moved = false;1486 }1487 }1488 if (this.isDragToList())1489 {1490 fakeDragItem = this.getItemAlias(this.dragItem);1491 if (fakeDragItem !== this.dragItem)1492 {1493 this.hideItem(this.dragItem);1494 this.dragItem = fakeDragItem;1495 this.adjustMoreButtonPosition();1496 this.updateSubmenuItems();1497 }1498 }1499 },1500 /**1501 * Updates submenu items relative to hidden items1502 * @private1503 * @method updateSubmenuItems1504 * @return {undefined}1505 */1506 updateSubmenuItems: function()1507 {1508 var hiddenItems = this.getHiddenItems();1509 var disabledItems = this.getDisabledItems();1510 var self = this;1511 var items = [];1512 var submenu, submenuItems, some;1513 submenu = this.getSubmenu();1514 if (submenu === null)1515 {1516 return;1517 }1518 submenuItems = submenu.menuItems;1519 if (!BX.type.isArray(submenuItems) || !submenuItems.length)1520 {1521 return;1522 }1523 items = disabledItems.concat(hiddenItems);1524 submenuItems.forEach(function(current)1525 {1526 some = [].some.call(items, function(someEl) {1527 return (1528 BX.hasClass(current.layout.item, self.dataValue(someEl, 'link')) ||1529 self.isDisabled(current.layout.item) ||1530 self.isSeporator(current.layout.item) || 1531 self.isDropzone(current.layout.item)1532 );1533 });1534 if (some)1535 {1536 self.showItem(current.layout.item);1537 }1538 else1539 {1540 self.hideItem(current.layout.item);1541 }1542 });1543 },1544 /**1545 * Sets styles for overed item1546 * @private1547 * @method setOverStyles1548 * @param {object} item1549 */1550 setOverStyles: function(item)1551 {1552 if (BX.type.isDomNode(item) && !BX.hasClass(item, this.classItemOver))1553 {1554 BX.addClass(item, this.classItemOver);1555 }1556 },1557 /**1558 * Unsets styles for overed item1559 * @private1560 * @method unsetOverStyles1561 * @param {object} item1562 * @return {undefined}1563 */1564 unsetOverStyles: function(item)1565 {1566 if (BX.type.isDomNode(item) && BX.hasClass(item, this.classItemOver))1567 {1568 BX.removeClass(item, this.classItemOver);1569 }1570 },1571 /**1572 * Gets value data attribute1573 * @private1574 * @method dataValue1575 * @param {object} item1576 * @param {string} key1577 * @return {string}1578 */1579 dataValue: function(item, key)1580 {1581 var result = '';1582 var tmpResult;1583 if (BX.type.isDomNode(item))1584 {1585 tmpResult = BX.data(item, key);1586 if (typeof(tmpResult) !== 'undefined') 1587 {1588 result = tmpResult;1589 } 1590 }1591 return result;1592 },1593 /**1594 * Executes script1595 * @private1596 * @method execScript1597 * @param {string} script1598 */1599 /*jshint -W061 */1600 execScript: function(script)1601 {1602 if (BX.type.isNotEmptyString(script))1603 {1604 eval(script);1605 }1606 },1607 /**1608 * Shows license window1609 * @return {undefined}1610 */1611 showLicenseWindow: function()1612 {1613 var popup;1614 if (!B24.licenseInfoPopup)1615 {1616 return;1617 }1618 popup = B24.licenseInfoPopup;1619 popup.init({1620 B24_LICENSE_BUTTON_TEXT: this.message('MIB_LICENSE_BUY_BUTTON'),1621 B24_TRIAL_BUTTON_TEXT: this.message('MIB_LICENSE_TRIAL_BUTTON'),1622 IS_FULL_DEMO_EXISTS: this.licenseParams.isFullDemoExists,1623 HOST_NAME: this.licenseParams.hostname,1624 AJAX_URL: this.licenseParams.ajaxUrl,1625 LICENSE_ALL_PATH: this.licenseParams.licenseAllPath,1626 LICENSE_DEMO_PATH: this.licenseParams.licenseDemoPath,1627 FEATURE_GROUP_NAME: this.licenseParams.featureGroupName,1628 AJAX_ACTIONS_URL: this.licenseParams.ajaxActionsUrl,1629 B24_FEATURE_TRIAL_SUCCESS_TEXT: this.message('MIB_LICENSE_WINDOW_TRIAL_SUCCESS_TEXT')1630 });1631 popup.show(1632 'main-buttons',1633 this.message('MIB_LICENSE_WINDOW_HEADER_TEXT'),1634 this.message('MIB_LICENSE_WINDOW_TEXT')1635 );1636 },1637 /**1638 * dragstart event handler1639 * @private1640 * @method _onDragStart1641 * @param {object} event ondragstart event object1642 * @return {undefined}1643 */1644 _onDragStart: function(event)1645 {1646 this.dragItem = this.getItem(event);1647 if (!BX.type.isDomNode(this.dragItem))1648 {1649 return;1650 }1651 if (this.isMoreButton(this.dragItem))1652 {1653 event.preventDefault();1654 return;1655 }1656 if (this.isSubmenuShown) 1657 {1658 this.isSubmenuShownOnDragStart = true;1659 }1660 else 1661 {1662 this.isSubmenuShownOnDragStart = false;1663 }1664 if (this.isListItem(this.dragItem)) 1665 {1666 this.visibleControllMoreButton();1667 this.showSubmenu();1668 }1669 this.setDragStyles();1670 },1671 /**1672 * dragend event handleer1673 * @private1674 * @method _onDragEnd1675 * @param {object} event dragend event object1676 * @return {undefined}1677 */1678 _onDragEnd: function(event)1679 {1680 event.preventDefault();1681 var item = this.getItem(event);1682 if (!BX.type.isDomNode(item))1683 {1684 return;1685 }1686 this.unsetDragStyles();1687 if (!this.isSubmenuShownOnDragStart)1688 {1689 this.refreshSubmenu();1690 this.closeSubmenu();1691 }1692 else1693 {1694 this.refreshSubmenu();1695 }1696 this.saveSettings();1697 this.dragItem = null;1698 this.overItem = null;1699 this.tmp.moved = false;1700 this.visibleControllMoreButton();1701 },1702 /**1703 * dragenter event handler1704 * @private1705 * @method _onDragEnter1706 * @param {object} event dragenter event object1707 * @return {undefined}1708 */1709 _onDragEnter: function(event)1710 {1711 var item = this.getItem(event);1712 if (!BX.type.isDomNode(item) || !this.isDropzone(item))1713 {1714 return;1715 }1716 },1717 /**1718 * dragover event handler1719 * @private1720 * @method _onDragOver1721 * @param {object} event dragover event object1722 * @return {undefined}1723 */1724 _onDragOver: function(event)1725 {1726 event.preventDefault();1727 var nextSiblingItem = null;1728 this.overItem = this.getItem(event);1729 if (!BX.type.isDomNode(this.overItem) ||1730 !BX.type.isDomNode(this.dragItem) ||1731 this.overItem === this.dragItem ||1732 this.isDisabled(this.overItem))1733 {1734 return;1735 } 1736 else if (this.isDropzone(this.overItem))1737 {1738 this.setOverStyles(this.overItem);1739 return;1740 }1741 this.fakeDragItem();1742 if (this.isNext(event) && this.isGoodPosition(event) && !this.isMoreButton(this.overItem))1743 {1744 nextSiblingItem = this.findNextSiblingByClass(1745 this.overItem,1746 this.classItem1747 );1748 if (this.isMoreButton(nextSiblingItem) && !this.tmp.moved)1749 {1750 nextSiblingItem = nextSiblingItem.previousElementSibling;1751 this.tmp.moved = true;1752 }1753 if (!BX.type.isDomNode(nextSiblingItem))1754 {1755 nextSiblingItem = this.findNextSiblingByClass(1756 this.overItem,1757 this.classSubmenuItem1758 );1759 }1760 if (BX.type.isDomNode(nextSiblingItem))1761 {1762 this.moveButton(nextSiblingItem);1763 this.moveButtonAlias(nextSiblingItem);1764 this.adjustMoreButtonPosition();1765 this.updateSubmenuItems();1766 }1767 }1768 if ((!this.isNext(event) && this.isGoodPosition(event) && !this.isMoreButton(this.overItem)) || 1769 (!this.isGoodPosition(event) && this.isMoreButton(this.overItem) && this.getVisibleItems().length === 1))1770 {1771 this.moveButton(this.overItem);1772 this.moveButtonAlias(this.overItem);1773 this.adjustMoreButtonPosition();1774 this.updateSubmenuItems();1775 }1776 },1777 /**1778 * dragleave event handler1779 * @private1780 * @method _onDragLeave1781 * @param {object} event dragleave event object1782 * @return {undefined}1783 */1784 _onDragLeave: function(event)1785 {1786 var item = this.getItem(event);1787 if (BX.type.isDomNode(item))1788 {1789 this.unsetOverStyles(event.target);1790 }1791 },1792 /**1793 * drop event handler1794 * @private1795 * @method _onDrop1796 * @param {object} event drop event object1797 * @return {undefined}1798 */1799 _onDrop: function(event)1800 {1801 var item = this.getItem(event);1802 if (!BX.type.isDomNode(item))1803 {1804 return;1805 }1806 if (this.isDropzone(item))1807 {1808 this.disableItem(this.dragItem);1809 this.adjustMoreButtonPosition();1810 }1811 this.unsetDragStyles();1812 },1813 /**1814 * submenuClose custom BX.PopupMenu event handler1815 * @private1816 * @method _onSubmenuClose1817 * @return {undefined}1818 */1819 _onSubmenuClose: function()1820 {1821 this.deactivateItem(this.moreButton);1822 this.setSubmenuShown(false);1823 },1824 /**1825 * resize window event handler1826 * @private1827 * @method _onResizeHandler1828 * @return {object} window resize event object1829 */1830 _onResizeHandler: function()1831 {1832 this.adjustMoreButtonPosition();1833 this.visibleControllMoreButton();1834 this.updateSubmenuItems();1835 },1836 /**1837 * click on more button event handler1838 * @private1839 * @method _onClickMoreButton1840 * @param {object} event click event object1841 * @return {undefined}1842 */1843 _onClickMoreButton: function(event)1844 {1845 event.preventDefault();1846 this.showSubmenu();1847 },1848 /**1849 * mouseover and mouseout events handler1850 * @private1851 * @method _onMouse1852 * @param {object} event mouseover and mouseout event object1853 * @return {undefined}1854 */1855 _onMouse: function(event)1856 {1857 var item = this.getItem(event);1858 if (event.type === 'mouseover' && !BX.hasClass(item, this.classItemOver))1859 {1860 BX.addClass(item, this.classItemOver);1861 }1862 if (event.type === 'mouseout' && BX.hasClass(item, this.classItemOver))1863 {1864 BX.removeClass(item, this.classItemOver);1865 }1866 },1867 /**1868 * click event handler1869 * @private1870 * @method _onClick1871 * @param {object} event1872 * @return {undefined}1873 */1874 _onClick: function(event)1875 {1876 var item = null;1877 var dataOnclick;1878 if (!this.isSublink(event.target))1879 {1880 item = this.getItem(event);1881 if (!BX.type.isDomNode(item))1882 {1883 return;1884 }1885 dataOnclick = this.dataValue(item, 'onclick');1886 if (BX.type.isNotEmptyString(dataOnclick))1887 {1888 event.preventDefault();1889 this.execScript(dataOnclick);1890 }1891 }1892 item = this.getItem(event);1893 if (BX.type.isDomNode(item) && this.isLocked(item))1894 {1895 event.preventDefault();1896 this.showLicenseWindow();1897 }1898 },1899 _onScroll: function()1900 {1901 if (BX.style(this.pinContainer, 'position') === 'fixed')1902 {1903 this.closeSubmenu();1904 }1905 },1906 /**1907 * Checks whether the item is disabled1908 * @private1909 * @method isDisabled1910 * @param {object} item1911 * @return {boolean}1912 */1913 isDisabled: function(item)1914 {1915 var result = false;1916 if (BX.type.isDomNode(item))1917 {1918 result = (1919 this.dataValue(item, 'disabled') === 'true' ||1920 BX.hasClass(item, this.classItemDisabled)1921 );1922 }1923 return result;1924 },1925 /**1926 * Checks whether the item is locked1927 * @private1928 * @method isLocked1929 * @param {object} item1930 * @return {boolean}1931 */1932 isLocked: function(item)1933 {1934 var result = false;1935 if (BX.type.isDomNode(item))1936 {1937 result = (1938 this.dataValue(item, 'locked') === 'true' ||1939 BX.hasClass(item, this.classItemLocked)1940 );1941 }1942 return result;1943 },1944 /**1945 * Checks whether the item is dropzone1946 * @private1947 * @method isOvered1948 * @param {object} item1949 * @return {boolean}1950 */1951 isDropzone: function(item)1952 {1953 return BX.hasClass(item, this.classDropzone);1954 },1955 /**1956 * Checks whether the item is over1957 * @private1958 * @method isOvered1959 * @param {object} item1960 * @return {boolean}1961 */1962 isOvered: function(item)1963 {1964 return BX.hasClass(item, this.classItemOver);1965 },1966 /**1967 * Checks whether the overed item is next1968 * @private1969 * @method isNext1970 * @param {object} event dragover event object1971 * @return {boolean}1972 */1973 isNext: function(event)1974 {1975 var dragItemRect = this.dragItem.getBoundingClientRect();1976 var overItemRect = this.overItem.getBoundingClientRect();1977 var styles = getComputedStyle(this.dragItem);1978 var dragItemMarginRight = parseInt(styles.marginRight.replace('px', ''));1979 var result = null;1980 if (this.isListItem(this.overItem))1981 {1982 result = (1983 event.clientX > (overItemRect.left - dragItemMarginRight) && event.clientX > dragItemRect.right1984 );1985 }1986 if (this.isSubmenuItem(this.overItem))1987 {1988 result = (1989 event.clientY > dragItemRect.top1990 );1991 }1992 return result;1993 },1994 /**1995 * Checks whether it is possible to move the item1996 * @private1997 * @method isGoodPosition1998 * @param {object} event dragover event object1999 * @return {boolean}2000 */2001 isGoodPosition: function(event)2002 {2003 var overItem = this.overItem;2004 var overItemRect, result;2005 if (!BX.type.isDomNode(overItem))2006 {2007 return;2008 }2009 overItemRect = overItem.getBoundingClientRect();2010 if (this.isListItem(overItem))2011 {2012 result = (2013 (this.isNext(event) && (event.clientX >= (overItemRect.left + (overItemRect.width / 2)))) ||2014 (!this.isNext(event) && (event.clientX <= (overItemRect.left + (overItemRect.width / 2))))2015 );2016 }2017 if (this.isSubmenuItem(overItem))2018 {2019 result = (2020 (this.isNext(event) && (event.clientY >= (overItemRect.top + (overItemRect.height / 2)))) ||2021 (!this.isNext(event) && (event.clientY <= (overItemRect.top + (overItemRect.height / 2))))2022 );2023 }2024 return result;2025 },2026 /**2027 * Checks whether the item is a submenu item2028 * @private2029 * @method isSubmenuItem2030 * @param {object} item2031 * @return {boolean}2032 */2033 isSubmenuItem: function(item)2034 {2035 return BX.hasClass(item, this.classSubmenuItem);2036 },2037 /**2038 * Checks whether the item is visible2039 * @private2040 * @method isVisibleItem2041 * @param {object} item 2042 * @return {boolean}2043 */2044 isVisibleItem: function(item)2045 {2046 if (!BX.type.isDomNode(item))2047 {2048 return;2049 }2050 return item.offsetTop === 0;2051 },2052 /**2053 * Checks whether the item is more button2054 * @private2055 * @method isMoreButton2056 * @param {object} item2057 * @return {boolean}2058 */2059 isMoreButton: function(item)2060 {2061 var result = false;2062 if (BX.type.isDomNode(item) && BX.hasClass(item, this.classItemMore))2063 {2064 result = true;2065 }2066 return result;2067 },2068 /**2069 * Checks whether the item is list item2070 * @private2071 * @method isListItem2072 * @param {object} item2073 * @return {boolean}2074 */2075 isListItem: function(item)2076 {2077 var result = false;2078 if (BX.type.isDomNode(item) && BX.hasClass(item, this.classItem))2079 {2080 result = true;2081 }2082 return result;2083 },2084 /**2085 * Checks whether the item is sublink2086 * @private2087 * @method isSublink2088 * @param {object} item2089 * @return {boolean}2090 */2091 isSublink: function(item)2092 {2093 var result = false;2094 if (BX.type.isDomNode(item))2095 {2096 result = BX.hasClass(item, this.classItemSublink);2097 }2098 return result;2099 },2100 /**2101 * Checks whether the item is seporator2102 * @private2103 * @method isSeporator2104 * @param {object} item2105 * @return {boolean}2106 */2107 isSeporator: function(item)2108 {2109 var result = false;2110 if (BX.type.isDomNode(item))2111 {2112 result = BX.hasClass(item, this.classSeporator);2113 }2114 return result;2115 },2116 /**2117 * Checks that the element is dragged into the submenu2118 * @return {boolean}2119 */2120 isDragToSubmenu: function()2121 {2122 return (!this.isSubmenuItem(this.dragItem) &&2123 this.isSubmenuItem(this.overItem)2124 );2125 },2126 /**2127 * Checks that the element is dragged into the list2128 * @return {boolean}2129 */2130 isDragToList: function()2131 {2132 return (2133 this.isSubmenuItem(this.dragItem) &&2134 !this.isSubmenuItem(this.overItem)2135 );2136 }2137 };2138}2139if (typeof(BX.Main.interfaceButtonsManager) === 'undefined')2140{2141 BX.Main.interfaceButtonsManager =2142 {2143 data: {},2144 init: function(params)2145 {2146 var container = null;2147 if (!BX.type.isPlainObject(params) || !('containerId' in params))2148 {2149 throw 'BX.Main.interfaceButtonsManager: containerId not set in params Object';2150 }2151 container = BX(params.containerId);2152 if (BX.type.isDomNode(container))2153 {2154 this.data[params.containerId] = new BX.Main.interfaceButtons(container, params);2155 }2156 else2157 {2158 BX(BX.delegate(function() {2159 container = BX(params.containerId);2160 if (!BX.type.isDomNode(container))2161 {2162 throw 'BX.Main.interfaceButtonsManager: container is not dom node';2163 }2164 this.data[params.containerId] = new BX.Main.interfaceButtons(container, params);2165 }, this));2166 }2167 },2168 getById: function(containerId)2169 {2170 var result = null;2171 if (BX.type.isString(containerId) && BX.type.isNotEmptyString(containerId))2172 {2173 try2174 {...

Full Screen

Full Screen

gridupdater.js

Source:gridupdater.js Github

copy

Full Screen

...30 headers = this.getParent().getHeaders();31 headers.forEach(function(header) {32 header = BX.cleanNode(header);33 rows.forEach(function(row) {34 if (BX.type.isDomNode(row))35 {36 header.appendChild(BX.clone(row));37 }38 });39 });40 }41 };42 /**43 * Appends head rows44 * @param {?HTMLTableRowElement[]} rows45 */46 BX.Grid.Updater.prototype.appendHeadRows = function(rows)47 {48 var headers;49 if (BX.type.isArray(rows) && rows.length)50 {51 headers = this.getParent().getHeaders();52 headers.forEach(function(header) {53 rows.forEach(function(row) {54 if (BX.type.isDomNode(row))55 {56 header.appendChild(BX.clone(row));57 }58 });59 });60 }61 };62 /**63 * Prepends head rows64 * @param {?HTMLTableRowElement[]} rows65 */66 BX.Grid.Updater.prototype.prependHeadRows = function(rows)67 {68 var headers;69 if (BX.type.isArray(rows) && rows.length)70 {71 headers = this.getParent().getHeaders();72 headers.forEach(function(header) {73 header = BX.cleanNode(header);74 rows.forEach(function(row) {75 if (BX.type.isDomNode(row))76 {77 header.prepend(BX.clone(row));78 }79 });80 });81 }82 };83 /**84 * Updates body row by row id85 * @param {?string|number} id86 * @param {HTMLTableRowElement} row87 */88 BX.Grid.Updater.prototype.updateBodyRowById = function(id, row)89 {90 if ((BX.type.isNumber(id) || BX.type.isNotEmptyString(id)) && BX.type.isDomNode(row))91 {92 var currentRow = this.getParent().getRows().getById(id);93 if (currentRow)94 {95 var currentNode = currentRow.getNode();96 BX.insertAfter(row, currentNode);97 BX.remove(currentNode);98 }99 }100 };101 /**102 * Updates all body rows.103 * @param {?HTMLTableRowElement[]} rows104 */105 BX.Grid.Updater.prototype.updateBodyRows = function(rows)106 {107 if (BX.type.isArray(rows))108 {109 var body = this.getParent().getBody();110 body.innerHTML = '';111 rows.forEach(function(current) {112 !!current && body.appendChild(current);113 });114 }115 };116 /**117 * Appends body rows.118 * @param {?HTMLTableRowElement[]} rows119 */120 BX.Grid.Updater.prototype.appendBodyRows = function(rows)121 {122 var body;123 if (BX.type.isArray(rows))124 {125 body = this.getParent().getBody();126 rows.forEach(function(current) {127 if (BX.type.isDomNode(current))128 {129 body.appendChild(current);130 }131 });132 }133 };134 /**135 * Prepends body rows136 * @param {?HTMLTableRowElement[]} rows137 */138 BX.Grid.Updater.prototype.prependBodyRows = function(rows)139 {140 var body;141 if (BX.type.isArray(rows))142 {143 body = this.getParent().getBody();144 rows.forEach(function(current) {145 if (BX.type.isDomNode(current))146 {147 BX.prepend(body, current);148 }149 });150 }151 };152 /**153 * Updates table footer rows.154 * @param {?HTMLTableRowElement[]} rows155 */156 BX.Grid.Updater.prototype.updateFootRows = function(rows)157 {158 var foot;159 if (BX.type.isArray(rows))160 {161 foot = BX.cleanNode(this.getParent().getFoot());162 rows.forEach(function(current) {163 if (BX.type.isDomNode(current))164 {165 foot.appendChild(current);166 }167 });168 }169 };170 /**171 * Updates total rows counter172 * @param {?HTMLElement} counter173 */174 BX.Grid.Updater.prototype.updateCounterTotal = function(counter)175 {176 var counterCell;177 if (BX.type.isDomNode(counter))178 {179 counterCell = BX.cleanNode(this.getParent().getCounterTotal());180 counterCell.appendChild(counter);181 }182 };183 /**184 * Updates grid pagination185 * @param {?HTMLElement} pagination186 */187 BX.Grid.Updater.prototype.updatePagination = function(pagination)188 {189 var paginationCell = this.getParent().getPagination().getContainer();190 if (!!paginationCell)191 {192 paginationCell.innerHTML = '';193 if (BX.type.isDomNode(pagination))194 {195 paginationCell.appendChild(pagination);196 }197 }198 };199 /**200 * Updates more button201 * @param {?HTMLElement} button202 */203 BX.Grid.Updater.prototype.updateMoreButton = function(button)204 {205 if (BX.type.isDomNode(button))206 {207 var buttonParent = BX.Grid.Utils.closestParent(this.getParent().getMoreButton().getNode());208 buttonParent.innerHTML = '';209 buttonParent.appendChild(button);210 }211 };212 /**213 * Updates group actions panel214 * @param {HTMLElement} panel215 */216 BX.Grid.Updater.prototype.updateGroupActions = function(panel)217 {218 var GroupActions = this.parent.getActionsPanel();219 if (!!GroupActions && BX.type.isDomNode(panel))220 {221 var panelNode = GroupActions.getPanel();222 if (BX.type.isDomNode(panelNode))223 {224 panelNode.innerHTML = '';225 var panelChild = BX.firstChild(panel);226 if (BX.type.isDomNode(panelChild))227 {228 panelNode.appendChild(panelChild);229 }230 }231 }232 };...

Full Screen

Full Screen

isDomNode.test.js

Source:isDomNode.test.js Github

copy

Full Screen

...4 document.body.innerHTML = '<div id="mock"></div><div class="mock"></div><div class="mock"></div><div class="mock"></div>';5 } );6 test( 'isDomNode with Real DOM Node', () => {7 const el = document.querySelector('#mock');8 const expectTest = isDomNode( el );9 expect( expectTest ).toEqual( true );10 } );11 test( 'isDomNode with Non-Existing DOM Node', () => {12 const el = document.querySelector('#mock-not-existing');13 const expectTest = isDomNode( el );14 expect( expectTest ).toEqual( false );15 } );16 test( 'isDomNode with NodeList', () => {17 const el = document.querySelectorAll('.mock');18 const expectTest = isDomNode( el );19 expect( expectTest ).toEqual( false );20 } );21 test( 'isDomNode with non-dom-node element {}', () => {22 const expectTest = isDomNode( {} );23 expect( expectTest ).toEqual( false );24 } );25 test( 'isDomNode with non-dom-node element []', () => {26 const expectTest = isDomNode( [] );27 expect( expectTest ).toEqual( false );28 } );29 test( 'isDomNode with non-dom-node element "hello"', () => {30 const expectTest = isDomNode( 'hello' );31 expect( expectTest ).toEqual( false );32 } );33 test( 'isDomNode with non-dom-node element 7', () => {34 const expectTest = isDomNode( 7 );35 expect( expectTest ).toEqual( false );36 } );37 test( 'isDomNode with non-dom-node element true', () => {38 const expectTest = isDomNode( true );39 expect( expectTest ).toEqual( false );40 } );41 test( 'isDomNode with non-dom-node element null', () => {42 const expectTest = isDomNode( null );43 expect( expectTest ).toEqual( false );44 } );45 test( 'isDomNode with non-dom-node element undefined', () => {46 const expectTest = isDomNode( undefined );47 expect( expectTest ).toEqual( false );48 } );49 test( 'isDomNode with 0 arguments', () => {50 const expectTest = isDomNode();51 expect( expectTest ).toEqual( false );52 } );...

Full Screen

Full Screen

dom.js

Source:dom.js Github

copy

Full Screen

...3//#commentToString4module("The module bd/dom",5 theFunction("[bd.isDomNode]",6 demo("[*]", function() {7 the(bd.isDomNode(undefined)).is(false);8 the(bd.isDomNode(null)).is(false);9 the(bd.isDomNode(0)).is(false);10 the(bd.isDomNode("")).is(false);11 the(bd.isDomNode(1)).is(false);12 the(bd.isDomNode("someNode")).is(false);13 the(bd.isDomNode(bd.body)).is(true);14 the(bd.isDomNode(bd.body.firstChild)).is(true);15 }))16);17});...

Full Screen

Full Screen

Jest Testing Tutorial

LambdaTest’s Jest Testing Tutorial covers step-by-step guides around Jest with code examples to help you be proficient with the Jest framework. The Jest tutorial has chapters to help you learn right from the basics of Jest framework to code-based tutorials around testing react apps with Jest, perform snapshot testing, import ES modules and more.

Chapters

  1. What is Jest Framework
  2. Advantages of Jest - Jest has 3,898,000 GitHub repositories, as mentioned on its official website. Learn what makes Jest special and why Jest has gained popularity among the testing and developer community.
  3. Jest Installation - All the prerequisites and set up steps needed to help you start Jest automation testing.
  4. Using Jest with NodeJS Project - Learn how to leverage Jest framework to automate testing using a NodeJS Project.
  5. Writing First Test for Jest Framework - Get started with code-based tutorial to help you write and execute your first Jest framework testing script.
  6. Jest Vocabulary - Learn the industry renowned and official jargons of the Jest framework by digging deep into the Jest vocabulary.
  7. Unit Testing with Jest - Step-by-step tutorial to help you execute unit testing with Jest framework.
  8. Jest Basics - Learn about the most pivotal and basic features which makes Jest special.
  9. Jest Parameterized Tests - Avoid code duplication and fasten automation testing with Jest using parameterized tests. Parameterization allows you to trigger the same test scenario over different test configurations by incorporating parameters.
  10. Jest Matchers - Enforce assertions better with the help of matchers. Matchers help you compare the actual output with the expected one. Here is an example to see if the object is acquired from the correct class or not. -

|<p>it('check_object_of_Car', () => {</p><p> expect(newCar()).toBeInstanceOf(Car);</p><p> });</p>| | :- |

  1. Jest Hooks: Setup and Teardown - Learn how to set up conditions which needs to be followed by the test execution and incorporate a tear down function to free resources after the execution is complete.
  2. Jest Code Coverage - Unsure there is no code left unchecked in your application. Jest gives a specific flag called --coverage to help you generate code coverage.
  3. HTML Report Generation - Learn how to create a comprehensive HTML report based on your Jest test execution.
  4. Testing React app using Jest Framework - Learn how to test your react web-application with Jest framework in this detailed Jest tutorial.
  5. Test using LambdaTest cloud Selenium Grid - Run your Jest testing script over LambdaTest cloud-based platform and leverage parallel testing to help trim down your test execution time.
  6. Snapshot Testing for React Front Ends - Capture screenshots of your react based web-application and compare them automatically for visual anomalies with the help of Jest tutorial.
  7. Bonus: Import ES modules with Jest - ES modules are also known as ECMAScript modules. Learn how to best use them by importing in your Jest testing scripts.
  8. Jest vs Mocha vs Jasmine - Learn the key differences between the most popular JavaScript-based testing frameworks i.e. Jest, Mocha, and Jasmine.
  9. Jest FAQs(Frequently Asked Questions) - Explore the most commonly asked questions around Jest framework, with their answers.

Run Jest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful