/**
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates.
 * All rights reserved.
 */
"use strict";
/*
 Copyright 2013 jQuery Foundation and other contributors
 Released under the MIT license.
 http://jquery.org/license
*/
define(["ojs/ojcore","jquery","hammerjs","promise","ojs/ojjquery-hammer","ojs/ojcomponentcore"],function(b,f,a){(function(){b.ya("oj.ojIndexer",f.oj.baseComponent,{defaultElement:"\x3cul\x3e",version:"1.2",widgetEventPrefix:"oj",options:{data:null},_ComponentCreate:function(){this._super();this.Aa()},hf:function(){var a;this._super();this.VT();this.u_();this.Gaa();a=this.Gn()[0];this.tj(a);this.$ia(a)},_destroy:function(){var a,c;this._super();this.Jla();this.element.removeClass("oj-component-initnode");
a=this.Gn()[0];this.Ek(a);this.Ila(a);c=this.AB();null!=c&&this.iO&&c.off(b.te.D.B5,this.iO);b.v.unwrap(this.element,f(a))},_setOption:function(a,b){this._superApply(arguments);"data"==a&&this.refresh()},widget:function(){return this.Gn()},refresh:function(){this._super();this.element.empty();this.VT();this.u_();this.jr=null},getNodeBySubId:function(a){var b,e,g,h,k;if(null==a)return this.element?this.element[0]:null;if("oj-indexer-prefix"===a.subId)for(a=a.prefix,b=this.element.children("li"),e=
0;e<b.length;e++){h=b.get(e);if(f(h).attr("data-range")==a)return h;k=f(h).attr("data-includes");if(null!=k)for(k=k.split("|"),g=0;g<k.length;g++)if(k[g]==a)return h}return null},getSubIdByNode:function(a){return null!=a&&(a=f(a).attr("data-range"),null!=a)?{subId:"oj-indexer-prefix",prefix:a}:null},u_:function(){this.element.attr("role","slider").attr("aria-orientation","vertical").attr("aria-describedby",this.element.prop("id")+":desc").attr("aria-valuemin",0).attr("aria-valuemax",Math.max(0,this.element.children().length-
1))},Jla:function(){this.element.removeAttr("role").removeAttr("aria-orientation").removeAttr("aria-describedby").removeAttr("aria-valuemin").removeAttr("aria-valuemax").removeAttr("aria-valuetext")},Gaa:function(){var a,c;a=b.v.Od()?"ariaTouchInstructionText":"ariaKeyboardInstructionText";c=f(document.createElement("div"));c.prop("id",this.element.prop("id")+":desc");c.addClass("oj-helper-hidden-accessible").text(this.A(a));this.Gn().append(c)},Gn:function(){null==this.Oy&&(this.Oy=this.Eaa());return this.Oy},
Eaa:function(){var a=f(document.createElement("div"));a.addClass("oj-indexer oj-component");this.element.parent()[0].replaceChild(a[0],this.element[0]);a.prepend(this.element);return a},VT:function(){var a,b,e,f,h,k,l;a=this.AB();if(null!=a){b=this.element;e=a.getIndexablePrefixes();f=a.getPrefixes();a=this.A("indexerOthers");h=this.widget().outerHeight();k=this.NA(e[0],f);b.append(k);k=k.outerHeight();h=Math.floor(h/k);this.Gn().removeClass("oj-indexer-abbr");h=Math.floor((e.length+1)/h)+1;1<h&&
this.Gn().addClass("oj-indexer-abbr");for(k=1+h;k<e.length;k=k+h+1)1<h?(l=this.$aa(e,k-h,k-1),b.append(l)):k--,l=e[k],l=this.NA(l,f),b.append(l);e=this.NA(e[e.length-1],f);b.append(e);e=this.NA(a);e.attr("data-others","true");b.append(e)}},NA:function(a,b){var e=f(document.createElement("li"));e.attr("data-range",a).text(a);null!=b&&-1==b.indexOf(a)&&e.addClass("oj-disabled");return e},$aa:function(a,b,e){var g,h="";g=f(document.createElement("li"));for(g.addClass("oj-indexer-ellipsis").attr("data-range",
a[b+Math.round((e-b)/2)]);b<e;b++)h=h+a[b]+"|";h+=a[e];g.attr("data-includes",h);return g},Aa:function(){var a=this,c;this.element.uniqueId().addClass("oj-component-initnode").attr("tabIndex",0);this._on(this.element,{click:function(b){a.sea(b)},keydown:function(b){a.nq(b)},focus:function(b){a.Rea(b)},blur:function(b){a.nea(b)}});c=this.AB();null!=c&&(this.iO=function(){a.refresh()},c.on(b.te.D.B5,this.iO))},sea:function(a){0===a.button&&(a=f(a.target),this.uL(a))},Rea:function(){this.Gn().addClass("oj-focus-ancestor");
null==this.jr&&this.eo(this.element.children("li").first())},nea:function(){this.Gn().removeClass("oj-focus-ancestor")},nq:function(a){var b,e=!1;switch(a.keyCode){case 38:b=this.jr.prev();break;case 40:b=this.jr.next();break;case 13:this.uL(this.jr),e=!0}null!=b&&0<b.length&&(e=!0,this.eo(b));e&&a.preventDefault()},eo:function(a){null!=this.jr&&this.jr.removeClass("oj-focus");a.addClass("oj-focus");this.Mla(a);this.jr=a},AB:function(){var a=this.option("data");if(null!=a&&(void 0==a.setPrefix||void 0==
a.getIndexablePrefixes||void 0==a.getPrefixes))throw"Invalid IndexerModel";return a},uL:function(a){var c=a.attr("data-range");a.attr("data-others")&&(c=b.te.PREFIX_OTHERS);this.vL(c)},vL:function(a){var b=this,e;this.AB().setPrefix(a).then(function(a){null!=a&&(e=b.ij(a),null!=e&&b.eo(e))})},Mla:function(a){var c,e="";c=a.attr("data-includes");null!=c?(c=c.split("|"),0<c.length&&(e=this.A("ariaInBetweenText",{first:c[0],second:c[c.length-1]}))):(c=a.attr("data-range"),e=c===b.te.PREFIX_OTHERS?this.A("ariaOthersLabel"):
c);a.hasClass("oj-disabled")&&(e=e+". "+this.A("ariaDisabledLabel"));this.element.attr("aria-valuetext",e);this.element.attr("aria-valuenow",a.index())},ij:function(a){var b,e,g,h,k;b=this.element.children();for(e=0;e<b.length;e++)if(g=b.get(e),h=f(g).attr("data-range"),k=f(g).attr("data-includes"),null!=h&&h==a||null!=k&&-1<k.indexOf(a))return f(g);return null},Ek:function(a){a&&this.De&&b.v.Qh(a,this.De)},tj:function(a){a&&(null==this.De&&(this.De=this.Se.bind(this)),b.v.eh(a,this.De))},Ila:function(a){f(a).off("panstart panmove panend")},
$ia:function(b){var c=this,e,g,h,k,l,m,n,p,r,s,q,t;e={recognizers:[[a.Pan,{direction:a.DIRECTION_VERTICAL}]]};f(b).Zk(e).on("panstart",function(a){g=a.gesture.target;h=c.element[0].getBoundingClientRect().left+5;k=g.getBoundingClientRect().top;c.uL(f(g));l=g;m=g.getAttribute("data-range");n=k}).on("panmove",function(a){p=n;n=k+a.gesture.deltaY;g=document.elementFromPoint(h,n);null!=g&&(r=n-p,l==g?(s=g.getAttribute("data-includes"),null!=s&&(s=s.split("|"),q=s.indexOf(m),t=null,0<r&&q<s.length-1?t=
s[q+1]:0>r&&0<q&&(t=s[q-1]),null!=t&&(m=t,c.vL(t)))):g.hasAttribute("data-range")&&(s=g.getAttribute("data-includes"),t=null,null!=s&&(0<r&&g==l.nextElementSibling?t=s[0]:0>r&&g==l.previousElementSibling&&(t=s[s.length-1])),null==t&&(t=g.getAttribute("data-range")),l=g,m=t,c.vL(m)))}).on("panend",function(){t=n=m=l=null})},Se:function(a,b){0<a&&0<b&&this.refresh()}})})();b.Xf=function(a){this.ld=a;this.Init()};o_("ListViewIndexerModel",b.Xf,b);b.b.ga(b.Xf,b.Hg,"oj.ListViewIndexerModel");b.Xf.prototype.getIndexablePrefixes=
function(){return this.ld.W.A("indexerCharacters").split("|")};b.b.g("ListViewIndexerModel.prototype.getIndexablePrefixes",{getIndexablePrefixes:b.Xf.prototype.getIndexablePrefixes});b.Xf.prototype.getPrefixes=function(){null==this.FM&&(this.FM=this.Cca());return this.FM};b.b.g("ListViewIndexerModel.prototype.getPrefixes",{getPrefixes:b.Xf.prototype.getPrefixes});b.Xf.prototype.Cca=function(){var a=[],b=this.ld.xw();if(null!=b)for(var e=this.getIndexablePrefixes(),g=0;g<e.length;g++){var h=e[g];b.each(function(){if(0==
f(this).text().indexOf(h))return a.push(h),!1})}return a};b.Xf.prototype.setPrefix=function(a){return a==b.te.PREFIX_OTHERS?this.Aka():this.Bka(a)};b.b.g("ListViewIndexerModel.prototype.setPrefix",{setPrefix:b.Xf.prototype.setPrefix});b.Xf.prototype.Aka=function(){var a,c=this,e,g,h,k,l;a=this.getIndexablePrefixes();return new Promise(function(m){e=null;g=c.ld.xw();null!=g&&g.each(function(){h=f(this).text();for(k=0;k<a.length;k++)if(l=a[k],0==h.indexOf(l))return!0;e=this;return!1});e?(c.ld.n_(e),
m(b.te.PREFIX_OTHERS)):m(null)})};b.Xf.prototype.Bka=function(a){var b,e,f=this,h=null,k;b=this.getIndexablePrefixes();e=b.indexOf(a);return new Promise(function(l){if(-1==e)l(null);else{for(;e<b.length;){a=b[e];k=f.pca(a);if(null!=k){f.ld.n_(k);h=a;break}e++}l(h)}})};b.Xf.prototype.pca=function(a){var b,e,g;e=this.ld.xw();null!=e&&e.each(function(){g=f(this).text();if(0==g.indexOf(a))return b=this,!1});return b};b.Xf.prototype.W1=function(){this.FM=null;this.handleEvent(b.te.D.CHANGE,{})};b.te=function(){};
o_("IndexerModel",b.te,b);b.te.PREFIX_OTHERS="__others__";o_("IndexerModel.PREFIX_OTHERS",b.te.PREFIX_OTHERS,b);b.te.D={CHANGE:"change"};o_("IndexerModel.EventType",b.te.D,b);b.te.prototype.setPrefix=function(){};b.b.g("IndexerModel.prototype.setPrefix",{setPrefix:b.te.prototype.setPrefix});b.te.prototype.getIndexablePrefixes=function(){};b.b.g("IndexerModel.prototype.getIndexablePrefixes",{getIndexablePrefixes:b.te.prototype.getIndexablePrefixes});b.te.prototype.getPrefixes=function(){};b.b.g("IndexerModel.prototype.getPrefixes",
{getPrefixes:b.te.prototype.getPrefixes})});