How to use this.parent method in istanbul

Best JavaScript code snippet using istanbul

presets.js

Source:presets.js Github

copy

Full Screen

1;(function() {2 'use strict';3 BX.namespace('BX.Filter');4 /**5 * Filter presets class6 * @param parent7 * @constructor8 */9 BX.Filter.Presets = function(parent)10 {11 this.parent = null;12 this.presets = null;13 this.container = null;14 this.init(parent);15 };16 BX.Filter.Presets.prototype = {17 init: function(parent)18 {19 this.parent = parent;20 },21 bindOnPresetClick: function()22 {23 (this.getPresets() || []).forEach(function(current) {24 BX.bind(current, 'click', BX.delegate(this._onPresetClick, this));25 }, this);26 },27 /**28 * Gets add preset field29 * @return {?HTMLElement}30 */31 getAddPresetField: function()32 {33 return BX.Filter.Utils.getByClass(this.getContainer(), this.parent.settings.classAddPresetField);34 },35 /**36 * Gets add preset name input37 * @return {?HTMLInputElement}38 */39 getAddPresetFieldInput: function()40 {41 return BX.Filter.Utils.getByClass(this.getAddPresetField(), this.parent.settings.classAddPresetFieldInput);42 },43 /**44 * Clears add preset input value45 */46 clearAddPresetFieldInput: function()47 {48 var input = this.getAddPresetFieldInput();49 input && (input.value = '');50 },51 /**52 * Finds preset node by child node53 * @param {?HTMLElement} node54 * @return {?HTMLElement}55 */56 normalizePreset: function(node)57 {58 if (!BX.hasClass(node, this.parent.settings.classPreset))59 {60 node = BX.findParent(node, {className: this.parent.settings.classPreset}, true, false);61 }62 return node;63 },64 /**65 * Deactivates all presets66 */67 deactivateAllPresets: function()68 {69 var presets = this.getPresets();70 var self = this;71 (presets || []).forEach(function(current) {72 if (BX.hasClass(current, self.parent.settings.classPresetCurrent))73 {74 BX.removeClass(current, self.parent.settings.classPresetCurrent)75 }76 });77 },78 /**79 * Creates sidebar preset item80 * @param {string} id - Preset id81 * @param {string} title - Preset title82 * @param {boolean} [isPinned] - Pass true is preset pinned83 */84 createSidebarItem: function(id, title, isPinned)85 {86 return BX.decl({87 block: 'sidebar-item',88 text: BX.util.htmlspecialcharsback(title),89 id: id,90 pinned: isPinned,91 noEditPinTitle: this.parent.getParam('MAIN_UI_FILTER__IS_SET_AS_DEFAULT_PRESET'),92 editNameTitle: this.parent.getParam('MAIN_UI_FILTER__EDIT_PRESET_TITLE'),93 removeTitle: this.parent.getParam('MAIN_UI_FILTER__REMOVE_PRESET'),94 editPinTitle: this.parent.getParam('MAIN_UI_FILTER__SET_AS_DEFAULT_PRESET'),95 dragTitle: this.parent.getParam('MAIN_UI_FILTER__DRAG_TITLE')96 });97 },98 /**99 * Highlights preset node as active100 * @param {?HTMLElement|string} preset - preset node or preset id101 */102 activatePreset: function(preset)103 {104 this.deactivateAllPresets();105 if (BX.type.isNotEmptyString(preset))106 {107 preset = this.getPresetNodeById(preset);108 }109 if (preset && !BX.hasClass(preset, this.parent.settings.classPresetCurrent))110 {111 BX.addClass(preset, this.parent.settings.classPresetCurrent);112 }113 },114 /**115 * Gets preset node by preset id116 * @param {string} id117 * @return {?HTMLElement}118 */119 getPresetNodeById: function(id)120 {121 var presets = this.getPresets();122 var result = presets.filter(function(current) {123 return BX.data(current, 'id') === id;124 }, this);125 return result.length > 0 ? result[0] : null;126 },127 /**128 * Gets preset id by preset node129 * @param {?HTMLElement} preset130 */131 getPresetId: function(preset)132 {133 return BX.data(preset, 'id');134 },135 /**136 * Updates preset name137 * @param {?HTMLElement} presetNode138 * @param {string} name139 */140 updatePresetName: function(presetNode, name)141 {142 var nameNode;143 if (BX.type.isDomNode(presetNode) && BX.type.isNotEmptyString(name))144 {145 nameNode = this.getPresetNameNode(presetNode);146 if (BX.type.isDomNode(nameNode))147 {148 BX.html(nameNode, name);149 }150 }151 },152 /**153 * Removes preset154 * @param {HTMLElement} presetNode155 * @param {string} presetId156 * @param {boolean} isDefault157 */158 removePreset: function(presetNode, presetId, isDefault)159 {160 var currentPresetId = this.getCurrentPresetId();161 var newPresets = [];162 var postData = {163 'preset_id': presetId,164 'is_default': isDefault165 };166 var getData = {167 'FILTER_ID': this.parent.getParam('FILTER_ID'),168 'action': 'REMOVE_FILTER'169 };170 this.parent.saveOptions(postData, getData);171 BX.remove(presetNode);172 if (BX.type.isArray(this.parent.params['PRESETS']))173 {174 newPresets = this.parent.params['PRESETS'].filter(function(current) {175 return current.ID !== presetId;176 }, this);177 this.parent.params['PRESETS'] = newPresets;178 }179 if (BX.type.isArray(this.parent.editablePresets))180 {181 newPresets = this.parent.editablePresets.filter(function(current) {182 return current.ID !== presetId;183 }, this);184 this.parent.editablePresets = newPresets;185 }186 if (presetId === currentPresetId)187 {188 this.parent.getSearch().removePreset();189 this.resetPreset();190 }191 },192 /**193 * Pin preset (Sets as default preset)194 * @param {string} presetId195 */196 pinPreset: function(presetId)197 {198 if (!BX.type.isNotEmptyString(presetId))199 {200 presetId = 'default_filter';201 }202 var presetNode = this.getPresetNodeById(presetId);203 if (this.parent.getParam('VALUE_REQUIRED_MODE'))204 {205 if (presetId === 'default_filter')206 {207 return;208 }209 }210 var params = {'FILTER_ID': this.parent.getParam('FILTER_ID'), 'GRID_ID': this.parent.getParam('GRID_ID'), 'action': 'PIN_PRESET'};211 var data = {preset_id: presetId};212 this.getPresets().forEach(function(current) {213 BX.removeClass(current, this.parent.settings.classPinnedPreset);214 }, this);215 BX.addClass(presetNode, this.parent.settings.classPinnedPreset);216 this.parent.saveOptions(data, params);217 },218 _onPresetClick: function(event) {219 var presetNode, presetId, presetData, isDefault, target, settings, parent;220 event.preventDefault();221 parent = this.parent;222 settings = parent.settings;223 target = event.target;224 presetNode = event.currentTarget;225 presetId = this.getPresetId(presetNode);226 presetData = this.getPreset(presetId);227 if (BX.hasClass(target, settings.classPinButton))228 {229 if (this.parent.isEditEnabled())230 {231 if (BX.hasClass(presetNode, settings.classPinnedPreset))232 {233 this.pinPreset("default_filter");234 }235 else236 {237 this.pinPreset(presetId)238 }239 }240 }241 if (BX.hasClass(target, settings.classPresetEditButton))242 {243 this.enableEditPresetName(presetNode);244 }245 if (BX.hasClass(target, settings.classPresetDeleteButton))246 {247 isDefault = 'IS_DEFAULT' in presetData ? presetData.IS_DEFAULT : false;248 this.removePreset(presetNode, presetId, isDefault);249 return false;250 }251 if (!BX.hasClass(target, settings.classPresetDragButton) &&252 !BX.hasClass(target, settings.classAddPresetFieldInput))253 {254 if (this.parent.isEditEnabled())255 {256 this.updateEditablePreset(this.getCurrentPresetId());257 }258 var currentPreset = this.getPreset(this.getCurrentPresetId());259 var preset = this.getPreset(presetId);260 currentPreset.ADDITIONAL = [];261 preset.ADDITIONAL = [];262 this.activatePreset(presetNode);263 this.applyPreset(presetId);264 if (!this.parent.isEditEnabled())265 {266 parent.applyFilter(null, true);267 if (event.isTrusted)268 {269 parent.closePopup();270 }271 if (parent.isAddPresetEnabled())272 {273 parent.disableAddPreset();274 }275 }276 }277 },278 /**279 * Applies default preset280 * @return {BX.Promise}281 */282 applyPinnedPreset: function()283 {284 var Filter = this.parent;285 var isPinned = this.isPinned(this.getCurrentPresetId());286 var promise;287 if (!isPinned)288 {289 var pinnedPresetId = this.getPinnedPresetId();290 var pinnedPresetNode = this.getPinnedPresetNode();291 var clear = false;292 var applyPreset = true;293 this.deactivateAllPresets();294 this.activatePreset(pinnedPresetNode);295 this.applyPreset(pinnedPresetId);296 promise = Filter.applyFilter(clear, applyPreset);297 Filter.closePopup();298 }299 else300 {301 promise = Filter.resetFilter();302 }303 return promise;304 },305 /**306 * Updates editable presets307 * @param {string} presetId308 */309 updateEditablePreset: function(presetId)310 {311 var fields = this.parent.getFilterFieldsValues();312 var presetRows = this.getFields().map(function(curr) { return BX.data(curr, 'name'); });313 var presetFields = this.parent.preparePresetFields(fields, presetRows);314 var preset = this.getPreset(presetId);315 preset.FIELDS = presetFields;316 preset.TITLE = this.getPresetInput(this.getPresetNodeById(presetId)).value;317 preset.ROWS = presetRows;318 },319 /**320 * Gets preset input node321 * @param presetNode322 * @return {?HTMLInputElement}323 */324 getPresetInput: function(presetNode)325 {326 return BX.Filter.Utils.getByClass(presetNode, this.parent.settings.classPresetEditInput);327 },328 /**329 * Enable edit preset name330 * @param {HTMLElement} presetNode331 */332 enableEditPresetName: function(presetNode)333 {334 var input = this.getPresetInput(presetNode);335 BX.addClass(presetNode, this.parent.settings.classPresetNameEdit);336 input.focus();337 //noinspection SillyAssignmentJS338 input.value = BX.util.htmlspecialcharsback(input.value);339 BX.bind(input, 'input', BX.delegate(this._onPresetNameInput, this));340 },341 _onPresetNameInput: function(event)342 {343 var Search = this.parent.getSearch();344 var inputValue = event.currentTarget.value;345 var presetNode = BX.findParent(event.currentTarget, {className: this.parent.settings.classPreset}, true, false);346 var presetId = this.getPresetId(presetNode);347 var currentPresetId = this.getCurrentPresetId();348 var data = {ID: presetId, TITLE: inputValue};349 if (presetId === currentPresetId)350 {351 Search.updatePreset(data);352 }353 },354 /**355 * Gets preset name node element356 * @param {HTMLElement} presetNode357 * @return {?HTMLElement}358 */359 getPresetNameNode: function(presetNode)360 {361 return BX.Filter.Utils.getByClass(presetNode, this.parent.settings.classPresetName);362 },363 /**364 * Disable edit name for preset365 * @param {HTMLElement} presetNode366 */367 disableEditPresetName: function(presetNode)368 {369 var input = this.getPresetInput(presetNode);370 BX.removeClass(presetNode, this.parent.settings.classPresetNameEdit);371 if (BX.type.isDomNode(input))372 {373 input.blur();374 BX.unbind(input, 'input', BX.delegate(this._onPresetNameInput, this));375 }376 },377 /**378 * Gets preset object379 * @param {string} presetId380 * @param {boolean} [isDefault = false] - gets from default presets collection381 * @return {?object}382 */383 getPreset: function(presetId, isDefault)384 {385 var presets = this.parent.getParam(isDefault ? 'DEFAULT_PRESETS' : 'PRESETS', []);386 if (this.parent.isEditEnabled() && !isDefault)387 {388 presets = this.parent.editablePresets;389 }390 var filtered = presets.filter(function(current) {391 return current.ID === presetId;392 });393 if (presetId === 'tmp_filter' && !filtered.length)394 {395 var tmpPreset = BX.clone(this.getPreset('default_filter'));396 tmpPreset.ID = 'tmp_filter';397 presets.push(tmpPreset);398 filtered.push(tmpPreset);399 }400 return filtered.length !== 0 ? filtered[0] : null;401 },402 /**403 * Gets preset field by preset name (id)404 * @param {string} presetId405 * @param {string} fieldName406 * @return {?object}407 */408 getPresetField: function(presetId, fieldName)409 {410 var preset = this.getPreset(presetId);411 var field = null;412 if (BX.type.isPlainObject(preset) && 'FIELDS' in preset && BX.type.isArray(preset.FIELDS))413 {414 field = preset.FIELDS.filter(function(current) {415 return current.NAME === fieldName;416 });417 field = field.length ? field[0] : null;418 }419 return field;420 },421 /**422 * Applies preset by id423 * @param {string} presetId424 * @param {boolean} [noValues = false]425 */426 applyPreset: function(presetId, noValues)427 {428 presetId = noValues ? 'default_filter' : presetId || 'default_filter';429 var preset = this.getPreset(presetId);430 if (presetId !== 'default_preset')431 {432 preset = this.extendPreset(preset);433 }434 this.parent.getSearch().updatePreset(preset);435 this.updatePresetFields(preset, noValues);436 },437 /**438 * Extends preset439 * @param {object} preset440 * @return {object}441 */442 extendPreset: function(preset)443 {444 var defaultPreset = BX.clone(this.getPreset('default_filter'));445 if (BX.type.isPlainObject(preset))446 {447 preset = BX.clone(preset);448 preset.FIELDS.forEach(function(curr) {449 var index;450 var someField = defaultPreset.FIELDS.some(function(defCurr, defIndex) {451 var result = false;452 if (defCurr.NAME === curr.NAME)453 {454 index = defIndex;455 result = true;456 }457 return result;458 }, this);459 if (someField && index || someField && index === 0)460 {461 defaultPreset.FIELDS[index] = curr;462 }463 else464 {465 if (!this.isEmptyField(curr))466 {467 defaultPreset.FIELDS.push(curr);468 }469 }470 }, this);471 preset.FIELDS = defaultPreset.FIELDS;472 }473 return preset;474 },475 /**476 * Checks field is empty477 * @param {object} field478 * @return {boolean}479 */480 isEmptyField: function(field)481 {482 var result = true;483 if (field.TYPE === this.parent.types.STRING)484 {485 if (field.VALUE && field.VALUE.length)486 {487 result = false;488 }489 }490 if (field.TYPE === this.parent.types.SELECT)491 {492 if (BX.type.isPlainObject(field.VALUE) && 'VALUE' in field.VALUE && field.VALUE.VALUE)493 {494 result = false;495 }496 }497 if (field.TYPE === this.parent.types.MULTI_SELECT)498 {499 if (BX.type.isArray(field.VALUE) && field.VALUE.length)500 {501 result = false;502 }503 }504 if (field.TYPE === this.parent.types.CUSTOM_DATE)505 {506 if (507 (BX.type.isArray(field.VALUE.days) && field.VALUE.days.length) ||508 (BX.type.isArray(field.VALUE.months) && field.VALUE.months.length) ||509 (BX.type.isArray(field.VALUE.years) && field.VALUE.years.length)510 )511 {512 result = false;513 }514 }515 if (field.TYPE === this.parent.types.CUSTOM_ENTITY)516 {517 if (BX.type.isPlainObject(field.VALUES))518 {519 if (BX.type.isNotEmptyString(field.VALUES._label) && BX.type.isNotEmptyString(field.VALUES._value))520 {521 result = false;522 }523 if (BX.type.isPlainObject(field.VALUES._label) &&524 BX.type.isPlainObject(field.VALUES._value) &&525 Object.keys(field.VALUES._label).length &&526 Object.keys(field.VALUES._value).length)527 {528 result = false;529 }530 if (BX.type.isArray(field.VALUES._label) &&531 BX.type.isArray(field.VALUES._value) &&532 field.VALUES._label.length &&533 field.VALUES._value.length)534 {535 result = false;536 }537 }538 }539 if (field.TYPE === this.parent.types.DATE)540 {541 var datesel = '_datesel' in field.VALUES ? field.VALUES._datesel : field.SUB_TYPE.VALUE;542 if (BX.type.isPlainObject(field.VALUES) &&543 (field.VALUES._from ||544 field.VALUES._to ||545 field.VALUES._month ||546 field.VALUES._quarter ||547 field.VALUES._year ||548 field.VALUES._days) ||549 (550 datesel === this.parent.dateTypes.CURRENT_DAY ||551 datesel === this.parent.dateTypes.CURRENT_WEEK ||552 datesel === this.parent.dateTypes.CURRENT_MONTH ||553 datesel === this.parent.dateTypes.CURRENT_QUARTER ||554 datesel === this.parent.dateTypes.LAST_7_DAYS ||555 datesel === this.parent.dateTypes.LAST_30_DAYS ||556 datesel === this.parent.dateTypes.LAST_60_DAYS ||557 datesel === this.parent.dateTypes.LAST_90_DAYS ||558 datesel === this.parent.dateTypes.LAST_WEEK ||559 datesel === this.parent.dateTypes.LAST_MONTH ||560 datesel === this.parent.dateTypes.TOMORROW ||561 datesel === this.parent.dateTypes.YESTERDAY ||562 datesel === this.parent.dateTypes.NEXT_WEEK ||563 datesel === this.parent.dateTypes.NEXT_MONTH564 )565 )566 {567 result = false;568 }569 }570 if (field.TYPE === this.parent.types.NUMBER)571 {572 if (BX.type.isPlainObject(field.VALUES) && (field.VALUES._from || field.VALUES._to))573 {574 result = false;575 }576 }577 if (field.TYPE === this.parent.types.CHECKBOX)578 {579 if (BX.type.isPlainObject(field.VALUE) && field.VALUE.VALUE)580 {581 result = false;582 }583 }584 return result;585 },586 /**587 * Resets preset588 * @param {boolean} [noValues]589 */590 resetPreset: function(noValues)591 {592 this.applyPreset('', noValues);593 },594 /**595 * Gets preset fields elements596 * @return {?HTMLElement[]}597 */598 getFields: function()599 {600 var container = this.parent.getFieldListContainer();601 var fields = null;602 if (BX.type.isDomNode(container))603 {604 fields = BX.Filter.Utils.getBySelector(container.parentNode, '.'+this.parent.settings.classFileldControlList+' > div', true);605 }606 return fields;607 },608 /**609 * Gets field element by field object610 * @param {object} fieldData611 * @return {?HTMLElement}612 */613 getField: function(fieldData)614 {615 var fields = this.getFields();616 var field = null;617 var tmpName, filtered;618 if (BX.type.isArray(fields) && fields.length)619 {620 filtered = fields.filter(function(current) {621 if (BX.type.isDomNode(current))622 {623 tmpName = BX.data(current, 'name');624 }625 return tmpName === fieldData.NAME;626 }, this);627 field = filtered.length > 0 ? filtered[0] : null;628 }629 return field;630 },631 /**632 * Removes field element by field object633 * @param {object} field634 */635 removeField: function(field)636 {637 var index, fieldName;638 if (BX.type.isPlainObject(field))639 {640 fieldName = field.NAME;641 field = this.getField(field);642 if (BX.type.isArray(this.parent.fieldsList))643 {644 index = this.parent.fieldsList.indexOf(field);645 if (index !== -1)646 {647 delete this.parent.fieldsList[index];648 }649 }650 this.parent.unregisterDragItem(field);651 }652 if (BX.type.isDomNode(field))653 {654 fieldName = BX.data(field, 'name');655 this.parent.getFields().deleteField(field);656 }657 if (!this.parent.isEditEnabled() && !this.parent.isAddPresetEnabled())658 {659 var currentPresetId = this.getCurrentPresetId();660 var currentPresetField = this.getPresetField(currentPresetId, fieldName);661 if (currentPresetField && !this.isEmptyField(currentPresetField))662 {663 this.deactivateAllPresets();664 this.parent.applyFilter();665 }666 }667 this.parent.saveFieldsSort();668 },669 /**670 * Adds field into filter field list by field object671 * @param {object} fieldData672 */673 addField: function(fieldData)674 {675 var container, control, controls;676 if (BX.type.isPlainObject(fieldData))677 {678 container = this.parent.getFieldListContainer();679 controls = this.parent.getControls();680 control = BX.type.isArray(controls) ? controls[controls.length-1] : null;681 if (BX.type.isDomNode(control))682 {683 if (control.nodeName !== 'INPUT')684 {685 control = BX.Filter.Utils.getByTag(control, 'input');686 }687 if (BX.type.isDomNode(control))688 {689 fieldData.TABINDEX = parseInt(control.getAttribute('tabindex')) + 1;690 }691 }692 else693 {694 fieldData.TABINDEX = 2;695 }696 if (BX.type.isDomNode(container))697 {698 control = this.createControl(fieldData);699 if (BX.type.isDomNode(control))700 {701 BX.append(control, container);702 if (BX.type.isArray(this.parent.fieldsList))703 {704 this.parent.fieldsList.push(control);705 }706 this.parent.registerDragItem(control);707 }708 }709 }710 if (!this.parent.isEditEnabled() && !this.parent.isAddPresetEnabled())711 {712 var currentPresetId = this.getCurrentPresetId();713 var currentPresetField = this.getPresetField(currentPresetId, fieldData.NAME);714 if (currentPresetField && !this.isEmptyField(currentPresetField))715 {716 this.parent.updatePreset('tmp_filter');717 this.deactivateAllPresets();718 this.parent.getSearch().updatePreset(this.getPreset('tmp_filter'));719 }720 }721 this.parent.saveFieldsSort();722 },723 /**724 * Creates field control by field object725 * @param {object} fieldData726 * @return {?HTMLElement}727 */728 createControl: function(fieldData)729 {730 var control;731 switch (fieldData.TYPE)732 {733 case this.parent.types.STRING : {734 control = this.parent.getFields().createInputText(fieldData);735 break;736 }737 case this.parent.types.SELECT : {738 control = this.parent.getFields().createSelect(fieldData);739 break;740 }741 case this.parent.types.MULTI_SELECT : {742 control = this.parent.getFields().createMultiSelect(fieldData);743 break;744 }745 case this.parent.types.NUMBER : {746 control = this.parent.getFields().createNumber(fieldData);747 break;748 }749 case this.parent.types.DATE : {750 control = this.parent.getFields().createDate(fieldData);751 break;752 }753 case this.parent.types.CUSTOM_DATE : {754 control = this.parent.getFields().createCustomDate(fieldData);755 break;756 }757 case this.parent.types.CUSTOM : {758 control = this.parent.getFields().createCustom(fieldData);759 break;760 }761 case this.parent.types.CUSTOM_ENTITY : {762 control = this.parent.getFields().createCustomEntity(fieldData);763 break;764 }765 default : {766 break;767 }768 }769 if (BX.type.isDomNode(control))770 {771 control.dataset.name = fieldData.NAME;772 control.FieldController = new BX.Filter.FieldController(control, this.parent);773 }774 return control;775 },776 /**777 * Removes not compared properties778 * @param {object} fields779 * @param {boolean} [noClean]780 */781 removeNotCompareVariables: function(fields, noClean)782 {783 if (BX.type.isPlainObject(fields))784 {785 var dateType = this.parent.dateTypes;786 if ('FIND' in fields)787 {788 delete fields.FIND;789 }790 if (!noClean)791 {792 Object.keys(fields).forEach(function(key) {793 if (key.indexOf('_numsel') !== -1)794 {795 delete fields[key];796 }797 if (key.indexOf('_datesel') !== -1)798 {799 var datesel = fields[key];800 if (datesel === dateType.EXACT ||801 datesel === dateType.RANGE ||802 datesel === dateType.PREV_DAYS ||803 datesel === dateType.NEXT_DAYS ||804 datesel === dateType.YEAR ||805 datesel === dateType.MONTH ||806 datesel === dateType.QUARTER ||807 datesel === dateType.NONE)808 {809 delete fields[key];810 }811 }812 if (fields[key] === '')813 {814 delete fields[key];815 }816 });817 }818 }819 },820 /**821 * Checks is modified preset field values822 * @param {string} presetId823 * @returns {boolean}824 */825 isPresetValuesModified: function(presetId)826 {827 var currentPresetData = this.getPreset(presetId);828 var presetFields = this.parent.preparePresetSettingsFields(currentPresetData.FIELDS);829 var currentFields = this.parent.getFilterFieldsValues();830 this.removeNotCompareVariables(presetFields);831 this.removeNotCompareVariables(currentFields);832 var comparedPresetFields = BX.Filter.Utils.sortObject(presetFields);833 var comparedCurrentFields = BX.Filter.Utils.sortObject(currentFields);834 return !Object.keys(comparedPresetFields).every(function(key) {835 return (836 comparedPresetFields[key] === comparedCurrentFields[key] ||837 ((BX.type.isPlainObject(comparedPresetFields[key]) || BX.type.isArray(comparedPresetFields[key])) &&838 BX.Filter.Utils.objectsIsEquals(comparedPresetFields[key], comparedCurrentFields[key]))839 );840 });841 },842 /**843 * Gets additional preset values844 * @param {string} presetId845 * @return {?object}846 */847 getAdditionalValues: function(presetId)848 {849 var currentPresetData = this.getPreset(presetId);850 var notEmptyFields = currentPresetData.FIELDS.filter(function(field) {851 return !this.isEmptyField(field);852 }, this);853 var presetFields = this.parent.preparePresetSettingsFields(notEmptyFields);854 var currentFields = this.parent.getFilterFieldsValues();855 this.removeNotCompareVariables(presetFields, true);856 this.removeNotCompareVariables(currentFields, true);857 this.removeSameProperties(currentFields, presetFields);858 return currentFields;859 },860 /**861 * Removes same object properties862 * @param {object} object1863 * @param {object} object2864 */865 removeSameProperties: function(object1, object2)866 {867 if (BX.type.isPlainObject(object1) && BX.type.isPlainObject(object2))868 {869 Object.keys(object2).forEach(function(key) {870 if (key in object1)871 {872 delete object1[key];873 }874 });875 }876 },877 /**878 * Removes additional field by field name879 * @param {string} name880 */881 removeAdditionalField: function(name)882 {883 var preset = this.getPreset(this.getCurrentPresetId());884 if (BX.type.isArray(preset.ADDITIONAL))885 {886 preset.ADDITIONAL = preset.ADDITIONAL.filter(function(field) {887 return field.NAME !== name;888 });889 }890 },891 /**892 * Updates preset fields list893 * @param {object} preset894 * @param {boolean} [noValues = false]895 */896 updatePresetFields: function(preset, noValues)897 {898 var fields, fieldListContainer;899 var fieldNodes = [];900 if (BX.type.isPlainObject(preset) && ('FIELDS' in preset))901 {902 fields = preset.FIELDS;903 if (BX.type.isArray(preset.ADDITIONAL))904 {905 preset.ADDITIONAL.forEach(function(field) {906 var replaced = false;907 field.IS_PRESET_FIELD = true;908 fields.forEach(function(presetField, index) {909 if (field.NAME === presetField.NAME)910 {911 fields[index] = field;912 replaced = true;913 }914 });915 if (!replaced)916 {917 fields.push(field);918 }919 });920 }921 (fields || []).forEach(function(fieldData, index) {922 fieldData.TABINDEX = index+1;923 if (noValues)924 {925 switch (fieldData.TYPE)926 {927 case this.parent.types.SELECT : {928 fieldData.VALUE = fieldData.ITEMS[0];929 break;930 }931 case this.parent.types.MULTI_SELECT : {932 fieldData.VALUE = [];933 break;934 }935 case this.parent.types.DATE : {936 fieldData.SUB_TYPE = fieldData.SUB_TYPES[0];937 fieldData.VALUES = {938 '_from': '',939 '_to': '',940 '_days': ''941 };942 break;943 }944 case this.parent.types.CUSTOM_DATE : {945 fieldData.VALUE = {946 'days': [],947 'months': [],948 'years': []949 };950 break;951 }952 case this.parent.types.NUMBER : {953 fieldData.SUB_TYPE = fieldData.SUB_TYPES[0];954 fieldData.VALUES = {955 '_from': '',956 '_to': ''957 };958 break;959 }960 case this.parent.types.CUSTOM_ENTITY : {961 fieldData.VALUES = {962 '_label': '',963 '_value': ''964 };965 break;966 }967 case this.parent.types.CUSTOM : {968 fieldData._VALUE = '';969 break;970 }971 default : {972 if ('VALUE' in fieldData)973 {974 if (BX.type.isArray(fieldData.VALUE))975 {976 fieldData.VALUE = [];977 }978 else979 {980 fieldData.VALUE = '';981 }982 }983 break;984 }985 }986 }987 fieldNodes.push(this.createControl(fieldData));988 }, this);989 this.parent.disableFieldsDragAndDrop();990 fieldListContainer = this.parent.getFieldListContainer();991 BX.cleanNode(fieldListContainer);992 if (fieldNodes.length)993 {994 fieldNodes.forEach(function(current, index) {995 if (BX.type.isDomNode(current))996 {997 if (preset.ID !== 'tmp_filter' &&998 preset.ID !== 'default_filter' &&999 !('IS_PRESET_FIELD' in fields[index]) &&1000 !this.isEmptyField(fields[index]))1001 {1002 BX.addClass(current, this.parent.settings.classPresetField);1003 }1004 BX.append(current, fieldListContainer);1005 }1006 }, this);1007 this.parent.enableFieldsDragAndDrop();1008 }1009 }1010 },1011 /**1012 * Shows current preset fields1013 */1014 showCurrentPresetFields: function()1015 {1016 var preset = this.getCurrentPresetData();1017 this.updatePresetFields(preset);1018 },1019 /**1020 * Gets current preset element1021 * @return {?HTMLElement}1022 */1023 getCurrentPreset: function()1024 {1025 return BX.Filter.Utils.getByClass(this.getContainer(), this.parent.settings.classPresetCurrent);1026 },1027 /**1028 * Gets current preset id1029 * @return {*}1030 */1031 getCurrentPresetId: function()1032 {1033 var current = this.getCurrentPreset();1034 var currentId = null;1035 if (BX.type.isDomNode(current))1036 {1037 currentId = this.getPresetId(current);1038 }1039 else1040 {1041 currentId = "tmp_filter";1042 }1043 return currentId;1044 },1045 /**1046 * Gets current preset data1047 * @return {?object}1048 */1049 getCurrentPresetData: function()1050 {1051 var currentId = this.getCurrentPresetId();1052 var currentData = null;1053 if (BX.type.isNotEmptyString(currentId))1054 {1055 currentData = this.getPreset(currentId);1056 currentData = this.extendPreset(currentData);1057 }1058 return currentData;1059 },1060 /**1061 * Gets presets container element1062 * @return {?HTMLElement}1063 */1064 getContainer: function()1065 {1066 return BX.Filter.Utils.getByClass(this.parent.getFilter(), this.parent.settings.classPresetsContainer);1067 },1068 /**1069 * Gets preset nodes1070 * @return {?HTMLElement[]}1071 */1072 getPresets: function()1073 {1074 return BX.Filter.Utils.getByClass(this.getContainer(), this.parent.settings.classPreset, true);1075 },1076 /**1077 * Gets default presets elements1078 * @return {?HTMLElement[]}1079 */1080 getDefaultPresets: function()1081 {1082 return BX.Filter.Utils.getByClass(this.getContainer(), this.parent.settings.classDefaultFilter, true);1083 },1084 /**1085 * Gets default preset element1086 * @return {?HTMLElement}1087 */1088 getPinnedPresetNode: function()1089 {1090 return BX.Filter.Utils.getByClass(this.getContainer(), this.parent.settings.classPinnedPreset);1091 },1092 /**1093 * Checks preset is pinned (default)1094 * @param presetId1095 * @return {boolean}1096 */1097 isPinned: function(presetId)1098 {1099 return this.getPinnedPresetId() === presetId;1100 },1101 /**1102 * Gets pinned (default) preset id1103 * @return {string}1104 */1105 getPinnedPresetId: function()1106 {1107 var node = this.getPinnedPresetNode();1108 var id = 'default_filter';1109 if (!!node)1110 {1111 var dataId = BX.data(node, 'id');1112 id = !!dataId ? dataId : id;1113 }1114 return id;1115 }1116 };...

Full Screen

Full Screen

sticky.js

Source:sticky.js Github

copy

Full Screen

1webshim.register('sticky', function($, webshim, window, document, undefined, featureOptions){2 "use strict";3 var uid = 0;4 var stickys = 0;5 var $window = $(window);6 function getCssValue(property, value, noPrefixes) {7 var prop = property + ':',8 el = document.createElement('test'),9 mStyle = el.style;10 if (!noPrefixes) {11 mStyle.cssText = prop + [ '-webkit-', '-moz-', '-ms-', '-o-', '' ].join(value + ';' + prop) + value + ';';12 } else {13 mStyle.cssText = prop + value;14 }15 return mStyle[ property ];16 }17 function getPos() {18 return {19 top: $.css(this, 'top'),20 bottom: $.css(this, 'bottom')21 };22 }23 var getWinScroll = (function () {24 var docElem;25 var prop = 'pageYOffset';26 return (prop in window) ?27 function () {28 return window[ prop ];29 } :30 ((docElem = document.documentElement), function () {31 return docElem.scrollTop;32 })33 ;34 })();35 var isTouch = 'ontouchstart' in window || window.matchMedia('(max-device-width: 721px)').matches;36 var support = {37 fixed: getCssValue('position', 'fixed', true),38 sticky: getCssValue('position', 'sticky')39 };40 var stickyMixin = {41 getPosition: function () {42 if(!this.isSticky){43 this.position = {44 top: this.$el.css('top'),45 bottom: this.$el.css('bottom')46 };47 if (((48 (this.position.top != 'auto' && this.position.bottom != 'auto') ||49 this.position.top == 'auto' && this.position.bottom == 'auto')) && this.$el.css('position') == 'static') {50 this.position = $.swap(this.$el[0], {position: 'absolute'}, getPos);51 }52 if (this.position.top !== 'auto') {53 this.ankered = 'top';54 } else if (this.position.bottom !== 'auto') {55 this.ankered = 'bottom';56 }57 if(this.ankered == 'top'){58 this.position.top = parseFloat(this.position.top, 10) || 0;59 } else if(this.ankered == 'bottom'){60 this.position.bottom = parseFloat(this.position.bottom, 10) || 0;61 }62 }63 },64 update: function (full) {65 if (!this.disabled && this.$el[0].offsetWidth) {66 if (full) {67 if(this.isSticky){68 this.removeSticky();69 }70 this.getPosition();71 }72 this.updateDimension();73 }74 },75 setTdWidth: function(){76 if(this.isTable){77 this.$el.find('td, th').each(this._setInlineWidth);78 }79 },80 _setInlineWidth: function(){81 $.data(this, 'inlineWidth', this.style.width);82 $(this).innerWidth($(this).innerWidth());83 },84 _restoreInlineWidth: function(){85 this.style.width = $.data(this, 'inlineWidth') || '';86 $.removeData(this, 'inlineWidth');87 },88 removeSticky: function(){89 this.$el.removeClass('ws-sticky-on');90 this.$el.css(this.stickyData.inline);91 this.$placeholder.detach();92 this.isSticky = false;93 if(this.isTable){94 this.$el.find('td, th').each(this._restoreInlineWidth);95 }96 },97 commonAddEvents: function(){98 var enableDisable;99 var that = this;100 var update = function() {101 that.update();102 };103 var stickyMedia = this.$el.data('stickymedia');104 var media = window.matchMedia && stickyMedia ? matchMedia(stickyMedia) : false;105 $window.one('load', update);106 $(document).on('updateshadowdom' + this.evtid, update);107 this.$el.on('updatesticky'+ this.evtid, function(e){108 that.update(true);109 e.stopPropagation();110 });111 this.$el.on('disablesticky'+ this.evtid, function(e){112 that.disable(true);113 e.stopPropagation();114 });115 this.$el.on('enablesticky'+ this.evtid, function(e){116 that.disable(false);117 e.stopPropagation();118 });119 this.$el.on('remove'+ this.evtid+' destroysticky'+ this.evtid, function(e) {120 $window.off(that.evtid);121 $(document).off(that.evtid);122 that.$el.off(that.evtid);123 that.$parent.off(that.evtid);124 that.$el.removeData('wsSticky').removeClass('ws-sticky');125 if (that.$placeholder) {126 that.$el.removeClass('ws-sticky-on');127 that.$placeholder.remove();128 }129 stickys--;130 e.stopPropagation();131 });132 if(media && media.addListener){133 enableDisable = function(){134 that.disable(!media.matches);135 };136 media.addListener(enableDisable);137 enableDisable();138 }139 },140 disable: function(disable){141 if(!arguments.length){142 return this.disabled;143 }144 if(this.disabled != disable){145 this.disabled = !!disable;146 if(this.disabled){147 if(this.isSticky){148 this.removeSticky();149 }150 } else {151 this.update(true);152 }153 }154 },155 setSticky: function(){156 if (!this.$placeholder) {157 this.$placeholder = this.isTable ? $(this.$el[0].cloneNode(true)) : $(document.createElement(this.$el[0].nodeName || 'div'));158 this.$placeholder.addClass('ws-fixedsticky-placeholder').removeClass('ws-sticky');159 }160 this.setTdWidth();161 this.$placeholder162 .insertAfter(this.$el)163 .outerHeight(this.stickyData.outerHeight, true)164 .outerWidth(this.stickyData.outerWidth)165 ;166 this.isSticky = true;167 this.$el.addClass('ws-sticky-on');168 if(!this.isTable){169 if( this.stickyData.width != this.$el.width()){170 this.$el.width(this.stickyData.width);171 }172 }173 },174 getCommonStickyData: function(){175 var marginTop = (parseFloat(this.$el.css('marginTop'), 10) || 0);176 this.stickyData.scrollTop = this.stickyData.top - marginTop;177 this.stickyData.outerHeight = this.$el.outerHeight(true);178 this.stickyData.bottom = this.stickyData.top + this.stickyData.outerHeight - marginTop;179 this.stickyData.width = this.$el.width();180 this.stickyData.outerWidth = this.$el.outerWidth();181 this.stickyData.marginLeft = parseFloat(this.$el.css('marginLeft'), 10) || 0;182 this.stickyData.offsetLeft = this.$el[0].offsetLeft;183 this.stickyData.inline.width = this.elStyle.width;184 this.stickyData.inline.marginLeft = this.elStyle.marginLeft;185 if(this.ankered == 'top'){186 this.stickyData.inline.top = this.elStyle.top;187 } else if(this.ankered == 'bottom'){188 this.stickyData.inline.bottom = this.elStyle.bottom;189 }190 },191 getCommonParentData: function(){192 this.parentData.paddingTop = (parseFloat(this.$parent.css('paddingTop'), 10) || 0);193 this.parentData.offsetTop = this.$parent.offset().top;194 this.parentData.top = this.parentData.offsetTop + (parseFloat(this.$parent.css('borderTopWidth'), 10) || 0) + this.parentData.paddingTop;195 this.parentData.height = this.$parent.height();196 this.parentData.bottom = this.parentData.top + this.parentData.height;197 }198 };199 if(isTouch && featureOptions.touchStrategy == 'disable'){return;}200 function Sticky(dom) {201 uid++;202 stickys++;203 this.evtid = '.wsstickyid' + uid;204 this.$el = $(dom).data('wsSticky', this);205 this.isTable = this.$el.is('thead, tbody, tfoot');206 this.$parent = this.$el.parent();207 this.elStyle = dom.style;208 this.ankered = '';209 this.isSticky = false;210 this.$placeholder = null;211 this.stickyData = {inline: {}};212 this.parentData = {};213 this.getParentData = this.getCommonParentData;214 this.addEvents();215 this.update(true);216 }217 $.extend(Sticky.prototype, stickyMixin, {218 addEvents: function () {219 var that = this;220 this.commonAddEvents();221 $window222 .on('scroll' + this.evtid, function () {223 if (!that.disabled && that.ankered && that.$el[0].offsetWidth) {224 that.updatePos();225 }226 })227 ;228 },229 getStickyData: function(){230 this.stickyData.top = this.$el.offset().top;231 this.getCommonStickyData();232 },233 updateDimension: function(fromPos){234 if(this.isSticky){235 this.removeSticky();236 }237 this.getParentData();238 this.getStickyData();239 if (this.ankered == 'bottom') {240 this.viewportBottomAnker = $window.height() - this.position.bottom;241 }242 if(!fromPos && this.ankered){243 this.updatePos(true);244 }245 },246 updatePos: function(fromDimension){247 var offset, shouldSticky, shouldMoveWith;248 var scroll = getWinScroll();249 if (this.ankered == 'top') {250 offset = scroll + this.position.top;251 if(this.stickyData.scrollTop < offset && scroll - 9 <= this.parentData.bottom){252 shouldMoveWith = ((offset + this.stickyData.outerHeight) - this.parentData.bottom) * -1;253 shouldSticky = true;254 }255 } else if (this.ankered == 'bottom') {256 offset = scroll + this.viewportBottomAnker;257 if(this.stickyData.bottom > offset &&258 offset + 9 >= this.parentData.top){259 shouldSticky = true;260 shouldMoveWith = offset - this.parentData.top - this.stickyData.outerHeight;261 }262 }263 if (shouldSticky) {264 if (!this.isSticky) {265 //updateDimension before layout trashing266 if(!fromDimension){267 this.updateDimension(true);268 }269 this.setSticky();270 }271 if(shouldMoveWith < 0){272 if(this.ankered == 'top'){273 this.elStyle.top = this.position.top + shouldMoveWith +'px';274 } else if(this.ankered == 'bottom'){275 this.elStyle.bottom = this.position.bottom + shouldMoveWith +'px';276 }277 }278 } else if (this.isSticky) {279 this.removeSticky();280 }281 }282 });283 function StickyParent(dom) {284 uid++;285 stickys++;286 this.evtid = '.wsstickyid' + uid;287 this.$el = $(dom).data('wsSticky', this);288 this.isTable = this.$el.is('thead, tbody, tfoot');289 this.$parent = this.$el.parent();290 this.elStyle = dom.style;291 this.ankered = '';292 this.isSticky = false;293 this.$placeholder = null;294 this.stickyData = {inline: {}};295 this.parentData = {};296 if(this.$parent.css('position') == 'static'){297 this.$parent.css('position', 'relative');298 }299 this.updatePos2 = this.updatePos2.bind(this);300 this.addEvents();301 this.update(true);302 }303 $.extend(StickyParent.prototype, stickyMixin, {304 addEvents: function () {305 var that = this;306 this.commonAddEvents();307 this.$parent308 .on('scroll' + this.evtid, function () {309 if (that.ankered && that.$el[0].offsetWidth) {310 that.updatePos();311 }312 })313 ;314 },315 getStickyData: function(){316 this.stickyData.top = this.$el[0].offsetTop;317 this.getCommonStickyData();318 },319 getParentData: function(){320 this.getCommonParentData();321 this.parentData.offsetBottom = this.parentData.top + this.$parent.outerHeight();322 },323 updateDimension: function(fromPos){324 var add;325 if(this.isSticky){326 this.removeSticky();327 }328 this.getParentData();329 this.getStickyData();330 this.viewport = $window.height();331 if(this.ankered == 'top'){332 add = Math.abs(this.position.top) + 9;333 } else if(this.ankered == 'bottom') {334 add = Math.abs(this.position.bottom) + 9;335 this.viewportBottomAnker = this.viewport - this.parentData.bottom;336 this.compareBottom = this.stickyData.bottom + this.position.bottom;337 this.addBottom = (this.parentData.bottom - this.parentData.paddingTop) - this.viewport;338 }339 this.viewPortMax = this.parentData.offsetBottom + add + 10;340 this.viewPortMin = this.parentData.offsetTop - add - this.viewport;341 if(!fromPos){342 this.updatePos(true);343 }344 },345 updatePos: function(fromDimension){346 var offset, shouldSticky;347 var scroll = this.$parent[0].scrollTop;348 if (this.ankered == 'top') {349 offset = scroll + this.position.top ;350 if(this.stickyData.scrollTop - this.parentData.paddingTop < offset){351 shouldSticky = true;352 }353 } else if (this.ankered == 'bottom') {354 if(scroll + this.parentData.height < this.compareBottom){355 shouldSticky = true;356 }357 }358 if (shouldSticky) {359 if (!this.isSticky) {360 //updateDimension before layout trashing361 if(!fromDimension){362 this.updateDimension(true);363 }364 this.setSticky();365 $window366 .off('scroll' + this.evtid, this.updatePos2)367 .on('scroll' + this.evtid, this.updatePos2)368 ;369 this.updatePos2(true);370 }371 } else if (this.isSticky) {372 this.removeSticky();373 $window.off('scroll' + this.evtid, this.updatePos2);374 }375 },376 updatePos2: function(init){377 var scrollTop = getWinScroll();378 if(init === true || (this.viewPortMax > scrollTop && scrollTop > this.viewPortMin)){379 if(this.ankered == 'top'){380 if(init === true || (this.viewPortMax > scrollTop && scrollTop > this.viewPortMin)){381 this.elStyle.top = this.position.top + this.parentData.top - scrollTop +'px';382 }383 } else if(this.ankered == 'bottom'){384 this.elStyle.bottom = this.position.bottom + (scrollTop - this.addBottom) +'px';385 }386 }387 }388 });389 var loadDomSupport = function(){390 loadDomSupport = $.noop;391 webshim.ready('WINDOWLOAD', function(){392 webshim.loader.loadList(['dom-extend']);393 webshim.ready('dom-extend', function(){394 webshim.addShadowDom();395 });396 });397 };398 var addSticky = function(){399 var stickyData = $.data(this, 'wsSticky');400 if(!stickyData){401 var $parent = $(this).parent();402 $(this).addClass('ws-sticky');403 if(($parent.css('overflowY') || $parent.css('overflow') || 'visible') == 'visible'){404 new Sticky(this);405 } else {406 //webshim.warn('currently not supported');407 new StickyParent(this);408 }409 loadDomSupport();410 } else if(stickyData.disable) {411 stickyData.disable(false);412 }413 };414 if (!support.sticky && support.fixed) {415 var selectors = {};416 var createUpdateDomSearch = function(media, sels){417 var i, created, elems;418 var updated = [];419 if(!selectors[media]){420 selectors[media] = {sels: {}, string: '',421 fn: function(context, insertedElement){422 var elems = $(selectors[media].string, context).add(insertedElement.filter(selectors[media].string));423 if(media){424 elems.data('stickymedia', media);425 }426 elems.each(addSticky);427 }428 };429 created = true;430 }431 for(i = 0; i < sels.length; i++){432 if(!selectors[media].sels[sels[i]]){433 selectors[media].sels[sels[i]] = true;434 updated.push(sels[i]);435 }436 }437 if(!created && !updated.length){return;}438 selectors[media].string = Object.keys(selectors[media].sels).join(', ');439 if(created){440 $(function(){441 webshim.addReady(selectors[media].fn);442 });443 } else if($.isReady){444 elems = $(updated.join(', '));445 if(media){446 elems.data('stickymedia', media);447 }448 elems.each(addSticky);449 }450 };451 createUpdateDomSearch('', ['.ws-sticky']);452 $(function(){453 $(document).on('wssticky', function(e){454 addSticky.call(e.target);455 });456 });457 if(featureOptions.parseCSS){458 if(window.Polyfill && Polyfill.prototype && Polyfill.prototype.doMatched){459 var onEnableRule = function(rule){460 var curSelectors = rule.getSelectors().split(/\,\s*/g);461 var media = (!rule._rule.media || !rule._rule.media.length) ? '' : rule.getMedia();462 createUpdateDomSearch(media || '', curSelectors);463 };464 Polyfill({declarations:["position:sticky"]})465 .doMatched(function(rules){466 rules.each(onEnableRule);467 })468 ;469 } else {470 webshim.warn('Polyfill for CSS polyfilling made easy has to be included');471 }472 }473 }474 if(document.readyState == 'complete'){475 webshim.isReady('WINDOWLOAD', true);476 }...

Full Screen

Full Screen

redBlackTree.js

Source:redBlackTree.js Github

copy

Full Screen

1var RedBlackTree = function(value, parent){2 this.value = value;3 if (parent) {4 this.color = "red";5 } else {6 this.color = "black";7 }8 this.left = null;9 this.right = null;10 this.parent = parent || null;11};12RedBlackTree.prototype.getGP = function() {13 if (this.parent) {14 return this.parent.parent;15 }16 return null;17};18RedBlackTree.prototype.getUnc = function() {19 if (this.getGP()) {20 if (this.getGP().right === this.parent) {21 return this.getGP().left;22 }23 if (this.getGP().left === this.parent) {24 return this.getGP().right;25 }26 }27 return null;28};29RedBlackTree.prototype.insert = function(value, atRoot){30 atRoot = atRoot || false;31 if (!atRoot && this.parent) {32 return this.parent.insert(value);33 } else {34 atRoot = true;35 }36 if (this.contains(value)) { return "Value already exists in tree."; }37 if (value < this.value) {38 if (this.left === null) {39 this.left = new RedBlackTree(value, this);40 this.left.checker();41 } else {42 this.left.insert(value, atRoot);43 }44 } else {45 if (this.right === null) {46 this.right = new RedBlackTree(value, this);47 this.right.checker();48 } else {49 this.right.insert(value, atRoot);50 }51 }52};53RedBlackTree.prototype.contains = function(value, atRoot){54 atRoot = atRoot || false;55 if (!atRoot && this.parent) {56 return this.parent.contains(value);57 } else {58 atRoot = true;59 }60 if (this.value === value) {61 return true;62 } else if (value < this.value && this.left !== null) {63 return this.left.contains(value, atRoot);64 } else if (value > this.value && this.right !== null) {65 return this.right.contains(value, atRoot);66 }67 return false;68};69RedBlackTree.prototype.depthFirstLog = function(callback, atRoot){70 atRoot = atRoot || false;71 if (!atRoot && this.parent) {72 this.parent.depthFirstLog(callback);73 } else {74 atRoot = true;75 callback(this);76 if (this.left !== null) {77 this.left.depthFirstLog(callback, atRoot);78 }79 if (this.right !== null) {80 this.right.depthFirstLog(callback, atRoot);81 }82 }83};84RedBlackTree.prototype.checker = function() {85 if (!this.parent) { this.color = "black"; }86 if (this.color === "red") {87 if (this.parent && this.parent.color === "red" && this.getUnc() && this.getUnc().color === "red") {88 this.getGP().toggleColor();89 this.parent.toggleColor();90 this.getUnc().toggleColor();91 }92 if (this.parent && this.parent.color === "red" && (this.getUnc() === null || this.getUnc().color === "black")93 && this.parent.right === this && this.getGP() && this.getGP().right === this.parent) {94 var greatGP;95 if (this.getGP().parent && this.getGP().parent.left === this.getGP()) {96 greatGP = 'right';97 } else if (this.getGP().parent && this.getGP().parent.right === this.getGP()) {98 greatGP = 'left';99 }100 this.getGP().right = null;101 if (this.parent.left) {102 this.parent.left.parent = this.getGP();103 this.getGP().right = this.parent.left;104 }105 var temp = this.getGP();106 this.parent.parent = this.getGP().parent;107 temp.parent = this.parent;108 this.parent.left = temp;109 if (this.getGP() && greatGP === 'right') {110 this.getGP().left = this.parent;111 } else if (this.getGP() && greatGP === 'left') {112 this.getGP().right = this.parent;113 }114 this.parent.left.toggleColor();115 this.parent.toggleColor();116 }117 if (this.parent && this.parent.color === "red" && (this.getUnc() === null || this.getUnc().color === "black")118 && this.parent.left === this && this.getGP() && this.getGP().right === this.parent) {119 if (this.getGP().parent && this.getGP().parent.right === this.getGP()) {120 this.getGP().parent.right = this;121 } else if (this.getGP().parent && this.getGP().parent.left === this.getGP()) {122 this.getGP().parent.left = this;123 }124 this.getGP().right = null;125 if (this.left) { this.getGP().right = this.left; }126 this.parent.left = null;127 if (this.right) { this.parent.left = this.right; }128 this.left = this.getGP();129 this.right = this.parent;130 this.parent = this.getGP().parent;131 this.left.parent = this;132 this.right.parent = this;133 if (this.left.right) {134 this.left.right.parent = this.left;135 }136 if (this.right.left) {137 this.right.left.parent = this.right;138 }139 this.toggleColor();140 this.left.toggleColor();141 }142 if (this.parent && this.parent.color === "red" && (this.getUnc() === null || this.getUnc().color === "black")143 && this.parent.left === this && this.getGP() && this.getGP().left === this.parent) {144 var greatGP;145 if (this.getGP().parent && this.getGP().parent.right === this.getGP()) {146 greatGP = 'left';147 } else if (this.getGP().parent && this.getGP().parent.left === this.getGP()) {148 greatGP = 'right';149 }150 this.getGP().left = null;151 if (this.parent.right) {152 this.parent.right.parent = this.getGP();153 this.getGP().left = this.parent.right;154 }155 var temp = this.getGP();156 this.parent.parent = this.getGP().parent;157 temp.parent = this.parent;158 this.parent.right = temp;159 if (this.getGP() && greatGP === 'left') {160 this.getGP().right = this.parent;161 } else if (this.getGP() && greatGP === 'right') {162 this.getGP().left = this.parent;163 }164 this.parent.right.toggleColor();165 this.parent.toggleColor();166 }167 if (this.parent && this.parent.color === "red" && (this.getUnc() === null || this.getUnc().color === "black")168 && this.parent.right === this && this.getGP() && this.getGP().left === this.parent) {169 if (this.getGP().parent && this.getGP().parent.right === this.getGP()) {170 this.getGP().parent.right = this;171 } else if (this.getGP().parent && this.getGP().parent.left === this.getGP()) {172 this.getGP().parent.left = this;173 }174 this.getGP().left = null;175 if (this.right) { this.getGP().left = this.right; }176 this.parent.right = null;177 if (this.left) { this.parent.right = this.left; }178 this.right = this.getGP();179 this.left = this.parent;180 this.parent = this.getGP().parent;181 this.left.parent = this;182 this.right.parent = this;183 if (this.right.left) {184 this.right.left.parent = this.right;185 }186 if (this.left.right) {187 this.left.right.parent = this.left;188 }189 this.toggleColor();190 this.right.toggleColor();191 }192 }193 if (this.parent) { this.parent.checker(); }194};195RedBlackTree.prototype.toggleColor = function() {196 if (this.color === "red") { this.color = "black"; }197 else { this.color = "red"; }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var express = require('express');2var app = express();3var http = require('http').Server(app);4var io = require('socket.io')(http);5var fs = require('fs');6app.use(express.static('public'));7app.use(express.static('node_modules'));8app.use(express.static('test'));9app.get('/', function(req, res){10 res.sendFile(__dirname + '/index.html');11});12app.get('/test', function(req, res){13 res.sendFile(__dirname + '/test.html');14});15app.get('/coverage', function(req, res){16 res.sendFile(__dirname + '/coverage.html');17});18app.get('/coverage.json', function(req, res){19 res.sendFile(__dirname + '/coverage/coverage.json');20});21app.get('/coverage/lcov-report/index.html', function(req, res){22 res.sendFile(__dirname + '/coverage/lcov-report/index.html');23});24app.get('/coverage/lcov-report/app.js.html', function(req, res){25 res.sendFile(__dirname + '/coverage/lcov-report/app.js.html');26});27app.get('/coverage/lcov-report/test.js.html', function(req, res){28 res.sendFile(__dirname + '/coverage/lcov-report/test.js.html');29});30app.get('/coverage/lcov-report/socket.io.js.html', function(req, res){31 res.sendFile(__dirname + '/coverage/lcov-report/socket.io.js.html');32});33app.get('/coverage/lcov-report/express.js.html', function(req, res){34 res.sendFile(__dirname + '/coverage/lcov-report/express.js.html');35});36app.get('/coverage/lcov-report/istanbul.js.html', function(req, res){37 res.sendFile(__dirname + '/coverage/lcov-report/istanbul.js.html');38});39app.get('/coverage/lcov-report/socket.io.js.html', function(req, res){40 res.sendFile(__dirname + '/coverage/lcov-report/socket.io.js.html');41});42app.get('/coverage/lcov-report/Socket.js.html', function

Full Screen

Using AI Code Generation

copy

Full Screen

1var istanbul = require('istanbul');2var collector = new istanbul.Collector();3var reporter = new istanbul.Reporter();4var sync = false;5var child = require('child_process').fork(__dirname + '/testChild.js', [], {silent: true});6child.on('message', function (m) {7 if (m.cmd === 'coverage') {8 collector.add(m.coverage);9 if (sync) {10 reporter.add('text');11 reporter.write(collector, true, function () {12 console.log('All reports generated');13 });14 }15 }16});17child.on('exit', function (code) {18 if (!sync) {19 reporter.add('text');20 reporter.write(collector, true, function () {21 console.log('All reports generated');22 });23 }24});25var istanbul = require('istanbul');26var collector = new istanbul.Collector();27var reporter = new istanbul.Reporter();28var sync = false;29var child = require('child_process').fork(__dirname + '/testChild2.js', [], {silent: true});30child.on('message', function (m) {31 if (m.cmd === 'coverage') {32 collector.add(m.coverage);33 if (sync) {34 reporter.add('text');35 reporter.write(collector, true, function () {36 console.log('All reports generated');37 });38 }39 }40});41child.on('exit', function (code) {42 if (!sync) {43 reporter.add('text');44 reporter.write(collector, true, function () {45 console.log('All reports generated');46 });47 }48});49var istanbul = require('istanbul');50var collector = new istanbul.Collector();51var reporter = new istanbul.Reporter();52var sync = false;53var child = require('child_process').fork(__dirname + '/testChild3.js', [], {silent: true});54child.on('message', function (m) {55 if (m.cmd === 'coverage') {56 collector.add(m.coverage);57 if (sync) {58 reporter.add('text');59 reporter.write(collector, true, function () {60 console.log('All reports generated');

Full Screen

Using AI Code Generation

copy

Full Screen

1var istanbul = require('istanbul');2var instrumenter = new istanbul.Instrumenter();3var code = 'function foo() { return 1; }';4var instrumented = instrumenter.instrumentSync(code, 'test.js');5console.log(instrumented);6var istanbul = require('istanbul');7var instrumenter = new istanbul.Instrumenter();8var code = 'function foo() { return 1; }';9var instrumented = instrumenter.instrumentSync(code, 'test.js');10console.log(instrumented);11var istanbul = require('istanbul');12var instrumenter = new istanbul.Instrumenter();13var code = 'function foo() { return 1; }';14var instrumented = instrumenter.instrumentSync(code, 'test.js');15console.log(instrumented);16var istanbul = require('istanbul');17var instrumenter = new istanbul.Instrumenter();18var code = 'function foo() { return 1; }';19var instrumented = instrumenter.instrumentSync(code, 'test.js');20console.log(instrumented);21var istanbul = require('istanbul');22var instrumenter = new istanbul.Instrumenter();23var code = 'function foo() { return 1; }';24var instrumented = instrumenter.instrumentSync(code, 'test.js');25console.log(instrumented);26var istanbul = require('istanbul');27var instrumenter = new istanbul.Instrumenter();28var code = 'function foo() { return 1; }';29var instrumented = instrumenter.instrumentSync(code, 'test.js');30console.log(instrumented);31var istanbul = require('istanbul');32var instrumenter = new istanbul.Instrumenter();33var code = 'function foo() { return 1; }';34var instrumented = instrumenter.instrumentSync(code, 'test.js');35console.log(instrumented);36var istanbul = require('istanbul');37var instrumenter = new istanbul.Instrumenter();

Full Screen

Using AI Code Generation

copy

Full Screen

1var istanbul = require('istanbul');2var reporter = new istanbul.Reporter();3reporter.add('lcov');4reporter.addAll(['lcov', 'text', 'text-summary']);5reporter.write(collector, true, function() {6 console.log('All reports generated');7});8var istanbul = require('istanbul');9var reporter = new istanbul.Reporter();10reporter.add('lcov');11reporter.addAll(['lcov', 'text', 'text-summary']);12reporter.write(collector, true, function() {13 console.log('All reports generated');14});15var istanbul = require('istanbul');16var reporter = new istanbul.Reporter();17reporter.add('lcov');18reporter.addAll(['lcov', 'text', 'text-summary']);19reporter.write(collector, true, function() {20 console.log('All reports generated');21});22var istanbul = require('istanbul');23var reporter = new istanbul.Reporter();24reporter.add('lcov');25reporter.addAll(['lcov', 'text', 'text-summary']);26reporter.write(collector, true, function() {27 console.log('All reports generated');28});29var istanbul = require('istanbul');30var reporter = new istanbul.Reporter();31reporter.add('lcov');32reporter.addAll(['lcov', 'text', 'text-summary']);33reporter.write(collector, true, function() {34 console.log('All reports generated');35});36var istanbul = require('istanbul');37var reporter = new istanbul.Reporter();38reporter.add('lcov');39reporter.addAll(['lcov', 'text', 'text-summary']);40reporter.write(collector, true, function() {41 console.log('All reports generated');42});43var istanbul = require('istanbul');44var reporter = new istanbul.Reporter();45reporter.add('

Full Screen

Using AI Code Generation

copy

Full Screen

1var istanbul = require('istanbul');2var collector = new istanbul.Collector();3var reporter = new istanbul.Reporter();4var sync = false;5var reportDir = './coverage';6var verbose = false;7var reportTypes = ['lcov', 'json', 'text-summary'];8var coverageVariable = '__coverage__';9var globalConfig = {10 reportOpts: { dir: reportDir },11};12var coverage = global[coverageVariable];13collector.add(coverage);14reporter.addAll(reportTypes);15reporter.write(collector, sync, function () {16 console.log('All reports generated');17});18"scripts": {19}

Full Screen

Using AI Code Generation

copy

Full Screen

1var a = require('./lib/a');2var b = require('./lib/b');3var c = new a();4var d = new b();5c.test();6d.test();7var a = function() {8 this.test = function() {9 console.log('test');10 this.parent();11 }12}13module.exports = a;14var b = function() {15 this.test = function() {16 console.log('test');17 this.parent();18 }19}20module.exports = b;21var c = function() {22 this.test = function() {23 console.log('test');24 this.parent();25 }26}27module.exports = c;

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run istanbul 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