How to use bound method in storybook-root

Best JavaScript code snippet using storybook-root

absoluteLayout.js

Source:absoluteLayout.js Github

copy

Full Screen

1/*! 2* WeX5 v3 (http://www.justep.com) 3* Copyright 2015 Justep, Inc.4* Licensed under Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) 5*/ 6define(function(require) {7 var $ = require("jquery");8 var xuiService = require("$UI/system/components/designerCommon/js/xuiService");9 var xuiDoc = xuiService.getXuiDoc();10 require('css!./css/absoluteLayout').load();11 12 var absoluteLayout = function(config) {13 this.domNode = this.templateNode = config.templateNode;14// this.domNode.setAttribute("tabindex",'0');15 16 $(this.domNode).on("beforeAddChild",function(event){ 17 event.config = {css:{width:200+"px",position:'absolute'}};18 event.width = 200;19 event.position = "absolute";20 });21 };2223 absoluteLayout.prototype = { 24 init : function(){25 var self = this;26 $(this.domNode).bind({27 mousedown:function(event){28 self._mousedown(event);29 },30 mouseup:function(event){31 self._mouseup(event);32 },33 keydown : function(event){ 34 self._keydown(event);35 },36 mousemove:function(event){37 self._mousemove(event);38 }});39 },40 41 _keydown : function(event){ 42 var dx = 0, dy = 0; 43 var selections = this.getSelections(); 44 if (selections.length > 0) {45 switch (event.keyCode) {46 case 37 : // 左移键47 dx = -1;48 break;49 case 38 :// 上移50 dy = -1;51 break;52 case 39 :// 右移53 dx = 1;54 break;55 case 40 :// 下移56 dy = 1;57 break;58 }59 if (dx !== 0 || dy !== 0) { 60 var ids = [],css = [];61 for(var i =0;i<selections.length;i+=1){62 var $e = $(selections[i]);63 var left = parseInt($e.css("left"),10) + dx;64 var top = parseInt($e.css("top"),10) + dy;65 if(left<0){66 left = 0;67 }68 if(top<0){69 top = 0;70 }71 ids.push(selections[i].getAttribute("d_id")); 72 css.push({top:top+"px",left:left+"px"});73 } 74 xuiDoc.batchSetCSS(ids,css);75 event.preventDefault(); 76 event.stopPropagation();77 return false;78 }79 }80 },81 82 _mousedown : function(event){ 83 var target = event.target;84 this.mousedownX = event.clientX;85 this.mousedownY = event.clientY;86 this.currentSelect = null;87 this.mouseDownTarget = event.target;88 this.action = null;89 if(!this.ownerDesigner.ctx.action && target == this.domNode){90 this.ownerDesigner.executeSelect(event,target);91 this._dragSelect(event);92 event.stopPropagation(); 93 }else{94 var currentE = this.ownerDesigner.findSelectableElement(target); 95 if(currentE.parentNode == this.domNode){ 96 this.currentSelect = currentE;97 if(!this.ownerDesigner.isSelected(currentE)){98 this.ownerDesigner.executeSelect(event,target); 99 }100 event.stopPropagation();101 }102 }103 },104 105 _mouseup : function(event) {106 if (this.ownerDesigner.ctx.action === null) {107 if (event.button == 2) {108 if(this.ownerDesigner.getSelections().length>1){109 this.ownerDesigner.dispatchEvent({110 event : "contextmenu",111 selections : JSON.stringify([this.domNode.getAttribute("d_id")]),112 componentNames : JSON.stringify([this.domNode.getAttribute("componentName")])113 });114 event.stopPropagation();115 }116 }117 }118 },119 120 _mousemove :function(event){121 var action = this.ownerDesigner.ctx.action ;122 if(action === this.ownerDesigner.actionType.READY_CREATE){ 123 if(event.target == this.domNode){124 this.ownerDesigner.insertPos = this.calcuInsertPos(event.clientX,event.clientY);125 event.stopPropagation();126 }127 }else if(this.action == this.ownerDesigner.actionType.MOVE){128 event.stopPropagation();129 }else if(!this.ownerDesigner.ctx.action){130 if(event.which==1 && this.currentSelect && (Math.abs(event.clientY-this.mousedownY)>5 || Math.abs(event.clientX-this.mousedownX)>5)){131 this.action = this.ownerDesigner.actionType.MOVE;132 this._dragMove(event);133 event.stopPropagation();134 }135 }136 },137 138 /**拖拽移动位置**/139 _dragMove : function(event){140 var self = this;141 var $currentTarget = $(this.ownerDesigner.findSelectableElement(this.mouseDownTarget));142 var $domNode = $(this.domNode);143 var elements = this.getSelections();144 var oldPos = [];145 var startX = event.clientX;146 var startY = event.clientY;147 var i,l = elements.length;148 var body = document.body;149 150 var minX = 10000, minY = 10000, maxX = 0, maxY = 0;151 var mostLeftE;// 记录最左边最上边的一个控件152 var mostTopE;// 记录最上边最左边的一个控件153 for (i = 0; i < l; i += 1) {154 var $e = $(elements[i]);155 var pos = $e.position();156 var bound = $e.getBound();157 oldPos.push({158 top : pos.top,159 left : pos.left160 });161162 if (bound.x < minX || bound.x == minX && bound.y < minY) {163 mostLeftE = elements[i];164 }165 if (bound.y < minY || bound.y == minY && bound.x < minX) {166 mostTopE = elements[i];167 }168 minX = Math.min(minX, bound.x);169 minY = Math.min(minY, bound.y);170 maxX = Math.max(maxX, bound.x + bound.w);171 maxY = Math.max(maxY, bound.y + bound.h);172 }173 var currentBound = {x:minX,y:minY,w:maxX-minX,h:maxY-minY}; //当前选择图形的区域信息174 175 var otherBounds = [];176 var childNodes = this.domNode.childNodes;177 for(i = 0;i<childNodes.length;i+=1){178 var childNode = childNodes[i];179 if(childNode.nodeType == 1 && !self.ownerDesigner.isSelected(childNode)){180 otherBounds.push($(childNode).getBound());181 }182 }183 184 var mouseMove = function(event){185 if(event.which !=1){186 mouseUp(event);187 event.stopPropagation();188 return;189 }190 var dx = event.clientX - startX;191 var dy = event.clientY - startY;192 193 194 currentBound.x = Math.max(minX + dx,0); //不允许拖出左边界或者上边界,最小坐标为5195 currentBound.y = Math.max(minY + dy,0); 196 currentBound = self.autoAlign(currentBound, otherBounds,self.domNode);//执行自动对齐后返回新的坐标点197 198199 for (i = 0; i < l; i += 1) {200 var newX = Math.round(oldPos[i].left + (currentBound.x - minX) + self.domNode.scrollLeft);201 var newY = Math.round(oldPos[i].top + (currentBound.y - minY) + self.domNode.scrollTop);202 if(newX<0){203 newX = 0;204 }205 if(newY<0){206 newY = 0;207 }208209 $(elements[i]).css({210 left : newX + "px",211 top : newY + "px"212 });213 if (elements[i].selectionBox) {214 elements[i].selectionBox.paint();215 }216 self.ownerDesigner.repaintResizeBoxes();217 } 218 self.showLocationTip($currentTarget);219 event.stopPropagation();220 };221 222 var mouseUp = function(event){223 self.action = null;224 if(self.locationTip){225 self.locationTip.remove();226 self.locationTip = null;227 }228 self.clearAlighLine(self.domNode);229 $domNode.unbind("mousemove", mouseMove);230 $(body).unbind("mouseup", mouseUp);231 self.ownerDesigner.dispatchStyleChangedEvent();232 };233 234 $domNode.bind("mousemove", mouseMove);235 $(body).bind("mouseup", mouseUp);236 },237 238 showLocationTip : function($targetElement){239 if(!this.locationTip){240 this.locationTip = $("<div style='z-index:10;position:absolute;height:14px;padding:2px;background:#FFFFB9;font-size:9px;'></div>").appendTo(this.domNode);241 }242 var top = $targetElement.css("top");243 var left = $targetElement.css("left");244 245 this.locationTip.css({top:top,left:left}).html(top+","+left); 246 },247 248 /**249 * 拖拽框选.250 */251 _dragSelect : function(event) {252 var currentE = event.target;253 if (currentE == this.domNode) {254 var self = this;255 var selectDiv;256 var offset = $(this.domNode).offset();257 var $domNode = $(currentE);258 var scrollOffset = {259 left : self.domNode.scrollLeft,260 top : self.domNode.scrollTop261 };// canvas.getParentScrollOffset(targetE);262 console.log("left:"+scrollOffset.left+"==top:"+scrollOffset.top);263 var x = event.clientX - offset.left + scrollOffset.left , y = event.clientY - offset.top + scrollOffset.top ;264 var oldX = event.clientX, oldY = event.clientY;265 266 var body = document.body;267 var mouseMove = function(event) {268 if(event.which != 1){269 //mouseUp(event);270 return;271 }272 273 if (!selectDiv) {274 selectDiv = $(275 "<div style='opacity:0.5;filter:alpha(opacity=50);background:white;position:absolute;line-height:1px;height:1px;border:1px dashed green;top:" + y + "px;left:" + x276 + "px'>&nbsp;</div>").appendTo(currentE);277 }278 var w = event.clientX - oldX ;279 var h = event.clientY - oldY ;280 281 var newScrollLeft = self.domNode.scrollLeft;282 if(newScrollLeft != scrollOffset.left){//滚动条在拖拽中滚动283 w += (newScrollLeft - scrollOffset.left);284 }285 var newScrollTop = self.domNode.scrollTop;286 if(newScrollTop != scrollOffset.top){ //滚动条在拖拽中滚动287 h += (newScrollTop - scrollOffset.top);288 }289 if (w < 1) {290 selectDiv.css("left", (x + w) + "px");291 }292 if (h < 1) {293 selectDiv.css("top", (y + h) + "px");294 }295 selectDiv.width(Math.abs(w));296 selectDiv.height(Math.abs(h));297 event.stopPropagation();298 };299300 var mouseUp = function(event) {301 $domNode.unbind("mousemove", mouseMove);302 $(body).unbind("mouseup", mouseUp);303 event.stopPropagation();304 if (selectDiv) {305 var dgBound = selectDiv.getBound();306 selectDiv.remove();307 var childNodes = currentE.childNodes;308 var isFirst = true;309 for ( var i = 0, l = childNodes.length; i < l; i++) {310 var childNode = childNodes[i];311 if(childNode.nodeType == 1 && childNode.getAttribute("d_id")){312 if (self.containInBound(dgBound, $(childNode).getBound())) {313 self.ownerDesigner[isFirst?"setSelection":"addSelection"](childNode);314 isFirst = false;315 }316 }317 }318 if(!isFirst){319 self.ownerDesigner.dispatchSelectionChangedEvent();320 }321 }322 selectDiv = null;323 };324 $domNode.bind("mousemove", mouseMove);325 $(body).bind("mouseup", mouseUp);326 }327 },328 329 getRegularBound : function(bound) {330 var x1 = bound.x + bound.w;331 var y1 = bound.y + bound.h;332 var minX = Math.min(bound.x, x1);333 var minY = Math.min(bound.y, y1);334 return {335 x : minX,336 y : minY,337 w : Math.abs(bound.w),338 h : Math.abs(bound.h)339 };340 },341342 /** 判断一个区域是否包含一个或者部分包含在另外一个区域中* */343 containInBound : function(sBound, tBound) {344 sBound = this.getRegularBound(sBound);345 return Math.abs((sBound.x + sBound.x + sBound.w)346 - (tBound.x + tBound.x + tBound.w)) < (sBound.x + sBound.w347 + tBound.x + tBound.w - sBound.x - tBound.x)348 && Math.abs((sBound.y + sBound.y + sBound.h)349 - (tBound.y + tBound.y + tBound.h)) < (sBound.y350 + sBound.h + tBound.y + tBound.h - sBound.y - tBound.y);351 },352 calcuInsertPos:function(clientX,clientY){ 353 this.ownerDesigner.hideCursor();354 var $domNode = $(this.domNode);355 var offset = $domNode.offset();356 return {position:"absolute",left:clientX - offset.left + this.domNode.scrollLeft,top:clientY - offset.top + this.domNode.scrollTop,parent:this.domNode,pos:1};357 },358 359 paintContent : function(){360 361 },362 363 getSelections : function(){364 var newSelections = [];365 var selections = this.ownerDesigner.getSelections();366 for(var i =0 ,l = selections.length;i<l;i+=1){367 if((!selections[i].getAttribute("d_id") && selections[i].parentNode != this.domNode) || selections[i] == this.domNode){368 continue;369 }370 newSelections.push(selections[i]);371 }372 return newSelections;373 },374375 /** 自动对齐* */376 autoAlign : function(currentBound/* 当前区域 */, otherBounds/* 数组,其他的区域 */, viewElement/* 视图元素 */,scrollTop,scrollLeft) {377 if (!otherBounds || otherBounds.length === 0) {378 return currentBound;379 }380 381 var div;382 if (!viewElement)383 viewElement = document.body;384 if (!viewElement.valignLine) {385 div = document.createElement("div");386 div.style.cssText = "left:0px;display:none;overflow:hidden;border-top:1px dotted green;position:absolute;width:100%;height:1px;";387 viewElement.appendChild(div);388 viewElement.valignLine = div;389 }390391 if (!viewElement.halignLine) {392 div = document.createElement("div");393 div.style.cssText = "top:0px;display:none;overflow:hidden;border-left:1px dotted green;position:absolute;width:1px;height:100%;";394 viewElement.appendChild(div);395 viewElement.halignLine = div;396 }397398 var minVOffset = {399 offset : 6,400 bound : null,401 align : null402 };403 var minHOffset = {404 offset : 6,405 bound : null,406 align : null407 };408 for ( var i = 0; i < otherBounds.length; i++) {409 var b2 = otherBounds[i];410 var top_top = Math.abs(currentBound.y - b2.y);411 if (top_top < minVOffset.offset) {412 minVOffset.offset = top_top;413 minVOffset.bound = b2;414 minVOffset.align = "top";415 }416 if (Math.abs(b2.h - currentBound.h) > 2) {// 高度不相同才比较417 var vcenter_vcenter = Math.abs(currentBound.y + currentBound.h / 2 - b2.y - b2.h / 2);418 if (vcenter_vcenter < minVOffset.offset) {419 minVOffset.offset = vcenter_vcenter;420 minVOffset.bound = b2;421 minVOffset.align = "vcenter";422 }423 var bottom_bottom = Math.abs(currentBound.y + currentBound.h - b2.y - b2.h);424 if (bottom_bottom < minVOffset.offset) {425 minVOffset.offset = bottom_bottom;426 minVOffset.bound = b2;427 minVOffset.align = "bottom";428 }429 }430431 var left_left = Math.abs(currentBound.x - b2.x);432 if (left_left < minHOffset.offset) {433 minHOffset.offset = left_left;434 minHOffset.bound = b2;435 minHOffset.align = "left";436 }437 if (Math.abs(b2.w - currentBound.w) > 2) {// 宽度不相同才比较438 var hcenter_hcenter = Math.abs(currentBound.x + currentBound.w / 2 - b2.x - b2.w / 2);439 if (hcenter_hcenter < minHOffset.offset) {440 minHOffset.offset = hcenter_hcenter;441 minHOffset.bound = b2;442 minHOffset.align = "hcenter";443 }444 var right_right = Math.abs(currentBound.x + currentBound.w - b2.x - b2.w);445 if (right_right < minHOffset.offset) {446 minHOffset.offset = right_right;447 minHOffset.bound = b2;448 minHOffset.align = "right";449 }450 }451452 }453454 // TODO 有偏移量处理455 if (minVOffset.bound) {456 var top;457 if (minVOffset.align == "top") {458 currentBound.y = minVOffset.bound.y;459 top = minVOffset.bound.y;460 } else if (minVOffset.align == "vcenter") {461 currentBound.y = minVOffset.bound.y + minVOffset.bound.h / 2 - currentBound.h / 2;462 top = (minVOffset.bound.y + minVOffset.bound.h / 2);463 } else {// bottom464 currentBound.y = minVOffset.bound.y + minVOffset.bound.h - currentBound.h;465 top = (minVOffset.bound.y + minVOffset.bound.h);466 }467 viewElement.valignLine.style.top = (top-1 + viewElement.scrollTop) + "px";468 viewElement.valignLine.style.left = viewElement.scrollLeft + "px";469 viewElement.valignLine.style.display = "block";470 } else {471 viewElement.valignLine.style.display = "none";472 }473474 if (minHOffset.bound) {475 var left ;476 if (minHOffset.align == "left") {477 currentBound.x = minHOffset.bound.x;478 left = (minHOffset.bound.x);479 } else if (minHOffset.align == "hcenter") {480 currentBound.x = minHOffset.bound.x + minHOffset.bound.w / 2 - currentBound.w / 2;481 left = (minHOffset.bound.x + minHOffset.bound.w / 2);482 } else {// right483 currentBound.x = minHOffset.bound.x + minHOffset.bound.w - currentBound.w;484 left = (minHOffset.bound.x + minHOffset.bound.w);485 }486 viewElement.halignLine.style.left = (left-2 + viewElement.scrollLeft) + "px";487 viewElement.halignLine.style.top = viewElement.scrollTop + "px";488 viewElement.halignLine.style.display = "block";489 } else {490 viewElement.halignLine.style.display = "none";491 }492493 return currentBound;494 },495496 /** 清除自动对齐线条* */497 clearAlighLine : function(viewElement) {498 if (!viewElement)499 viewElement = document.body;500 if (viewElement.valignLine)501 viewElement.valignLine.parentNode.removeChild(viewElement.valignLine);//.style.display="none";502 if (viewElement.halignLine)503 viewElement.halignLine.parentNode.removeChild(viewElement.halignLine);//.style.display="none";504 viewElement.halignLine = null;505 viewElement.valignLine = null;506 },507 /**顶部或者左边对齐**/508 topOrLeftAlign : function(direction/*方向 left or top*/){509 var selections = this.getSelections();510 if(selections.length === 0){511 return;512 }513 var minValue = 10000;514 var i,l = selections.length;515 for(i =0;i<l;i+=1){516 var tempLeft = parseInt($(selections[i]).css(direction),10);517 if(tempLeft<minValue){518 minValue = tempLeft;519 }520 }521 var ids = [],css = [];522 for(i =0,l = selections.length;i<l;i+=1){523 ids.push(selections[i].getAttribute("d_id")); 524 var cfg = {};525 cfg[direction] = minValue+"px";526 css.push(cfg);527 }528 xuiDoc.batchSetCSS(ids,css);529 },530 531 bottomOrRightAlign : function(direction,item1,item2){532 var selections = this.getSelections();533 if(selections.length === 0){534 return;535 }536 var maxValue = 0;537 var i,l = selections.length;538 for(i =0;i<l;i+=1){539 var bound = $(selections[i]).getBound();540 var tempValue = bound[item1] + bound[item2];541 if(tempValue > maxValue){542 maxValue = tempValue;543 }544 }545 546 var ids = [],css = [];547 for(i =0,l = selections.length;i<l;i+=1){548 var currentValue = maxValue - $(selections[i]).getBound()[item2] -1;549 ids.push(selections[i].getAttribute("d_id")); 550 var cfg = {};551 cfg[direction] = currentValue+"px";552 css.push(cfg);553 }554 xuiDoc.batchSetCSS(ids,css);555 },556 557 onBuildMenu : function(config){558 var list = this.ownerDesigner.getSelections();559 if(list.length == 1 && list[0] == this.domNode){560 config.menuItems = []; 561 }562 },563 564 centerAlign : function(direction,item1,item2){565 var selections = this.getSelections();566 if(selections.length === 0){567 return;568 }569 var ids = [],css = [];570 var baseBound = $(selections[0]).getBound();571 var baseValue = baseBound[item1] + baseBound[item2]/2;572 for(var i =1,l = selections.length;i<l;i+=1){573 var newValue = baseValue - $(selections[i]).getBound()[item2]/2;574 ids.push(selections[i].getAttribute("d_id")); 575 var cfg = {};576 cfg[direction] = newValue+"px";577 css.push(cfg);578 }579 xuiDoc.batchSetCSS(ids,css);580 },581 582 spaceEqually : function(direction,item1,item2){583 var selections = this.getSelections();584 selections.sort(function(a,b){585 return parseInt($(a).css(direction),10) > parseInt($(b).css(direction),10)?1:-1;586 });587 var l = selections.length;588 var bound0 = $(selections[0]).getBound();589 var boundLast = $(selections[l-1]).getBound();590 591 var min_x = bound0[item1] + bound0[item2];592 var max_x = boundLast[item1];593 var dis = max_x - min_x;594 595 var i ;596 for(i = 1;i<l-1;i++){ 597 dis -= $(selections[i]).getBound()[item2];598 }599 var avg = (dis)/(l-1);600 if(avg<=0){ 601 avg = 20;602 }603 var ids = [],css = [];604 var newValue = min_x + (direction == 'left'?avg:0);//TODO: 垂直方向为何取0?605 for(i = 1;i<l;i++){606 var cfg = {};607 cfg[direction] = newValue+"px";608 ids.push(selections[i].getAttribute("d_id")); 609 css.push(cfg);610 newValue += $(selections[i]).getBound()[item2] + avg;611 }612 xuiDoc.batchSetCSS(ids,css);613 },614 615 replicateSize : function(sizeType,item){616 var selections = this.getSelections();617 if(selections.length < 2){618 return;619 }620 var ids = [],css = [];621 var newValue = $(selections[0]).getBound()[item];622 for(var i =1,l = selections.length;i<l;i+=1){623 ids.push(selections[i].getAttribute("d_id")); 624 var cfg = {};625 cfg[sizeType] = newValue+"px";626 css.push(cfg);627 }628 xuiDoc.batchSetCSS(ids,css);629 },630 631 /**632 * 左对齐.633 */634 leftAlign : function(){635 this.topOrLeftAlign("left");636 },637 638 /** 顶部对齐 **/639 topAlign : function(){640 this.topOrLeftAlign("top");641 },642 643 /** 右对齐 **/644 rightAlign : function(){645 this.bottomOrRightAlign("left", "x", "w");646 }, 647 648 /** 底部对齐 **/649 bottomAlign : function(){650 this.bottomOrRightAlign("top", "y", "h");651 },652 653 /**水平中心对齐**/654 horizontalCenterAlign : function(){655 this.centerAlign("top", "y", "h");656 },657 658 /**垂直中心对齐**/659 verticalCenterAlign : function(){660 this.centerAlign("left", "x", "w");661 },662 663 /**水平等间距**/664 horizontalSpaceEqually : function(){665 this.spaceEqually("left", "x", "w");666 },667 668 /**垂直等间距**/669 verticalSpaceEqually : function(){670 this.spaceEqually("top", "y", "h");671 },672 673 /**复制宽度**/674 replicateWidth : function(){675 this.replicateSize("width", "w");676 },677 678 /**复制高度**/679 replicateHeight : function(){680 this.replicateSize("height", "h");681 },682 683 /** 水平居中*/684 horizontalCenter : function(){685 var selections = this.getSelections();686 if(selections.length < 2){687 return;688 }689 var ids = [],css = [];690 var pWidth = $(this.domNode).getBound()["w"];691 for(var i =0,l = selections.length;i<l;i+=1){692 var newValue = (pWidth-$(selections).getBound().w)/2;693 ids.push(selections[i].getAttribute("d_id")); 694 var cfg = {};695 cfg["left"] = newValue+"px";696 $(selections[i]).css(cfg);697 this.ownerDesigner.reSelect(selections[i],true);698 css.push(cfg);699 }700 xuiDoc.batchSetCSS(ids,css);701 },702 703 /**垂直居中**/704 verticalCenter : function(){705 var selections = this.getSelections();706 if(selections.length < 2){707 return;708 }709 var ids = [],css = [];710 var pHeight = $(this.domNode).getBound()["h"];711 for(var i =0,l = selections.length;i<l;i+=1){712 var newValue = (pHeight-$(selections).getBound().h)/2;713 ids.push(selections[i].getAttribute("d_id")); 714 var cfg = {};715 cfg["top"] = newValue+"px";716 $(selections[i]).css(cfg);717 this.ownerDesigner.reSelect(selections[i],true);718 css.push(cfg);719 }720 xuiDoc.batchSetCSS(ids,css);721 }722 };723724 return {725 '$UI/system/components/justep/absoluteLayout/absoluteLayout' : absoluteLayout726 }; ...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...21 t.deepEqual(func(1, 2), [undefined, 1, 2], 'unbound func with right args');22 t.deepEqual(func(1, 2, 3), [undefined, 1, 2], 'unbound func with too many args');23 var bound = callBind(func);24 t.equal(bound.length, func.length + 1, 'function length is preserved', { skip: !functionsHaveConfigurableLengths });25 t.deepEqual(bound(), [undefined, undefined, undefined], 'bound func with too few args');26 t.deepEqual(bound(1, 2), [1, 2, undefined], 'bound func with right args');27 t.deepEqual(bound(1, 2, 3), [1, 2, 3], 'bound func with too many args');28 var boundR = callBind(func, sentinel);29 t.equal(boundR.length, func.length, 'function length is preserved', { skip: !functionsHaveConfigurableLengths });30 t.deepEqual(boundR(), [sentinel, undefined, undefined], 'bound func with receiver, with too few args');31 t.deepEqual(boundR(1, 2), [sentinel, 1, 2], 'bound func with receiver, with right args');32 t.deepEqual(boundR(1, 2, 3), [sentinel, 1, 2], 'bound func with receiver, with too many args');33 var boundArg = callBind(func, sentinel, 1);34 t.equal(boundArg.length, func.length - 1, 'function length is preserved', { skip: !functionsHaveConfigurableLengths });35 t.deepEqual(boundArg(), [sentinel, 1, undefined], 'bound func with receiver and arg, with too few args');36 t.deepEqual(boundArg(2), [sentinel, 1, 2], 'bound func with receiver and arg, with right arg');37 t.deepEqual(boundArg(2, 3), [sentinel, 1, 2], 'bound func with receiver and arg, with too many args');38 t.test('callBind.apply', function (st) {39 var aBound = callBind.apply(func);40 st.deepEqual(aBound(sentinel), [sentinel, undefined, undefined], 'apply-bound func with no args');41 st.deepEqual(aBound(sentinel, [1], 4), [sentinel, 1, undefined], 'apply-bound func with too few args');...

Full Screen

Full Screen

idb-keyrange.js

Source:idb-keyrange.js Github

copy

Full Screen

1description("Test IndexedDB's KeyRange.");2if (window.layoutTestController)3 layoutTestController.waitUntilDone();4function checkSingleKeyRange(value)5{6 keyRange = evalAndLog("indexedDB.makeSingleKeyRange(" + value + ")");7 shouldBe("keyRange.left", "" + value);8 shouldBe("keyRange.right", "" + value);9 shouldBe("keyRange.flags", "keyRange.SINGLE");10}11function checkLeftBoundKeyRange(value, open)12{13 keyRange = evalAndLog("indexedDB.makeLeftBoundKeyRange(" + value + "," + open + ")");14 shouldBe("keyRange.left", "" + value);15 shouldBeNull("keyRange.right");16 shouldBe("keyRange.flags", open ? "keyRange.LEFT_OPEN" : "keyRange.LEFT_BOUND");17}18function checkRightBoundKeyRange(value, open)19{20 keyRange = evalAndLog("indexedDB.makeRightBoundKeyRange(" + value + "," + open + ")");21 shouldBe("keyRange.right", "" + value);22 shouldBeNull("keyRange.left");23 shouldBe("keyRange.flags", open ? "keyRange.RIGHT_OPEN" : "keyRange.RIGHT_BOUND");24}25function checkBoundKeyRange(left, right, openLeft, openRight)26{27 keyRange = evalAndLog("indexedDB.makeBoundKeyRange(" + left + "," + right + "," + openLeft + "," + openRight + ")");28 shouldBe("keyRange.left", "" + left);29 shouldBe("keyRange.right", "" + right);30 leftFlags = keyRange.flags & (keyRange.LEFT_OPEN | keyRange.LEFT_BOUND);31 shouldBe("leftFlags", openLeft ? "keyRange.LEFT_OPEN" : "keyRange.LEFT_BOUND");32 rightFlags = keyRange.flags & (keyRange.RIGHT_OPEN | keyRange.RIGHT_BOUND);33 shouldBe("rightFlags", openRight ? "keyRange.RIGHT_OPEN" : "keyRange.RIGHT_BOUND");34}35function test()36{37 checkSingleKeyRange(1);38 checkSingleKeyRange("'a'");39 checkLeftBoundKeyRange(10, true);40 checkLeftBoundKeyRange(11, false);41 checkLeftBoundKeyRange(12);42 checkLeftBoundKeyRange("'aa'", true);43 checkLeftBoundKeyRange("'ab'", false);44 checkLeftBoundKeyRange("'ac'");45 checkRightBoundKeyRange(20, true);46 checkRightBoundKeyRange(21, false);47 checkRightBoundKeyRange(22);48 checkRightBoundKeyRange("'ba'", true);49 checkRightBoundKeyRange("'bb'", false);50 checkRightBoundKeyRange("'bc'");51 checkBoundKeyRange(30, 40);52 checkBoundKeyRange(31, 41, false, false);53 checkBoundKeyRange(32, 42, false, true);54 checkBoundKeyRange(33, 43, true, false);55 checkBoundKeyRange(34, 44, true, true);56 checkBoundKeyRange("'aaa'", "'aba'", false, false);57 checkBoundKeyRange("'aab'", "'abb'");58 checkBoundKeyRange("'aac'", "'abc'", false, false);59 checkBoundKeyRange("'aad'", "'abd'", false, true);60 checkBoundKeyRange("'aae'", "'abe'", true, false);61 checkBoundKeyRange("'aaf'", "'abf'", true, true);62 done();63}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const story = storybookRoot.story('My story', 'My description');2story.add('My story', () => {3 return (4});5import storybookRoot from 'storybook-root';6storybookRoot.configure(() => {7 require('./test.js');8}, module);

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 storybook-root 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