Solved

Jquery UI Progress Bar Not Working Since NoConflict Added?

Posted on 2014-07-28
4
776 Views
Last Modified: 2014-07-29
Our MVC 5 web uses Jquery 1.11.0 and we're adding a Jquery UI progress Bar which uses Jquery 1.10.2... We want to isolate the progress bar script by encapsulation so any updates via Nuget doesn't interfere...

This Jquery UI Progress Bar worked perfectly until adding $.noConflict() like you see below. I have been to the Jquery web site and found this solution, but It doesn't work...
 
<div>
    <div id="progressbar"><div class="progress-label">Loading...</div></div>
</div> 

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">

<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript"> var j$1102 = $.noConflict(true); </script>
<script type="text/javascript" src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<script>
    
    (function (jQuery) 
    {
        var percentage = 46;
        var progressbar = $("#progressbar");
        var progressLabel = $(".progress-label");

        progressbar.progressbar({
            value: false,
            change: function () {
                progressLabel.text(progressbar.progressbar("value") + "%");
            },
            complete: function () {
                progressLabel.text("Complete!");
            }
        });

        function progress() {
            var val = progressbar.progressbar("value") || 0;
            progressbar.progressbar("value", val + 1);
            if (val <= 45)
            {
                setTimeout(progress, 80);
            }
        }
        setTimeout(progress, 1000);
    })
        (j$1102);

</script>

Open in new window

0
Comment
Question by:WorknHardr
  • 2
  • 2
4 Comments
 
LVL 43

Accepted Solution

by:
Rob earned 500 total points
ID: 40225982
Firstly let's try this as the $ is not available unless you explicitly make it so and you're specifying the variable 'jQuery' not $ as passed to the anonymous function:

Example of using $ as a local variable: http://jsbin.com/fiyaco/1/edit?js,console,output
// change jQuery to $ and it should be used as priority over the global $.  
   (function ($) 
    {
        var percentage = 46;
        var progressbar = $("#progressbar");
        var progressLabel = $(".progress-label");

        progressbar.progressbar({
            value: false,
            change: function () {
                progressLabel.text(progressbar.progressbar("value") + "%");
            },
            complete: function () {
                progressLabel.text("Complete!");
            }
        });

        function progress() {
            var val = progressbar.progressbar("value") || 0;
            progressbar.progressbar("value", val + 1);
            if (val <= 45)
            {
                setTimeout(progress, 80);
            }
        }
        setTimeout(progress, 1000);
    })
        (j$1102);

Open in new window


Any questions, please let me know.
0
 

Author Comment

by:WorknHardr
ID: 40226741
It's working! Here are my latest changes ...

<script src="//code.jquery.com/jquery-1.11.1.js"></script>   //running 'global scope' version...

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>  //using this 'local scope' version
<script type="text/javascript" src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<script>

    var j$1102 = $.noConflict(true);

    (function ($) {
      ...
    })(j$1102);

</script>
0
 
LVL 43

Expert Comment

by:Rob
ID: 40228177
Yep - looks good.  Was there anything else related to this I can help with? otherwise just go ahead and close the question.
0
 

Author Closing Comment

by:WorknHardr
ID: 40228231
Thx
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question