gramps/data/javascript/jquery.flexbox.min.js
John Ralls 3fd0762ae0 Move the HTML resources from gramps/plugins/webstuff to data and images
So that they're together with the other resources instead of in 
site-package/gramps. Aside from a better source and installation 
layout, this makes it easier to bundle them.



svn: r22576
2013-06-23 22:47:25 +00:00

10 lines
13 KiB
JavaScript

/*
* jQuery FlexBox $Version: 0.9.6 $
*
* Copyright (c) 2008-2010 Noah Heldman and Fairway Technologies (http://www.fairwaytech.com/flexbox)
* Licensed under Ms-PL (http://www.codeplex.com/flexbox/license)
*
* $Date: 2010-11-24 01:02:00 PM $
* $Rev: 0.9.6.1 $
*/
(function(a){a.flexbox=function(N,I){var K=false,p=[],J=[],f=0,l="\u25CA",Q=false,x=I.paging&&I.paging.pageSize?I.paging.pageSize:0,F=false,D=a(N).css("position","relative").css("z-index",0);var P=a('<input type="hidden"/>').attr("id",D.attr("id")+"_hidden").attr("name",D.attr("id")).val(I.initialId).appendTo(D);var z=a("<input/>").attr("id",D.attr("id")+"_input").attr("autocomplete","off").addClass(I.inputClass).css("width",I.width+"px").appendTo(D).click(function(o){if(I.watermark!==""&&this.value===I.watermark){this.value=""}else{this.select()}}).focus(function(o){a(this).removeClass("watermark")}).blur(function(o){if(this.value===""){P.val("")}setTimeout(function(){if(!z.data("active")){b()}},200)}).keydown(L);if(I.initialValue!==""){z.val(I.initialValue).removeClass("watermark")}else{z.val(I.watermark).addClass("watermark")}var g=0;if(I.showArrow&&I.showResults){var E=function(){if(q.is(":visible")){b()}else{z.focus();if(I.watermark!==""&&z.val()===I.watermark){z.val("")}else{z.select()}if(K){clearTimeout(K)}K=setTimeout(function(){G(1,true,I.arrowQuery)},I.queryDelay)}};var i=a("<span></span>").attr("id",D.attr("id")+"_arrow").addClass(I.arrowClass).addClass("out").hover(function(){a(this).removeClass("out").addClass("over")},function(){a(this).removeClass("over").addClass("out")}).mousedown(function(){a(this).removeClass("over").addClass("active")}).mouseup(function(){a(this).removeClass("active").addClass("over")}).click(E).appendTo(D);g=i.width();z.css("width",(I.width-g)+"px")}if(!I.allowInput){I.selectFirstMatch=false;z.click(E)}var O=z.outerHeight()-z.height()-2;var s=z.outerWidth()-2;var j=z.outerHeight();if(O===0){s+=4;j+=4}else{if(O!==4){s+=O;j+=O}}var q=a("<div></div>").attr("id",D.attr("id")+"_ctr").css("width",s+g).css("top",j).css("left",0).addClass(I.containerClass).appendTo(D).mousedown(function(o){z.data("active",true)}).hide();var c=a("<div></div>").addClass(I.contentClass).appendTo(q).scroll(function(){Q=true});var u=a("<div></div>").appendTo(q);D.css("height",z.outerHeight());function L(X){var V=0;if(typeof(X.ctrlKey)!=="undefined"){if(X.ctrlKey){V|=1}if(X.shiftKey){V|=2}}else{if(X.modifiers&Event.CONTROL_MASK){V|=1}if(X.modifiers&Event.SHIFT_MASK){V|=2}}if(/16$|17$/.test(X.keyCode)){return}var W=X.keyCode===9,U=X.keyCode===27;var T=X.keyCode===9&&V>0;var o=X.keyCode===8;if(W){if(k()){w()}}if((/27$|38$|33$|34$/.test(X.keyCode)&&q.is(":visible"))||(/13$|40$/.test(X.keyCode))||!I.allowInput){if(X.preventDefault){X.preventDefault()}if(X.stopPropagation){X.stopPropagation()}X.cancelBubble=true;X.returnValue=false;switch(X.keyCode){case 38:M();break;case 40:if(q.is(":visible")){t()}else{v(true)}break;case 13:if(k()){w()}else{v(true)}break;case 27:b();break;case 34:if(!F){if(I.paging){a("#"+D.attr("id")+"n").click()}else{R()}}break;case 33:if(!F){if(I.paging){a("#"+D.attr("id")+"p").click()}else{H()}}break;default:if(!I.allowInput){return}}}else{if(!U&&!W&&!T){v(false,o)}}}function v(o,U){if(K){clearTimeout(K)}var T=U?I.queryDelay*5:I.queryDelay;K=setTimeout(function(){G(1,o,"")},T)}function G(W,T,V){if(T){V=""}var U=V&&V.length>0?V:a.trim(z.val());if(U.length>=I.minChars||T){if(c.outerHeight()>0){c.css("height",c.outerHeight())}c.html("").attr("scrollTop",0);var o=n(U,W);if(o){c.css("height","auto");A(o.data,U);e(W,o.t)}else{var X={q:U,p:W,s:x,contentType:"application/json; charset=utf-8"};var Y=function(af,ac){if(ac===true){U=ac}var aa=parseInt(af[I.totalProperty]);if(isNaN(aa)&&I.paging){if(I.maxCacheBytes<=0){alert('The "maxCacheBytes" configuration option must be greater\nthan zero when implementing client-side paging.')}aa=af[I.resultsProperty].length;var Z=aa/x;if(aa%x>0){Z=parseInt(++Z)}for(var ae=1;ae<=Z;ae++){var ad={};ad[I.totalProperty]=aa;ad[I.resultsProperty]=af[I.resultsProperty].splice(0,x);if(ae===1){ab=A(ad,U)}S(U,ae,x,aa,ad,ab)}}else{var ab=A(af,U);S(U,W,x,aa,af,ab)}e(W,aa);c.css("height","auto");F=false};if(typeof(I.source)==="object"){if(I.allowInput){Y(B(I.source,X))}else{Y(I.source)}}else{F=true;if(I.method.toUpperCase()=="POST"){a.post(I.source,X,Y,"json")}else{a.getJSON(I.source,X,Y)}}}}else{b()}}function B(X,Y){var T={};T[I.resultsProperty]=[];T[I.totalProperty]=0;var o=0;for(var V=0;V<X[I.resultsProperty].length;V++){var W=X[I.resultsProperty][V][I.displayValue].toLowerCase().indexOf(Y.q.toLowerCase());if((I.matchAny&&W!==-1)||(!I.matchAny&&W===0)){T[I.resultsProperty][o++]=X[I.resultsProperty][V];T[I.totalProperty]+=1}}if(I.paging){var Z=(Y.p-1)*Y.s;var U=(Z+Y.s)>T[I.totalProperty]?T[I.totalProperty]-Z:Y.s;T[I.resultsProperty]=T[I.resultsProperty].splice(Z,U)}return T}function e(U,T){u.html("").removeClass(I.paging.cssClass);if(I.showResults&&I.paging&&T>x){var o=T/x;if(T%x>0){o=parseInt(++o)}h(o,U,T)}}function r(U,T,o){if(/^13$|^39$|^37$/.test(U.keyCode)){if(U.preventDefault){U.preventDefault()}if(U.stopPropagation){U.stopPropagation()}U.cancelBubble=true;U.returnValue=false;switch(U.keyCode){case 13:if(/^\d+$/.test(T)&&T>0&&T<=o){G(T,true)}else{alert("Please enter a page number between 1 and "+o)}break;case 39:a("#"+D.attr("id")+"n").click();break;case 37:a("#"+D.attr("id")+"p").click();break}}}function y(o){G(parseInt(a(this).attr("page")),true,z.attr("pq"));return false}function h(aj,af,X){var U="&lt;&lt;",ac="&lt;",ad="&gt;",W="&gt;&gt;",T="...";u.addClass(I.paging.cssClass);var aa=a("<a/>").attr("href","#").addClass("page").click(y),ai=a("<span></span>").addClass("page"),V=D.attr("id");if(af>1){aa.clone(true).attr("id",V+"f").attr("page",1).html(U).appendTo(u);aa.clone(true).attr("id",V+"p").attr("page",af-1).html(ac).appendTo(u)}else{ai.clone(true).html(U).appendTo(u);ai.clone(true).html(ac).appendTo(u)}if(I.paging.style==="links"){var o=I.paging.maxPageLinks;if(aj<=o){for(var ag=1;ag<=aj;ag++){if(ag===af){ai.clone(true).html(af).appendTo(u)}else{aa.clone(true).attr("page",ag).html(ag).appendTo(u)}}}else{if((af+parseInt(o/2))>aj){startPage=aj-o+1}else{startPage=af-parseInt(o/2)}if(startPage>1){aa.clone(true).attr("page",startPage-1).html(T).appendTo(u)}else{startPage=1}for(var ag=startPage;ag<startPage+o;ag++){if(ag===af){ai.clone(true).html(ag).appendTo(u)}else{aa.clone(true).attr("page",ag).html(ag).appendTo(u)}}if(aj>(startPage+o)){aa.clone(true).attr("page",ag).html(T).appendTo(u)}}}else{if(I.paging.style==="input"){var ae=a("<input/>").addClass("box").click(function(ak){this.select()}).keypress(function(ak){return r(ak,this.value,aj)}).val(af).appendTo(u)}}if(af<aj){aa.clone(true).attr("id",V+"n").attr("page",+af+1).html(ad).appendTo(u);aa.clone(true).attr("id",V+"l").attr("page",aj).html(W).appendTo(u)}else{ai.clone(true).html(ad).appendTo(u);ai.clone(true).html(W).appendTo(u)}var Z=(af-1)*x+1;var ab=(Z>(X-x))?X:Z+x-1;if(I.paging.showSummary){var ah={start:Z,end:ab,total:X,page:af,pages:aj};var Y=I.paging.summaryTemplate.applyTemplate(ah);a("<br/>").appendTo(u);a("<span></span>").addClass(I.paging.summaryClass).html(Y).appendTo(u)}}function n(U,V){var T=U+l+V;if(J[T]){for(var o=0;o<p.length;o++){if(p[o]===T){p.unshift(p.splice(o,1)[0]);return J[T]}}}return false}function S(Y,Z,W,U,X,T){if(I.maxCacheBytes>0){while(p.length&&(f+T>I.maxCacheBytes)){var V=p.pop();f-=V.size}var o=Y+l+Z;J[o]={q:Y,p:Z,s:W,t:U,size:T,data:X};p.push(o);f+=T}}function A(ab,T){var ad=0,o=0;if(!ab){return}P.val(z.val());if(parseInt(ab[I.totalProperty])===0&&I.noResultsText&&I.noResultsText.length>0){c.addClass(I.noResultsClass).html(I.noResultsText);q.show();return}else{c.removeClass(I.noResultsClass)}for(var X=0;X<ab[I.resultsProperty].length;X++){var V=ab[I.resultsProperty][X],ag=I.resultTemplate.applyTemplate(V),W=T===ag,U=false,af=false,Y=V[I.displayValue];if(!W&&I.highlightMatches&&T!==""){var aa=T,ac=Y.toLowerCase().indexOf(T.toLowerCase()),Z='<span class="'+I.matchClass+'">'+Y.substr(ac,T.length)+"</span>";if(ag.match("<(.|\n)*?>")){af=true;aa="(>)([^<]*?)("+T+")((.|\n)*?)(<)";Z='$1$2<span class="'+I.matchClass+'">$3</span>$4$6'}ag=ag.replace(new RegExp(aa.replace("[", "\\["),I.highlightMatchesRegExModifier),Z)}if(I.autoCompleteFirstMatch&&!af&&X===0){if(T.length>0&&Y.toLowerCase().indexOf(T.toLowerCase())===0){z.attr("pq",T);P.val(V[I.hiddenValue]);z.val(V[I.displayValue]);U=m(T.length,z.val().length)}}if(!I.showResults){return}$row=a("<div></div>").attr("id",V[I.hiddenValue]).attr("val",V[I.displayValue]).addClass("row").html(ag).appendTo(c);if(W||(++o==1&&I.selectFirstMatch)||U){$row.addClass(I.selectClass)}ad+=ag.length}if(ad===0){b();return}q.parent().css("z-index",11000);q.show();c.children("div").mouseover(function(){c.children("div").removeClass(I.selectClass);a(this).addClass(I.selectClass)}).mouseup(function(ah){ah.preventDefault();ah.stopPropagation();w()});if(I.maxVisibleRows>0){var ae=$row.outerHeight()*I.maxVisibleRows;c.css("max-height",ae)}return ad}function m(U,T){var o=z[0];if(o.createTextRange){var V=o.createTextRange();V.moveStart("character",U);V.moveEnd("character",T-o.value.length);V.select()}else{if(o.setSelectionRange){o.setSelectionRange(U,T)}}o.focus();return true}String.prototype.applyTemplate=function(T){try{if(T===""){return this}return this.replace(/{([^{}]*)}/g,function(V,U){var Y;if(U.indexOf(".")!==-1){var X=U.split(".");var Z=T;for(var W=0;W<X.length;W++){Z=Z[X[W]]}Y=Z}else{Y=T[U]}if(typeof Y==="string"||typeof Y==="number"){return Y}else{throw (V)}})}catch(o){alert("Invalid JSON property "+o+" found when trying to apply resultTemplate or paging.summaryTemplate.\nPlease check your spelling and try again.")}};function b(){z.data("active",false);D.css("z-index",0);q.hide()}function k(){if(!q.is(":visible")){return false}var o=c.children("div."+I.selectClass);if(!o.length){o=false}return o}function w(){$curr=k();if($curr){P.val($curr.attr("id"));z.val($curr.attr("val")).focus();b();if(I.onSelect){I.onSelect.apply(z[0])}}}function C(){try{document.getBoxObjectFor(document.body);return true}catch(o){return false}}function d(){try{document.body.getBoundingClientRect();return true}catch(o){return false}}function R(){$curr=k();if($curr&&$curr.next().length>0){$curr.removeClass(I.selectClass);for(var o=0;o<I.maxVisibleRows;o++){if($curr.next().length>0){$curr=$curr.next()}}$curr.addClass(I.selectClass);var T=c.attr("scrollTop");c.attr("scrollTop",T+c.height())}else{if(!$curr){c.children("div:first-child").addClass(I.selectClass)}}}function H(){$curr=k();if($curr&&$curr.prev().length>0){$curr.removeClass(I.selectClass);for(var o=0;o<I.maxVisibleRows;o++){if($curr.prev().length>0){$curr=$curr.prev()}}$curr.addClass(I.selectClass);var T=c.attr("scrollTop");c.attr("scrollTop",T-c.height())}else{if(!$curr){c.children("div:last-child").addClass(I.selectClass)}}}function t(){$curr=k();if($curr&&$curr.next().length>0){$curr.removeClass(I.selectClass).next().addClass(I.selectClass);var X=c.attr("scrollTop"),W=$curr[0],V,T,o;if(C()){V=document.getBoxObjectFor(c[0]).y+c.attr("offsetHeight");T=document.getBoxObjectFor(W).y+$curr.attr("offsetHeight");o=document.getBoxObjectFor(W).height}else{if(d()){V=c[0].getBoundingClientRect().bottom;var U=W.getBoundingClientRect();T=U.bottom;o=T-U.top}}if(T>=V){c.attr("scrollTop",X+o)}}else{if(!$curr){c.children("div:first-child").addClass(I.selectClass)}}}function M(){$curr=k();if($curr&&$curr.prev().length>0){$curr.removeClass(I.selectClass).prev().addClass(I.selectClass);var Y=c.attr("scrollTop"),X=$curr[0],T=$curr.parent()[0],V,W,o;if(C()){o=document.getBoxObjectFor(X).height;V=document.getBoxObjectFor(c[0]).y-(o*2);W=document.getBoxObjectFor(X).y-document.getBoxObjectFor(c[0]).y}else{if(d()){V=T.getBoundingClientRect().top;var U=X.getBoundingClientRect();W=U.top;o=U.bottom-W}}if(W<=V){c.attr("scrollTop",Y-o)}}else{if(!$curr){c.children("div:last-child").addClass(I.selectClass)}}}};a.fn.flexbox=function(d,b){if(!d){return}try{var e=a.fn.flexbox.defaults;var f=a.extend({},e,b);for(var g in f){if(e[g]===undefined){throw ("Invalid option specified: "+g+"\nPlease check your spelling and try again.")}}f.source=d;if(b){f.paging=(b.paging||b.paging==null)?a.extend({},e.paging,b.paging):false;for(var g in f.paging){if(e.paging[g]===undefined){throw ("Invalid option specified: "+g+"\nPlease check your spelling and try again.")}}if(b.displayValue&&!b.hiddenValue){f.hiddenValue=b.displayValue}}this.each(function(){new a.flexbox(this,f)});return this}catch(c){if(typeof c==="object"){alert(c.message)}else{alert(c)}}};a.fn.flexbox.defaults={method:"GET",queryDelay:100,allowInput:true,containerClass:"ffb",contentClass:"content",selectClass:"ffb-sel",inputClass:"ffb-input",arrowClass:"ffb-arrow",matchClass:"ffb-match",noResultsText:"No matching results",noResultsClass:"ffb-no-results",showResults:true,selectFirstMatch:true,autoCompleteFirstMatch:false,highlightMatches:true,highlightMatchesRegExModifier:"i",matchAny:true,minChars:1,showArrow:true,arrowQuery:"",onSelect:false,maxCacheBytes:32768,resultTemplate:"{name}",displayValue:"name",hiddenValue:"id",initialValue:"",initialId:"",watermark:"",width:200,resultsProperty:"results",totalProperty:"total",maxVisibleRows:0,paging:{style:"input",cssClass:"paging",pageSize:10,maxPageLinks:5,showSummary:true,summaryClass:"summary",summaryTemplate:"Displaying {start}-{end} of {total} results"}};a.fn.setValue=function(b){var c="#"+this.attr("id");a(c+"_hidden,"+c+"_input").val(b).removeClass("watermark")}})(jQuery);