#StackBounty: #javascript #jquery Regex comma seperating thousands and keeping two decimals

Bounty: 50

I recently came up with this code while answering another StackOverflow question. Basically, on blur, this code will properly comma separate by thousands and leave the decimal at two digits (like how USD is written [7,745.56]).

I was wondering, is there a way to update the regex to accommodate for decimals as well as thousands, without doing the messy .toFixed(2). Especially, because I don’t need to display the decimals if no decimals are specified. Additionally, I would like to knock off any decimals passed 2 (even if that means ’rounding down’).

Input -> Target Output

7456 -> 7,456
45345 -> 45,345
25.23523534 -> 25.23
3333.239 -> 3,333.23
234.99 -> 234.99
2300.99 -> 2,300.99
23123123123.22 -> 23,123,123,123.22

Current Regex

var format = function (num) {
    return parseFloat(num).toFixed(2).replace(/B(?=(d{3})+(?!d))/g, ",")
}
$(function () {
    $("#principalAmtOut").blur(function (e) {
        $(this).val(format($(this).val()));
    });
});
https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
<input id="principalAmtOut" type="text" />


Get this bounty!!!

#StackBounty: #magento2 #javascript #performance #knockoutjs Magento 2: javascript elements load slowly

Bounty: 150

Checkout forms, gallery on product pages, and more elements loaded by javascript take up to 4 seconds to load.

What can be done to make javascript elements load faster?

Update:

I’m using a custom theme which inherits from Blank theme. I’ve not added additional JS files, only made minor changes to them for translation purposes.
All caches are enabled.
It is a live site in production mode.

Pages loading times:

Category and product pages: 5 to 6 seconds.
Cart and checkout: 9 to 10 seconds. (is it normal?)

On product pages, product images are the last to load. This can be annoying for the user. Is it possible to make them load faster / before other elements on the page?

product page
category page


Get this bounty!!!

#StackBounty: #magento2 #javascript #uicomponent #knockoutjs #requirejs Magento 2 : How to Detect Checkout Step Change

Bounty: 50

I am trying to figure out the best method of detecting a step change in Magento 2’s checkout. For example going from shipping details to payment, or vice versa.

I have done some digging and in vendor/magento/module-checkout/view/frontend/web/js/model/step-navigator.js I can use next() which fires on the continue button, and navigateTo() which fires when a user clicks on the checkoutstep directly – but both methods seem rather hacky, there must be a cleaner way to detect a step change regardless of how and which step.

I was hoping for a stepChange() function or something similar that fires whenever a checkout step change happens.

My question:

What is the best method to trigger my custom JS when a checkout step change occurs?


Get this bounty!!!

#StackBounty: #javascript #jquery #html #css #twitter-bootstrap-3 JQUERY.COUNTO.JS: On Scroll Count Numbers NOT OnLoad

Bounty: 50

I’m working with one page website and I want to add a counting numbers with it, so I use javascript.countTo.js. I created every section to group related data and I put the section counter <section id="counters"> below my portfolio section <section class="justaddheight portfolio">. Everytime the page load the number count and when I scroll I always see that numbers stop or ended it’s counting. Now, I want the number counts when I scroll and get into the section counter <section id="counters">. In addition, I used WOW.js and easingJS with my site, it’s the best if you combined the code with it, but it also acceptable if not. The code are the following below:

index.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title></title>
        <meta http-equiv="X-UA-Compatible" content="IE=Edge">
        <meta name="viewport" content="width=device-width, initial-scale=1"><!--The Viewport-->
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <!--Character Set-->
        <meta http-equiv="Cache-control" content="no-cache"> <!--The No-Cache-->

        <!--///////////////////////////////////////////////////////
                            CSS 
        ///////////////////////////////////////////////////////-->
        <link rel="stylesheet" href="css/animate.min.css">
        <!-- Bootstrap -->
        <link rel="stylesheet" href="css/bootstrap.min.css">
        <!-- Font-Awesome -->
        <link rel="stylesheet" href="css/font-awesome.min.css">
        <!-- Icomoon-->
        <link rel="stylesheet" href="css/icomoon.css">
        <!-- Simple Line Icons -->
        <link rel="stylesheet" href="css/simple-line-icons.css">     
        <!-- Fonts -->
        <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700' rel='stylesheet' type='text/css'>


        <!--///////////////////////////////////////////////////////
                            JAVASCRIPT 
        ///////////////////////////////////////////////////////-->

        <!-- jQuery -->
        http://js/jquery.js
        <!-- Bootstrap -->
        http://js/bootstrap.min.js
        <!-- Wow -->
        http://js/wow.min.js
        <!-- Counter -->
        http://js/jquery.countTo.js
        <!--Easing-->
        http://js/jquery.easing.1.3.js        
        <!--Custom JS-->
        http://js/custom.js
    </head>
    <body id="top">
        <section class="justaddheight text-center about" >
            <h1>SCROLL DOWN</h1>
            <p>First, Scroll Now</p>
            <p>Second, try Again but wait for few seconds before scroll to identify.</p>
        </section>
         <section class="justaddheight service">

        </section>
         <section class="justaddheight portfolio">

        </section>
        <section id="counters">
            
89 Finished projects
</div>
2343409 Templates
</div>
1302 Cup of coffees
</div>
52 Happy clients
</div> </div> </div> </section> </body> </html> <style type="text/css"> /* USE JUST TO ADJUST HEIGHT*/ .justaddheight{ height: 500px; } .text-center{ text-align: center; } </style> $('.counter-number').countTo();


Get this bounty!!!

#StackBounty: #javascript #performance #animation #canvas #raycasting Hoc462 – A Raycaster

Bounty: 50

For the past week, I’ve been making a raycaster in JS and if you want a live demo, you can try it here. It ran smoothly before I added variable height walls but now it is very slow (~15 FPS) so I want to know how to make it run faster.

I’d also like it if somebody would review the code normally so that I can improve it further.

var ctx = c.getContext("2d");
var mapCtx = minimap.getContext("2d");
var MINI_MAP_SCALE = 8;
var OUTSIDE_THE_MAP = -1;
var NO_HIT = 0;
var IS_HIT = 1;
var X_HIT = 0;
var Y_HIT = 1;
var UP = 1;
var DOWN = -1;
var LEFT = -1;
var RIGHT = 1;
var TEXTURED_WALL = 10;
var COLORED_WALL = 11;
var SPRITE = 12;
var SORT_BY_DISTANCE = (a, b) => {return b.distance - a.distance};
function drawMiniMap() {
    if (minimap.width !== player.map.width * MINI_MAP_SCALE || minimap.height !== player.map.height * MINI_MAP_SCALE) {
        minimap.width = player.map.width * MINI_MAP_SCALE;
        minimap.height = player.map.height * MINI_MAP_SCALE;
    }
    mapCtx.fillStyle = "white";
    mapCtx.fillRect(0, 0, minimap.width, minimap.height);
    for (var y = 0; y < player.map.height; y++)
        for (var x = 0; x < player.map.width; x++)
            if (player.map.get(x, y) > 0) {
                mapCtx.fillStyle = "rgb(200, 200, 200)";
                mapCtx.fillRect(
                    x * MINI_MAP_SCALE,
                    y * MINI_MAP_SCALE,
                    MINI_MAP_SCALE, MINI_MAP_SCALE
                );
            }
    updateMiniMap();
}
function updateMiniMap() {
    player.map.sprites.forEach(sprite => {
        mapCtx.fillStyle = "rgb(0, 200, 200)";
        mapCtx.fillRect(
            sprite.x * MINI_MAP_SCALE,
            sprite.z * MINI_MAP_SCALE,
            MINI_MAP_SCALE, MINI_MAP_SCALE
        );
        mapCtx.fillStyle = "black";
        mapCtx.fillRect(
            player.x * MINI_MAP_SCALE - 2,
            player.y * MINI_MAP_SCALE - 2,
            4, 4
        );
    });
    mapCtx.beginPath();
    mapCtx.moveTo(player.x * MINI_MAP_SCALE, player.y * MINI_MAP_SCALE);
    mapCtx.lineTo(
        (player.x + Math.cos(player.rot) * 4) * MINI_MAP_SCALE,
        (player.y + Math.sin(player.rot) * 4) * MINI_MAP_SCALE
    );
    mapCtx.stroke();
}
class Player {
    constructor() {
        this.x = 0;
        this.y = 0;
        this.dirX = 1
        this.dirY = 0; 
        this.planeX = 0;
        this.planeY = 0.66;
        this.dir = 0;
        this.rot = 0;
        this.speed = 0;
        this.moveSpeed = 0.4;
        this.rotSpeed = 6 * Math.PI / 180;
        this.map = null;
        return this;
    }
    move() {
        var moveStep = this.speed * this.moveSpeed;
        this.rot += this.dir * this.rotSpeed;
        var newX = this.x + Math.cos(player.rot) * moveStep;
        var newY = this.y + Math.sin(player.rot) * moveStep;
        var currentMapBlock = this.map.get(newX|0, newY|0);
        if (currentMapBlock === OUTSIDE_THE_MAP || currentMapBlock > 0) {
            this.stopMoving();
            return;
        };
        this.x = newX;
        this.y = newY;
        this.rotateDirectionAndPlane(this.dir * this.rotSpeed);
        return this;
    }
    rotateDirectionAndPlane(angle) {
        var oldDirX = this.dirX;
        this.dirX = this.dirX * Math.cos(angle) - this.dirY * Math.sin(angle);
        this.dirY = oldDirX * Math.sin(angle) + this.dirY * Math.cos(angle);
        var oldPlaneX = this.planeX;
        this.planeX = this.planeX * Math.cos(angle) - this.planeY * Math.sin(angle);
        this.planeY = oldPlaneX * Math.sin(angle) + this.planeY * Math.cos(angle);
        this.stopMoving();
    }
    setXY(x, y) {
        this.x = x;
        this.y = y;
        return this;
    }
    setRot(angle) {
        var difference = angle - this.rot;
        this.rot = angle;
        this.rotateDirectionAndPlane(difference);
        return this;
    }
    startMoving(direction) {
        switch (direction) {
            case "up":
                this.speed = UP; break;
            case "down":
                this.speed = DOWN; break;
            case "left":
                this.dir = LEFT; break;
            case "right":
                this.dir = RIGHT; break;
        }
        return this;
    }
    stopMoving() {
        this.speed = 0;
        this.dir = 0;
        return this;
    }
    castRays() {
        this.move();
        var visibleSprites = [];
        var zBuffer = [];
        Object.keys(this.map.wallTypes).forEach(typeID => {
            this.castRaysToSpecifiedWallType(this.map.wallTypes[typeID], zBuffer);
        });
        this.map.sprites.forEach(sprite => {
            var spriteX = sprite.x - this.x;
            var spriteY = sprite.z - this.y;
            var invDet = 1 / (this.planeX * this.dirY - this.dirX * this.planeY);
            var transformX = invDet * (this.dirY * spriteX - this.dirX * spriteY);
            var transformY = invDet * (-this.planeY * spriteX + this.planeX * spriteY);
            if (transformY > 0) {
                var spriteScreenX = (c.width / 2) * (1 + transformX / transformY);
                var spriteHeight = Math.abs(c.height / transformY);
                var imaginedHeight = sprite.y * spriteHeight;
                var drawStartY = -imaginedHeight / 2 + c.height / 2 - imaginedHeight;
                var drawEndY = imaginedHeight / 2 + c.height / 2 - imaginedHeight;
                var spriteWidth = Math.abs(c.height / transformY);
                var drawStartX = -spriteWidth / 2 + spriteScreenX;
                var drawEndX = spriteWidth / 2 + spriteScreenX;
                var spriteImage = sprite.texture;
                var texHeight = spriteImage.image.height;
                var texWidth = spriteImage.image.width;
                zBuffer.push({
                    type: SPRITE,
                    drawX: drawStartX,
                    drawY: drawStartY,
                    texture: spriteImage,
                    width: spriteWidth,
                    height: spriteHeight,
                    distance: transformY
                });
            }
        });
        return zBuffer.sort(SORT_BY_DISTANCE);
    }
    castRaysToSpecifiedWallType(wallType, zBuffer) {
        for (var x = 0; x < c.width; x++) {
            var cameraX = 2 * x / c.width - 1;
            var rayPosX = this.x;
            var rayPosY = this.y;
            var rayDirX = this.dirX + this.planeX * cameraX;
            var rayDirY = this.dirY + this.planeY * cameraX;
            var mapX = rayPosX | 0;
            var mapY = rayPosY | 0;
            var deltaDistX = Math.sqrt(1 + (rayDirY * rayDirY) / (rayDirX * rayDirX));
            var deltaDistY = Math.sqrt(1 + (rayDirX * rayDirX) / (rayDirY * rayDirY));
            var stepX = 0;
            var stepY = 0;
            var sideDistX = 0;
            var sideDistY = 0;
            var wallDistance = 0;
            var giveUp = false;
            if (rayDirX < 0) {
                stepX = -1;
                sideDistX = (rayPosX - mapX) * deltaDistX;
            } else {
                stepX = 1;
                sideDistX = (mapX + 1 - rayPosX) * deltaDistX;
            }
            if (rayDirY < 0) {
                stepY = -1;
                sideDistY = (rayPosY - mapY) * deltaDistY;
            } else {
                stepY = 1;
                sideDistY = (mapY + 1 - rayPosY) * deltaDistY;
            }
            var hit = NO_HIT;
            var side = X_HIT;
            while (hit === NO_HIT) {
                if (sideDistX < sideDistY) {
                    sideDistX += deltaDistX;
                    mapX += stepX;
                    side = X_HIT;
                } else {
                    sideDistY += deltaDistY;
                    mapY += stepY;
                    side = Y_HIT;   
                }
                var currentMapBlock = this.map.get(mapX, mapY);
                if (currentMapBlock === OUTSIDE_THE_MAP || this.map.wallTypes[currentMapBlock] === wallType) {
                    hit = IS_HIT;
                    if (currentMapBlock === OUTSIDE_THE_MAP) {
                        giveUp = true;
                    }
                }
            }
            if (giveUp) {continue;}
            if (side === X_HIT) {
                wallDistance = (mapX - rayPosX + (1 - stepX) / 2) / rayDirX;
            } else {
                wallDistance = (mapY - rayPosY + (1 - stepY) / 2) / rayDirY;
            }
            var color = wallType.color;
            var wallHeight = wallType.height;
            var lineHeight = c.height / wallDistance;
            var drawEnd = lineHeight / 2 + c.height / 2;
            lineHeight *= wallHeight < 0 ? 0 : wallHeight;
            var drawStart = drawEnd - lineHeight;
            var exactHitPositionX = rayPosY + wallDistance * rayDirY;
            var exactHitPositionY = rayPosX + wallDistance * rayDirX;
            if (side === X_HIT) {
                var wallX = exactHitPositionX;
            } else {
                var wallX = exactHitPositionY;
            }
            var currentBuffer = {};
            zBuffer.push(currentBuffer);
            currentBuffer.side = side;
            currentBuffer.start = drawStart;
            currentBuffer.end = drawEnd;
            currentBuffer.x = x; 
            currentBuffer.distance = wallDistance;
            if (color instanceof Texture) {
                currentBuffer.type = TEXTURED_WALL;
                var texture = color;
                currentBuffer.texture = texture;
                wallX -= wallX | 0;
                var textureX = wallX * texture.image.width;
                if ((side === X_HIT && rayDirX > 0) || (side === Y_HIT && rayDirY < 0)) {
                    textureX = texture.image.width - textureX - 1;
                }
                currentBuffer.textureX = textureX;
            } else {
                currentBuffer.type = COLORED_WALL;
                currentBuffer.color = color;
            }
        }

    }
    render(zBuffer) {
        zBuffer.forEach(currentBuffer => {
            var side = currentBuffer.side;
            var drawStart = currentBuffer.start;
            var drawEnd = currentBuffer.end;
            var {
                side,
                texture,
                textureX,
                color,
                x,
                drawX,
                drawY,
                width,
                height,
                start: drawStart,
                end: drawEnd
            } = currentBuffer;
            var lineHeight = drawEnd - drawStart;
            if (currentBuffer.type === TEXTURED_WALL) {
                ctx.globalAlpha = 1;
                ctx.fillStyle = "black";
                ctx.fillRect(x, drawStart, 1, lineHeight);
                if (side === Y_HIT) {
                    ctx.globalAlpha = .7;
                } else {
                    ctx.globalAlpha = 1;
                }
                ctx.drawImage(texture.image, textureX, 0, 1, texture.image.height, x, drawStart, 1, lineHeight);
            } else if (currentBuffer.type === COLORED_WALL) {
                ctx.globalAlpha = 1;
                ctx.fillStyle = "black";
                ctx.fillRect(x, drawStart, 1, lineHeight);
                if (side === Y_HIT) {
                    ctx.globalAlpha = .7;
                } else {
                    ctx.globalAlpha = 1;
                }
                ctx.fillStyle = "rgb("+color[0]+", "+color[1]+", "+color[2]+")";
                ctx.fillRect(x, drawStart, 1, lineHeight);
            } else if (currentBuffer.type === SPRITE) {
                ctx.globalAlpha = 1;
                ctx.drawImage(texture.image, 0, 0, texture.image.width, texture.image.height, drawX, drawY, width, height);
            }
        });

    }
}
class Grid {
    constructor(wallGrid, wallTextures, sprites) {
        this.wallGrid = wallGrid;
        this.height = wallGrid.length;
        this.width = this.height === 0 ? 0 : wallGrid[0].length;
        this.wallTypes = wallTextures || {};
        this.sprites = sprites || [];
        return this;
    }
    get(x, y) {
        x = x | 0;
        y = y | 0;
        var currentMapBlock = this.wallGrid[y];
        if (currentMapBlock === undefined) return OUTSIDE_THE_MAP;
        currentMapBlock = currentMapBlock[x];
        if (currentMapBlock === undefined) return OUTSIDE_THE_MAP;
        return currentMapBlock;
    }

}
class Texture {
    constructor(src, width, height) {
        this.image = new Image();
        this.image.src = src;
        width ? this.image.width = width : 0;
        height ? this.image.height = height : 0;
    }
}
class Sprite {
    constructor(texture, x, y, z){
        this.texture = texture;
        this.x = x;
        this.y = y;
        this.z = z;
    }
}

class Wall {
    constructor(height, color) {
        this.height = height;
        this.color = color;
    }
}
var player = new Player();
player.x = player.y = 3;
player.map = new Grid([
    [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1],
    [1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1],
    [1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,0,0,0,0,1,1,2,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,0,0,0,0,0,0,0,1],
    [1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
], {'1': new Wall(2, new Texture('walls.png')), '2': new Wall(4, [255, 0, 0]) }, [new Sprite(new Texture('walls.png'), 4, 1, 4)]);
var keyCodes = {
    "38": "up",
    "40": "down",
    "37": "left",
    "39": "right"
}
document.addEventListener("keydown", function(e) {
    player.startMoving(keyCodes[e.keyCode]);
});
document.addEventListener("keyup", function(e) {
    player.stopMoving(keyCodes[e.keyCode]);
});
var isDragging = false;
c.addEventListener("mousedown", startDragging);
window.addEventListener("mouseup", endDragging);
c.addEventListener("touchstart", startDragging);
c.addEventListener("touchend", endDragging);
c.addEventListener("mousemove", whileDragging);
c.addEventListener("touchmove", whileDragging);
var mouseX = 0;
var pmouseX = 0;
var mouseY = 0;
var pmouseY = 0;
function whileDragging(e) {
    var event;
    e.preventDefault();
    if (e.touches) {
        event = e.touches[0];
    } else {
        event = e;
    }
    pmouseX = mouseX;
    pmouseY = mouseY;
    mouseX = event.pageX - c.offsetLeft;
    mouseY = event.pageY - c.offsetTop;
    if (isDragging) {
        player.setRot(player.rot + (mouseX - pmouseX) / c.width * 2);
        player.speed = -(mouseY - pmouseY) / c.height * 15;
    }
}
function startDragging(e) {
    var event;
    e.preventDefault();
    if (e.touches) {
        event = e.touches[0];
    } else {
        event = e;
    }
    mouseX = event.pageX - c.offsetLeft;
    mouseY = event.pageY - c.offsetTop;
    isDragging = true;
}
function endDragging(e) {
    e.preventDefault();
    isDragging = false;
}
function renderLoop() {
    ctx.clearRect(0, 0, c.width, c.height);
    player.render(player.castRays());
}
requestAnimationFrame(function animate() {
    if (c.clientWidth !== c.width || c.clientHeight !== c.height) {
        c.width = c.clientWidth;
        c.height = c.clientHeight;
    }
    renderLoop();
    drawMiniMap();
    requestAnimationFrame(animate);
});


Get this bounty!!!

#StackBounty: #javascript #ajax #internet-explorer #amazon-s3 #web-worker CORS XMLHttpRequest fails in IE10-11 web worker

Bounty: 200

I’m trying to make a cross-origin XMLHttpRequest from within a web worker. The setup is as follows:

  • The original request is made to the same domain example.com
  • The server redirects (302) the request to s3.amazon.com
  • S3 is properly set up for CORS, responding with the proper Access-Control-Allow-Origin header

The code is as follows:

var xhr = new XMLHttpRequest();
//this will redirect to 'https://s3.amazon.com/...'
xhr.open('GET', 'https://example.com/document/1234/download');
xhr.send(null);

Chrome, Firefox, Safari, and MS Edge on Win 10

This code properly follows the redirect, both when called from the main JS file and from a web worker.

IE 10/11 on Win 7

This code properly follows the redirect only when called from the main JS file. When called from a web worker, the request is aborted without an error or log message.

It’s possible to make this work by editing the browser security settings and enabling “Access data sources across domains,” but it is not viable to expect users to do so.

Questions

  1. Is there some special setup required to make IE 10/11 follow the redirect?
  2. Is there a way to get better output from IE 10/11 other than an opaque aborted request?


Get this bounty!!!

#StackBounty: #javascript #internet-explorer #frameset IE href="javascript:customFunction()" not firing on first frame load

Bounty: 450

I have a custom date picker popup that isn’t working in IE sometimes. It works in Chrome and Edge fine.

The code looks something like this:

<frameset>
    <frame>Buttons for next/prev month/year</frame>
    <frame>This is the actual calendar that gets redrawn when the above buttons are used
        <a href="javascript:parent.opener.setDate(1);">1</a> //there's a different anchor tag for each day of the month
    </frame>
<frameset>

So here’s where it gets kind of weird. We have two networks, call them old and new. Old has probably a lot of undocumented global policy changes and new is probably close to the gov standard. This works on any browser on the old network, but not IE (11) on the new network. It works in Edge though. Additionally, if the top frame buttons are used to pick the next/prev month, or just the “Today” button, then all of the bottom frame anchor links work normally. There are no console errors/warnings, nothing in the network monitor showing a request returned an error code, the clicks just don’t register. I put a breakpoint inside customFunction() and it won’t break when the links don’t work, but it will break if the link will work.

The only other thing that seems odd to me is that the code for the whole popup looks something like:

str = "<frameset><frame name='topFrame' " + 
    "src='javascript:parent.opener.drawTop'></frame><frame name='bottomFrame' "+
    "src='javascript:parent.opener.drawBottom'><frame</frameset>"

document.write(str);

I did look to check and the code that redraws the bottom frame when the prev/next/etc buttons are used is the same function that gets called during the first load.

However, what seems odd about this is that on the first load the DOM inspector shows everything (top frame, bottom frame including all the individual numbers for each day of the month, etc), but the Debugger (F12 tools) doesn’t show the code loaded with the document.write(str); line. To be able to see that code and set break points I have to use the prev/next buttons and then an additional .html file shows up in Debugger which has the constructed HTML that matches the DOM.


Get this bounty!!!

#StackBounty: #javascript #node.js #amazon-web-services #express #amazon-s3 Allowing users to upload content to s3

Bounty: 150

I have an S3 bucket named BUCKET on region BUCKET_REGION. I’m trying to allow users of my web and mobile apps to upload image files to these bucket, provided that they meet certain restrictions based on Content-Type and Content-Length (namely, I want to only allow jpegs less than 3mbs to be uploaded). Once uploaded, the files should be publicly accessible.

Based on fairly extensive digging through AWS docs, I assume that the process should look something like this on my frontend apps:

const a = await axios.post('my-api.com/get_s3_id');

const b = await axios.put(`https://{BUCKET}.amazonaws.com/{a.id}`, {
   // ??
   headersForAuth: a.headersFromAuth,
   file: myFileFromSomewhere // i.e. HTML5 File() object
});

// now can do things like <img src={`https://{BUCKET}.amazonaws.com/{a.id}`} />
// UNLESS the file is over 3mb or not an image/jpeg, in which case I want it to be throwing errors

where on my backend API I’d be doing something like

import aws from 'aws-sdk';
import uuid from 'uuid';
app.post('/get_s3_id', (req, res, next) => {
  // do some validation of request (i.e. checking user Ids)
  const s3 = new aws.S3({region: BUCKET_REGION});
  const id = uuid.v4();
  // TODO do something with s3 to make it possible for anyone to upload pictures under 3mbs that have the s3 key === id
  res.json({id, additionalAWSHeaders});
});

What I’m not sure about is what exact S3 methods I should be looking at.


Here are some things that don’t work:

  • I’ve seen a lot of mentions of (a very old) API accessible with s3.getSignedUrl('putObject', ...). However, this doesn’t seem to support reliably setting a ContentLength — at least anymore. (See http://stackoverflow.com/a/28699269/251162.)

  • I’ve also seen a closer-to-working example using an HTTP POST with form-data API that is also very old. I guess that this might get it done if there are no alternatives but I am concerned that it is no longer the “right” way to do things — additionally, it seems to doing a lot of manual encrypting etc and not using the official node SDK. (See http://stackoverflow.com/a/28638155/251162.)


Get this bounty!!!

#StackBounty: #magento2 #magento-2.1 #javascript #search Magento 2 – Enabled show/hide functionality on header search

Bounty: 50

I’ve currently got the following phtml file in my theme:

Vender/Theme/Magento_Search/templates/form.mini.phtml

and the following js file inside of my theme as well:

Vender/Theme/Magento_Search/web/form-mini.js

I’ve done some changes to the form-mini.js trying to show and hide the search on a desktop site as well as the mobile side.

mediaCheck({
    //media: '(max-width: 768px)',
     entry: function () {
         this.isExpandable = true;
     }.bind(this),
         exit: function () {
         this.isExpandable = false;
         this.element.removeAttr('aria-expanded');
    }.bind(this)
});

So i commented out the media query to stop the script running on anything less than 768px but, nothing. On clicking the label the aria-expanded still doesn’t toggle.

This is my first time looking at the search functionality, any help would be awesome.

Thanks


Get this bounty!!!

#StackBounty: #javascript #node.js #express #cookies #axios Axios doesn't send cookies in requests to the server

Bounty: 50

I am sending requests from the client to my Express.js server using Axios.

I set a cookie on the client and I want to read that cookie from all Axios requests without adding them manually to request by hand.

This is my clientside request example:

axios.get(`some api url`).then(response => ...

I tried to access headers or cookies by using these properties in my Express.js server:

req.headers
req.cookies

Neither of them contained any cookies. I am using cookie parser middleware:

app.use(cookieParser())

How do I make Axios send cookies in requests automatically?


Get this bounty!!!