Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moving saved dom elements into specific div so we don't pollute the d…

…om and have potential selector problems.
  • Loading branch information...
commit 3814a8405599350f682342d435304c10bb0d038a 1 parent ad283f1
@ibjhb authored
Showing with 32 additions and 18 deletions.
  1. +27 −14 jquery.pageslide.js
  2. +5 −4 jquery.pageslide.min.js
View
41 jquery.pageslide.js
@@ -7,6 +7,7 @@
direction: "left", // default direction is left.
modal: false, // if true, the only way to close the pageslide is to define an explicit close class.
ajaxReload: true,
+ idPrefix: 'slide',
_identifier: $(this)
}, options);
@@ -65,6 +66,15 @@
$("body").append( psSlideBlanket );
$("#pageslide-blanket").click(function(){ return false; });
}
+
+ // Create empty div for page/dom storage later.
+ if (!settings.ajaxReload){
+ if (!$('div#pageSlideStore').length){
+ $('<div>')
+ .attr('id', 'pageSlideStore')
+ .appendTo('body');
+ }
+ }
// Callback events for window resizing
$(window).resize(function(){
@@ -93,21 +103,22 @@
$("#pageslide-body-wrap").animate(direction, settings.duration, function() {
var pageURL = $(elm).attr("href");
- var pageContent = $('div[id=' + pageURL + ']');
+ var idSelector = settings.idPrefix + pageURL.replace(".", "");
+ var pageContent = $('div#pageSlideStore').find("div#" + idSelector);
+
// If ajaxReload is false, if the page is on the DOM, use it. Otherwise, grab it from ajax
if (!settings.ajaxReload && pageContent.length){
var data = pageContent.html();
- _doSlide(data, pageURL);
+ _doSlide(data, idSelector);
} else {
$.ajax({
type: "GET",
url: pageURL,
success: function(data){
- _doSlide(data, pageURL);
+ _doSlide(data, idSelector);
}
});
}
-
});
};
@@ -124,7 +135,7 @@
}
};
- var _doSlide = function(data, url){
+ var _doSlide = function(data, idSelector){
$("#pageslide-content")
.css("width", settings.width)
.html(data)
@@ -142,15 +153,17 @@
});
});
- // We don't need to save this to the DOM if we are going to re-request the pages every time:
- if (!settings.ajaxReload){
- // Append the file to the DOM so we don't have to re-request it:
- $('<div>')
- .attr('id', url)
- .html(data)
- .appendTo('body')
- .hide();
- }
+ // We don't need to save this to the DOM if we are going to re-request the pages every time:
+ var pageContent = $('div#pageSlideStore').find("div#" + idSelector);
+ if (!settings.ajaxReload && !pageContent.length){
+ // Append the file to the DOM so we don't have to re-request it:
+ $('<div></div>')
+ .attr('id', idSelector)
+ .html(data)
+ .appendTo('body div#pageSlideStore')
+ .hide();
+ }
+
}
// fixes an annoying horizontal scrollbar.
function _overflowFixAdd(){($.browser.msie) ? $("body, html").css({overflowX:'hidden'}) : $("body").css({overflowX:'hidden'});}
View
9 jquery.pageslide.min.js
@@ -1,7 +1,8 @@
(function(a){a.fn.pageSlide=function(f){function g(d){if(a("#pageslide-slide-wrap").width()!=0)return false;c.modal==true&&a("#pageslide-blanket").toggle().animate({opacity:"0.8"},"fast","linear");if(c.direction=="right"){direction={right:"-"+c.width};a("#pageslide-slide-wrap").css({left:0});a.browser.msie?a("body, html").css({overflowX:"hidden"}):a("body").css({overflowX:"hidden"})}else{direction={left:"-"+c.width};a("#pageslide-slide-wrap").css({right:0})}a("#pageslide-slide-wrap").animate({width:c.width},
-c.duration);a("#pageslide-body-wrap").animate(direction,c.duration,function(){var b=a(d).attr("href"),e=a("div[id="+b+"]");if(!c.ajaxReload&&e.length){e=e.html();h(e,b)}else a.ajax({type:"GET",url:b,success:function(j){h(j,b)}})})}function i(d){a(d)[0].button!=2&&a("#pageslide-slide-wrap").css("width")!="0px"&&a.fn.pageSlideClose(c)}var c=a.extend({width:"300px",duration:"normal",direction:"left",modal:false,ajaxReload:true,_identifier:a(this)},f),k={position:"fixed",width:"0",top:"0",height:"100%",
-zIndex:"999"},l={position:"relative",zIndex:"0"},m={position:"absolute",top:"0px",left:"0px",height:"100%",width:"100%",opacity:"0.0",backgroundColor:"black",zIndex:"1",display:"none"},h=function(d,b){a("#pageslide-content").css("width",c.width).html(d).queue(function(){a(this).dequeue();a(this).find(".pageslide-close").unbind("click").click(function(e){i(e);a(this).find("pageslide-close").unbind("click")})});c.ajaxReload||a("<div>").attr("id",b).html(d).appendTo("body").hide()};(function(d){if(a("#pageslide-body-wrap, #pageslide-content, #pageslide-slide-wrap").size()==
-0){var b=document.createElement("div");a(b).css(l);a(b).attr("id","pageslide-body-wrap").width(a("body").width());a("body").contents().wrapAll(b);b=document.createElement("div");a(b).attr("id","pageslide-content").width(c.width);var e=document.createElement("div");a(e).css(k);a(e).attr("id","pageslide-slide-wrap").append(b);a("body").append(e)}if(a("#pageslide-blanket").size()==0&&c.modal==true){b=document.createElement("div");a(b).css(m);a(b).attr("id","pageslide-blanket");a("body").append(b);a("#pageslide-blanket").click(function(){return false})}a(window).resize(function(){a("#pageslide-body-wrap").width(a("body").width())});
-a(d).attr("rel","pageslide")})(this);return this.each(function(){a(this).unbind("click").bind("click",function(){g(this);a("#pageslide-slide-wrap").unbind("click").click(function(d){if(d.target.tagName!="A")return false});c.modal!=true&&a(document).unbind("click").click(function(d){if(d.target.tagName!="A"){i(d);return false}});return false})})}})(jQuery);
+c.duration);a("#pageslide-body-wrap").animate(direction,c.duration,function(){var b=a(d).attr("href"),e=c.idPrefix+b.replace(".",""),h=a("div#pageSlideStore").find("div#"+e);if(!c.ajaxReload&&h.length){b=h.html();i(b,e)}else a.ajax({type:"GET",url:b,success:function(k){i(k,e)}})})}function j(d){a(d)[0].button!=2&&a("#pageslide-slide-wrap").css("width")!="0px"&&a.fn.pageSlideClose(c)}var c=a.extend({width:"300px",duration:"normal",direction:"left",modal:false,ajaxReload:true,idPrefix:"slide",_identifier:a(this)},
+f),l={position:"fixed",width:"0",top:"0",height:"100%",zIndex:"999"},m={position:"relative",zIndex:"0"},n={position:"absolute",top:"0px",left:"0px",height:"100%",width:"100%",opacity:"0.0",backgroundColor:"black",zIndex:"1",display:"none"},i=function(d,b){a("#pageslide-content").css("width",c.width).html(d).queue(function(){a(this).dequeue();a(this).find(".pageslide-close").unbind("click").click(function(h){j(h);a(this).find("pageslide-close").unbind("click")})});var e=a("div#pageSlideStore").find("div#"+
+b);!c.ajaxReload&&!e.length&&a("<div></div>").attr("id",b).html(d).appendTo("body div#pageSlideStore").hide()};(function(d){if(a("#pageslide-body-wrap, #pageslide-content, #pageslide-slide-wrap").size()==0){var b=document.createElement("div");a(b).css(m);a(b).attr("id","pageslide-body-wrap").width(a("body").width());a("body").contents().wrapAll(b);b=document.createElement("div");a(b).attr("id","pageslide-content").width(c.width);var e=document.createElement("div");a(e).css(l);a(e).attr("id","pageslide-slide-wrap").append(b);
+a("body").append(e)}if(a("#pageslide-blanket").size()==0&&c.modal==true){b=document.createElement("div");a(b).css(n);a(b).attr("id","pageslide-blanket");a("body").append(b);a("#pageslide-blanket").click(function(){return false})}c.ajaxReload||a("div#pageSlideStore").length||a("<div>").attr("id","pageSlideStore").appendTo("body");a(window).resize(function(){a("#pageslide-body-wrap").width(a("body").width())});a(d).attr("rel","pageslide")})(this);return this.each(function(){a(this).unbind("click").bind("click",
+function(){g(this);a("#pageslide-slide-wrap").unbind("click").click(function(d){if(d.target.tagName!="A")return false});c.modal!=true&&a(document).unbind("click").click(function(d){if(d.target.tagName!="A"){j(d);return false}});return false})})}})(jQuery);
(function(a){a.fn.pageSlideClose=function(f){var g=a.extend({width:"300px",duration:"normal",direction:"left",modal:false,_identifier:a(this)},f);(function(){g.modal==true&&a("#pageslide-blanket").is(":visible")&&a("#pageslide-blanket").animate({opacity:"0.0"},"fast","linear",function(){a(this).hide()})})();direction=a("#pageslide-slide-wrap").css("left")!="0px"?{left:"0"}:{right:"0"};a("#pageslide-body-wrap").animate(direction,g.duration);a("#pageslide-slide-wrap").animate({width:"0"},g.duration,
function(){a("#pageslide-content").css("width","0px").empty();a("#pageslide-body-wrap, #pageslide-slide-wrap").css("left","");a("#pageslide-body-wrap, #pageslide-slide-wrap").css("right","");a.browser.msie?a("body, html").css({overflowX:""}):a("body").css({overflowX:""})})}})(jQuery);(function(a){a(document).ready(function(){a(document).keyup(function(f){!a("#pageslide-blanket").is(":visible")&&f.keyCode==27&&a.fn.pageSlideClose()})})})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.