How to use selectTransform method in mountebank

Best JavaScript code snippet using mountebank

custom.js

Source:custom.js Github

copy

Full Screen

1// JavaScript Document2//Handle fading notifications3$(document).ready(function()4{5 var delay = 5000;6 7 $('.fading-notification').each(function()8 {9 $(this).delay(delay).fadeOut(500);10 11 delay = delay + 500;12 });13});14//create queue15var warcryQueues = [];16warcryQueues['internal'] = [];17var WarcryQueue = function(queueName)18{19 var add = function(fnc)20 {21 if (typeof queueName != 'undefined')22 {23 if (typeof warcryQueues[queueName] == 'undefined')24 {25 warcryQueues[queueName] = []26 }27 warcryQueues[queueName].push(fnc);28 }29 else30 {31 warcryQueues['internal'].push(fnc);32 }33 };34 35 var goNext = function()36 {37 if (typeof queueName != 'undefined')38 {39 //check if we have some functions in the queue40 if ($(warcryQueues[queueName]).size() < 1)41 {42 return false;43 }44 45 var fnc = warcryQueues[queueName].shift();46 if (typeof fnc == 'function')47 {48 fnc();49 }50 else51 {52 console.log('WarcryQueue: There are no other functions in the queue "'+queueName+'".');53 }54 }55 else56 {57 //check if we have some functions in the queue58 if ($(warcryQueues['internal']).size() < 1)59 {60 return false;61 }62 63 var fnc = warcryQueues['internal'].shift();64 if (typeof fnc == 'function')65 {66 fnc();67 }68 else69 {70 console.log('WarcryQueue: There are no other functions in the queue.');71 }72 }73 };74 75 var clear = function()76 {77 if (typeof queueName != 'undefined')78 {79 warcryQueues[queueName] = []80 }81 else82 {83 warcryQueue['internal'] = []84 }85 };86 87 var size = function()88 {89 if (typeof queueName != 'undefined')90 {91 return $(warcryQueues[queueName]).size();92 }93 else94 {95 return $(warcryQueues['internal']).size();96 }97 };98 99 return {100 add: add,101 goNext: goNext,102 clear: clear,103 size: size,104 };105}; 106//ajax update status107function updateRealmStatus(id)108{109 var $this = $('#realm-status-' + id);110 var $realm = id;111 112 $.get(113 $BaseURL + '/ajax.php?phase=19', 114 { 115 id: $realm,116 },117 function(data)118 {119 if (data == '1')120 {121 $this.addClass('online');122 }123 else124 {125 $this.addClass('offline');126 }127 //next in queue128 WarcryQueue('onload').goNext();129 }130 ); 131}132function updateLogonStatus()133{134 var $this = $('#logon-status2');135 136 $.get(137 $BaseURL + '/ajax.php?phase=20', 138 function(data)139 {140 if (data == '1')141 {142 $this.addClass('online');143 $this.html('Online');144 }145 else146 {147 $this.addClass('offline');148 $this.html('Offline');149 }150 //next in queue151 WarcryQueue('onload').goNext();152 }153 ); 154}155function updateTeamspeakStatus()156{157 var $this = $('#teeamspeak-status');158 159 //next in queue160 WarcryQueue('onload').goNext();161 return;162 163 $.get(164 "teamspeakStatus.php", 165 function(data)166 {167 if (data == '1')168 {169 $this.addClass('online');170 $this.html('Online');171 }172 else173 {174 $this.addClass('offline');175 $this.html('Offline');176 }177 //next in queue178 WarcryQueue('onload').goNext();179 }180 ); 181}182function css_browser_selector(u)183{184 var ua=u.toLowerCase();185 var is=function(t)186 {187 return ua.indexOf(t)>-1188 };189 190 var g='gecko',w='webkit',s='safari',o='opera',m='mobile';191 var h=document.documentElement;192 var b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js'];193 194 c = b.join(' ');195 h.className += ' '+c;196 197 return c;198}199$(function()200{201 css_browser_selector(navigator.userAgent);202});203function convertDateToUTC(date)204{ 205 return new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds()); 206}207// function to calculate local time208// in a different city209// given the city's UTC offset210function calcTime(city, offset)211{212 // create Date object for current location213 var d = new Date();214 // convert to msec215 // add local time zone offset216 // get UTC time in msec217 var utc = d.getTime() + (d.getTimezoneOffset() * 60000);218 // create new Date object for different city219 // using supplied offset220 var nd = new Date(utc + (3600000*parseInt(offset)));221 // return time as a string222 return nd.toString();223}224//Server time Cloack225function ServerTimeCloack()226{227 var currentTime = new Date(calcTime($TIMEZONE, $TIMEZONEOFFSET));228 229 var h = currentTime.getHours();230 var m = currentTime.getMinutes();231 var s = currentTime.getSeconds();232 233 setTimeout(function() { ServerTimeCloack(); }, 1000);234 if (h < 10)235 {236 h = "0" + h;237 }238 if (m < 10)239 {240 m = "0" + m;241 }242 if (s < 10)243 {244 s = "0" + s;245 }246 247 var myClock = document.getElementById('server-time-cloack');248 if (myClock)249 {250 myClock.textContent = h + ":" + m + ":" + s;251 myClock.innerText = h + ":" + m + ":" + s;252 }253}254//-----------------------------------------------------------------------//255//---------------- SelectTransform, jQuery plugin -----------------------//256//---------------------- Script by ChoMPi -------------------------------//257//-----------------------------------------------------------------------//258(function($)259{260 var $isListOpen = false;261 var $currentlyOpenList = null;262 var $lastScrollTimestamp = null;263 var $minTimeBetweenScroll = 200; //Time in miliseconds264 265 var methods =266 {267 listState : 'closed',268 269 defaults :270 {271 container: null,272 list: null,273 selected: null,274 arrow: null,275 scrollConfig: { scrollBy: 5, },276 searchQueue: null,277 isScrollable: false,278 },279 280 init : function(config)281 {282 //if we have the element283 if ($(this).length < 1)284 {285 return;286 }287 288 //If the init hasent been called yet289 if (typeof $(this).data('SelectTransform') == 'undefined')290 {291 $(this).data('SelectTransform', {config: null});292 //merge the defaults with the passed config 293 $(this).data('SelectTransform').config = $.extend({}, methods.defaults, config);294 }295 else296 {297 //merge the old config with the passed one298 $(this).data('SelectTransform').config = $.extend({}, $(this).data('SelectTransform').config, config);299 }300 301 var config = $(this).data('SelectTransform').config;302 //get the instance of the element303 var $element = $(this);304 305 //hide the select form306 $element.css({display: 'none'});307 308 //create new element which will represent the select309 var container = document.createElement('div');310 //check if the element has attribute ID 311 if (typeof $element.attr('id') != 'undefined')312 {313 $(container).attr('id', $element.attr('id'));314 }315 $(container).attr('class', 'js-select');316 //append the new element317 $element.after(container);318 //bind click event to open the dropdown list319 $(container).bind('click', function(event)320 {321 event.stopPropagation();322 $element.SelectTransform('clickEvent');323 });324 325 config.container = $(container);326 327 //create the div which will contain the selected option328 var selected = document.createElement('div');329 $(selected).attr('class', 'js-select-selected');330 $(container).append(selected);331 332 config.selected = $(selected);333 //create the div which will contain the arrow334 var arrow = document.createElement('div');335 $(arrow).attr('class', 'js-select-arrow');336 $(selected).after(arrow);337 338 config.arrow = $(arrow);339 340 //create new div which will be the container of the list341 var dropdownCont = document.createElement('div');342 $(dropdownCont).attr('class', 'js-select-list-container');343 $(dropdownCont).attr('id', 'js-list-container');344 $(dropdownCont).css({display: 'none', zIndex: 101});345 $(config.container).append(dropdownCont);346 347 config.listContainer = $(dropdownCont);348 //scrollbar manager349 var listItemCount = $element.find('option').length;350 351 //if the items are more than scrollBy variable, append scrollbar352 if (listItemCount > config.scrollConfig.scrollBy)353 {354 config.isScrollable = true;355 356 //create the scrollbar357 //create the top controller358 var topController = document.createElement('div');359 $(topController).attr('class', 'js-select-list-top-controller');360 $(topController).attr('id', 'js-list-top-controller');361 $(topController).attr('align', 'center');362 $(config.listContainer).append(topController);363 $(topController).append('<p></p>');364 $(topController).bind('click', function(event)365 {366 event.stopPropagation();367 $element.SelectTransform('ScrollUp');368 });369 config.topController = $(topController);370 371 //create new div which will be the scroller of the list372 var dropdownScroller = document.createElement('div');373 $(dropdownScroller).attr('class', 'js-select-list-scroller');374 $(dropdownScroller).attr('id', 'js-list-scroller');375 $(config.listContainer).append(dropdownScroller);376 377 config.listScroller = $(dropdownScroller);378 379 //Create new div which will be the container of the options380 var dropdown = document.createElement('div');381 $(dropdown).attr('class', 'js-select-list-scrollable');382 $(dropdown).attr('id', 'js-list');383 $(config.listScroller).append(dropdown);384 config.list = $(dropdown);385 386 //create the bottom controller387 var bottomController = document.createElement('div');388 $(bottomController).attr('class', 'js-select-list-bottom-controller');389 $(bottomController).attr('id', 'js-list-bottom-controller');390 $(bottomController).attr('align', 'center');391 $(config.listContainer).append(bottomController);392 $(bottomController).append('<p></p>');393 $(bottomController).bind('click', function(event)394 {395 event.stopPropagation();396 $element.SelectTransform('ScrollDown');397 });398 399 config.bottomController = $(bottomController);400 }401 else402 {403 //Create new div which will be the container of the options404 var dropdown = document.createElement('div');405 $(dropdown).attr('class', 'js-select-list');406 $(dropdown).attr('id', 'js-list');407 $(config.listContainer).append(dropdown);408 config.list = $(dropdown);409 }410 //append the options to the container411 $element.find('option').each(function(index, element)412 {413 var option = document.createElement('ul');414 $(option).attr('id', index);415 $(option).attr('class', 'js-select-list-option');416 $(option).html($(element).html());417 418 //check if HTML var is assigned419 if (typeof $(element).attr('getHtmlFrom') != 'undefined')420 {421 var htmlElement = $(element).attr('getHtmlFrom');422 423 //check if the assigned element exists424 if ($(htmlElement).length > 0)425 {426 $(option).html($(htmlElement).html());427 }428 }429 430 //copy the element style param431 if (typeof $(element).attr('style') != 'undefined')432 {433 $(option).attr('style', $(element).attr('style'));434 }435 436 //copy the element class param437 if (typeof $(element).attr('class') != 'undefined')438 {439 $(option).addClass($(element).attr('class'));440 }441 442 ///bind the event handlers443 if(typeof $(element).attr('selected') != 'undefined')444 {445 //check if HTML var is assigned446 if (typeof $(element).attr('getHtmlFrom') != 'undefined')447 {448 var htmlElement = $(element).attr('getHtmlFrom');449 450 //check if the assigned element exists451 if ($(htmlElement).length > 0)452 {453 $(config.selected).html($(htmlElement).html());454 }455 }456 else457 {458 $(config.selected).html($(element).html());459 }460 461 $(option).addClass('js-select-list-option-selected');462 if(typeof $(element).attr('disabled') != 'undefined')463 {464 $(option).addClass('js-select-list-option-disabled');465 //wont bind anything on this one466 $(option).unbind('click');467 $(option).bind('click', function(event){ event.stopPropagation(); });468 }469 else470 {471 //bind click event to simply close the list472 $(option).bind('click', function(event)473 { 474 event.stopPropagation();475 $element.SelectTransform('selectEvent', {option: element, index: index});476 });477 }478 }479 else480 {481 //bind the select handler482 if(typeof $(element).attr('disabled') != 'undefined')483 {484 $(option).addClass('js-select-list-option-disabled');485 486 //wont bind anything on this one487 $(option).bind('click', function(event)488 { 489 event.stopPropagation();490 });491 }492 else493 {494 $(option).bind('click', function(event)495 { 496 event.stopPropagation();497 $element.SelectTransform('selectEvent', {option: element, index: index});498 });499 }500 }501 502 //append the option to the container503 $(config.list).append(option);504 });505 506 },507 508 clickEvent : function()509 {510 var config = $(this).data('SelectTransform').config;511 $element = $(this);512 513 //check if we have opened list514 if ($isListOpen)515 {516 //deactivate the arrow517 $currentlyOpenList.data('SelectTransform').config.arrow.removeClass('js-select-arrow-active');518 //close the option list519 $currentlyOpenList.SelectTransform('closeList');520 521 //unbind HTML click event522 $('html').unbind('click');523 }524 else 525 //if the list is closed526 {527 //activate the arrow528 $(config.arrow).addClass('js-select-arrow-active');529 //open the option list530 $(this).SelectTransform('openList');531 532 //bind click element to the HTML to close the dropdown list if the click is outside the select form533 $('html').bind('click', function(event)534 {535 event.stopPropagation();536 $element.SelectTransform('clickEvent');537 });538 }539 },540 541 openList : function()542 {543 var $element = $(this);544 var config = $(this).data('SelectTransform').config;545 546 //open the options list547 $(config.listContainer).slideDown('fast');548 549 //define that one list is already opened550 $isListOpen = true;551 $currentlyOpenList = $(this);552 553 //check if we have scrolling list554 if (config.isScrollable)555 {556 if (!$(config.listContainer).hasClass('js-select-list-container-scrollable'))557 $(config.listContainer).addClass('js-select-list-container-scrollable');558 559 //create the shearchbox element560 var searchbox = document.createElement('input');561 $(searchbox).css({ opacity: 0, position: 'fixed', top: '0px', left: '0px' });562 $(searchbox).attr('type', 'text');563 $(searchbox).attr('id', 'js-select-searchbox');564 565 $('body').append(searchbox);566 //focus the searchbox567 $(searchbox).focus();568 569 config.searchBox = $(searchbox);570 571 $(searchbox).on('keyup', function(event)572 {573 //prevent Enter key574 if (event.keyCode == '13')575 {576 event.preventDefault(); 577 return false;578 }579 580 //get the searchbox text581 var text = $(searchbox).val();582 583 $(config.list).children('ul').each(function(index, element)584 {585 var thisString = $(this).html();586 587 //convert both strings to lower case588 text = text.toLowerCase();589 thisString = thisString.toLowerCase();590 591 //if there is no text just go to the top592 if (text == '' || text == null)593 {594 clearTimeout(config.searchQueue);595 config.searchQueue = setTimeout(function(){ $element.SelectTransform('ScrollTo', 0); }, 300);596 }597 else if (thisString.indexOf(text) >= 0)598 {599 clearTimeout(config.searchQueue);600 config.searchQueue = setTimeout(function(){ $element.SelectTransform('ScrollTo', index); }, 300);601 }602 });603 });604 605 //Bind the mouse wheel events606 config.list.on('mousewheel', function(event, delta)607 {608 //stop the page from being scrolled609 event.preventDefault();610 611 //break if the last scroll was too soon612 if ($lastScrollTimestamp != null && (parseInt($lastScrollTimestamp) + $minTimeBetweenScroll) >= parseInt(event.timeStamp))613 {614 //console.log('Mouse wheel too soon.');615 return false;616 }617 618 //update the last scroll timestamp619 $lastScrollTimestamp = event.timeStamp;620 621 //get the direction 622 var dir = delta > 0 ? 'Up' : 'Down';623 624 //if scrolling up625 if (dir == 'Up')626 {627 $element.SelectTransform('ScrollUp');628 }629 else630 {631 $element.SelectTransform('ScrollDown');632 }633 634 return false;635 });636 } 637 },638 639 closeList : function()640 {641 var config = $(this).data('SelectTransform').config;642 $isListOpen = false;643 $currentlyOpenList = null;644 //close the options list645 $(config.listContainer).slideUp('fast');646 647 //check if we have scrolling list648 if (config.isScrollable)649 {650 //destroy the searchbox651 $(config.searchBox).detach();652 }653 654 //off the mousewheel event655 config.list.off('mousewheel');656 },657 658 unselectOption: function()659 {660 var config = $(this).data('SelectTransform').config;661 $element = $(this);662 663 $option = $(this).find(':selected');664 665 //remove the selected666 $option.removeAttr('selected');667 668 //find the selected option in our custom list669 $selectedInList = $(config.list).find('.js-select-list-option-selected');670 $selectedInList.removeClass('js-select-list-option-selected');671 /*if (!$selectedInList.hasClass('js-select-list-option-disabled'))672 {673 //bind the select handler674 $selectedInList.unbind('click').bind('click', function(event)675 { 676 event.stopPropagation();677 $element.SelectTransform('selectEvent', {option: $option, index: $option.index()});678 });679 }*/680 },681 682 selectOption: function(options)683 {684 var config = $(this).data('SelectTransform').config;685 $element = $(this);686 687 //set the option attr selected 688 $(options.option).attr('selected', 'selected');689 690 //find the option in our custom list691 $selectedInList = $(config.list).find('#'+options.index);692 693 //add class selected694 $selectedInList.addClass('js-select-list-option-selected');695 696 /*//bind click events697 $selectedInList.unbind('click').bind('click', function(event)698 { 699 event.stopPropagation();700 $element.SelectTransform('clickEvent');701 });*/702 },703 704 selectEvent: function(options)705 {706 var config = $(this).data('SelectTransform').config;707 $element = $(this);708 709 var text = $(options.option).html();710 711 //remove the selected712 $(this).SelectTransform('unselectOption');713 714 //check if HTML var is assigned715 if (typeof $(options.option).attr('getHtmlFrom') != 'undefined')716 {717 var htmlElement = $(options.option).attr('getHtmlFrom');718 719 //check if the assigned element exists720 if ($(htmlElement).length > 0)721 {722 $(config.selected).html($(htmlElement).html());723 }724 }725 else726 {727 //update the selected text728 $(config.selected).html(text);729 }730 731 //select the option732 $(this).SelectTransform('selectOption', {option: options.option, index: options.index});733 734 //close the list735 $element.SelectTransform('clickEvent');736 737 //trigger change event738 $element.trigger('change'); 739 },740 741 quickSelect: function(options)742 {743 var config = $(this).data('SelectTransform').config;744 $element = $(this);745 746 var text = $(options.option).html();747 748 //remove the selected749 $(this).SelectTransform('unselectOption');750 751 //check if HTML var is assigned752 if (typeof $(options.option).attr('getHtmlFrom') != 'undefined')753 {754 var htmlElement = $(options.option).attr('getHtmlFrom');755 756 //check if the assigned element exists757 if ($(htmlElement).length > 0)758 {759 $(config.selected).html($(htmlElement).html());760 }761 }762 else763 {764 //update the selected text765 $(config.selected).html(text);766 }767 768 //select the option769 $(this).SelectTransform('selectOption', {option: options.option, index: options.index}); 770 },771 772 ScrollUp : function()773 {774 var config = $(this).data('SelectTransform').config;775 $element = $(this);776 777 //check if we need setup778 var isSetupDone = $(config.list).attr('isSetupDone');779 if (typeof isSetupDone == 'undefined' || isSetupDone != '1')780 {781 $element.SelectTransform('ScrollSetup');782 }783 //get some config variables784 var currentOffset = parseInt($(config.list).attr('currentOffset'));785 var totalOptions = parseInt($(config.list).attr('totalOptions'));786 787 var scrollToOffset = currentOffset - config.scrollConfig.scrollBy;788 789 if (scrollToOffset < 0)790 {791 scrollToOffset = 0;792 }793 794 //find the option we want to scroll to795 var $find = config.list.children('#' + scrollToOffset );796 797 $(config.list).stop(true,true).animate({ marginTop: '-' + ($find.position().top) + 'px' }, 400);798 799 //update the current offset800 $(config.list).attr('currentOffset', scrollToOffset);801 802 //focus the searchbox if exists803 if (typeof config.searchBox != 'undefined')804 {805 config.searchBox.attr('value', '');806 config.searchBox.focus();807 }808 },809 810 ScrollDown : function()811 {812 var config = $(this).data('SelectTransform').config;813 $element = $(this);814 815 //check if we need setup816 var isSetupDone = $(config.list).attr('isSetupDone');817 if (typeof isSetupDone == 'undefined' || isSetupDone != '1')818 {819 $element.SelectTransform('ScrollSetup');820 }821 822 //get some config variables823 var currentOffset = parseInt($(config.list).attr('currentOffset'));824 var totalOptions = parseInt($(config.list).attr('totalOptions'));825 826 var scrollToOffset = currentOffset + config.scrollConfig.scrollBy;827 828 //if the next scroll offset is greater than the total options829 if (scrollToOffset > (totalOptions - config.scrollConfig.scrollBy))830 {831 //null the next scroll offset to the total options - scroll by value832 scrollToOffset = totalOptions - config.scrollConfig.scrollBy;833 }834 //find the option we want to scroll to835 var $find = config.list.children('#' + scrollToOffset );836 837 $(config.list).stop(true,true).animate({ marginTop: '-' + ($find.position().top) + 'px' }, 400);838 839 //update the current offset840 $(config.list).attr('currentOffset', scrollToOffset);841 842 //focus the searchbox if exists843 if (typeof config.searchBox != 'undefined')844 {845 config.searchBox.attr('value', '');846 config.searchBox.focus();847 }848 },849 850 ScrollTo : function(index)851 {852 var config = $(this).data('SelectTransform').config;853 var $element = $(this);854 //check if we need setup855 var isSetupDone = $(config.list).attr('isSetupDone');856 if (typeof isSetupDone == 'undefined' || isSetupDone != '1')857 {858 $element.SelectTransform('ScrollSetup');859 }860 //get some config variables861 var currentOffset = parseInt($(config.list).attr('currentOffset'));862 var totalOptions = parseInt($(config.list).attr('totalOptions'));863 864 //if the next scroll offset is greater than the total options865 if (index > (totalOptions - config.scrollConfig.scrollBy))866 {867 //null the next scroll offset to the total options - scroll by value868 index = totalOptions - config.scrollConfig.scrollBy;869 }870 871 //find the option we want to scroll to872 var $find = config.list.children('#' + index );873 874 $(config.list).stop(true,true).animate({ marginTop: '-' + ($find.position().top) + 'px' }, 400);875 876 //update the current offset877 $(config.list).attr('currentOffset', index); 878 879 },880 881 ScrollSetup : function()882 {883 var config = $(this).data('SelectTransform').config;884 $element = $(this);885 886 //set some default values to the element directly887 $(config.list).attr('totalOptions', config.list.children('ul').length);888 $(config.list).attr('currentOffset', '0');889 890 $(config.list).attr('isSetupDone', '1');891 },892 }893 894 $.fn.SelectTransform = function(method)895 {896 if (methods[method])897 {898 return methods[method].apply(this, Array.prototype.slice.call( arguments, 1 ));899 }900 else if (typeof method === 'object' || ! method)901 {902 return methods.init.apply(this, arguments);903 }904 else905 {906 $.error( 'Method ' + method + ' does not exist on jQuery.SelectTransform' );907 } 908 };909})(jQuery);910//-----------------------------------------------------------------------//911//-------------------- Loading Bar, jQuery plugin -----------------------//912//---------------------- Script by ChoMPi -------------------------------//913//-----------------------------------------------------------------------//914(function($)915{916 var methods =917 {918 init : function()919 {920 //if we have the element921 if ($(this).length < 1)922 {923 return;924 }925 926 //get the instance of the element927 var $element = $(this);928 929 //create the bar930 $element.append('<div class="loading-bar" align="left"><span id="bar"></span></div>');931 932 //run to state 1933 $element.LoadingBar('state1'); 934 },935 936 state1 : function(callback)937 {938 var $element = $(this);939 $element.find('#bar').stop(true,true).animate({ width: '100px' }, 1000, function()940 {941 $(this).css('width', '100px');942 943 if (typeof callback == 'function')944 {945 callback();946 }947 });948 },949 950 state2 : function(callback)951 {952 var $element = $(this);953 954 $element.find('#bar').stop(true,true).animate({ width: '200px' }, 500, function()955 {956 $(this).css('width', '200px');957 958 if (typeof callback == 'function')959 {960 callback();961 }962 });963 },964 965 state3 : function(callback)966 {967 var $element = $(this);968 $element.find('#bar').stop(true,true).animate({ width: '300px' }, 500, function()969 {970 $(this).css('width', '300px');971 if (typeof callback == 'function')972 {973 callback();974 }975 });976 },977 978 state4 : function(callback)979 {980 var $element = $(this);981 $element.find('#bar').stop(true,true).animate({ width: '400px' }, 500, function()982 {983 $(this).css('width', '400px');984 985 if (typeof callback == 'function')986 {987 callback();988 }989 });990 },991 992 restart : function()993 {994 var $element = $(this);995 996 $element.find('#bar').css('width', '0px');997 },998 }999 1000 $.fn.LoadingBar = function(method)1001 {1002 if (methods[method])1003 {1004 return methods[method].apply(this, Array.prototype.slice.call( arguments, 1 ));1005 }1006 else if (typeof method === 'object' || ! method)1007 {1008 return methods.init.apply(this, arguments);1009 }1010 else1011 {1012 $.error( 'Method ' + method + ' does not exist on jQuery.LoadingBar');1013 } 1014 };...

Full Screen

Full Screen

dataViewObjectEvaluationUtils.ts

Source:dataViewObjectEvaluationUtils.ts Github

copy

Full Screen

1/*2* Power BI Visualizations3*4* Copyright (c) Microsoft Corporation5* All rights reserved. 6 * MIT License7*8* Permission is hereby granted, free of charge, to any person obtaining a copy9* of this software and associated documentation files (the ""Software""), to deal10* in the Software without restriction, including without limitation the rights11* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell12* copies of the Software, and to permit persons to whom the Software is13* furnished to do so, subject to the following conditions:14* 15 * The above copyright notice and this permission notice shall be included in 16 * all copies or substantial portions of the Software.17* 18 * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,23* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN24* THE SOFTWARE.25*/26module powerbi.data {27 export interface DataViewObjectDefinitionsByRepetition {28 metadataOnce?: DataViewObjectDefinitionsForSelector;29 userDefined?: DataViewObjectDefinitionsForSelector[];30 metadata?: DataViewObjectDefinitionsForSelector[];31 data: DataViewObjectDefinitionsForSelectorWithRule[];32 }33 export interface DataViewObjectDefinitionsForSelector {34 selector?: Selector;35 objects: DataViewNamedObjectDefinition[];36 }37 export interface DataViewObjectDefinitionsForSelectorWithRule extends DataViewObjectDefinitionsForSelector {38 rules?: RuleEvaluation[];39 }40 export interface DataViewNamedObjectDefinition {41 name: string;42 properties: DataViewObjectPropertyDefinitions;43 }44 export module DataViewObjectEvaluationUtils {45 export function evaluateDataViewObjects(46 evalContext: IEvalContext,47 objectDescriptors: DataViewObjectDescriptors,48 objectDefns: DataViewNamedObjectDefinition[]): DataViewObjects {49 debug.assertValue(evalContext, 'evalContext');50 debug.assertValue(objectDescriptors, 'objectDescriptors');51 debug.assertValue(objectDefns, 'objectDefns');52 let objects: DataViewObjects;53 for (let j = 0, jlen = objectDefns.length; j < jlen; j++) {54 let objectDefinition = objectDefns[j],55 objectName = objectDefinition.name;56 let evaluatedObject: DataViewObject = DataViewObjectEvaluator.run(57 evalContext,58 objectDescriptors[objectName],59 objectDefinition.properties);60 if (!evaluatedObject)61 continue;62 if (!objects)63 objects = {};64 // NOTE: this currently has last-object-wins semantics.65 objects[objectName] = evaluatedObject;66 }67 return objects;68 }69 export function groupObjectsBySelector(objectDefinitions: DataViewObjectDefinitions): DataViewObjectDefinitionsByRepetition {70 debug.assertAnyValue(objectDefinitions, 'objectDefinitions');71 let grouped: DataViewObjectDefinitionsByRepetition = {72 data: [],73 };74 if (objectDefinitions) {75 for (let objectName in objectDefinitions) {76 let objectDefnList = objectDefinitions[objectName];77 for (let i = 0, len = objectDefnList.length; i < len; i++) {78 let objectDefn = objectDefnList[i];79 ensureDefinitionListForSelector(grouped, objectDefn.selector).objects.push({80 name: objectName,81 properties: objectDefn.properties,82 });83 }84 }85 }86 return grouped;87 }88 function ensureDefinitionListForSelector(grouped: DataViewObjectDefinitionsByRepetition, selector: Selector): DataViewObjectDefinitionsForSelector {89 debug.assertValue(grouped, 'grouped');90 debug.assertAnyValue(selector, 'selector');91 if (!selector) {92 if (!grouped.metadataOnce)93 grouped.metadataOnce = { objects: [] };94 return grouped.metadataOnce;95 }96 let groupedObjects: DataViewObjectDefinitionsForSelector[];97 if (selector.data) {98 groupedObjects = grouped.data;99 }100 else if (selector.metadata) {101 if (!grouped.metadata)102 grouped.metadata = [];103 groupedObjects = grouped.metadata;104 }105 else if (selector.id) {106 if (!grouped.userDefined)107 grouped.userDefined = [];108 groupedObjects = grouped.userDefined;109 }110 debug.assert(!!groupedObjects, 'GroupedObjects is not defined. Indicates malformed selector.');111 for (let item of groupedObjects) {112 if (Selector.equals(selector, item.selector))113 return item;114 }115 let item: DataViewObjectDefinitionsForSelector = {116 selector: selector,117 objects: [],118 };119 groupedObjects.push(item);120 return item;121 }122 export function addImplicitObjects(123 objectsForAllSelectors: DataViewObjectDefinitionsByRepetition,124 objectDescriptors: DataViewObjectDescriptors,125 columns: DataViewMetadataColumn[],126 selectTransforms: DataViewSelectTransform[]): void {127 debug.assertValue(objectsForAllSelectors, 'objectsForAllSelectors');128 debug.assertValue(objectDescriptors, 'objectDescriptors');129 debug.assertValue(columns, 'columns');130 debug.assertAnyValue(selectTransforms, 'selectTransforms');131 if (selectTransforms) {132 addDefaultFormatString(objectsForAllSelectors, objectDescriptors, columns, selectTransforms);133 addDefaultValue(objectsForAllSelectors, objectDescriptors, columns, selectTransforms);134 }135 }136 function addDefaultFormatString(137 objectsForAllSelectors: DataViewObjectDefinitionsByRepetition,138 objectDescriptors: DataViewObjectDescriptors,139 columns: DataViewMetadataColumn[],140 selectTransforms: DataViewSelectTransform[]): void {141 debug.assertValue(objectsForAllSelectors, 'objectsForAllSelectors');142 debug.assertValue(objectDescriptors, 'objectDescriptors');143 debug.assertValue(columns, 'columns');144 debug.assertValue(selectTransforms, 'selectTransforms');145 let formatStringProp = DataViewObjectDescriptors.findFormatString(objectDescriptors);146 if (!formatStringProp)147 return;148 for (let selectIdx = 0, selectLen = selectTransforms.length; selectIdx < selectLen; selectIdx++) {149 let selectTransform = selectTransforms[selectIdx];150 if (!selectTransform)151 continue;152 debug.assertValue(selectTransform.queryName, 'selectTransform.queryName');153 applyFormatString(154 objectsForAllSelectors,155 formatStringProp,156 selectTransform.queryName,157 selectTransform.format || getColumnFormatForIndex(columns, selectIdx));158 }159 }160 /** Registers properties for default value, if the properties are not explicitly provided. */161 function addDefaultValue (162 objectsForAllSelectors: DataViewObjectDefinitionsByRepetition,163 objectDescriptors: DataViewObjectDescriptors,164 columns: DataViewMetadataColumn[],165 selectTransforms: DataViewSelectTransform[]): void {166 debug.assertValue(objectsForAllSelectors, 'objectsForAllSelectors');167 debug.assertValue(objectDescriptors, 'objectDescriptors');168 debug.assertValue(columns, 'columns');169 debug.assertValue(selectTransforms, 'selectTransforms');170 let defaultValueProp = DataViewObjectDescriptors.findDefaultValue(objectDescriptors);171 if (!defaultValueProp)172 return;173 for (let selectTransform of selectTransforms) {174 if (!selectTransform)175 continue;176 debug.assertValue(selectTransform.queryName, 'selectTransform.queryName');177 applyDefaultValue(178 objectsForAllSelectors,179 defaultValueProp,180 selectTransform.queryName,181 selectTransform.defaultValue);182 }183 }184 function getColumnFormatForIndex(columns: DataViewMetadataColumn[], selectIdx: number): string {185 for (let columnIdx = 0, columnLen = columns.length; columnIdx < columnLen; columnIdx++) {186 let column = columns[columnIdx];187 if (!column || column.index !== selectIdx)188 continue;189 return column.format;190 }191 }192 function applyFormatString(193 objectsForAllSelectors: DataViewObjectDefinitionsByRepetition,194 formatStringProp: DataViewObjectPropertyIdentifier,195 queryName: string,196 formatStringValue: string): void {197 if (!formatStringValue)198 return;199 // There is a format string specified -- apply it as an object property, if there is not already one specified.200 applyMetadataProperty(201 objectsForAllSelectors,202 formatStringProp,203 { metadata: queryName },204 SQExprBuilder.text(formatStringValue));205 }206 function applyDefaultValue(207 objectsForAllSelectors: DataViewObjectDefinitionsByRepetition,208 defaultValueProp: DataViewObjectPropertyIdentifier,209 queryName: string,210 defaultValue: DefaultValueDefinition): void {211 if (!defaultValue)212 return;213 // There is a default value specified -- apply it as an object property, if there is not already one specified.214 applyMetadataProperty(215 objectsForAllSelectors,216 defaultValueProp,217 { metadata: queryName },218 defaultValue);219 }220 function applyMetadataProperty(221 objectsForAllSelectors: DataViewObjectDefinitionsByRepetition,222 propertyId: DataViewObjectPropertyIdentifier,223 selector: Selector,224 value: DataViewObjectPropertyDefinition): void {225 let objectDefns: DataViewObjectDefinitionsForSelector[];226 if (selector) {227 let metadataObjects = objectsForAllSelectors.metadata;228 if (!metadataObjects)229 metadataObjects = objectsForAllSelectors.metadata = [];230 objectDefns = metadataObjects;231 }232 else {233 let metadataOnce = objectsForAllSelectors.metadataOnce;234 if (!metadataOnce)235 metadataOnce = objectsForAllSelectors.metadataOnce = { selector: selector, objects: [] };236 objectDefns = [metadataOnce];237 }238 let targetMetadataObject = findWithMatchingSelector(objectDefns, selector);239 let targetObjectDefn: DataViewNamedObjectDefinition;240 if (targetMetadataObject) {241 let targetObjectDefns = targetMetadataObject.objects;242 targetObjectDefn = findExistingObject(targetObjectDefns, propertyId.objectName);243 if (targetObjectDefn) {244 if (targetObjectDefn.properties[propertyId.propertyName])245 return;246 }247 else {248 targetObjectDefn = {249 name: propertyId.objectName,250 properties: {},251 };252 targetObjectDefns.push(targetObjectDefn);253 }254 }255 else {256 targetObjectDefn = {257 name: propertyId.objectName,258 properties: {}259 };260 objectDefns.push({261 selector: selector,262 objects: [targetObjectDefn],263 });264 }265 targetObjectDefn.properties[propertyId.propertyName] = value;266 }267 function findWithMatchingSelector(objects: DataViewObjectDefinitionsForSelector[], selector: Selector): DataViewObjectDefinitionsForSelector {268 debug.assertValue(objects, 'objects');269 debug.assertAnyValue(selector, 'selector');270 for (let i = 0, len = objects.length; i < len; i++) {271 let object = objects[i];272 if (Selector.equals(object.selector, selector))273 return object;274 }275 }276 function findExistingObject(objectDefns: DataViewNamedObjectDefinition[], objectName: string): DataViewNamedObjectDefinition {277 debug.assertValue(objectDefns, 'objectDefns');278 debug.assertValue(objectName, 'objectName');279 for (let i = 0, len = objectDefns.length; i < len; i++) {280 let objectDefn = objectDefns[i];281 if (objectDefn.name === objectName)282 return objectDefn;283 }284 }285 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var imposter = {2 {3 {4 "equals": {5 }6 }7 {8 "is": {9 "headers": {10 },11 "body": {12 }13 }14 }15 {16 "options": {17 "transformer": {18 "options": {19 }20 }21 }22 }23 }24};25var mb = require('mountebank');26var Q = require('q');27var defer = Q.defer();28mb.create(imposter, defer.makeNodeResolver());29defer.promise.then(function (response) {30 console.log('response', response);31 return Q.nfcall(mb.get, '/imposters');32}).then(function (response) {33 console.log('response', response);34 return Q.nfcall(mb.del, '/imposters');35}).then(function (response) {36 console.log('response', response);37}).done();

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var imposter = {3 {4 {5 equals: {6 }7 }8 {9 is: {10 headers: {11 },12 body: {13 }14 }15 }16 }17};18mb.create(imposter).then(function () {19 return mb.get('/imposters');20}).then(function (response) {21 console.log(response.body);22});23[{"port":4545,"protocol":"http","stubs":[{"predicates":[{"equals":{"method":"GET","path":"/test"}}],"responses":[{"is":{"headers":{"Content-Type":"application/json"},"body":{"name":"test"}}}]}]}]24{25 {26 "equals": {27 }28 }29 {30 "is": {31 "headers": {32 },33 "body": {34 }35 }36 }37 "behaviors": {38 "selectTransform": {39 "request": {40 },41 {42 "select": {43 },44 "transform": {45 "body": {46 }47 }48 }49 }50 }51}

Full Screen

Using AI Code Generation

copy

Full Screen

1const mb = require('mountebank');2const imposter = {3 {4 {5 equals: {6 }7 }8 {9 is: {10 }11 }12 }13};14mb.create(imposter)15 .then(() => mb.post('/imposters/3000/stubs', {16 {17 equals: {18 }19 }20 {21 is: {22 }23 }24 }))25 .then(() => mb.post('/imposters/3000/stubs', {26 {27 equals: {28 }29 }30 {31 is: {32 }33 }34 }))35 .then(() => mb.post('/imposters/3000/stubs', {36 {37 equals: {38 }39 }40 {41 is: {42 }43 }44 }))45 .then(() => mb.post('/imposters/3000/stubs', {46 {47 equals: {48 }49 }50 {51 is: {52 }53 }54 }))55 .then(() => mb.post('/imposters/3000/stubs', {56 {57 equals: {58 }59 }60 {61 is: {62 }63 }64 }))65 .then(() => mb.post('/imposters/3000/stubs', {66 {67 equals: {68 }69 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2mb.start({3}).then(function () {4 return mb.post('/imposters', {5 {6 {7 equals: {8 }9 }10 {11 is: {12 }13 }14 }15 });16}).then(function (response) {17 var imposter = response.body;18 var request = {19 {20 {21 equals: {22 }23 }24 {25 is: {26 }27 }28 }29 _links: {30 self: {31 }32 }33 };34 return mb.selectTransform(request, function (stub) {35 stub.responses[0].is.body += '!';36 return stub;37 });38}).then(function (response) {39 console.log(response.body);40 return mb.del('/imposters');41}).then(function () {42 return mb.stop();43}).catch(function (error) {44 console.error(error);45});

Full Screen

Using AI Code Generation

copy

Full Screen

1const mb = require('mountebank');2const port = 2525;3 {4 {5 {6 "is": {7 "headers": {8 },9 }10 }11 }12 }13];14mb.create(port, imposters).then(() => console.log('mountebank is ready'));15const mb = require('mountebank');16const port = 2525;17 {18 {19 {20 "is": {21 "headers": {22 },23 }24 }25 }26 }27];28mb.create(port, imposters).then(() => console.log('mountebank is ready'));29const mb = require('mountebank');30const port = 2525;31 {32 {33 {34 "is": {35 "headers": {36 },37 }38 }39 }40 }41];42mb.create(port, imposters).then(() => console.log('mountebank is ready'));43const mb = require('mountebank');44const port = 2525;45 {

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert'),2 mb = require('mountebank');3var imposter = mb.create({4});5imposter.addStub({6 predicates: [{7 equals: {8 }9 }],10 responses: [{11 is: {12 headers: {13 },14 }15 }]16});17imposter.start();18imposter.get('/test', function (error, response, body) {19 assert.ifError(error);20 assert.strictEqual(response.statusCode, 200);21 assert.strictEqual(body, 'Hello World');22 imposter.stop();23});24var assert = require('assert'),25 mb = require('mountebank');26var imposter = mb.create({27});28imposter.addStub({29 predicates: [{30 equals: {31 }32 }],33 responses: [{34 is: {35 headers: {36 },37 }38 }]39});40imposter.start();41imposter.get('/test', function (error, response, body) {42 assert.ifError(error);43 assert.strictEqual(response.statusCode, 200);44 assert.strictEqual(body, 'Hello World');45 imposter.stop();46});47var assert = require('assert'),48 mb = require('mountebank');49var imposter = mb.create({50});51imposter.addStub({52 predicates: [{53 equals: {

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert'),2 mb = require('mountebank');3mb.create({ port: 2525 }, function (error, mbServer) {4 assert.ok(!error, JSON.stringify(error));5 mbServer.post('/imposters', {6 {7 { equals: { method: 'GET', path: '/test' } }8 {9 is: {10 headers: { 'Content-Type': 'application/json' },11 body: JSON.stringify({ hello: 'world' })12 },13 _behaviors: {14 selectTransform: {15 select: {16 },17 transform: {18 }19 }20 }21 }22 }23 }, function (error, imposter) {24 assert.ok(!error, JSON.stringify(error));25 mbServer.get('/test', function (error, response) {26 assert.ok(!error, JSON.stringify(error));27 assert.strictEqual(response.statusCode, 200);28 assert.strictEqual(response.body, JSON.stringify({ hello: 'goodbye' }));29 mbServer.del('/imposters/' + imposter.port, function () {30 mbServer.close();31 });32 });33 });34});35var assert = require('assert'),36 mb = require('mountebank

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var port = 2525;3var imposter = {4 {5 {6 equals: {7 }8 }9 {10 is: {11 }12 }13 }14};15mb.create({ port: port, ipWhitelist: ['*'] }, function () {16 mb.post('/imposters', imposter, function (error, response) {17 console.log('Created imposter at ' + mbUrl + '/imposters/' + response.body.port);18 });19});20var mb = require('mountebank');21var port = 2525;22var imposter = {23 {24 {25 equals: {26 }27 }28 {29 is: {30 }31 }32 }33};34mb.create({ port: port, ipWhitelist: ['*'] }, function () {35 mb.post('/imposters', imposter, function (error, response) {36 console.log('Created imposter at ' + mbUrl + '/imposters/' + response.body.port);37 });38});39var mb = require('mountebank');40var port = 2525;41var imposter = {42 {43 {44 equals: {45 }46 }

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 mountebank 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