Solved

Jquery UI Progress Bar Not Working Since NoConflict Added?

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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)

707 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

17 Experts available now in Live!

Get 1:1 Help Now