I am trying to include a jquery plugin in an MVC application via bundling css and js files.
But the functionality does not work.
I am aware about how to bundle the files with bundles.add(….)
What exactly am I doing wrong?
bundles.Add(new ScriptBundle("~/bundles/js").Include(
"~/js/rainbow.min.js",
"~/js/tiksluscarousel.js"));
bundles.Add(new StyleBundle("~/bundles/css").Include(
"~/css/animate.css",
"~/css/normalize.css",
"~/css/tiksluscarousel.css",
"~/css/github.css"));
#Styles.Render("~/bundles/css")
#Scripts.Render("~/bundles/js")
Global asax: BundleConfig.RegisterBundles(BundleTable.Bundles);
Index.cshtml:
<div id="fruits">
<ul>
<li><img src="~/images/fruits1.jpg" /></li>
<li><img src="~/images/fruits2.jpg" /></li>
<li><img src="~/images/fruits3.jpg" /></li>
<li><img src="~/images/fruits4.jpg" /></li>
<li><img src="~/images/fruits5.jpg" /></li>
<li><img src="~/images/fruits6.jpg" /></li>
<li><img src="~/images/fruits7.jpg" /></li>
<li><img src="~/images/fruits8.jpg" /></li>
</ul>
</div>
<script language="javascript">
$(document).ready(function(){
$("#fruits").tiksluscarousel({width:640,height:480,nav:'thumbnails',current:1,type:'zoom'});
});
</script>
After adding the files to a bundle you'll need to reference the bundle in your headers, and be sure to register your bundles in your Global.asax file i.e.
Global file:
// Registers default bundle collection
BundleConfig.RegisterBundles(BundleTable.Bundles);
You also need to split the bundles to register styles and scripts separately so in your headers you can run:
Layout Sheet:
#Styles.Render("~/bundleLocation/cssBundleName")
#Scripts.Render("~/bundleLocation/scriptBundleName")
The final item (which is what this one is), the bundle names can't be the same as the folder locations of the bundles so where there is
bundles.Add(new ScriptBundle("~/bundles/js").Include(
"~/js/rainbow.min.js",
"~/js/tiksluscarousel.js"));
bundles.Add(new StyleBundle("~/bundles/css").Include(
"~/css/animate.css",
"~/css/normalize.css",
"~/css/tiksluscarousel.css",
"~/css/github.css"));
You'll just need to rename the ScriptBundles to something other than /js and /css
i.e
bundles.Add(new ScriptBundle("~/bundles/jsScripts").Include(
"~/js/rainbow.min.js",
"~/js/tiksluscarousel.js"));
bundles.Add(new StyleBundle("~/bundles/cssStyles").Include(
"~/css/animate.css",
"~/css/normalize.css",
"~/css/tiksluscarousel.css",
"~/css/github.css"));
This is just a routing convention of MVC where it will be confused by the bundle name and attempt to link a non-existing folder
Related
I need to add a default value to a filter in Jquery mobile 1.3.0.
But the example below do not work.
<ul data-role="listview" data-autodividers="false" data-filter="true" data-inset="true" id="listviewID">
<?php foreach($countryList as $country): ?>
<li value="<?php echo trim(country); ?>"><?php echo trim(country); ?></li>
<?php endforeach; ?>
</ul>
$(document).ready(function() {
$(".ui-input-text.ui-body-c").val('Canada');
$('#listviewID').listview('refresh');
});
Refreshing the listview wont work, as it has already been rendered. The hack is modifying the input and firing an change event.
$(document).ready(function(){
$("#listviewID").prev("form").find("input[data-type=search]").val('Canada').trigger("change");
});
Note that the selector looks for the inmediate previous form (automatically created by jQM when you specify filterable) and the input with [data-type=search], thats more specific than .ui-input-text.ui-body-c.
FIDDLE
I am missing something simple, but can'T find it. In my asp.net MVC5 project, I want to use bootstrap-switch. This is what I've done:
BundleConfig.cs: added bootstrap-switch.css and bootstrap.switch.js as follows,
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js",
"~/Scripts/bootstrap-switch.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/bootstrap-switch.css",
"~/Content/site.css"));
(and made sure the files are at those locations).
Then, in a view I tried the following three checkboxes,
<input type="checkbox" class="switch" />
<input type="checkbox" class="switch" name="box" />
<input type="checkbox"
data-on-text="Option A"
data-off-text="Option B"
data-size="mini"
name="box2" />
and added, at the bottom of the view file,
<script>
$("[name='box']").bootstrapSwitch();
$("[name='box2']").bootstrapSwitch();
</script>
But when I run the project, the checkbox looks like the standard checkbox (no CSS, or functions have been added).
I've read a lot of posts on this (my code follows http://www.bootstrap-switch.org/ verbatim), but can't find my mistake.
Late and obvious, but perhaps useful for someone. The checkboxes need to be initialized when the document is ready.
<script>
$(document).ready(function() {
$("[name='box']").bootstrapSwitch();
$("[name='box2']").bootstrapSwitch();
});
</script>
The problem was that if you include the js files in the bundle, it is rendered last on the page. Hence, if you use javascipt on your view that references a .js library loaded in the bundle, it does not work to put it at the end of the view file, rather render the scripts section,
#section scripts{
<script>
$(".indent-1").css("background", "green");
</script>
}
This will then appear on the html file after the libraries are imported.
I am having an issue launching the popup from another javascript file, I boot the popup correctly form the index.html (had to put the javascript in the #main .
Now I can't launch it from a helper.js file (it loads the content properly as before but when I click the it doesn't launch the popup, whilst I copied the same code and it works straight from the index.html.
content = '<li data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-icon="arrow-r" data-iconpos="right" class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-li-has-thumb ui-btn-up-c">'+
'<div class="ui-btn-inner ui-li">'+
'<div class="ui-btn-text">'+
'<a id="btnChoicePopup" href="#" data-rel="popup" class="ui-link-inherit">'+
'<img src="http://www.luc.edu/media/lucedu/sustainability-new/images/food_icon-1109x1089.png" class="ui-li-thumb">'+
'<h3 class="ui-li-heading">Food</h3>'+
'<p class="ui-li-desc">Im hungry!</p>'+
'</a>'+
'</div>'+
'<span class="ui-icon ui-icon-arrow-r ui-icon-shadow"> </span>'+
'</div></li>';
$('.home').html(content).trigger("create");'
Any ideas? Here is the
Fiddle.
I found my mistake, I had the (#btnPopupChoice).click on another page (index.html) I just moved it right after the $('.home').html(content).trigger("create");' in the javascript file and worked.
i am trying to implement the slider from this site
http://bxslider.com/
i used the exact procedure what they said but still my code is not working
can you guys tell me how to fix it
i am providing my fiddle code blow
http://jsfiddle.net/v3efb/3/
http://jsfiddle.net/v3efb/3/embedded/result/
providing my code below
<ul class="bxslider">
<li><img src="http://maxcdn.webappers.com/img/2009/01/jquery-carousel.png" /></li>
<li><img src="http://maxcdn.webappers.com/img/2009/01/jquery-carousel.png" /></li>
<li><img src="http://maxcdn.webappers.com/img/2009/01/jquery-carousel.png" /></li>
<li><img src="http://maxcdn.webappers.com/img/2009/01/jquery-carousel.png" /></li>
</ul>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<!-- bxSlider Javascript file -->
<script src="/js/jquery.bxslider.min.js"></script>
<!-- bxSlider CSS file -->
<link href="/lib/jquery.bxslider.css" rel="stylesheet" />
<script>
$(document).ready(function(){
$('.bxslider').bxSlider();
});
</script>
jsFiddle DEMO
In your markup, you are using relative paths to jquery.min.js, bxslider.min.js and bxslider.css files.
That means those files are locally available in their respective subfolders.
However, jsFiddle does not know the complete URL path, aka the absolute path, to those files.
Change the paths so they are a complete URL.
Tip: In jsFiddle, you can import .js and .css files as assets using the Add Resources panel on left side.
I'm developing a phonegap/jquery-mobile test application (I'm new in this technologies) for android and I want show inside my app an image stored on internet site. During app startup in avd I receive this notification when put in my index.html this element:
<img src="http://www.comolakeboats.it/images/stories/boats/gommone_12_150x100.jpg" width="120px;" />
Application Error - the connection to the server was unsuccessfull (file:///android_asset/www/index.html)
On log.cat I can see this error:
E/DroidGap(337): DroidGap: TIMEOUT ERROR! - calling webViewClient
I already checked connection both from browser and inside my application with an external link and in both case I can reach internet site.
What I'm missing? Exists a solution (maybe the same) suitable for Iphone,too?
This is my code:
<body>
<div data-role="page" id="home_it">
<div data-role="header" data-theme="a" id="it">
<h1>TEST</h1>
<div data-role="navbar" data-iconpos="right" data-theme="a">
<ul>
<li>Tel:+3933333333</li>
<li>Email</li>
</ul>
</div>
<div class="ui-body ui-body-c"><!-- ui-body-b">-->
<p>Some text</p>
<button id="my_list_button">Mostra</button>
</div>
</div>
<div data-role="content" class="ui-body">
<ul data-role="listview" id="my_list">
<li data-role="list-divider">My list</li>
<li>
<a href="http://www.comolakeboats.it" rel="external">
<img src="http://www.comolakeboats.it/images/stories/boats/gommone_12_150x100.jpg" width="120px;" />
<h3>title foo foo</h3>
<p style="color:red">foo foo foo foo</p>
</a>
</li>
</ul>
</div>
<div data-role="footer">
<div data-role="navbar" data-iconpos="right" data-theme="a">
<ul>
<li> </li>
<li><a id="exit-app" data-icon="back"> </a></li>
</ul>
</div>
</div>
</div>
</body>
Thank you in advance
Did you actually update the phonegap's whitelist? that tells the app which URLs it's allowed to access. You can also add a * to it, as described here
Hope this helps
If you put higher values in defaultactivity:
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
super.loadUrl("file:///android_asset/www/index.html", 60000);
It won't time out but it will take ages for your app to run...
Maybe the most simple you can do is download the image and add it to your project. In that case just make the src attribute of the <img> tag reference the image path inside your project.
A few notes that might help you:
the index.html has to be a full html document ...
you have to set the permissions to use the internet, in AndroidManifest.xml
the test device has to have an internet connection (try opening the image url on the device browser first).
I have set the whitelist in my cordova.xml to ".*" but it still displays the same error so I tried looking for other solutions and found this out:
http://community.phonegap.com/nitobi/topics/phonegap_build_viewebclient_timeout_error_on_android_device
His solution was to redirect the page from the index.html to a main page. I don't know why it worked for me but happy that it did. If you would see any problem doing this work around please do comment, I don't want to encounter other major problems in the future because of this.
I have the same problem. Finally i find the reason is "Content-Security-Policy" setting in head of the html!. You can simply remove the line like this:
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">