Solved

Jquery UI Progress Bar Not Working Since NoConflict Added?

Posted on 2014-07-28
4
747 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 42

Accepted Solution

by:
Rob Jurd, EE MVE 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 42

Expert Comment

by:Rob Jurd, EE MVE
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

912 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now