#StackBounty: #javascript MicroFront Ends Recommendations

Bounty: 50

Any one having ideas on using Self contained systems in angular 4 ?

Objective :
Divide Angular in to sub applications such a way that each sub application can be self deployed & Can be written by a separate Team.

Get this bounty!!!

#StackBounty: #javascript #testing #mocking #jestjs #jest How to mock functions in the same module using jest

Bounty: 100

What’s the best way to correctly mock the following example?

The problem is that after import time, foo keeps the reference to the original unmocked bar.


export function bar () {
    return 'bar';

export function foo () {
    return `I am foo. bar is ${bar()}`;


import * as module from '../src/module';

describe('module', () => {
    let barSpy;

    beforeEach(() => {
        barSpy = jest.spyOn(

    afterEach(() => {

    it('foo', () => {
        console.log(jest.isMockFunction(module.bar)); // outputs true

        module.bar.mockReturnValue('fake bar');

        console.log(module.bar()); // outputs 'fake bar';

        expect(module.foo()).toEqual('I am foo. bar is fake bar');
         * does not work! we get the following:
         *  Expected value to equal:
         *    "I am foo. bar is fake bar"
         *  Received:
         *    "I am foo. bar is bar"


EDIT: I could change:

export function foo () {
    return `I am foo. bar is ${bar()}`;


export function foo () {
    return `I am foo. bar is ${exports.bar()}`;

but this is p. ugly in my opinion to do everywhere :/

Get this bounty!!!

#StackBounty: #javascript #css #ms-office #office-js #office-ui-fabric Make the command bar unresponsive

Bounty: 50

I want to use office-ui-fabric with angularjs, so I am trying to use ng-office-ui-fabric.

In the following example, when the wide of the screen is limited, we can observe that the span (eg, 3rd, 14) are hidden. This is not what I want; I want them to be always displayed no matter the width of the screen.

Does anyone know how to make the command bar unresponsive?

<!DOCTYPE html>
  <link rel="stylesheet" href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-core/2.6.3/css/fabric.min.css" />
  <link rel="stylesheet" href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-core/2.6.3/css/fabric.components.min.css" />
<body ng-app="YourApp"> 
3rd 14
angular.module('YourApp', ['officeuifabric.core', 'officeuifabric.components']) .controller('YourController', function () {}) </body> </html>

Get this bounty!!!

#StackBounty: #javascript #function #binding #prototype #this confusion over how "softBind" function works

Bounty: 50

I’m currently studying javascript by following the “you dont know js” series.

In section “this & object prototype“, the author came up with an way to soft bind this.

However, I am extremely confused by the code. So I was wondering if someone could kindly explain it to me, steps by steps, what the code really does?

//step 1: if "softBind" property does not exist on `Function.prototye`

if (!Function.prototype.softBind) {

    //step 2: create a property named "softBind" on "Function.prototype" and assign to "softBind" the following function 

    Function.prototype.softBind = function(obj) {

        //step 3: what is the point of assigning "this" to the variable "fn"?
        //what does "this" represent at this point in time?

        var fn = this,

            //step 4: I understand that "arguments" is an array-like object, i.e. "arguments" is not a true array. 
            //But you can convert "arguments" to an true array by using "[].slice.call(arguments)". 
            //The thing I dont understand here is, why the 1? 
            //I understand it tells "slice" method to start slicing at index 1, but why 1? 
            //And what is the purpose of "curried" variable? 

            curried = [].slice.call( arguments, 1 ),

            bound = function bound() {

                //step 5: I understand what "apply" function does

                return fn.apply(

                    //step 6: I dont really understand how "!this" works. 

                    (!this ||

                        //step 7: utterly confused...   

                        (typeof window !== "undefined" &&
                            this === window) ||
                        (typeof global !== "undefined" &&
                            this === global)

                    //step 8: if the above statements evaluates to "true", then use "obj", 
                    //otherwise, use "this"

                    ) ? obj : this,

                    //step 9: can't I write "curried.concat(arguments)" instead?
                    //why the convoluted syntax?

                    curried.concat.apply( curried, arguments )

        //step 10: Why assign the "fn.prototype" to "bound.prototype"?

        bound.prototype = Object.create( fn.prototype );
        return bound;

I’m very sorry for the long question, but I thought instead of dividing the question into several posts, it is more convenient if they are put into one place.

Get this bounty!!!

#StackBounty: #javascript #xpath Evaluating an XPath with document.evaluate()

Bounty: 50

The Problem Statement:

Filter all nodes with an existing attribute that starts with a specific string (temp for example purposes). Print an array of node string representations as a result.

The Code:

var result = document.evaluate("//*[@*[starts-with(name(), 'temp')]]", document, null, XPathResult.ANY_TYPE, null);

var node = result.iterateNext(); 
var nodes = [];
while (node) {
  node = result.iterateNext();

The code is a bit bulky for such a straightforward problem. Is there a simpler and a more concise way to get an array of nodes from a document.evaluate() result?

Get this bounty!!!

#StackBounty: #javascript #pdf #d3.js #svg #pdf-generation D3.js SVG giving it an ID or adding the SVG to PDF

Bounty: 300

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">

    <link rel="stylesheet" type="text/css" href="style.css">


<table align="center">
    <caption style="text-align: left; font-weight: bold">DETTE ER EN FAKTURABRIK</caption>
        <td id="str1">Kategori 1</td>
        <td id="nr1">10000</td>
        <td id="str2">Kategori 2</td>
        <td id="nr2">20000</td>
        <td id="str3">Kategori 3</td>
        <td id="nr3">30000</td>
        <td id="str4">Kategori 4</td>
        <td id="nr4">40000</td>
        <td id="str5">Kategori 5</td>
        <td id="nr5">50000</td>
        <td id="str6">Kategori 6</td>
        <td id="nr6">60000</td>
        <td id="str7">Kategori 7</td>
        <td id="nr7">70000</td>
        <td id="str8">Kategori 8</td>
        <td id="nr8">80000</td>

<svg class="chart" style="display: block; margin:auto;"></svg>
//Add event listener document.getElementById("getPdf").addEventListener("click", getPdf); function getPdf() { //Get svg markup as string var svg = document.getElementById('svg-container').innerHTML; if (svg) svg = svg.replace(/r?n|r/g, '').trim(); var canvas = document.createElement('canvas'); var context = canvas.getContext('2d'); context.clearRect(0, 0, canvas.width, canvas.height); canvg(canvas, svg); var imgData = canvas.toDataURL('image/png'); // Generate PDF var doc = new jsPDF('p', 'pt', 'a4'); doc.addImage(imgData, 'PNG', 40, 40, 100, 100); //doc.text(20, 20, 'Hello world!'); doc.save('save', 'test.pdf'); } var data = [ $("#nr1").text(), $("#nr2").text(), $("#nr3").text(), $("#nr4").text(), $("#nr5").text(), $("#nr6").text(), $("#nr7").text(), $("#nr8").text()]; var margin = {top: 20, right: 10, bottom: 30, left: 70}, width = 800 - margin.left - margin.right, height = 500 - margin.top - margin.bottom; var y = d3.scale.linear() .domain([0,100000]) .range([height, 0]); var x = d3.scale.ordinal() .rangeRoundBands([0, width], .1) .domain(d3.entries(data).map(function(d) { return "Kategori " + d.key; })); var xAxis = d3.svg.axis() .scale(x) .orient("bottom"); var yAxis = d3.svg.axis() .scale(y) .orient("left"); var svg = d3.select("body").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(-6," + height + ")") .call(xAxis); svg.append("g") .attr("class", "y axis") .call(yAxis) .append("text") .attr("transform", "rotate(-90)") .attr("y", 6) .attr("dy", ".71em") .style("text-anchor", "end") .text("Kroner"); var bar = svg.selectAll() .data(d3.entries(data)) .enter().append("rect") .attr("x", function(d) { return x("Kategori " + d.key) + x.rangeBand()/2 }) .attr("width", x.rangeBand()/2) .attr("y", function(d) { return y(d.value ); }) .attr("height", function(d) { return height - y(d.value); }) .style( "fill", "#66a3ff" ); bar.append("text") .attr("x", function(d) { return x("Kategori " + d.key) + x.rangeBand() / 2; }) .attr("dx", -3) // padding-right .attr("dy", ".35em") // vertical-align: middle .attr("text-anchor", "end") // text-align: right .text( function(d) { return d.value; }); </body> </html>

So I am generating a vertical bar chart SVG with D3.js

However, I cannot figure out two things

  1. How to give the SVG chart an id to then select it with var svg =

    (currently it will select a blue rectangle I made with HTML and put it in the PDF)

  2. Transforming the SVG chart to an image or using
    doc.addSVG to add it to my PDF.

Get this bounty!!!

#StackBounty: #javascript #jquery Ajax Tooltip – bypass so not to use bootstrap

Bounty: 50

I found this code on stackoverflow.com and I would like to ask how do I do the same but without using bootstrap, I would only like to use jquery (if needed) ?

The code below works great but I would like to know how would I do this without using bootstrap.

Thanks for any help.


<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">

                html: true,
                placement: "auto",
                container: 'body',
                trigger: 'hover'

            // show this LOADING popover

            // requesting data from unsing url from data-poload attribute
            $.get(el.data('poload'), function (d) {
                // set new content to popover
                el.data('bs.popover').options.content = d;

                // reshow popover with new content
        // Without this handler popover flashes on first mouseout
        function() { }

<img src="alerts.gif" data-poload="test3.php?id=1"><BR><BR><BR>
<img src="alerts.gif" data-poload="test3.php?id=2"><BR><BR><BR>
<img src="alerts.gif" data-poload="test3.php?id=3"><BR><BR><BR>

Get this bounty!!!

#StackBounty: #javascript #html #internet-explorer #jsf onchange event and programmatic input value change conflict on IE

Bounty: 50

I’ve noticed that in different versions of Internet Explorer the onchange event is not captured when the value of an input is altered by a js function, behavior that does not occur with other browsers such as Mozilla or Chrome.

Investigating a little I found that the correct operation of onchange in IE is not guaranteed when the value is altered by js:

Example (test on IE):

function onchangeRequest(){
  console.log('onchange fired');

function changeValue (input){
        input.value +=  "add"
<h4> focus lost doesnt invoke onchangeRequest() </h4>

<input id="valueInput"  onkeyup="changeValue(this);" onchange="onchangeRequest();" />

<h4> focus lost invokes onchangeRequest() </h4>

<input id="valueInput" onchange="onchangeRequest();" />

I have not found a convincing explanation of the reasons why IE does not solve those situations correctly and although there are alternatives to get the same behavior, such as implementing onchange withonfocs and onblur saving the previous value of the input and Checking if there were changes, I would like to know the reasons why this behavior occurs.

Get this bounty!!!

#StackBounty: #javascript #chart.js Stepped line with null values in chart.js

Bounty: 50

I have data: [10,5,null,10,5], and labels: [2010, 2011, 2012, 2013, 2014]

I’d like to draw a stepped line which has a gap between 2012 and 2013.
When I set steppedLine to true, it only drew a vertical line at 2011 but no horizontal line to connect 2011 and 2012, as the value of 2012 is null. If I set spanGaps to true, it will draw a line from 2011 to 2013 at value 5.

Basically what I’m looking for is to draw a line if the starting value is a number and the ending value is null, but not vice versa


Related codes in controller:

    _this.lines = {};
    _this.lines.labels = [2010,2011,2012,2013,2014];
    _this.lines.data = [
        [10, 5, null, 10, 5]    
    _this.lines.series = ['Now'];
    _this.lines.options = {
        scales: {
            xAxes: [{
                type: 'time',
                time: {
                    parser: 'DD MMM YYYY'
            yAxes: [{
                type: 'linear',
                ticks: {
                    beginAtZero: true
    _this.lines.datasetOverride = [{
        fill: false,
        spanGaps: true,
        steppedLine: true


<canvas class="chart chart-line" chart-labels="ctrl.lines.labels" chart-data="ctrl.lines.data" chart-options="ctrl.lines.options" chart-series="ctrl.lines.series" chart-dataset-override="ctrl.lines.datasetOverride" height="140" responsive=true></canvas>

Get this bounty!!!

#StackBounty: #javascript #angularjs #leaflet #angular-leaflet-directive Mouse over Popup on multiple markers leaflet.js?

Bounty: 50

so I have a leaflet map with lot of markers placed on it. I want to have a popup with like the status of asset etc on ‘hover’ over the marker. I see some examples on google and try to implement but none of them is firing any events. here is my code with my attempt. how can i achieve this feature? do i have to use somekind of tooltip instead of popup?

  buildMarkerLayer = (rawAssetsObjects) => {
    let markersGroup = null;
    var self = this;

    markersGroup = L.markerClusterGroup({
        spiderfyOnMaxZoom: true,
        showCoverageOnHover: true,
        zoomToBoundsOnClick: true,
        spiderfyDistanceMultiplier: 2

      self.$localForage.getItem('showAllAreas').then((_showAll) => {


    angular.forEach(rawAssetsObjects, function(_asset) {

        if(_asset.latitude && _asset.longitude){
            _asset.longitude), {
            id: _asset.id,
            icon: L.divIcon({
                html: self.siMarkers.createHTMLMarker(_asset)
            }).on('click', function(e) {
                //dismiss the event timeline 

                //set the selected asset to a shared service for availability in
                //other controllers
                //inform detail controller of a newly selected asset to query
            }).bindPopup('work').on('mouseover',function(ev) {

    return markersGroup

so I added the mouseover function and is responding on the console with error, so at least i know the listening part is working
enter image description here

Get this bounty!!!