forked from jmkphlp/slidious
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.slidious.min.js
10 lines (10 loc) · 3.81 KB
/
jquery.slidious.min.js
1
2
3
4
5
6
7
8
9
10
/**
* @file
* jQuery Slidious
*
* @version 0.9.3
* @author Christian Hanne <[email protected]>
* @link http://www.christianhanne.de
* @link http://demo.christianhanne.de/jquery_slidious
*/
(function(e){"use strict";e.fn.slidious=function(t,n,r){var i=this,s=null,o=0,u=0,a={},f={wrapper:"",wrapInit:false,autoScan:true,preLoad:"linked",anispeed:500,initUrl:"",hideMenu:true,links:[],onInit:function(){},onEnter:function(){},onLeave:function(){},onLoad:function(){}};a.init=function(){if(e("#slidious").size()===0){f=e.extend(f,t);f.elemsByPos={};f.elemsByUrl={};e("a",i).each(function(){if(e(this).attr("href")&&e(this).attr("data-x")&&e(this).attr("data-y")){var t={x:parseInt(e(this).attr("data-x"),10),y:parseInt(e(this).attr("data-y"),10),url:e.trim(e(this).attr("href"))},n=t.x+1,r=t.y+1,i=f.links.length;o=n>o?n:o;u=r>u?r:u;f.links.push(t);f.elemsByPos[t.x+"-"+t.y]=i;f.elemsByUrl[encodeURIComponent(t.url)]=i}});if(f.initUrl===""&&f.wrapInit===true){f.initUrl=location.href}else if(f.initUrl===""&&f.links.length>0){f.initUrl=f.links[0].url}if(f.hideMenu===true){i.css({display:"none"})}s=e("<div>").attr("id","slidious").data("slidious",f).css({top:0,left:0,width:o*100+"%",height:u*100+"%",position:"fixed"});var n=e("body");if(f.wrapInit!==true){n.append(s)}else{var r=a.getElementByUrl(f.initUrl);if(r){if(f.wrapper!==""){n=n.find(f.wrapper)}var l=a.getJQueryElement(r);l.find(".slidious-content").append(e("<div>").html(n.html()));s.append(l);n.html("").append(s)}}var c=null;for(var h in f.links){if(f.links.hasOwnProperty(h)){if(e("#slidious-"+f.links[h].x+"-"+f.links[h].y).size()===0){c=a.getJQueryElement(f.links[h]);s.append(c)}}}f.onInit(i,f);if(f.preLoad==="all"){a.preloadElements(f.links)}a.gotoUrl(f.initUrl)}else{s=e("#slidious");f=s.data("slidious")}};a.getJQueryElement=function(t){return e("<div>").attr("id","slidious-"+t.x+"-"+t.y).addClass("slidious-element").data(t).css({top:t.y*(100/u)+"%",left:t.x*(100/o)+"%",width:100/o+"%",height:100/u+"%",position:"absolute"}).append(e("<div>").addClass("slidious-content"))};a.getElementByUrl=function(t){var n=null,r=null;t=encodeURIComponent(e.trim(t))||"";r=f.elemsByUrl[t];if(r!==null){n=e.extend({},f.links[r])}return n};a.getElementByPosition=function(t,n){var r=null,i=null;i=f.elemsByPos[t+"-"+n];if(i!==null){r=e.extend({},f.links[i])}return r};a.gotoUrl=function(e){var t=a.getElementByUrl(e)||false;if(t){a.gotoElement(t)}};a.gotoElement=function(t){var n=e("#slidious-"+t.x+"-"+t.y),r=e(".slidious-active");if(n.hasClass("slidious-loaded")){f.onLeave(i,r,n);r.removeClass("slidious-active");s.animate({top:-1*t.y*100+"%",left:-1*t.x*100+"%"},f.speed,function(){f.onEnter(i,r,n);n.addClass("slidious-active")})}else{a.preloadElements([t],t)}};a.preloadElements=function(t,n){var r=e(".slidious-active");n=n||{};for(var s in t){if(t.hasOwnProperty(s)){var o=e("#slidious-"+t[s].x+"-"+t[s].y);if(!o.hasClass("slidious-loading")&&!o.hasClass("slidious-loaded")){o.addClass("slidious-loading");e.get(t[s].url,function(o){var u=a.getElementByUrl(this.url),l=[],c=e("<div>").html(o),h=e("#slidious-"+u.x+"-"+u.y);if(f.wrapper){c=c.find(f.wrapper)}c.appendTo(h.find(".slidious-content"));h.removeClass("slidious-loading").addClass("slidious-loaded");if(f.autoScan===true){h.find("a").not(".slidious-scanned").click(function(t){var n=a.getElementByUrl(e(this).attr("href"));if(n!==null){a.gotoElement(n);t.preventDefault()}}).each(function(){e(this).addClass("slidious-scanned");var t=a.getElementByUrl(e(this).attr("href"));if(t!==null){l.push(t)}})}f.onLoad(i,r,h);if(n.x===t[s].x&&n.y===t[s].y){if(f.preLoad==="linked"){a.preloadElements(l)}a.gotoElement(t[s])}},"html")}}}};switch(t){case"islocal":return a.getElementByUrl(n)!==null;case"goto":var l=null;if(n&&r){l=a.getElementByPosition(n,r)}else if(n){l=a.getElementByUrl(n)}if(l!==null){a.gotoElement(l)}return s;default:a.init();return s}}})(jQuery)