- shadowbox stops working after jquery function call
- <link href="CSS/main.css" rel="stylesheet" type="text/css" />
- <script type="text/javascript" src="shadowbox-3.0.3/shadowbox.js"></script>
- <script type="text/javascript">
- Shadowbox.init();
- </script>
- <p id="compas"><a href="images/coverage.jpg" rel="shadowbox" title="Coverage map"></a></p>
- Shadowbox.clearCache();
- Shadowbox.setup();
- <base href="http://62.162.170.125/"/>
- <div id="menu">
- <ul>
- <li><a id="menu-home" href="index.html" rel="http://jfcoder.com/test/homecontent.html">Home</a></li>
- <li><a id="menu-services" href="services.html" rel="http://jfcoder.com/test/servicescontent.html">Services</a></li>
- <li><a id="menu-tour" href="tour.html" rel="http://jfcoder.com/test/tourcontent.html">Tour</a></li>
- <li><a id="menulogin" href="login.html">Login</a></li>
- </ul>
- </div>
- var boxInitialize = function(){
- try {
- if (!Shadowbox.initialized) {
- Shadowbox.init();
- Shadowbox.initialized = true;
- } else {
- Shadowbox.clearCache();
- Shadowbox.setup();
- }
- } catch(e) {
- try {
- Shadowbox.init();
- } catch(e) {};
- }
- };
- boxInitialize();
- window.onload = boxInitialize; // Note, no () at the end, which execute the function
- var $ = jQuery,
- $content = jQuery("#content"), // This is "caching" the jQuery selected result
- view = '',
- detectcachedview = '',
- $fragment,
- s = Object.prototype.toString,
- init;
- var loadCallback = function(response, status, xhr){
- if (init != '' && s.call(init) == '[object Function]') {
- boxInitialize();
- }
- if (xhr.success()
- && view != ''
- && typeof view == 'string'
- && view.length > 1) {
- $fragment = $content.clone(true, true);
- cacheContent(view, $fragment);
- }
- };
- var cacheContent = function(key, $data){
- if (typeof key == 'string'
- && key.length > 1
- && $data instanceof jQuery) {
- $content.data(key, $data.html());
- $content.data(detectcachedview, true);
- }
- };
- var setContent = function(html){
- $content.empty().html(html);
- if (init != '' && s.call(init) == '[object Function]') {
- boxInitialize();
- }
- };
- var menuLoadContent = function(){
- // This is where I cancel the request; we're going to show the same thing
- // again, so why not just cancel?
- if (view == this.id || !this.rel) {
- return false;
- }
- // I use this in setContent() and loadCallback() functions to detect if
- // the Shadowbox needs to be cleared and re-setup. This and code below
- // resolve the issue you were having with the compass functionality.
- init = this.id == 'menu-home' ? boxInitialize : '';
- view = this.id;
- detectcachedview = "__" + view;
- // This is what blocks the superfluous $.load() calls for content that's
- // already been cached.
- if ($content.data(detectcachedview) === true) {
- setContent($content.data(view));
- return false;
- }
- // Now I have this in two different spots; there's also one up in
- // loadCallback(). Why? Because I want to cache the content that
- // loaded on the initial page view, so if you try to go back to
- // it, you'll just pickup what was sent with the full document.
- // Also note I'm cloning $content, and then get it's .html()
- // in cacheContent().
- $fragment = $content.clone(true, true);
- cacheContent(view, $fragment);
- // See how I use the loadCallback as a function reference, and omit
- // the () so it's not called immediately?
- $content.load(this.rel, loadCallback);
- // These return false's in this function block the link from navigating
- // to it's href URL.
- return false;
- };
- jQuery("#menu a[rel]").click(menuLoadContent);
- $(".content").load('index.html?contentonly=true');
- var $content = $('.content');
- $content.find('.content-view').hide();
- $content.find('#services-content').show();