I want to implement Navigation Drawer by using panel with list of buttons (each openning other page). Problem occurs when I go back to the previous page and I try to open panel again. Button which is supposed to do that doesn't work, it only lights up in blue.
Start
http://imgur.com/WeNactN
Open panel
http://imgur.com/492rnXN
Back in first page, button does not work
http://imgur.com/UnX7Jk4
Here's my index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div data-role="page" id="firstPage">
<div data-role="panel" id="myPanel" data-display="overlay">
<h2>Menu</h2>
<br/>
<ul data-role="listview">
<li><a href="#firstPage" data-rel="close" >First Page</a></li>
<li><a href="#secondPage" data-rel="close" >Second Page</a></li>
</ul>
</div>
<div data-role="header">
<h1>First Page</h1>
Open Panel
</div>
<div data-role="main" class="ui-content">
<p>FirstPage</p>
</div>
</div>
<div data-role="page" id="secondPage">
<div data-role="panel" id="myPanel" data-display="overlay">
<h2>Menu</h2>
<br/>
<ul data-role="listview">
<li><a href="#firstPage" data-rel="close" >First Page</a></li>
<li><a href="#secondPage" data-rel="close" >Second Page</a></li>
</ul>
</div>
<div data-role="header">
<h1>Second Page</h1>
Open Panel
</div>
<div data-role="main" class="ui-content">
<p>Second Page</p>
</div>
</body>
Any advice or suggestions will be greatly appreciated.
You have 2 panel divs with same ID id="myPanel"
changing the id of second panel should resolve the issue.
Related
I'm using Three iframe inside index files with 3 Tabs. I want to load or refresh the files inside the iframe when each tab is selected.
Here is my index files
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<ul class="nav nav-tabs" id="myTab">
<li class="active"><a data-target="#home" data-toggle="tab">Enter</a></li>
<li><a data-target="#profile" data-toggle="tab" >Display</a></li>
<li><a data-target="#messages" data-toggle="tab">Search</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="home">
<iframe src="EnterBook.php" ></iframe>
</div>
<div class="tab-pane" id="profile" >
<iframe src="DisplayBooks.php" ></iframe>
</div>
<div class="tab-pane" id="messages">
<iframe src="SearchBooks.php" ></iframe>
</div>
</div>
I did look over other solution but nothing helped.. Please anyone can have a look over it.
You need to add click event handler to every tab and in callback function get relevant iframe of clicked tab and change reset src attribute of it or use Location.reload()
document.querySelectorAll('#myTab a').forEach(function(ele){
ele.onclick = function(){
var iframe = document.querySelector(this.dataset.target+'>iframe');
iframe.src = iframe.src;
}
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<ul class="nav nav-tabs" id="myTab">
<li class="active">
<a data-target="#home" data-toggle="tab">Enter</a>
</li>
<li>
<a data-target="#profile" data-toggle="tab" >Display</a>
</li>
<li>
<a data-target="#messages" data-toggle="tab">Search</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="home">
<iframe src="https://stacksnippets.net/"></iframe>
</div>
<div class="tab-pane" id="profile">
<iframe src="https://stacksnippets.net/"></iframe>
</div>
<div class="tab-pane" id="messages">
<iframe src="https://stacksnippets.net"></iframe>
</div>
</div>
So I have been building a new website recently and experimenting a lot with jQuery.
Unfortunately I seem to be having a massive problem getting my jquery file to actually work in the website.
Here is the html code. As you can see, I have jquery added by CDN and the javascript is in a totally separate file. I added an alert into the primary function just to check if it's even reading what I have put and I am stuck.
<html>
<head>
<!--Browser Data-->
<meta charset="utf-8">
<!--Meta Data -->
<title>website</title>
<meta name="description" content="The Official Page of website">
<meta name="Keywords" content="some website stuff">
<meta name="author" content="me">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSS File Locations -->
<link rel="stylesheet" href="css/main.css">
<!-- Javascript File Locations -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<!-- Fonts used -->
<link href="https://fonts.googleapis.com/css?family=Germania+One" rel="stylesheet">
</head>
<body>
<!-- A logo will go here but here is some text for now -->
<H1 ID="Logo">website</H1>
<!-- The menu bar -->
<ul class="menu" ID="Menu_Bar">
<li Class="Menu_Item" ID="Home">
<a Class="Menu_Link" href="index.html">Home</a>
</li>
<li Class="Menu_Item" ID="About_Us">
<a Class="Menu_Link" href="about.html">About Us</a>
</li>
<li Class="Menu_Item" ID="Events">
<a Class="Menu_Link" href="events.html">Events</a>
</li>
<li Class="Menu_Item" ID="Contact">
<a Class="Menu_Link" href="contact.html">Contact Us</a>
</li>
</ul>
<!-- An image of the stuff-->
<img ID="theGang" src="assets/thegang.png"/>
</body>
</html>
Here is the JQuery.
$(document).ready(function(){
$("button").click(function(){
$("#theGang").fadeIn(3000);
alert("it worked");
});
});
I'm just not sure why it's not working.
By the way the javascript file is in a sub folder called js and called main.js and the html is called index.html
Based on your comments it looks like all you needed to do was remove the event handler for the nonexistent button element. This enables the fadeIn and alert.
$(document).ready(function(){
$("#theGang").fadeIn(3000);
//alert("it worked");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- A logo will go here but here is some text for now -->
<H1 ID="Logo">website</H1>
<!-- The menu bar -->
<ul class="menu" ID="Menu_Bar">
<li Class="Menu_Item" ID="Home">
<a Class="Menu_Link" href="index.html">Home</a>
</li>
<li Class="Menu_Item" ID="About_Us">
<a Class="Menu_Link" href="about.html">About Us</a>
</li>
<li Class="Menu_Item" ID="Events">
<a Class="Menu_Link" href="events.html">Events</a>
</li>
<li Class="Menu_Item" ID="Contact">
<a Class="Menu_Link" href="contact.html">Contact Us</a>
</li>
</ul>
<!-- An image of the stuff-->
<img ID="theGang" src="https://image.freepik.com/free-photo/cute-cat-picture_1122-449.jpg" style="display: none;"/>
I'm trying to build a working external panel but am having some issues. Here's the HTML:
<html>
<head>
<title>My Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
/* add panel */
$( document ).on( "mobileinit" , function() {
var panel = '<div>panel</div>';
$( "body" ).prepend( panel ); /* or .append */
});
</script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script>
/* initialize panel and contents */
$(function() {
$( "[data-role=panel]" ).panel().enhanceWithin(); /* or #panelID or .class */
});
</script>
</head>
<body>
<div data-role="panel" class="panel left panel-01" data-position="left" data-display="push" id="panel-01">
<ul data-role="listview" data-theme="a">
<li>My Profile</li>
<li>Recent Activities</li>
<li>FAQ </li>
<li>Terms and Use</li>
<li>Full Site</li>
<li>About Us</li>
<li>Contact Us</li>
<li>Privacy Policy</li>
</ul>
</div>
<div data-role="page" id="home" data-position="fixed">
<div data-role="header"> menu
<h1>Home</h1>
</div>
<div data-role="content" class="content">content
<div data-role="listview" style="margin:1em; border-radius:10px;">
<ul data-role="listview" style="margin:1em; border-radius:10px;">
<li>About us
</li>
</ul>
</div>
</div>
</div>
<div data-role="page" id="about" data-position="fixed">
<div data-role="header"> menu
<h1>About us</h1>
</div>
<div data-role="content" class="content">About us
<div data-role="listview" style="margin:1em; border-radius:10px;">
<ul data-role="listview" style="margin:1em; border-radius:10px;">
<li>Home
</li>
</ul>
</div>
</div>
<div data-role="footer">
<!--<h4>Footer</h4>-->footer</div>
</div>
<div data-role="page" id="profile" data-position="fixed">
<div data-role="header"> menu
<h1>My Profile</h1>
</div>
<div data-role="content" class="content">About us
<div data-role="listview" style="margin:1em; border-radius:10px;">
<ul data-role="listview" style="margin:1em; border-radius:10px;">
<li>Profiles
</li>
</ul>
</div>
</div>
</div>
</body>
</html>
I'm testing this in Chrome and I'm getting:
Uncaught TypeError: undefined is not a function
The code was taken from different sources but seems to be a typical example of loading an external panel.
How do I correct the "undefined function" error?
You have to include jQuery mobile before on()
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script>
/* add panel */
$( document ).on( "mobileinit" , function() {
var panel = '<div>panel</div>';
$( "body" ).prepend( panel ); /* or .append */
});
</script>
I am using jQuery but its not working in my webpage.
jquery-1.10.2.min.js is used for TAB and jquery.lightbox-0.5.js" is used for Photo gallery with jquery.js scripting file.
Now though it shows the tab buttons and the thumbnails of the gallery, when I click on the tabs the tab doesn't work and photo gallery doesn't work too.
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery.opacityrollover.js" type="text/javascript"></script>
<!--[if lt IE 7]>
<div style=' clear: both; text-align:center; position: relative;'>
<img src="http://storage.ie6countdown.com/assets/100/images/banners/warning_bar_0000_us.jpg" border="0" alt="" />
</div>
<![endif]-->
<!--[if lt IE 9]>
<script type="text/javascript" src="js/html5.js"></script>
<link rel="stylesheet" href="css/ie.css" type="text/css" media="screen">
<![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.lightbox-0.5.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquery.lightbox-0.5.css" media="screen" />
<!-- / fim dos arquivos utilizados pelo jQuery lightBox plugin -->
<!-- Ativando o jQuery lightBox plugin -->
<script type="text/javascript">
$(function() {
$('#photog a').lightBox();
});
</script>
<style type="text/css">
/* jQuery lightBox plugin - Gallery style */
</head>
<body id="page1">
<!--==============================header=================================-->
<header>
<div class="row-2">
<div class="main">
<div class="container_12">
<div class="grid_9">
<div id="logom">
<img src="images/logo-iie.png" width="43" height="54" alt="IIE LOGO" />
</div>
<h1>
<a class="logo" href="index.html">Indian Institute of Entrepreneurship</a>
<span>Clusters in North East Region</span>
</h1>
An Organisation of the Ministry Of Micro, Small and Medium Enterprises(MSME),<br>
Govt.of India
An ISO 9001:2008 Certified Organisation
</div>
<div id="logor"><img src="images/logo-rrc.png" width="51" height="54" alt="IIE LOGO" /></div>
</div>
<div class="clear"></div>
</div>
</div>
<div class="row-1">
<div class="main">
<div class="container_12">
<div class="grid_12">
<!-- Main navigation -->
<nav class="main-navigation clearfix span12" role="navigation">
<ul>
<li>Home</li>
<li>About</li>
<li>RRC Team</li>
<li>
Clusters
<ul class="sub-menu">
<li>Assam
<ul class="sub-menu">
<li>Sipajhar Handloom Cluster</li>
<li>Dhamdhama Handloom Cluster</li>
<li>Pyranga Eri Cluster</li>
<li>Rontholi Jewellery Cluster</li>
<li>Bogulamari Jute Cluster</li>
<li>Asharikandi Terracotta Cluster</li>
<li>Japi Cluster</li>
<li>Incense Sticks cluster</li>
</ul>
</li>
<li>Manipur
<ul class="sub-menu">
<li>Kouna Grass Cluster</li>
<li>Imphal Handloom Cluster</li>
<li>Greater Imphal Jewellery Cluster</li>
</ul>
</li>
<li>Mizoram
<ul class="sub-menu">
<li>Baktwang Wood Carpentry Cluster</li>
<li>Bairabi Bamboo cluster</li>
</ul>
</li>
<li>Sikkim
<ul class="sub-menu">
<li>Okhrey Carpet Making Cluster</li>
</ul>
</li>
<li>Tripura
<ul class="sub-menu">
<li>Hapania Jute Cluster</li>
</ul>
</li>
<li>Meghalaya
<ul class="sub-menu">
<li>Strawberry Cluster, Ri-Bhoi</li>
<li>Umden Eri Cluster</li>
<li>Cashew Nut Cluster, Selsela</li>
</ul>
</li>
<li>Arunachal Pradesh
<ul class="sub-menu">
<li>Tawang Carpet Making Cluster</li>
<li>Dirang Food Processing Cluster</li>
</ul>
</li>
</ul>
</li>
<li class="current">Photo Gallery</li>
<li>Contact</li>
</ul>
</nav> <!-- #main-navigation -->
</div>
</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</header>
<!-- content -->
<section id="content">
<div class="bg-top">
<div class="bg-top-2">
<div class="bg">
<div class="bg-top-shadow">
<div class="main">
<div class="gallery p3">
<div class="wrapper indent-bot">
<span class="title img-indent3">Gallery</span>
<div class="cleaner_h10"> </div>
<!--------------------------------------->
<div id="w" class="clearfix">
<ul id="sidemenu">
<li>
<i class="icon-info-sign icon-large"></i><strong>Assam</strong>
</li>
<li>
<i class="icon-lightbulb icon-large"></i><strong>Manipur</strong>
</li>
<li>
<i class="icon-envelope icon-large"></i><strong>Mizoram</strong>
</li>
<li>
<i class="icon-envelope icon-large"></i><strong>Sikkim</strong>
</li>
<li>
<i class="icon-envelope icon-large"></i><strong>Tripura</strong>
</li>
<li>
<i class="icon-envelope icon-large"></i><strong>Meghalaya</strong>
</li>
<li>
<i class="icon-envelope icon-large"></i><strong>Arunachal</strong>
</li>
</ul>
<div id="contab">
<div id="assam-content" class="contabblock">
<h1>Assam</h1>
</div><!-- #end -->
<div id="manipur-content" class="contabblock hidden">
<h1>Manipur</h1>
</div><!-- #end -->
<div id="mizoram-content" class="contabblock hidden">
<h1>Mizoram</h1>
</div><!-- #end -->
<div id="sikkim-content" class="contabblock hidden">
<h1>Sikkim</h1>
</div><!-- #end -->
<div id="tripura-content" class="contabblock hidden">
<h1>Tripura</h1>
</div><!-- #end -->
<div id="meghalaya-content" class="contabblock hidden">
<h1>MIzoram</h1>
</div><!-- #end -->
<div id="arunachal-content" class="contabblock hidden">
<h1>Arunachal Pradesh</h1>
</div><!-- #end -->
</div><!-- #end #content -->
</div><!-- #end #w -->
<!--------------------------------------->
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!--==============================footer=================================-->
<footer>
<div class="main">
<div class="container_12">
<div class="wrapper2">
<div class="grid_4">
<div>© 2014 All right reserved</div>
<!-- {%FOOTER_LINK} -->
</div>
<div class="grid_4">
<div>Powered by: Third Eye</div>
</div>
<div class="grid_4">
<ul class="list-services">
<li></li>
<li><a class="item-2" href="#"></a></li>
</ul>
</div>
</div>
</div>
</div>
</footer>
<script type="text/javascript">
$(function(){
$('#sidemenu a').on('click', function(e){
e.preventDefault();
if($(this).hasClass('open')) {
// do nothing because the link is already open
} else {
var oldcontent = $('#sidemenu a.open').attr('href');
var newcontent = $(this).attr('href');
$(oldcontent).fadeOut('fast', function(){
$(newcontent).fadeIn().removeClass('hidden');
$(oldcontent).addClass('hidden');
});
$('#sidemenu a').removeClass('open');
$(this).addClass('open');
}
});
});
</script>
</body>
</html>
I don't really know what your script does but just by reading it I see this problem:
var oldcontent = $('#sidemenu a.open').attr('href');
var newcontent = $(this).attr('href');
So oldcontent and newcontent are a bunch of strings containing links (URLs) like "http://....." etc.
Then you're trying to make those "strings" fade:
$(oldcontent).fadeOut('fast', function(){
$(newcontent).fadeIn().removeClass('hidden');
$(oldcontent).addClass('hidden');
});
I think something is missing in between...
I have created a simple two page example, first page has a list view and the second just a <h1>, however when the second page gets loaded there are now ui styles applied to it automatically? Do I have to call something manually or is there an issue with how I've laid out the navigation? Code below any help much appreciated.
index.html
<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<title>Page One</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script>
</head>
<body>
<div data-role="page" data-theme="a" id="second">
<div data-role="header">
<h1 id="logo" class="ui-title">Header</h1>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true" data-theme="c" data-split-theme="d">
<li class="ui-li-has-thumb">
<img class="ui-li-thumb" src="http://jquerymobile.com/demos/1.0a2/docs/lists/images/album-bb.jpg" />
<h3 class="ui-li-heading">FooBar</h3>
<p class="ui-li-desc">Progress</p>
</li>
<li class="ui-li-has-thumb">
<img class="ui-li-thumb" src="http://jquerymobile.com/demos/1.0a2/docs/lists/images/album-bb.jpg" />
<h3 class="ui-li-heading">FooBar</h3>
<p class="ui-li-desc">Progress</p>
</li>
</ul>
</div>
<div data-role="footer" data-position="fixed">
<div data-role="navbar" class="ui-glyphish">
<ul>
<li><a class="ui-btn-active" id="quickfind" href="index.html" data-icon="custom">QuickFind</a></li>
<li><a id="lessons" href="lessons.html&ui-page=listview-1" data-icon="custom" data-theme="a">Lessons</a></li>
<li><a id="progress" href="#" data-icon="custom" data-theme="a">Progress</a></li>
<li><a id="favs" href="#" data-icon="custom" data-theme="a">Favs</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
second.html
<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<title>Page Two</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1 id="logo" class="ui-title">Second</h1>
</div>
<div data-role="content">
<h1>Hello Page Two</h1>
</div>
<div data-role="footer" data-position="fixed">
<div data-role="navbar" class="ui-glyphish">
<ul>
<li><a class="ui-btn-active" id="quickfind" href="index.html" data-icon="custom">QuickFind</a></li>
<li><a id="lessons" href="lessons.html&ui-page=listview-1" data-icon="custom" data-theme="a">Lessons</a></li>
<li><a id="progress" href="#" data-icon="custom" data-theme="a">Progress</a></li>
<li><a id="favs" href="#" data-icon="custom" data-theme="a">Favs</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
This was actually a know bug and fixed in commit https://github.com/jquery/jquery-mobile/commit/80d56e655bac8aa6205a0c1f5a9877493a5ced71
AFAIK that's what it's designed to do: when you link to an HTML page it inserts it's body as content within and between the jQuery mobile context of a header and footer. If you want full control of the HTML you have to put rel="external" in your links otherwise they're loaded via AJAX, parsed for content and inserted dynamically.
http://jquerymobile.com/demos/1.0a2/#docs/pages/docs-pages.html
Try with
href="index.html?" instead of href="index.html"
and
href="second.html?" instead of href="second.html"