#StackBounty: #javascript #jquery Trigger event upon jQuery being loaded

Bounty: 50

I’m merging the use of the YouTube iFrame API and jQuery loaded in through a script tag that has the defer flag set. The defer flag must be set as the client has a perfect Google page insight score and wishes to maintain that score.

The YouTube API, upon being fully loaded and ready for use, immediatley calls a function that I define onYouTubeIframeAPIReady. It will then later call onPlayerReady upon the player being fully loaded and rendered.

I wish to use jQuery in this function, but just using jQuery inside the onPlayerReady function will be creating a race condition (hoping the jQuery library has finished loading by the time onPlayerReady gets called).

It occured to me a workable solution would be to use the onPlayerReady function to set a variable before calling a function that tests for both the player and jQuery. Another function sets a variable upon jQuery being ready and calls the same test function.

I have some code that works, but the part that checks for jQuery seems messy to me, and also introduces a small amount of extra unneccessary delay. I was wondering if anyone knows of a better way to run something the instant jQuery becomes available. Basically, are there callbacks for jQuery becoming available built into the library itself?

My current code is as follows:

var ready = {
    'jquery': false,
    'youtube' false
},
testJQueryLoaded;

testJQueryLoaded = function() {
    if(typeof jQuery == 'undefined') {
        window.setTimeout(function() {
            testJQueryLoaded();
        }, 25);
        return;
    }

    ready.jquery = true;
    postLibraryLoad();
};

testJQueryLoaded();

function onYouTubeIframeAPIReady() {
    // Stuff
};

function onPlayerReady() {
    ready.youtube = true;
    postLibraryLoad();
};

function postLibraryLoad() {
    if(!ready.jquery || !ready.youtube) {
        return;
    }

    // More stuff
};


Get this bounty!!!

#StackBounty: #jquery #html #css #css3 #width How do I get my styled select menu to be 100% width of the parent container in Chrome?

Bounty: 150

I’m creating a form with a text box and a styled select menu (essentially a DIV with other DIVs within it). I would like both items to be the same width, preferably not a fixed pixel width, but rather 100% of the available space. I have

  
*
*
Select Notification Time Above Below

in which I specify 100% width for the text box …

input[type=text] {
  margin-bottom: 20px;
  margin-top: 10px;
  padding: 15px;
  border-radius: 5px;
  border: 1px solid #7ac9b7;
  box-sizing: border-box;
  width: 100%;
  /*  added property  */
}

and then “100%” for the width of the styled DIV menu (done through jQuery). This works great on Firefox — https://jsfiddle.net/yj3cdvfy/3/ , but in Chrome its not looking so aligned. Notice the text of the styled select mneu is wrapping and the text box is exceeding the boundary of the parent container. I thought Chrome was supposed to be the good browser! Anyway, what do I need to do to get things working in Chrome the same way as in Firefox?


Get this bounty!!!

#StackBounty: #jquery #jquery-3 #jquery-2.0 unlike jquery 1 and 2, jquery 3 ajax handler is executing newly added html+js only after co…

Bounty: 50

I’ve made a jsbin to show the problem:
http://jsbin.com/dexeqiz/edit?html,js,output

having this html:

  

and js:

$.get('...', function(){
$('#scripts')
  .append("$(function(){$('#log').append('3

');});"); $('#log').append('<p>1</p>'); $('#log').append('<p>2</p>'); });

in jquery 1 and 2

it will render in the #log 1 2 3

but in jquery 3 it will render 3 1 2

this is a problem because sometimes my code expects that the code that was appended in the line before was executed before calling the next line


right now my only workaround is to put the code after .append(newhtml) inside a setTimeout, but I would prefer not to do that because it looks slightly slower for the user. I would much rather have something like $.when(append).done(function(){code})


Get this bounty!!!

#StackBounty: #jquery #asp.net #asp.net-mvc #jquery-forms-plugin jQuery Form Plugin’s File Upload issue when string returned from server

Bounty: 50

I am trying to use jQuery Form Plugin to upload files. It is uploading to a ASP.NET MVC controller action with a return type string.

Controller Action with String return type

 [HttpPost]
 public string PracticeInfoFormUpload(HttpPostedFileBase myfile, FormCollection formCollection)
 {
      //Store the file on disk (Logic excluded for brevity)
      return “good”;
 }

The file is uploaded and response is displayed in Chrome and Firefox. But when I use IE, it is showing the response string in a new page. How to fix this to work in IE also?

Note: The file is getting uploaded correctly in IE also. The problem is what it does with the response unlike other browsers.

Note: I am using IE-10

Expected Result and IE Issue

enter image description here

enter image description here

jQuery

http://malsup.github.com/jquery.form.js  

        $(function () {
            var bar = $('.bar');
            var percent = $('.percent');
            var status = $('#status');

            $('#frmUpload').ajaxForm({
                beforeSend: function () {
                    status.empty();
                    var percentVal = '0%';
                    bar.width(percentVal)
                    percent.html(percentVal);
                },
                uploadProgress: function (event, position, total, percentComplete) {
                    var percentVal = percentComplete + '%';
                    bar.width(percentVal)
                    percent.html(percentVal);
                },
                success: function () {
                    var percentVal = '100%';
                    bar.width(percentVal)
                    percent.html(percentVal);
                },
                complete: function (xhr) {
                    var returnMessage = xhr.responseText;
                    //alert(xhr.responseText);
                    //status.html(xhr.responseText);
                    if (returnMessage == "good") {
                        status.html('
File successfully uploaded
'); } else { status.html('
Error! Please try again
'); } } }); });

HTML

  
@using (Html.BeginForm("PracticeInfoFormUpload", "Home", FormMethod.Post, new { enctype = "multipart/form-data", name = "frmUpload", id = "frmUpload" })) {
<input type="submit" value="Upload " style="margin:2px 0 2px 120px;" class="approvalRadioBackground"> }
0%
</div>
</div> </div>


Get this bounty!!!

#StackBounty: #javascript #jquery #html #css Transforming Vertical Tab to Accordion

Bounty: 50

I’m trying to turn my vertical tab into an accordion view when the page is less than 480px and back to vertical tab view if it is not. I’ve tried to use @media screen and (min-width: 480px) {} + adding the vertical tab CSS styling but I ended up going no where with it. Then I tried searching a way on how to do this online. I ended up finding some examples but they used different methods on how to accomplish this effect. How can I get this vertical tab transform into an accordion when the screen is less than 480px?

The Link below is an example of the effect I’m going for. (when looking at the example resize the window to see the vertical tab/accordion effect)

Example: https://codepen.io/thejettmiller/pen/hqnua

$(document).ready(function() {


  //----------Select the first tab and div by default

  $('#vertical_tab_nav > ul > li > a').eq(0).addClass("selected");
  $('#vertical_tab_nav > div > article').eq(0).css('display', 'block');


  //---------- This assigns an onclick event to each tab link("a" tag) and passes a parameter to the showHideTab() function

  $('#vertical_tab_nav > ul').click(function(e) {

    if ($(e.target).is("a")) {

      /*Handle Tab Nav*/
      $('#vertical_tab_nav > ul > li > a').removeClass("selected");
      $(e.target).addClass("selected");

      /*Handles Tab Content*/
      var clicked_index = $("a", this).index(e.target);
      $('#vertical_tab_nav > div > article').css('display', 'none');
      $('#vertical_tab_nav > div > article').eq(clicked_index).fadeIn();

    }

    $(this).blur();
    return false;

  });


}); //end ready
    /* if in drawer mode */
    $(".tab_drawer_heading").click(function() {
      
      $(".tab_content").hide();
      var d_activeTab = $(this).attr("rel"); 
      $("#"+d_activeTab).fadeIn();
      
      $(".tab_drawer_heading").removeClass("d_active");
      $(this).addClass("d_active");
      
      $("ul.tabs li").removeClass("active");
      $("ul.tabs li[rel^='"+d_activeTab+"']").addClass("active");
    });
    
body {
  margin: 0px;
  padding: 20px;
  background: #9adde5;
  font-family: arial, sans-serif;
  font-size: 10pt;
  line-height: 15pt;
}


/*---------- vertical tab nav */

#vertical_tab_nav {
  display: block;
  width: 100%;
}

#vertical_tab_nav ul {
  display: block;
  float: left;
  margin: 0px;
  padding: 0px;
  list-style: none;
  overflow: hidden;
  width: 30%;
  border-radius: 10px 0 0 10px;
  background: #555;
}

#vertical_tab_nav li {
  border-bottom: 1px solid #000;
  margin-bottom: 1px;
  text-align: left;
  padding: 0px;
}

#vertical_tab_nav li:last-child {
  margin-bottom: 0px;
  border-bottom: 0px;
}

#vertical_tab_nav li a {
  display: block;
  font-size: 14pt;
  color: #fff;
  text-decoration: none;
  padding: 7%;
  background: #57cac9;
  background: -webkit-linear-gradient(top, #444, #333);
  background: -moz-linear-gradient(top, #444, #333);
}

#vertical_tab_nav li a.selected {
  background: #fff;
  color: #000;
}

#vertical_tab_nav div {
  display: block;
  float: left;
  background: #fff;
  background: #fff;
  width: 64%;
  min-height: 500px;
  padding: 10px 3% 3% 3%;
  border-radius: 0 10px 10px 0;
}

#vertical_tab_nav div article {
  display: none;
  margin: 0px;
  color: #555;
}

#vertical_tab_nav div article p {
  margin: 0px 0px 20px 0px;
}

.tab_drawer_heading {
  display: none;
}

@media screen and (max-width: 781px) {
  ul.tabs {
    display: none;
  }
  .tab_container {
    display: block;
    margin: 0 auto;
    width: 95%;
    border-top: none;
    border-radius: 0;
    box-shadow: 0px 0px 10px black;
  }
  .tab_drawer_heading {
    background-color: #ccc;
    color: #000;
    margin: 0;
    padding: 5px 20px;
    display: block;
    cursor: pointer;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    text-align: center;
    &:hover {
      background: #ccc;
    }
  }
  .d_active {
    background: #fff;
  }
}
https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js


<section id="vertical_tab_nav">

  <ul class="tabs">
    <li><a href="index.html">Tab One</a></li>
    <li class="selected"><a href="index.html">Tab Two</a></li>
    <li><a href="index.html">Tab Three</a></li>
    <li><a href="index.html">Tab Four</a></li>
  </ul>

  

Tab Content One

Adult education is essential for Democracy of India. The number of grown up illiterates is great. All college and senior School students should come forward to visit villages in the summer vacation. Each one will teach one there. This will remove illiteracy and strengthen our democracy. I happened to see a one day cricket match between Pakistan and Australia at Wankhade Stadium, Mumbai. I went for a fun. But I witnessed a horrible sight. Two thousand ticketless cricket fans gate crashed. There was a stampede. Three persons died and twenty were injured. Administration was responsible for it.

Tab Content Two

City Anti-pollution Drive demands certain steps from all the citizens of ABC city. All house-holders should pack the waste in a plastic bag and put the bag in front of their house. The bag will be replaced with an empty bag by the Municipal van every morning. They should maintain the cleanliness of the city. This will make the city pollution free. My visit to a slum area after the rainy season was a sad affair. The pits were still full of rain water. There was mud all around. The polluted water had caused various diseases. There was no home without a sick person. Small children suffered from stomach troubles. The government should immediately rush to the help of the sufferers in the slum area.

Tab Content Three

I saw a man climbing down a water pipe. He had a knife in his hand. I hit his hand with a brick. He fell down on the ground and I jumped upon him. Soon others reached there and we handed him over to the police. A tragedy took place yesterday when a Matador fell into a canal. The driver of the Matador tried to save an auto-rickshaw and lost control on the vehicle. About fifty students were travelling in it. The people from the nearby villages saved twenty-seven students. The dead bodies of the drowned were recovered. It was a very painful sight.

Tab Content Four

City life is full of fun. There are parks and picnic spots to visit. We have cinema halls to see movies. We have electricity which runs our factories, light and cools our home and helps us in seeing T.V. There are all type of amenities like water, health check up and transport. Sometimes circus shows and magic shows entertain the city people. I was lucky to escape death by a few seconds.' A bomb blasted in the compartment of Nilanchal Express. The overcrowded compartment made me to get down. Anyhow the loss was great. About ten people died and many got injured. It was the job of a terrorist. The government should intensify searching operations in trains.1
</section>


Get this bounty!!!

#StackBounty: #magento2 #javascript #frontend #jquery #requirejs window.on 'load', function not useable with require JS loaded …

Bounty: 50

I am trying to use $(window).on('load', function(){}); in file that is being pulled into my template with require JS, but no matter how i configure the JS, it will not execute.

The odd part is, this code will execute fine when placed in tags in the phtml, so i know it’s not an issue with the JS itself.

In my template file i have this code:


{
    "*": {
        "Magento_Cms/js/tester": {}
    }
}

And i know this is calling in the correct JS file, as i have tested the console.log inside and outside the $(window).on('load', function(){});. When i hit the page, tester 1 always prints, tester 2 does not. Inside the JS file i have:

define([
    'jquery'
], function ($) {
    'use strict';
    console.log('tester 1');
    $(window).on('load', function(){
        console.log('tester 2');
    });
});

If i take this code and put it in the template file itself, it always prints:


    require([
        'jquery'
    ], function ($) {
        'use strict';
        $(window).on('load', function(){
            console.log('tester 1');
        });
    });

So the logical conclusion would be that there is an issue with require JS loading in this JS file, but how could i track this down and test to see why this is not loading correctly?


Get this bounty!!!

#StackBounty: #magento2 #javascript #frontend #jquery #requirejs window.on 'load', function not useable with require JS loaded …

Bounty: 50

I am trying to use $(window).on('load', function(){}); in file that is being pulled into my template with require JS, but no matter how i configure the JS, it will not execute.

The odd part is, this code will execute fine when placed in tags in the phtml, so i know it’s not an issue with the JS itself.

In my template file i have this code:


{
    "*": {
        "Magento_Cms/js/tester": {}
    }
}

And i know this is calling in the correct JS file, as i have tested the console.log inside and outside the $(window).on('load', function(){});. When i hit the page, tester 1 always prints, tester 2 does not. Inside the JS file i have:

define([
    'jquery'
], function ($) {
    'use strict';
    console.log('tester 1');
    $(window).on('load', function(){
        console.log('tester 2');
    });
});

If i take this code and put it in the template file itself, it always prints:


    require([
        'jquery'
    ], function ($) {
        'use strict';
        $(window).on('load', function(){
            console.log('tester 1');
        });
    });

So the logical conclusion would be that there is an issue with require JS loading in this JS file, but how could i track this down and test to see why this is not loading correctly?


Get this bounty!!!

#StackBounty: #magento2 #javascript #frontend #jquery #requirejs window.on 'load', function not useable with require JS loaded …

Bounty: 50

I am trying to use $(window).on('load', function(){}); in file that is being pulled into my template with require JS, but no matter how i configure the JS, it will not execute.

The odd part is, this code will execute fine when placed in tags in the phtml, so i know it’s not an issue with the JS itself.

In my template file i have this code:


{
    "*": {
        "Magento_Cms/js/tester": {}
    }
}

And i know this is calling in the correct JS file, as i have tested the console.log inside and outside the $(window).on('load', function(){});. When i hit the page, tester 1 always prints, tester 2 does not. Inside the JS file i have:

define([
    'jquery'
], function ($) {
    'use strict';
    console.log('tester 1');
    $(window).on('load', function(){
        console.log('tester 2');
    });
});

If i take this code and put it in the template file itself, it always prints:


    require([
        'jquery'
    ], function ($) {
        'use strict';
        $(window).on('load', function(){
            console.log('tester 1');
        });
    });

So the logical conclusion would be that there is an issue with require JS loading in this JS file, but how could i track this down and test to see why this is not loading correctly?


Get this bounty!!!

#StackBounty: #magento2 #javascript #frontend #jquery #requirejs window.on 'load', function not useable with require JS loaded …

Bounty: 50

I am trying to use $(window).on('load', function(){}); in file that is being pulled into my template with require JS, but no matter how i configure the JS, it will not execute.

The odd part is, this code will execute fine when placed in tags in the phtml, so i know it’s not an issue with the JS itself.

In my template file i have this code:


{
    "*": {
        "Magento_Cms/js/tester": {}
    }
}

And i know this is calling in the correct JS file, as i have tested the console.log inside and outside the $(window).on('load', function(){});. When i hit the page, tester 1 always prints, tester 2 does not. Inside the JS file i have:

define([
    'jquery'
], function ($) {
    'use strict';
    console.log('tester 1');
    $(window).on('load', function(){
        console.log('tester 2');
    });
});

If i take this code and put it in the template file itself, it always prints:


    require([
        'jquery'
    ], function ($) {
        'use strict';
        $(window).on('load', function(){
            console.log('tester 1');
        });
    });

So the logical conclusion would be that there is an issue with require JS loading in this JS file, but how could i track this down and test to see why this is not loading correctly?


Get this bounty!!!

#StackBounty: #magento2 #javascript #frontend #jquery #requirejs window.on 'load', function not useable with require JS loaded …

Bounty: 50

I am trying to use $(window).on('load', function(){}); in file that is being pulled into my template with require JS, but no matter how i configure the JS, it will not execute.

The odd part is, this code will execute fine when placed in tags in the phtml, so i know it’s not an issue with the JS itself.

In my template file i have this code:


{
    "*": {
        "Magento_Cms/js/tester": {}
    }
}

And i know this is calling in the correct JS file, as i have tested the console.log inside and outside the $(window).on('load', function(){});. When i hit the page, tester 1 always prints, tester 2 does not. Inside the JS file i have:

define([
    'jquery'
], function ($) {
    'use strict';
    console.log('tester 1');
    $(window).on('load', function(){
        console.log('tester 2');
    });
});

If i take this code and put it in the template file itself, it always prints:


    require([
        'jquery'
    ], function ($) {
        'use strict';
        $(window).on('load', function(){
            console.log('tester 1');
        });
    });

So the logical conclusion would be that there is an issue with require JS loading in this JS file, but how could i track this down and test to see why this is not loading correctly?


Get this bounty!!!