diff --git a/NEWS.md b/NEWS.md index ffcb93e51..a5639fd32 100644 --- a/NEWS.md +++ b/NEWS.md @@ -27,6 +27,14 @@ shiny 1.1.0.9001 * Fixed [#2093](https://github.com/rstudio/shiny/issues/2093): Make sure bookmark scope directory does not exist before trying to create it. [#2168](https://github.com/rstudio/shiny/pull/2168) +* Upgrade selectize.js from 0.12.1 to 0.12.4 [#2028](https://github.com/rstudio/shiny/issues/2028) + +* Addressed [#2079](https://github.com/rstudio/shiny/issues/2079): Added `coords_img`, `coords_css`, and `img_css_ratio` fields containing x and y location information for plot brush, hover, and click events. [#2183](https://github.com/rstudio/shiny/pull/2183) + +### Bug fixes + +* Fixed [#2033](https://github.com/rstudio/shiny/issues/2033): RStudio Viewer window not closed on `shiny::stopApp()`. Thanks, @vnijs! [#2047](https://github.com/rstudio/shiny/pull/2047) + ### Documentation Updates * Addressed [#1864](https://github.com/rstudio/shiny/issues/1864) by changing `optgroup` documentation to use `list` instead of `c`. ([#2084](https://github.com/rstudio/shiny/pull/2084)) diff --git a/R/bootstrap.R b/R/bootstrap.R index 2224f599e..445ee9b0c 100644 --- a/R/bootstrap.R +++ b/R/bootstrap.R @@ -1489,8 +1489,9 @@ downloadLink <- function(outputId, label="Download", class=NULL, ...) { #' \code{\link{navbarPage}}. #' #' @param name Name of icon. Icons are drawn from the -#' \href{http://fontawesome.io/icons/}{Font Awesome} and -#' \href{http://getbootstrap.com/components/#glyphicons}{Glyphicons"} +#' \href{https://fontawesome.com/v4.7.0/}{Font Awesome} (currently icons from +#' the v4.7.0 set are supported) and +#' \href{http://getbootstrap.com/components/#glyphicons}{Glyphicons} #' libraries. Note that the "fa-" and "glyphicon-" prefixes should not be used #' in icon names (i.e. the "fa-calendar" icon should be referred to as #' "calendar") diff --git a/R/image-interact.R b/R/image-interact.R index cad6291ea..8e072935a 100644 --- a/R/image-interact.R +++ b/R/image-interact.R @@ -86,6 +86,8 @@ brushedPoints <- function(df, brush, xvar = NULL, yvar = NULL, if (use_x) { if (is.null(xvar)) stop("brushedPoints: not able to automatically infer `xvar` from brush") + if (!(xvar %in% names(df))) + stop("brushedPoints: `xvar` ('", xvar ,"') not in names of input") # Extract data values from the data frame x <- asNumber(df[[xvar]]) keep_rows <- keep_rows & (x >= brush$xmin & x <= brush$xmax) @@ -93,6 +95,8 @@ brushedPoints <- function(df, brush, xvar = NULL, yvar = NULL, if (use_y) { if (is.null(yvar)) stop("brushedPoints: not able to automatically infer `yvar` from brush") + if (!(yvar %in% names(df))) + stop("brushedPoints: `yvar` ('", yvar ,"') not in names of input") y <- asNumber(df[[yvar]]) keep_rows <- keep_rows & (y >= brush$ymin & y <= brush$ymax) } @@ -118,6 +122,19 @@ brushedPoints <- function(df, brush, xvar = NULL, yvar = NULL, # $ xmax : num 4.22 # $ ymin : num 13.9 # $ ymax : num 19.8 +# $ coords_css:List of 4 +# ..$ xmin: int 260 +# ..$ xmax: int 298 +# ..$ ymin: num 112 +# ..$ ymax: num 205 +# $ coords_img:List of 4 +# ..$ xmin: int 325 +# ..$ xmax: num 372 +# ..$ ymin: num 140 +# ..$ ymax: num 257 +# $ img_css_ratio:List of 2 +# ..$ x: num 1.25 +# ..$ y: num 1.25 # $ mapping: Named list() # $ domain :List of 4 # ..$ left : num 1.36 @@ -143,6 +160,19 @@ brushedPoints <- function(df, brush, xvar = NULL, yvar = NULL, # $ ymax : num 20.4 # $ panelvar1: int 6 # $ panelvar2: int 0 +# $ coords_css:List of 4 +# ..$ xmin: int 260 +# ..$ xmax: int 298 +# ..$ ymin: num 112 +# ..$ ymax: num 205 +# $ coords_img:List of 4 +# ..$ xmin: int 325 +# ..$ xmax: num 372 +# ..$ ymin: num 140 +# ..$ ymax: num 257 +# $ img_css_ratio:List of 2 +# ..$ x: num 1.25 +# ..$ y: num 1.25 # $ mapping :List of 4 # ..$ x : chr "wt" # ..$ y : chr "mpg" @@ -245,20 +275,25 @@ nearPoints <- function(df, coordinfo, xvar = NULL, yvar = NULL, if (is.null(yvar)) stop("nearPoints: not able to automatically infer `yvar` from coordinfo") + if (!(xvar %in% names(df))) + stop("nearPoints: `xvar` ('", xvar ,"') not in names of input") + if (!(yvar %in% names(df))) + stop("nearPoints: `yvar` ('", yvar ,"') not in names of input") + # Extract data values from the data frame x <- asNumber(df[[xvar]]) y <- asNumber(df[[yvar]]) # Get the coordinates of the point (in img pixel coordinates) - point_img <- scaleCoords(coordinfo$x, coordinfo$y, coordinfo) + point_img <- coordinfo$coords_img # Get coordinates of data points (in img pixel coordinates) data_img <- scaleCoords(x, y, coordinfo) # Get x/y distances (in css coordinates) dist_css <- list( - x = (data_img$x - point_img$x) / coordinfo$pixelratio$x, - y = (data_img$y - point_img$y) / coordinfo$pixelratio$y + x = (data_img$x - point_img$x) / coordinfo$img_css_ratio$x, + y = (data_img$y - point_img$y) / coordinfo$img_css_ratio$y ) # Distances of data points to the target point, in css pixels. @@ -306,9 +341,15 @@ nearPoints <- function(df, coordinfo, xvar = NULL, yvar = NULL, # List of 7 # $ x : num 4.37 # $ y : num 12 -# $ pixelratio:List of 2 -# ..$ x: num 2 -# ..$ y: num 2 +# $ coords_css:List of 2 +# ..$ x: int 286 +# ..$ y: int 192 +# $ coords_img:List of 2 +# ..$ x: num 358 +# ..$ y: int 240 +# $ img_css_ratio:List of 2 +# ..$ x: num 1.25 +# ..$ y: num 1.25 # $ mapping : Named list() # $ domain :List of 4 # ..$ left : num 1.36 @@ -330,9 +371,15 @@ nearPoints <- function(df, coordinfo, xvar = NULL, yvar = NULL, # List of 9 # $ x : num 3.78 # $ y : num 17.1 -# $ pixelratio:List of 2 -# ..$ x: num 2 -# ..$ y: num 2 +# $ coords_css:List of 2 +# ..$ x: int 286 +# ..$ y: int 192 +# $ coords_img:List of 2 +# ..$ x: num 358 +# ..$ y: int 240 +# $ img_css_ratio:List of 2 +# ..$ x: num 1.25 +# ..$ y: num 1.25 # $ panelvar1 : int 6 # $ panelvar2 : int 0 # $ mapping :List of 4 diff --git a/inst/www/shared/selectize/css/selectize.bootstrap3.css b/inst/www/shared/selectize/css/selectize.bootstrap3.css index cfb2bfa2f..799a4114c 100644 --- a/inst/www/shared/selectize/css/selectize.bootstrap3.css +++ b/inst/www/shared/selectize/css/selectize.bootstrap3.css @@ -1,5 +1,5 @@ /** - * selectize.bootstrap3.css (v0.12.1) - Bootstrap 3 Theme + * selectize.bootstrap3.css (v0.12.4) - Bootstrap 3 Theme * Copyright (c) 2013–2015 Brian Reavis & contributors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this @@ -108,6 +108,12 @@ .selectize-control.plugin-remove_button .disabled [data-value] .remove { border-left-color: rgba(77, 77, 77, 0); } +.selectize-control.plugin-remove_button .remove-single { + position: absolute; + right: 28px; + top: 6px; + font-size: 23px; +} .selectize-control { position: relative; } @@ -276,6 +282,7 @@ overflow-y: auto; overflow-x: hidden; max-height: 200px; + -webkit-overflow-scrolling: touch; } .selectize-control.single .selectize-input, .selectize-control.single .selectize-input input { diff --git a/inst/www/shared/selectize/js/selectize.min.js b/inst/www/shared/selectize/js/selectize.min.js index fe955bc00..d11be61f6 100644 --- a/inst/www/shared/selectize/js/selectize.min.js +++ b/inst/www/shared/selectize/js/selectize.min.js @@ -1,3 +1,3 @@ -/*! selectize.js - v0.12.1 | https://github.com/brianreavis/selectize.js | Apache License (v2) */ -!function(a,b){"function"==typeof define&&define.amd?define("sifter",b):"object"==typeof exports?module.exports=b():a.Sifter=b()}(this,function(){var a=function(a,b){this.items=a,this.settings=b||{diacritics:!0}};a.prototype.tokenize=function(a){if(a=d(String(a||"").toLowerCase()),!a||!a.length)return[];var b,c,f,h,i=[],j=a.split(/ +/);for(b=0,c=j.length;c>b;b++){if(f=e(j[b]),this.settings.diacritics)for(h in g)g.hasOwnProperty(h)&&(f=f.replace(new RegExp(h,"g"),g[h]));i.push({string:j[b],regex:new RegExp(f,"i")})}return i},a.prototype.iterator=function(a,b){var c;c=f(a)?Array.prototype.forEach||function(a){for(var b=0,c=this.length;c>b;b++)a(this[b],b,this)}:function(a){for(var b in this)this.hasOwnProperty(b)&&a(this[b],b,this)},c.apply(a,[b])},a.prototype.getScoreFunction=function(a,b){var c,d,e,f;c=this,a=c.prepareSearch(a,b),e=a.tokens,d=a.options.fields,f=e.length;var g=function(a,b){var c,d;return a?(a=String(a||""),d=a.search(b.regex),-1===d?0:(c=b.string.length/a.length,0===d&&(c+=.5),c)):0},h=function(){var a=d.length;return a?1===a?function(a,b){return g(b[d[0]],a)}:function(b,c){for(var e=0,f=0;a>e;e++)f+=g(c[d[e]],b);return f/a}:function(){return 0}}();return f?1===f?function(a){return h(e[0],a)}:"and"===a.options.conjunction?function(a){for(var b,c=0,d=0;f>c;c++){if(b=h(e[c],a),0>=b)return 0;d+=b}return d/f}:function(a){for(var b=0,c=0;f>b;b++)c+=h(e[b],a);return c/f}:function(){return 0}},a.prototype.getSortFunction=function(a,c){var d,e,f,g,h,i,j,k,l,m,n;if(f=this,a=f.prepareSearch(a,c),n=!a.query&&c.sort_empty||c.sort,l=function(a,b){return"$score"===a?b.score:f.items[b.id][a]},h=[],n)for(d=0,e=n.length;e>d;d++)(a.query||"$score"!==n[d].field)&&h.push(n[d]);if(a.query){for(m=!0,d=0,e=h.length;e>d;d++)if("$score"===h[d].field){m=!1;break}m&&h.unshift({field:"$score",direction:"desc"})}else for(d=0,e=h.length;e>d;d++)if("$score"===h[d].field){h.splice(d,1);break}for(k=[],d=0,e=h.length;e>d;d++)k.push("desc"===h[d].direction?-1:1);return i=h.length,i?1===i?(g=h[0].field,j=k[0],function(a,c){return j*b(l(g,a),l(g,c))}):function(a,c){var d,e,f;for(d=0;i>d;d++)if(f=h[d].field,e=k[d]*b(l(f,a),l(f,c)))return e;return 0}:null},a.prototype.prepareSearch=function(a,b){if("object"==typeof a)return a;b=c({},b);var d=b.fields,e=b.sort,g=b.sort_empty;return d&&!f(d)&&(b.fields=[d]),e&&!f(e)&&(b.sort=[e]),g&&!f(g)&&(b.sort_empty=[g]),{options:b,query:String(a||"").toLowerCase(),tokens:this.tokenize(a),total:0,items:[]}},a.prototype.search=function(a,b){var c,d,e,f,g=this;return d=this.prepareSearch(a,b),b=d.options,a=d.query,f=b.score||g.getScoreFunction(d),a.length?g.iterator(g.items,function(a,e){c=f(a),(b.filter===!1||c>0)&&d.items.push({score:c,id:e})}):g.iterator(g.items,function(a,b){d.items.push({score:1,id:b})}),e=g.getSortFunction(d,b),e&&d.items.sort(e),d.total=d.items.length,"number"==typeof b.limit&&(d.items=d.items.slice(0,b.limit)),d};var b=function(a,b){return"number"==typeof a&&"number"==typeof b?a>b?1:b>a?-1:0:(a=h(String(a||"")),b=h(String(b||"")),a>b?1:b>a?-1:0)},c=function(a){var b,c,d,e;for(b=1,c=arguments.length;c>b;b++)if(e=arguments[b])for(d in e)e.hasOwnProperty(d)&&(a[d]=e[d]);return a},d=function(a){return(a+"").replace(/^\s+|\s+$|/g,"")},e=function(a){return(a+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")},f=Array.isArray||$&&$.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},g={a:"[aÀÁÂÃÄÅàáâãäåĀāąĄ]",c:"[cÇçćĆčČ]",d:"[dđĐďĎ]",e:"[eÈÉÊËèéêëěĚĒēęĘ]",i:"[iÌÍÎÏìíîïĪī]",l:"[lłŁ]",n:"[nÑñňŇńŃ]",o:"[oÒÓÔÕÕÖØòóôõöøŌō]",r:"[rřŘ]",s:"[sŠšśŚ]",t:"[tťŤ]",u:"[uÙÚÛÜùúûüůŮŪū]",y:"[yŸÿýÝ]",z:"[zŽžżŻźŹ]"},h=function(){var a,b,c,d,e="",f={};for(c in g)if(g.hasOwnProperty(c))for(d=g[c].substring(2,g[c].length-1),e+=d,a=0,b=d.length;b>a;a++)f[d.charAt(a)]=c;var h=new RegExp("["+e+"]","g");return function(a){return a.replace(h,function(a){return f[a]}).toLowerCase()}}();return a}),function(a,b){"function"==typeof define&&define.amd?define("microplugin",b):"object"==typeof exports?module.exports=b():a.MicroPlugin=b()}(this,function(){var a={};a.mixin=function(a){a.plugins={},a.prototype.initializePlugins=function(a){var c,d,e,f=this,g=[];if(f.plugins={names:[],settings:{},requested:{},loaded:{}},b.isArray(a))for(c=0,d=a.length;d>c;c++)"string"==typeof a[c]?g.push(a[c]):(f.plugins.settings[a[c].name]=a[c].options,g.push(a[c].name));else if(a)for(e in a)a.hasOwnProperty(e)&&(f.plugins.settings[e]=a[e],g.push(e));for(;g.length;)f.require(g.shift())},a.prototype.loadPlugin=function(b){var c=this,d=c.plugins,e=a.plugins[b];if(!a.plugins.hasOwnProperty(b))throw new Error('Unable to find "'+b+'" plugin');d.requested[b]=!0,d.loaded[b]=e.fn.apply(c,[c.plugins.settings[b]||{}]),d.names.push(b)},a.prototype.require=function(a){var b=this,c=b.plugins;if(!b.plugins.loaded.hasOwnProperty(a)){if(c.requested[a])throw new Error('Plugin has circular dependency ("'+a+'")');b.loadPlugin(a)}return c.loaded[a]},a.define=function(b,c){a.plugins[b]={name:b,fn:c}}};var b={isArray:Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)}};return a}),function(a,b){"function"==typeof define&&define.amd?define("selectize",["jquery","sifter","microplugin"],b):"object"==typeof exports?module.exports=b(require("jquery"),require("sifter"),require("microplugin")):a.Selectize=b(a.jQuery,a.Sifter,a.MicroPlugin)}(this,function(a,b,c){"use strict";var d=function(a,b){if("string"!=typeof b||b.length){var c="string"==typeof b?new RegExp(b,"i"):b,d=function(a){var b=0;if(3===a.nodeType){var e=a.data.search(c);if(e>=0&&a.data.length>0){var f=a.data.match(c),g=document.createElement("span");g.className="highlight";var h=a.splitText(e),i=(h.splitText(f[0].length),h.cloneNode(!0));g.appendChild(i),h.parentNode.replaceChild(g,h),b=1}}else if(1===a.nodeType&&a.childNodes&&!/(script|style)/i.test(a.tagName))for(var j=0;j/g,">").replace(/"/g,""")},B=function(a){return(a+"").replace(/\$/g,"$$$$")},C={};C.before=function(a,b,c){var d=a[b];a[b]=function(){return c.apply(a,arguments),d.apply(a,arguments)}},C.after=function(a,b,c){var d=a[b];a[b]=function(){var b=d.apply(a,arguments);return c.apply(a,arguments),b}};var D=function(a){var b=!1;return function(){b||(b=!0,a.apply(this,arguments))}},E=function(a,b){var c;return function(){var d=this,e=arguments;window.clearTimeout(c),c=window.setTimeout(function(){a.apply(d,e)},b)}},F=function(a,b,c){var d,e=a.trigger,f={};a.trigger=function(){var c=arguments[0];return-1===b.indexOf(c)?e.apply(a,arguments):void(f[c]=arguments)},c.apply(a,[]),a.trigger=e;for(d in f)f.hasOwnProperty(d)&&e.apply(a,f[d])},G=function(a,b,c,d){a.on(b,c,function(b){for(var c=b.target;c&&c.parentNode!==a[0];)c=c.parentNode;return b.currentTarget=c,d.apply(this,[b])})},H=function(a){var b={};if("selectionStart"in a)b.start=a.selectionStart,b.length=a.selectionEnd-b.start;else if(document.selection){a.focus();var c=document.selection.createRange(),d=document.selection.createRange().text.length;c.moveStart("character",-a.value.length),b.start=c.text.length-d,b.length=d}return b},I=function(a,b,c){var d,e,f={};if(c)for(d=0,e=c.length;e>d;d++)f[c[d]]=a.css(c[d]);else f=a.css();b.css(f)},J=function(b,c){if(!b)return 0;var d=a("").css({position:"absolute",top:-99999,left:-99999,width:"auto",padding:0,whiteSpace:"pre"}).text(b).appendTo("body");I(c,d,["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"]);var e=d.width();return d.remove(),e},K=function(a){var b=null,c=function(c,d){var e,f,g,h,i,j,k,l;c=c||window.event||{},d=d||{},c.metaKey||c.altKey||(d.force||a.data("grow")!==!1)&&(e=a.val(),c.type&&"keydown"===c.type.toLowerCase()&&(f=c.keyCode,g=f>=97&&122>=f||f>=65&&90>=f||f>=48&&57>=f||32===f,f===q||f===p?(l=H(a[0]),l.length?e=e.substring(0,l.start)+e.substring(l.start+l.length):f===p&&l.start?e=e.substring(0,l.start-1)+e.substring(l.start+1):f===q&&"undefined"!=typeof l.start&&(e=e.substring(0,l.start)+e.substring(l.start+1))):g&&(j=c.shiftKey,k=String.fromCharCode(c.keyCode),k=j?k.toUpperCase():k.toLowerCase(),e+=k)),h=a.attr("placeholder"),!e&&h&&(e=h),i=J(e,a)+4,i!==b&&(b=i,a.width(i),a.triggerHandler("resize")))};a.on("keydown keyup update blur",c),c()},L=function(c,d){var e,f,g,h,i=this;h=c[0],h.selectize=i;var j=window.getComputedStyle&&window.getComputedStyle(h,null);if(g=j?j.getPropertyValue("direction"):h.currentStyle&&h.currentStyle.direction,g=g||c.parents("[dir]:first").attr("dir")||"",a.extend(i,{order:0,settings:d,$input:c,tabIndex:c.attr("tabindex")||"",tagType:"select"===h.tagName.toLowerCase()?v:w,rtl:/rtl/i.test(g),eventNS:".selectize"+ ++L.count,highlightedValue:null,isOpen:!1,isDisabled:!1,isRequired:c.is("[required]"),isInvalid:!1,isLocked:!1,isFocused:!1,isInputHidden:!1,isSetup:!1,isShiftDown:!1,isCmdDown:!1,isCtrlDown:!1,ignoreFocus:!1,ignoreBlur:!1,ignoreHover:!1,hasOptions:!1,currentResults:null,lastValue:"",caretPos:0,loading:0,loadedSearches:{},$activeOption:null,$activeItems:[],optgroups:{},options:{},userOptions:{},items:[],renderCache:{},onSearchChange:null===d.loadThrottle?i.onSearchChange:E(i.onSearchChange,d.loadThrottle)}),i.sifter=new b(this.options,{diacritics:d.diacritics}),i.settings.options){for(e=0,f=i.settings.options.length;f>e;e++)i.registerOption(i.settings.options[e]);delete i.settings.options}if(i.settings.optgroups){for(e=0,f=i.settings.optgroups.length;f>e;e++)i.registerOptionGroup(i.settings.optgroups[e]);delete i.settings.optgroups}i.settings.mode=i.settings.mode||(1===i.settings.maxItems?"single":"multi"),"boolean"!=typeof i.settings.hideSelected&&(i.settings.hideSelected="multi"===i.settings.mode),i.initializePlugins(i.settings.plugins),i.setupCallbacks(),i.setupTemplates(),i.setup()};return e.mixin(L),c.mixin(L),a.extend(L.prototype,{setup:function(){var b,c,d,e,g,h,i,j,k,l=this,m=l.settings,n=l.eventNS,o=a(window),p=a(document),q=l.$input;if(i=l.settings.mode,j=q.attr("class")||"",b=a("
").addClass(m.wrapperClass).addClass(j).addClass(i),c=a("
").addClass(m.inputClass).addClass("items").appendTo(b),d=a('').appendTo(c).attr("tabindex",q.is(":disabled")?"-1":l.tabIndex),h=a(m.dropdownParent||b),e=a("
").addClass(m.dropdownClass).addClass(i).hide().appendTo(h),g=a("
").addClass(m.dropdownContentClass).appendTo(e),l.settings.copyClassesToDropdown&&e.addClass(j),b.css({width:q[0].style.width}),l.plugins.names.length&&(k="plugin-"+l.plugins.names.join(" plugin-"),b.addClass(k),e.addClass(k)),(null===m.maxItems||m.maxItems>1)&&l.tagType===v&&q.attr("multiple","multiple"),l.settings.placeholder&&d.attr("placeholder",m.placeholder),!l.settings.splitOn&&l.settings.delimiter){var u=l.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");l.settings.splitOn=new RegExp("\\s*"+u+"+\\s*")}q.attr("autocorrect")&&d.attr("autocorrect",q.attr("autocorrect")),q.attr("autocapitalize")&&d.attr("autocapitalize",q.attr("autocapitalize")),l.$wrapper=b,l.$control=c,l.$control_input=d,l.$dropdown=e,l.$dropdown_content=g,e.on("mouseenter","[data-selectable]",function(){return l.onOptionHover.apply(l,arguments)}),e.on("mousedown click","[data-selectable]",function(){return l.onOptionSelect.apply(l,arguments)}),G(c,"mousedown","*:not(input)",function(){return l.onItemSelect.apply(l,arguments)}),K(d),c.on({mousedown:function(){return l.onMouseDown.apply(l,arguments)},click:function(){return l.onClick.apply(l,arguments)}}),d.on({mousedown:function(a){a.stopPropagation()},keydown:function(){return l.onKeyDown.apply(l,arguments)},keyup:function(){return l.onKeyUp.apply(l,arguments)},keypress:function(){return l.onKeyPress.apply(l,arguments)},resize:function(){l.positionDropdown.apply(l,[])},blur:function(){return l.onBlur.apply(l,arguments)},focus:function(){return l.ignoreBlur=!1,l.onFocus.apply(l,arguments)},paste:function(){return l.onPaste.apply(l,arguments)}}),p.on("keydown"+n,function(a){l.isCmdDown=a[f?"metaKey":"ctrlKey"],l.isCtrlDown=a[f?"altKey":"ctrlKey"],l.isShiftDown=a.shiftKey}),p.on("keyup"+n,function(a){a.keyCode===t&&(l.isCtrlDown=!1),a.keyCode===r&&(l.isShiftDown=!1),a.keyCode===s&&(l.isCmdDown=!1)}),p.on("mousedown"+n,function(a){if(l.isFocused){if(a.target===l.$dropdown[0]||a.target.parentNode===l.$dropdown[0])return!1;l.$control.has(a.target).length||a.target===l.$control[0]||l.blur(a.target)}}),o.on(["scroll"+n,"resize"+n].join(" "),function(){l.isOpen&&l.positionDropdown.apply(l,arguments)}),o.on("mousemove"+n,function(){l.ignoreHover=!1}),this.revertSettings={$children:q.children().detach(),tabindex:q.attr("tabindex")},q.attr("tabindex",-1).hide().after(l.$wrapper),a.isArray(m.items)&&(l.setValue(m.items),delete m.items),x&&q.on("invalid"+n,function(a){a.preventDefault(),l.isInvalid=!0,l.refreshState()}),l.updateOriginalInput(),l.refreshItems(),l.refreshState(),l.updatePlaceholder(),l.isSetup=!0,q.is(":disabled")&&l.disable(),l.on("change",this.onChange),q.data("selectize",l),q.addClass("selectized"),l.trigger("initialize"),m.preload===!0&&l.onSearchChange("")},setupTemplates:function(){var b=this,c=b.settings.labelField,d=b.settings.optgroupLabelField,e={optgroup:function(a){return'
'+a.html+"
"},optgroup_header:function(a,b){return'
'+b(a[d])+"
"},option:function(a,b){return'
'+b(a[c])+"
"},item:function(a,b){return'
'+b(a[c])+"
"},option_create:function(a,b){return'
Add '+b(a.input)+"
"}};b.settings.render=a.extend({},e,b.settings.render)},setupCallbacks:function(){var a,b,c={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",clear:"onClear",option_add:"onOptionAdd",option_remove:"onOptionRemove",option_clear:"onOptionClear",optgroup_add:"onOptionGroupAdd",optgroup_remove:"onOptionGroupRemove",optgroup_clear:"onOptionGroupClear",dropdown_open:"onDropdownOpen",dropdown_close:"onDropdownClose",type:"onType",load:"onLoad",focus:"onFocus",blur:"onBlur"};for(a in c)c.hasOwnProperty(a)&&(b=this.settings[c[a]],b&&this.on(a,b))},onClick:function(a){var b=this;b.isFocused||(b.focus(),a.preventDefault())},onMouseDown:function(b){{var c=this,d=b.isDefaultPrevented();a(b.target)}if(c.isFocused){if(b.target!==c.$control_input[0])return"single"===c.settings.mode?c.isOpen?c.close():c.open():d||c.setActiveItem(null),!1}else d||window.setTimeout(function(){c.focus()},0)},onChange:function(){this.$input.trigger("change")},onPaste:function(b){var c=this;c.isFull()||c.isInputHidden||c.isLocked?b.preventDefault():c.settings.splitOn&&setTimeout(function(){for(var b=a.trim(c.$control_input.val()||"").split(c.settings.splitOn),d=0,e=b.length;e>d;d++)c.createItem(b[d])},0)},onKeyPress:function(a){if(this.isLocked)return a&&a.preventDefault();var b=String.fromCharCode(a.keyCode||a.which);return this.settings.create&&"multi"===this.settings.mode&&b===this.settings.delimiter?(this.createItem(),a.preventDefault(),!1):void 0},onKeyDown:function(a){var b=(a.target===this.$control_input[0],this);if(b.isLocked)return void(a.keyCode!==u&&a.preventDefault());switch(a.keyCode){case g:if(b.isCmdDown)return void b.selectAll();break;case i:return void(b.isOpen&&(a.preventDefault(),a.stopPropagation(),b.close()));case o:if(!a.ctrlKey||a.altKey)break;case n:if(!b.isOpen&&b.hasOptions)b.open();else if(b.$activeOption){b.ignoreHover=!0;var c=b.getAdjacentOption(b.$activeOption,1);c.length&&b.setActiveOption(c,!0,!0)}return void a.preventDefault();case l:if(!a.ctrlKey||a.altKey)break;case k:if(b.$activeOption){b.ignoreHover=!0;var d=b.getAdjacentOption(b.$activeOption,-1);d.length&&b.setActiveOption(d,!0,!0)}return void a.preventDefault();case h:return void(b.isOpen&&b.$activeOption&&(b.onOptionSelect({currentTarget:b.$activeOption}),a.preventDefault()));case j:return void b.advanceSelection(-1,a);case m:return void b.advanceSelection(1,a);case u:return b.settings.selectOnTab&&b.isOpen&&b.$activeOption&&(b.onOptionSelect({currentTarget:b.$activeOption}),b.isFull()||a.preventDefault()),void(b.settings.create&&b.createItem()&&a.preventDefault());case p:case q:return void b.deleteSelection(a)}return!b.isFull()&&!b.isInputHidden||(f?a.metaKey:a.ctrlKey)?void 0:void a.preventDefault()},onKeyUp:function(a){var b=this;if(b.isLocked)return a&&a.preventDefault();var c=b.$control_input.val()||"";b.lastValue!==c&&(b.lastValue=c,b.onSearchChange(c),b.refreshOptions(),b.trigger("type",c))},onSearchChange:function(a){var b=this,c=b.settings.load;c&&(b.loadedSearches.hasOwnProperty(a)||(b.loadedSearches[a]=!0,b.load(function(d){c.apply(b,[a,d])})))},onFocus:function(a){var b=this,c=b.isFocused;return b.isDisabled?(b.blur(),a&&a.preventDefault(),!1):void(b.ignoreFocus||(b.isFocused=!0,"focus"===b.settings.preload&&b.onSearchChange(""),c||b.trigger("focus"),b.$activeItems.length||(b.showInput(),b.setActiveItem(null),b.refreshOptions(!!b.settings.openOnFocus)),b.refreshState()))},onBlur:function(a,b){var c=this;if(c.isFocused&&(c.isFocused=!1,!c.ignoreFocus)){if(!c.ignoreBlur&&document.activeElement===c.$dropdown_content[0])return c.ignoreBlur=!0,void c.onFocus(a);var d=function(){c.close(),c.setTextboxValue(""),c.setActiveItem(null),c.setActiveOption(null),c.setCaret(c.items.length),c.refreshState(),(b||document.body).focus(),c.ignoreFocus=!1,c.trigger("blur")};c.ignoreFocus=!0,c.settings.create&&c.settings.createOnBlur?c.createItem(null,!1,d):d()}},onOptionHover:function(a){this.ignoreHover||this.setActiveOption(a.currentTarget,!1)},onOptionSelect:function(b){var c,d,e=this;b.preventDefault&&(b.preventDefault(),b.stopPropagation()),d=a(b.currentTarget),d.hasClass("create")?e.createItem(null,function(){e.settings.closeAfterSelect&&e.close()}):(c=d.attr("data-value"),"undefined"!=typeof c&&(e.lastQuery=null,e.setTextboxValue(""),e.addItem(c),e.settings.closeAfterSelect?e.close():!e.settings.hideSelected&&b.type&&/mouse/.test(b.type)&&e.setActiveOption(e.getOption(c))))},onItemSelect:function(a){var b=this;b.isLocked||"multi"===b.settings.mode&&(a.preventDefault(),b.setActiveItem(a.currentTarget,a))},load:function(a){var b=this,c=b.$wrapper.addClass(b.settings.loadingClass);b.loading++,a.apply(b,[function(a){b.loading=Math.max(b.loading-1,0),a&&a.length&&(b.addOption(a),b.refreshOptions(b.isFocused&&!b.isInputHidden)),b.loading||c.removeClass(b.settings.loadingClass),b.trigger("load",a)}])},setTextboxValue:function(a){var b=this.$control_input,c=b.val()!==a;c&&(b.val(a).triggerHandler("update"),this.lastValue=a)},getValue:function(){return this.tagType===v&&this.$input.attr("multiple")?this.items:this.items.join(this.settings.delimiter)},setValue:function(a,b){var c=b?[]:["change"];F(this,c,function(){this.clear(b),this.addItems(a,b)})},setActiveItem:function(b,c){var d,e,f,g,h,i,j,k,l=this;if("single"!==l.settings.mode){if(b=a(b),!b.length)return a(l.$activeItems).removeClass("active"),l.$activeItems=[],void(l.isFocused&&l.showInput());if(d=c&&c.type.toLowerCase(),"mousedown"===d&&l.isShiftDown&&l.$activeItems.length){for(k=l.$control.children(".active:last"),g=Array.prototype.indexOf.apply(l.$control[0].childNodes,[k[0]]),h=Array.prototype.indexOf.apply(l.$control[0].childNodes,[b[0]]),g>h&&(j=g,g=h,h=j),e=g;h>=e;e++)i=l.$control[0].childNodes[e],-1===l.$activeItems.indexOf(i)&&(a(i).addClass("active"),l.$activeItems.push(i));c.preventDefault()}else"mousedown"===d&&l.isCtrlDown||"keydown"===d&&this.isShiftDown?b.hasClass("active")?(f=l.$activeItems.indexOf(b[0]),l.$activeItems.splice(f,1),b.removeClass("active")):l.$activeItems.push(b.addClass("active")[0]):(a(l.$activeItems).removeClass("active"),l.$activeItems=[b.addClass("active")[0]]);l.hideInput(),this.isFocused||l.focus()}},setActiveOption:function(b,c,d){var e,f,g,h,i,j=this;j.$activeOption&&j.$activeOption.removeClass("active"),j.$activeOption=null,b=a(b),b.length&&(j.$activeOption=b.addClass("active"),(c||!y(c))&&(e=j.$dropdown_content.height(),f=j.$activeOption.outerHeight(!0),c=j.$dropdown_content.scrollTop()||0,g=j.$activeOption.offset().top-j.$dropdown_content.offset().top+c,h=g,i=g-e+f,g+f>e+c?j.$dropdown_content.stop().animate({scrollTop:i},d?j.settings.scrollDuration:0):c>g&&j.$dropdown_content.stop().animate({scrollTop:h},d?j.settings.scrollDuration:0)))},selectAll:function(){var a=this;"single"!==a.settings.mode&&(a.$activeItems=Array.prototype.slice.apply(a.$control.children(":not(input)").addClass("active")),a.$activeItems.length&&(a.hideInput(),a.close()),a.focus())},hideInput:function(){var a=this;a.setTextboxValue(""),a.$control_input.css({opacity:0,position:"absolute",left:a.rtl?1e4:-1e4}),a.isInputHidden=!0},showInput:function(){this.$control_input.css({opacity:1,position:"relative",left:0}),this.isInputHidden=!1},focus:function(){var a=this;a.isDisabled||(a.ignoreFocus=!0,a.$control_input[0].focus(),window.setTimeout(function(){a.ignoreFocus=!1,a.onFocus()},0))},blur:function(a){this.$control_input[0].blur(),this.onBlur(null,a)},getScoreFunction:function(a){return this.sifter.getScoreFunction(a,this.getSearchOptions())},getSearchOptions:function(){var a=this.settings,b=a.sortField;return"string"==typeof b&&(b=[{field:b}]),{fields:a.searchField,conjunction:a.searchConjunction,sort:b}},search:function(b){var c,d,e,f=this,g=f.settings,h=this.getSearchOptions();if(g.score&&(e=f.settings.score.apply(this,[b]),"function"!=typeof e))throw new Error('Selectize "score" setting must be a function that returns a function');if(b!==f.lastQuery?(f.lastQuery=b,d=f.sifter.search(b,a.extend(h,{score:e})),f.currentResults=d):d=a.extend(!0,{},f.currentResults),g.hideSelected)for(c=d.items.length-1;c>=0;c--)-1!==f.items.indexOf(z(d.items[c].id))&&d.items.splice(c,1);return d},refreshOptions:function(b){var c,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s;"undefined"==typeof b&&(b=!0);var t=this,u=a.trim(t.$control_input.val()),v=t.search(u),w=t.$dropdown_content,x=t.$activeOption&&z(t.$activeOption.attr("data-value"));for(g=v.items.length,"number"==typeof t.settings.maxOptions&&(g=Math.min(g,t.settings.maxOptions)),h={},i=[],c=0;g>c;c++)for(j=t.options[v.items[c].id],k=t.render("option",j),l=j[t.settings.optgroupField]||"",m=a.isArray(l)?l:[l],e=0,f=m&&m.length;f>e;e++)l=m[e],t.optgroups.hasOwnProperty(l)||(l=""),h.hasOwnProperty(l)||(h[l]=[],i.push(l)),h[l].push(k);for(this.settings.lockOptgroupOrder&&i.sort(function(a,b){var c=t.optgroups[a].$order||0,d=t.optgroups[b].$order||0;return c-d}),n=[],c=0,g=i.length;g>c;c++)l=i[c],t.optgroups.hasOwnProperty(l)&&h[l].length?(o=t.render("optgroup_header",t.optgroups[l])||"",o+=h[l].join(""),n.push(t.render("optgroup",a.extend({},t.optgroups[l],{html:o})))):n.push(h[l].join(""));if(w.html(n.join("")),t.settings.highlight&&v.query.length&&v.tokens.length)for(c=0,g=v.tokens.length;g>c;c++)d(w,v.tokens[c].regex);if(!t.settings.hideSelected)for(c=0,g=t.items.length;g>c;c++)t.getOption(t.items[c]).addClass("selected");p=t.canCreate(u),p&&(w.prepend(t.render("option_create",{input:u})),s=a(w[0].childNodes[0])),t.hasOptions=v.items.length>0||p,t.hasOptions?(v.items.length>0?(r=x&&t.getOption(x),r&&r.length?q=r:"single"===t.settings.mode&&t.items.length&&(q=t.getOption(t.items[0])),q&&q.length||(q=s&&!t.settings.addPrecedence?t.getAdjacentOption(s,1):w.find("[data-selectable]:first"))):q=s,t.setActiveOption(q),b&&!t.isOpen&&t.open()):(t.setActiveOption(null),b&&t.isOpen&&t.close())},addOption:function(b){var c,d,e,f=this;if(a.isArray(b))for(c=0,d=b.length;d>c;c++)f.addOption(b[c]);else(e=f.registerOption(b))&&(f.userOptions[e]=!0,f.lastQuery=null,f.trigger("option_add",e,b))},registerOption:function(a){var b=z(a[this.settings.valueField]);return!b||this.options.hasOwnProperty(b)?!1:(a.$order=a.$order||++this.order,this.options[b]=a,b)},registerOptionGroup:function(a){var b=z(a[this.settings.optgroupValueField]);return b?(a.$order=a.$order||++this.order,this.optgroups[b]=a,b):!1},addOptionGroup:function(a,b){b[this.settings.optgroupValueField]=a,(a=this.registerOptionGroup(b))&&this.trigger("optgroup_add",a,b)},removeOptionGroup:function(a){this.optgroups.hasOwnProperty(a)&&(delete this.optgroups[a],this.renderCache={},this.trigger("optgroup_remove",a))},clearOptionGroups:function(){this.optgroups={},this.renderCache={},this.trigger("optgroup_clear")},updateOption:function(b,c){var d,e,f,g,h,i,j,k=this;if(b=z(b),f=z(c[k.settings.valueField]),null!==b&&k.options.hasOwnProperty(b)){if("string"!=typeof f)throw new Error("Value must be set in option data");j=k.options[b].$order,f!==b&&(delete k.options[b],g=k.items.indexOf(b),-1!==g&&k.items.splice(g,1,f)),c.$order=c.$order||j,k.options[f]=c,h=k.renderCache.item,i=k.renderCache.option,h&&(delete h[b],delete h[f]),i&&(delete i[b],delete i[f]),-1!==k.items.indexOf(f)&&(d=k.getItem(b),e=a(k.render("item",c)),d.hasClass("active")&&e.addClass("active"),d.replaceWith(e)),k.lastQuery=null,k.isOpen&&k.refreshOptions(!1)}},removeOption:function(a,b){var c=this;a=z(a);var d=c.renderCache.item,e=c.renderCache.option;d&&delete d[a],e&&delete e[a],delete c.userOptions[a],delete c.options[a],c.lastQuery=null,c.trigger("option_remove",a),c.removeItem(a,b)},clearOptions:function(){var a=this;a.loadedSearches={},a.userOptions={},a.renderCache={},a.options=a.sifter.items={},a.lastQuery=null,a.trigger("option_clear"),a.clear()},getOption:function(a){return this.getElementWithValue(a,this.$dropdown_content.find("[data-selectable]"))},getAdjacentOption:function(b,c){var d=this.$dropdown.find("[data-selectable]"),e=d.index(b)+c;return e>=0&&ed;d++)if(c[d].getAttribute("data-value")===b)return a(c[d]);return a()},getItem:function(a){return this.getElementWithValue(a,this.$control.children())},addItems:function(b,c){for(var d=a.isArray(b)?b:[b],e=0,f=d.length;f>e;e++)this.isPending=f-1>e,this.addItem(d[e],c)},addItem:function(b,c){var d=c?[]:["change"];F(this,d,function(){var d,e,f,g,h,i=this,j=i.settings.mode;return b=z(b),-1!==i.items.indexOf(b)?void("single"===j&&i.close()):void(i.options.hasOwnProperty(b)&&("single"===j&&i.clear(c),"multi"===j&&i.isFull()||(d=a(i.render("item",i.options[b])),h=i.isFull(),i.items.splice(i.caretPos,0,b),i.insertAtCaret(d),(!i.isPending||!h&&i.isFull())&&i.refreshState(),i.isSetup&&(f=i.$dropdown_content.find("[data-selectable]"),i.isPending||(e=i.getOption(b),g=i.getAdjacentOption(e,1).attr("data-value"),i.refreshOptions(i.isFocused&&"single"!==j),g&&i.setActiveOption(i.getOption(g))),!f.length||i.isFull()?i.close():i.positionDropdown(),i.updatePlaceholder(),i.trigger("item_add",b,d),i.updateOriginalInput({silent:c})))))})},removeItem:function(a,b){var c,d,e,f=this;c="object"==typeof a?a:f.getItem(a),a=z(c.attr("data-value")),d=f.items.indexOf(a),-1!==d&&(c.remove(),c.hasClass("active")&&(e=f.$activeItems.indexOf(c[0]),f.$activeItems.splice(e,1)),f.items.splice(d,1),f.lastQuery=null,!f.settings.persist&&f.userOptions.hasOwnProperty(a)&&f.removeOption(a,b),d0),b.$control_input.data("grow",!c&&!d)},isFull:function(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems},updateOriginalInput:function(a){var b,c,d,e,f=this;if(a=a||{},f.tagType===v){for(d=[],b=0,c=f.items.length;c>b;b++)e=f.options[f.items[b]][f.settings.labelField]||"",d.push('");d.length||this.$input.attr("multiple")||d.push(''),f.$input.html(d.join(""))}else f.$input.val(f.getValue()),f.$input.attr("value",f.$input.val());f.isSetup&&(a.silent||f.trigger("change",f.$input.val()))},updatePlaceholder:function(){if(this.settings.placeholder){var a=this.$control_input;this.items.length?a.removeAttr("placeholder"):a.attr("placeholder",this.settings.placeholder),a.triggerHandler("update",{force:!0})}},open:function(){var a=this;a.isLocked||a.isOpen||"multi"===a.settings.mode&&a.isFull()||(a.focus(),a.isOpen=!0,a.refreshState(),a.$dropdown.css({visibility:"hidden",display:"block"}),a.positionDropdown(),a.$dropdown.css({visibility:"visible"}),a.trigger("dropdown_open",a.$dropdown))},close:function(){var a=this,b=a.isOpen;"single"===a.settings.mode&&a.items.length&&a.hideInput(),a.isOpen=!1,a.$dropdown.hide(),a.setActiveOption(null),a.refreshState(),b&&a.trigger("dropdown_close",a.$dropdown)},positionDropdown:function(){var a=this.$control,b="body"===this.settings.dropdownParent?a.offset():a.position();b.top+=a.outerHeight(!0),this.$dropdown.css({width:a.outerWidth(),top:b.top,left:b.left})},clear:function(a){var b=this;b.items.length&&(b.$control.children(":not(input)").remove(),b.items=[],b.lastQuery=null,b.setCaret(0),b.setActiveItem(null),b.updatePlaceholder(),b.updateOriginalInput({silent:a}),b.refreshState(),b.showInput(),b.trigger("clear"))},insertAtCaret:function(b){var c=Math.min(this.caretPos,this.items.length);0===c?this.$control.prepend(b):a(this.$control[0].childNodes[c]).before(b),this.setCaret(c+1)},deleteSelection:function(b){var c,d,e,f,g,h,i,j,k,l=this;if(e=b&&b.keyCode===p?-1:1,f=H(l.$control_input[0]),l.$activeOption&&!l.settings.hideSelected&&(i=l.getAdjacentOption(l.$activeOption,-1).attr("data-value")),g=[],l.$activeItems.length){for(k=l.$control.children(".active:"+(e>0?"last":"first")),h=l.$control.children(":not(input)").index(k),e>0&&h++,c=0,d=l.$activeItems.length;d>c;c++)g.push(a(l.$activeItems[c]).attr("data-value")); -b&&(b.preventDefault(),b.stopPropagation())}else(l.isFocused||"single"===l.settings.mode)&&l.items.length&&(0>e&&0===f.start&&0===f.length?g.push(l.items[l.caretPos-1]):e>0&&f.start===l.$control_input.val().length&&g.push(l.items[l.caretPos]));if(!g.length||"function"==typeof l.settings.onDelete&&l.settings.onDelete.apply(l,[g])===!1)return!1;for("undefined"!=typeof h&&l.setCaret(h);g.length;)l.removeItem(g.pop());return l.showInput(),l.positionDropdown(),l.refreshOptions(!0),i&&(j=l.getOption(i),j.length&&l.setActiveOption(j)),!0},advanceSelection:function(a,b){var c,d,e,f,g,h,i=this;0!==a&&(i.rtl&&(a*=-1),c=a>0?"last":"first",d=H(i.$control_input[0]),i.isFocused&&!i.isInputHidden?(f=i.$control_input.val().length,g=0>a?0===d.start&&0===d.length:d.start===f,g&&!f&&i.advanceCaret(a,b)):(h=i.$control.children(".active:"+c),h.length&&(e=i.$control.children(":not(input)").index(h),i.setActiveItem(null),i.setCaret(a>0?e+1:e))))},advanceCaret:function(a,b){var c,d,e=this;0!==a&&(c=a>0?"next":"prev",e.isShiftDown?(d=e.$control_input[c](),d.length&&(e.hideInput(),e.setActiveItem(d),b&&b.preventDefault())):e.setCaret(e.caretPos+a))},setCaret:function(b){var c=this;if(b="single"===c.settings.mode?c.items.length:Math.max(0,Math.min(c.items.length,b)),!c.isPending){var d,e,f,g;for(f=c.$control.children(":not(input)"),d=0,e=f.length;e>d;d++)g=a(f[d]).detach(),b>d?c.$control_input.before(g):c.$control.append(g)}c.caretPos=b},lock:function(){this.close(),this.isLocked=!0,this.refreshState()},unlock:function(){this.isLocked=!1,this.refreshState()},disable:function(){var a=this;a.$input.prop("disabled",!0),a.$control_input.prop("disabled",!0).prop("tabindex",-1),a.isDisabled=!0,a.lock()},enable:function(){var a=this;a.$input.prop("disabled",!1),a.$control_input.prop("disabled",!1).prop("tabindex",a.tabIndex),a.isDisabled=!1,a.unlock()},destroy:function(){var b=this,c=b.eventNS,d=b.revertSettings;b.trigger("destroy"),b.off(),b.$wrapper.remove(),b.$dropdown.remove(),b.$input.html("").append(d.$children).removeAttr("tabindex").removeClass("selectized").attr({tabindex:d.tabindex}).show(),b.$control_input.removeData("grow"),b.$input.removeData("selectize"),a(window).off(c),a(document).off(c),a(document.body).off(c),delete b.$input[0].selectize},render:function(a,b){var c,d,e="",f=!1,g=this,h=/^[\t \r\n]*<([a-z][a-z0-9\-_]*(?:\:[a-z][a-z0-9\-_]*)?)/i;return("option"===a||"item"===a)&&(c=z(b[g.settings.valueField]),f=!!c),f&&(y(g.renderCache[a])||(g.renderCache[a]={}),g.renderCache[a].hasOwnProperty(c))?g.renderCache[a][c]:(e=g.settings.render[a].apply(this,[b,A]),("option"===a||"option_create"===a)&&(e=e.replace(h,"<$1 data-selectable")),"optgroup"===a&&(d=b[g.settings.optgroupValueField]||"",e=e.replace(h,'<$1 data-group="'+B(A(d))+'"')),("option"===a||"item"===a)&&(e=e.replace(h,'<$1 data-value="'+B(A(c||""))+'"')),f&&(g.renderCache[a][c]=e),e)},clearCache:function(a){var b=this;"undefined"==typeof a?b.renderCache={}:delete b.renderCache[a]},canCreate:function(a){var b=this;if(!b.settings.create)return!1;var c=b.settings.createFilter;return!(!a.length||"function"==typeof c&&!c.apply(b,[a])||"string"==typeof c&&!new RegExp(c).test(a)||c instanceof RegExp&&!c.test(a))}}),L.count=0,L.defaults={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:!0,diacritics:!0,create:!1,createOnBlur:!1,createFilter:null,highlight:!0,openOnFocus:!0,maxOptions:1e3,maxItems:null,hideSelected:null,addPrecedence:!1,selectOnTab:!1,preload:!1,allowEmptyOption:!1,closeAfterSelect:!1,scrollDuration:60,loadThrottle:300,loadingClass:"loading",dataAttr:"data-data",optgroupField:"optgroup",valueField:"value",labelField:"text",optgroupLabelField:"label",optgroupValueField:"value",lockOptgroupOrder:!1,sortField:"$order",searchField:["text"],searchConjunction:"and",mode:null,wrapperClass:"selectize-control",inputClass:"selectize-input",dropdownClass:"selectize-dropdown",dropdownContentClass:"selectize-dropdown-content",dropdownParent:null,copyClassesToDropdown:!0,render:{}},a.fn.selectize=function(b){var c=a.fn.selectize.defaults,d=a.extend({},c,b),e=d.dataAttr,f=d.labelField,g=d.valueField,h=d.optgroupField,i=d.optgroupLabelField,j=d.optgroupValueField,k=function(b,c){var h,i,j,k,l=b.attr(e);if(l)for(c.options=JSON.parse(l),h=0,i=c.options.length;i>h;h++)c.items.push(c.options[h][g]);else{var m=a.trim(b.val()||"");if(!d.allowEmptyOption&&!m.length)return;for(j=m.split(d.delimiter),h=0,i=j.length;i>h;h++)k={},k[f]=j[h],k[g]=j[h],c.options.push(k);c.items=j}},l=function(b,c){var k,l,m,n,o=c.options,p={},q=function(a){var b=e&&a.attr(e);return"string"==typeof b&&b.length?JSON.parse(b):null},r=function(b,e){b=a(b);var i=z(b.attr("value"));if(i||d.allowEmptyOption)if(p.hasOwnProperty(i)){if(e){var j=p[i][h];j?a.isArray(j)?j.push(e):p[i][h]=[j,e]:p[i][h]=e}}else{var k=q(b)||{};k[f]=k[f]||b.text(),k[g]=k[g]||i,k[h]=k[h]||e,p[i]=k,o.push(k),b.is(":selected")&&c.items.push(i)}},s=function(b){var d,e,f,g,h;for(b=a(b),f=b.attr("label"),f&&(g=q(b)||{},g[i]=f,g[j]=f,c.optgroups.push(g)),h=a("option",b),d=0,e=h.length;e>d;d++)r(h[d],f)};for(c.maxItems=b.attr("multiple")?null:1,n=b.children(),k=0,l=n.length;l>k;k++)m=n[k].tagName.toLowerCase(),"optgroup"===m?s(n[k]):"option"===m&&r(n[k])};return this.each(function(){if(!this.selectize){var e,f=a(this),g=this.tagName.toLowerCase(),h=f.attr("placeholder")||f.attr("data-placeholder");h||d.allowEmptyOption||(h=f.children('option[value=""]').text());var i={placeholder:h,options:[],optgroups:[],items:[]};"select"===g?l(f,i):k(f,i),e=new L(f,a.extend(!0,{},c,i,b))}})},a.fn.selectize.defaults=L.defaults,a.fn.selectize.support={validity:x},L.define("drag_drop",function(){if(!a.fn.sortable)throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".');if("multi"===this.settings.mode){var b=this;b.lock=function(){var a=b.lock;return function(){var c=b.$control.data("sortable");return c&&c.disable(),a.apply(b,arguments)}}(),b.unlock=function(){var a=b.unlock;return function(){var c=b.$control.data("sortable");return c&&c.enable(),a.apply(b,arguments)}}(),b.setup=function(){var c=b.setup;return function(){c.apply(this,arguments);var d=b.$control.sortable({items:"[data-value]",forcePlaceholderSize:!0,disabled:b.isLocked,start:function(a,b){b.placeholder.css("width",b.helper.css("width")),d.css({overflow:"visible"})},stop:function(){d.css({overflow:"hidden"});var c=b.$activeItems?b.$activeItems.slice():null,e=[];d.children("[data-value]").each(function(){e.push(a(this).attr("data-value"))}),b.setValue(e),b.setActiveItem(c)}})}}()}}),L.define("dropdown_header",function(b){var c=this;b=a.extend({title:"Untitled",headerClass:"selectize-dropdown-header",titleRowClass:"selectize-dropdown-header-title",labelClass:"selectize-dropdown-header-label",closeClass:"selectize-dropdown-header-close",html:function(a){return'
'+a.title+'×
'}},b),c.setup=function(){var d=c.setup;return function(){d.apply(c,arguments),c.$dropdown_header=a(b.html(b)),c.$dropdown.prepend(c.$dropdown_header)}}()}),L.define("optgroup_columns",function(b){var c=this;b=a.extend({equalizeWidth:!0,equalizeHeight:!0},b),this.getAdjacentOption=function(b,c){var d=b.closest("[data-group]").find("[data-selectable]"),e=d.index(b)+c;return e>=0&&e
',a=a.firstChild,c.body.appendChild(a),b=d.width=a.offsetWidth-a.clientWidth,c.body.removeChild(a)),b},e=function(){var e,f,g,h,i,j,k;if(k=a("[data-group]",c.$dropdown_content),f=k.length,f&&c.$dropdown_content.width()){if(b.equalizeHeight){for(g=0,e=0;f>e;e++)g=Math.max(g,k.eq(e).height());k.css({height:g})}b.equalizeWidth&&(j=c.$dropdown_content.innerWidth()-d(),h=Math.round(j/f),k.css({width:h}),f>1&&(i=j-h*(f-1),k.eq(f-1).css({width:i})))}};(b.equalizeHeight||b.equalizeWidth)&&(C.after(this,"positionDropdown",e),C.after(this,"refreshOptions",e))}),L.define("remove_button",function(b){if("single"!==this.settings.mode){b=a.extend({label:"×",title:"Remove",className:"remove",append:!0},b);var c=this,d=''+b.label+"",e=function(a,b){var c=a.search(/(<\/[^>]+>\s*)$/);return a.substring(0,c)+b+a.substring(c)};this.setup=function(){var f=c.setup;return function(){if(b.append){var g=c.settings.render.item;c.settings.render.item=function(){return e(g.apply(this,arguments),d)}}f.apply(this,arguments),this.$control.on("click","."+b.className,function(b){if(b.preventDefault(),!c.isLocked){var d=a(b.currentTarget).parent();c.setActiveItem(d),c.deleteSelection()&&c.setCaret(c.items.length)}})}}()}}),L.define("restore_on_backspace",function(a){var b=this;a.text=a.text||function(a){return a[this.settings.labelField]},this.onKeyDown=function(){var c=b.onKeyDown;return function(b){var d,e;return b.keyCode===p&&""===this.$control_input.val()&&!this.$activeItems.length&&(d=this.caretPos-1,d>=0&&d0)&&d.items.push({score:c,id:e})}):g.iterator(g.items,function(a,b){d.items.push({score:1,id:b})}),e=g.getSortFunction(d,b),e&&d.items.sort(e),d.total=d.items.length,"number"==typeof b.limit&&(d.items=d.items.slice(0,b.limit)),d};var b=function(a,b){return"number"==typeof a&&"number"==typeof b?a>b?1:ab?1:b>a?-1:0)},c=function(a,b){var c,d,e,f;for(c=1,d=arguments.length;c=0&&a.data.length>0){var f=a.data.match(c),g=document.createElement("span");g.className="highlight";var h=a.splitText(e),i=(h.splitText(f[0].length),h.cloneNode(!0));g.appendChild(i),h.parentNode.replaceChild(g,h),b=1}}else if(1===a.nodeType&&a.childNodes&&!/(script|style)/i.test(a.tagName))for(var j=0;j/g,">").replace(/"/g,""")},B={};B.before=function(a,b,c){var d=a[b];a[b]=function(){return c.apply(a,arguments),d.apply(a,arguments)}},B.after=function(a,b,c){var d=a[b];a[b]=function(){var b=d.apply(a,arguments);return c.apply(a,arguments),b}};var C=function(a){var b=!1;return function(){b||(b=!0,a.apply(this,arguments))}},D=function(a,b){var c;return function(){var d=this,e=arguments;window.clearTimeout(c),c=window.setTimeout(function(){a.apply(d,e)},b)}},E=function(a,b,c){var d,e=a.trigger,f={};a.trigger=function(){var c=arguments[0];return b.indexOf(c)===-1?e.apply(a,arguments):void(f[c]=arguments)},c.apply(a,[]),a.trigger=e;for(d in f)f.hasOwnProperty(d)&&e.apply(a,f[d])},F=function(a,b,c,d){a.on(b,c,function(b){for(var c=b.target;c&&c.parentNode!==a[0];)c=c.parentNode;return b.currentTarget=c,d.apply(this,[b])})},G=function(a){var b={};if("selectionStart"in a)b.start=a.selectionStart,b.length=a.selectionEnd-b.start;else if(document.selection){a.focus();var c=document.selection.createRange(),d=document.selection.createRange().text.length;c.moveStart("character",-a.value.length),b.start=c.text.length-d,b.length=d}return b},H=function(a,b,c){var d,e,f={};if(c)for(d=0,e=c.length;d").css({position:"absolute",top:-99999,left:-99999,width:"auto",padding:0,whiteSpace:"pre"}).text(b).appendTo("body");H(c,d,["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"]);var e=d.width();return d.remove(),e},J=function(a){var b=null,c=function(c,d){var e,f,g,h,i,j,k,l;c=c||window.event||{},d=d||{},c.metaKey||c.altKey||(d.force||a.data("grow")!==!1)&&(e=a.val(),c.type&&"keydown"===c.type.toLowerCase()&&(f=c.keyCode,g=f>=97&&f<=122||f>=65&&f<=90||f>=48&&f<=57||32===f,f===q||f===p?(l=G(a[0]),l.length?e=e.substring(0,l.start)+e.substring(l.start+l.length):f===p&&l.start?e=e.substring(0,l.start-1)+e.substring(l.start+1):f===q&&"undefined"!=typeof l.start&&(e=e.substring(0,l.start)+e.substring(l.start+1))):g&&(j=c.shiftKey,k=String.fromCharCode(c.keyCode),k=j?k.toUpperCase():k.toLowerCase(),e+=k)),h=a.attr("placeholder"),!e&&h&&(e=h),i=I(e,a)+4,i!==b&&(b=i,a.width(i),a.triggerHandler("resize")))};a.on("keydown keyup update blur",c),c()},K=function(a){var b=document.createElement("div");return b.appendChild(a.cloneNode(!0)),b.innerHTML},L=function(a,b){b||(b={});var c="Selectize";console.error(c+": "+a),b.explanation&&(console.group&&console.group(),console.error(b.explanation),console.group&&console.groupEnd())},M=function(c,d){var e,f,g,h,i=this;h=c[0],h.selectize=i;var j=window.getComputedStyle&&window.getComputedStyle(h,null);if(g=j?j.getPropertyValue("direction"):h.currentStyle&&h.currentStyle.direction,g=g||c.parents("[dir]:first").attr("dir")||"",a.extend(i,{order:0,settings:d,$input:c,tabIndex:c.attr("tabindex")||"",tagType:"select"===h.tagName.toLowerCase()?v:w,rtl:/rtl/i.test(g),eventNS:".selectize"+ ++M.count,highlightedValue:null,isOpen:!1,isDisabled:!1,isRequired:c.is("[required]"),isInvalid:!1,isLocked:!1,isFocused:!1,isInputHidden:!1,isSetup:!1,isShiftDown:!1,isCmdDown:!1,isCtrlDown:!1,ignoreFocus:!1,ignoreBlur:!1,ignoreHover:!1,hasOptions:!1,currentResults:null,lastValue:"",caretPos:0,loading:0,loadedSearches:{},$activeOption:null,$activeItems:[],optgroups:{},options:{},userOptions:{},items:[],renderCache:{},onSearchChange:null===d.loadThrottle?i.onSearchChange:D(i.onSearchChange,d.loadThrottle)}),i.sifter=new b(this.options,{diacritics:d.diacritics}),i.settings.options){for(e=0,f=i.settings.options.length;e").addClass(n.wrapperClass).addClass(j).addClass(i),c=a("
").addClass(n.inputClass).addClass("items").appendTo(b),d=a('').appendTo(c).attr("tabindex",u.is(":disabled")?"-1":m.tabIndex),h=a(n.dropdownParent||b),e=a("
").addClass(n.dropdownClass).addClass(i).hide().appendTo(h),g=a("
").addClass(n.dropdownContentClass).appendTo(e),(l=u.attr("id"))&&(d.attr("id",l+"-selectized"),a("label[for='"+l+"']").attr("for",l+"-selectized")),m.settings.copyClassesToDropdown&&e.addClass(j),b.css({width:u[0].style.width}),m.plugins.names.length&&(k="plugin-"+m.plugins.names.join(" plugin-"),b.addClass(k),e.addClass(k)),(null===n.maxItems||n.maxItems>1)&&m.tagType===v&&u.attr("multiple","multiple"),m.settings.placeholder&&d.attr("placeholder",n.placeholder),!m.settings.splitOn&&m.settings.delimiter){var w=m.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");m.settings.splitOn=new RegExp("\\s*"+w+"+\\s*")}u.attr("autocorrect")&&d.attr("autocorrect",u.attr("autocorrect")),u.attr("autocapitalize")&&d.attr("autocapitalize",u.attr("autocapitalize")),m.$wrapper=b,m.$control=c,m.$control_input=d,m.$dropdown=e,m.$dropdown_content=g,e.on("mouseenter","[data-selectable]",function(){return m.onOptionHover.apply(m,arguments)}),e.on("mousedown click","[data-selectable]",function(){return m.onOptionSelect.apply(m,arguments)}),F(c,"mousedown","*:not(input)",function(){return m.onItemSelect.apply(m,arguments)}),J(d),c.on({mousedown:function(){return m.onMouseDown.apply(m,arguments)},click:function(){return m.onClick.apply(m,arguments)}}),d.on({mousedown:function(a){a.stopPropagation()},keydown:function(){return m.onKeyDown.apply(m,arguments)},keyup:function(){return m.onKeyUp.apply(m,arguments)},keypress:function(){return m.onKeyPress.apply(m,arguments)},resize:function(){m.positionDropdown.apply(m,[])},blur:function(){return m.onBlur.apply(m,arguments)},focus:function(){return m.ignoreBlur=!1,m.onFocus.apply(m,arguments)},paste:function(){return m.onPaste.apply(m,arguments)}}),q.on("keydown"+o,function(a){m.isCmdDown=a[f?"metaKey":"ctrlKey"],m.isCtrlDown=a[f?"altKey":"ctrlKey"],m.isShiftDown=a.shiftKey}),q.on("keyup"+o,function(a){a.keyCode===t&&(m.isCtrlDown=!1),a.keyCode===r&&(m.isShiftDown=!1),a.keyCode===s&&(m.isCmdDown=!1)}),q.on("mousedown"+o,function(a){if(m.isFocused){if(a.target===m.$dropdown[0]||a.target.parentNode===m.$dropdown[0])return!1;m.$control.has(a.target).length||a.target===m.$control[0]||m.blur(a.target)}}),p.on(["scroll"+o,"resize"+o].join(" "),function(){m.isOpen&&m.positionDropdown.apply(m,arguments)}),p.on("mousemove"+o,function(){m.ignoreHover=!1}),this.revertSettings={$children:u.children().detach(),tabindex:u.attr("tabindex")},u.attr("tabindex",-1).hide().after(m.$wrapper),a.isArray(n.items)&&(m.setValue(n.items),delete n.items),x&&u.on("invalid"+o,function(a){a.preventDefault(),m.isInvalid=!0,m.refreshState()}),m.updateOriginalInput(),m.refreshItems(),m.refreshState(),m.updatePlaceholder(),m.isSetup=!0,u.is(":disabled")&&m.disable(),m.on("change",this.onChange),u.data("selectize",m),u.addClass("selectized"),m.trigger("initialize"),n.preload===!0&&m.onSearchChange("")},setupTemplates:function(){var b=this,c=b.settings.labelField,d=b.settings.optgroupLabelField,e={optgroup:function(a){return'
'+a.html+"
"},optgroup_header:function(a,b){return'
'+b(a[d])+"
"},option:function(a,b){return'
'+b(a[c])+"
"},item:function(a,b){return'
'+b(a[c])+"
"},option_create:function(a,b){return'
Add '+b(a.input)+"
"}};b.settings.render=a.extend({},e,b.settings.render)},setupCallbacks:function(){var a,b,c={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",clear:"onClear",option_add:"onOptionAdd",option_remove:"onOptionRemove",option_clear:"onOptionClear",optgroup_add:"onOptionGroupAdd",optgroup_remove:"onOptionGroupRemove",optgroup_clear:"onOptionGroupClear",dropdown_open:"onDropdownOpen",dropdown_close:"onDropdownClose",type:"onType",load:"onLoad",focus:"onFocus",blur:"onBlur"};for(a in c)c.hasOwnProperty(a)&&(b=this.settings[c[a]],b&&this.on(a,b))},onClick:function(a){var b=this;b.isFocused||(b.focus(),a.preventDefault())},onMouseDown:function(b){var c=this,d=b.isDefaultPrevented();a(b.target);if(c.isFocused){if(b.target!==c.$control_input[0])return"single"===c.settings.mode?c.isOpen?c.close():c.open():d||c.setActiveItem(null),!1}else d||window.setTimeout(function(){c.focus()},0)},onChange:function(){this.$input.trigger("change")},onPaste:function(b){var c=this;return c.isFull()||c.isInputHidden||c.isLocked?void b.preventDefault():void(c.settings.splitOn&&setTimeout(function(){var b=c.$control_input.val();if(b.match(c.settings.splitOn))for(var d=a.trim(b).split(c.settings.splitOn),e=0,f=d.length;eh&&(j=g,g=h,h=j),e=g;e<=h;e++)i=l.$control[0].childNodes[e],l.$activeItems.indexOf(i)===-1&&(a(i).addClass("active"),l.$activeItems.push(i));c.preventDefault()}else"mousedown"===d&&l.isCtrlDown||"keydown"===d&&this.isShiftDown?b.hasClass("active")?(f=l.$activeItems.indexOf(b[0]),l.$activeItems.splice(f,1),b.removeClass("active")):l.$activeItems.push(b.addClass("active")[0]):(a(l.$activeItems).removeClass("active"),l.$activeItems=[b.addClass("active")[0]]);l.hideInput(),this.isFocused||l.focus()}},setActiveOption:function(b,c,d){var e,f,g,h,i,j=this;j.$activeOption&&j.$activeOption.removeClass("active"),j.$activeOption=null,b=a(b),b.length&&(j.$activeOption=b.addClass("active"),!c&&y(c)||(e=j.$dropdown_content.height(),f=j.$activeOption.outerHeight(!0),c=j.$dropdown_content.scrollTop()||0,g=j.$activeOption.offset().top-j.$dropdown_content.offset().top+c,h=g,i=g-e+f,g+f>e+c?j.$dropdown_content.stop().animate({scrollTop:i},d?j.settings.scrollDuration:0):g=0;c--)f.items.indexOf(z(d.items[c].id))!==-1&&d.items.splice(c,1);return d},refreshOptions:function(b){var c,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s;"undefined"==typeof b&&(b=!0);var t=this,u=a.trim(t.$control_input.val()),v=t.search(u),w=t.$dropdown_content,x=t.$activeOption&&z(t.$activeOption.attr("data-value"));for(g=v.items.length,"number"==typeof t.settings.maxOptions&&(g=Math.min(g,t.settings.maxOptions)),h={},i=[],c=0;c0||p,t.hasOptions?(v.items.length>0?(r=x&&t.getOption(x),r&&r.length?q=r:"single"===t.settings.mode&&t.items.length&&(q=t.getOption(t.items[0])),q&&q.length||(q=s&&!t.settings.addPrecedence?t.getAdjacentOption(s,1):w.find("[data-selectable]:first"))):q=s,t.setActiveOption(q),b&&!t.isOpen&&t.open()):(t.setActiveOption(null),b&&t.isOpen&&t.close())},addOption:function(b){var c,d,e,f=this;if(a.isArray(b))for(c=0,d=b.length;c=0&&e0),b.$control_input.data("grow",!c&&!d)},isFull:function(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems},updateOriginalInput:function(a){var b,c,d,e,f=this;if(a=a||{},f.tagType===v){for(d=[],b=0,c=f.items.length;b'+A(e)+"");d.length||this.$input.attr("multiple")||d.push(''), +f.$input.html(d.join(""))}else f.$input.val(f.getValue()),f.$input.attr("value",f.$input.val());f.isSetup&&(a.silent||f.trigger("change",f.$input.val()))},updatePlaceholder:function(){if(this.settings.placeholder){var a=this.$control_input;this.items.length?a.removeAttr("placeholder"):a.attr("placeholder",this.settings.placeholder),a.triggerHandler("update",{force:!0})}},open:function(){var a=this;a.isLocked||a.isOpen||"multi"===a.settings.mode&&a.isFull()||(a.focus(),a.isOpen=!0,a.refreshState(),a.$dropdown.css({visibility:"hidden",display:"block"}),a.positionDropdown(),a.$dropdown.css({visibility:"visible"}),a.trigger("dropdown_open",a.$dropdown))},close:function(){var a=this,b=a.isOpen;"single"===a.settings.mode&&a.items.length&&(a.hideInput(),a.$control_input.blur()),a.isOpen=!1,a.$dropdown.hide(),a.setActiveOption(null),a.refreshState(),b&&a.trigger("dropdown_close",a.$dropdown)},positionDropdown:function(){var a=this.$control,b="body"===this.settings.dropdownParent?a.offset():a.position();b.top+=a.outerHeight(!0),this.$dropdown.css({width:a.outerWidth(),top:b.top,left:b.left})},clear:function(a){var b=this;b.items.length&&(b.$control.children(":not(input)").remove(),b.items=[],b.lastQuery=null,b.setCaret(0),b.setActiveItem(null),b.updatePlaceholder(),b.updateOriginalInput({silent:a}),b.refreshState(),b.showInput(),b.trigger("clear"))},insertAtCaret:function(b){var c=Math.min(this.caretPos,this.items.length);0===c?this.$control.prepend(b):a(this.$control[0].childNodes[c]).before(b),this.setCaret(c+1)},deleteSelection:function(b){var c,d,e,f,g,h,i,j,k,l=this;if(e=b&&b.keyCode===p?-1:1,f=G(l.$control_input[0]),l.$activeOption&&!l.settings.hideSelected&&(i=l.getAdjacentOption(l.$activeOption,-1).attr("data-value")),g=[],l.$activeItems.length){for(k=l.$control.children(".active:"+(e>0?"last":"first")),h=l.$control.children(":not(input)").index(k),e>0&&h++,c=0,d=l.$activeItems.length;c0&&f.start===l.$control_input.val().length&&g.push(l.items[l.caretPos]));if(!g.length||"function"==typeof l.settings.onDelete&&l.settings.onDelete.apply(l,[g])===!1)return!1;for("undefined"!=typeof h&&l.setCaret(h);g.length;)l.removeItem(g.pop());return l.showInput(),l.positionDropdown(),l.refreshOptions(!0),i&&(j=l.getOption(i),j.length&&l.setActiveOption(j)),!0},advanceSelection:function(a,b){var c,d,e,f,g,h,i=this;0!==a&&(i.rtl&&(a*=-1),c=a>0?"last":"first",d=G(i.$control_input[0]),i.isFocused&&!i.isInputHidden?(f=i.$control_input.val().length,g=a<0?0===d.start&&0===d.length:d.start===f,g&&!f&&i.advanceCaret(a,b)):(h=i.$control.children(".active:"+c),h.length&&(e=i.$control.children(":not(input)").index(h),i.setActiveItem(null),i.setCaret(a>0?e+1:e))))},advanceCaret:function(a,b){var c,d,e=this;0!==a&&(c=a>0?"next":"prev",e.isShiftDown?(d=e.$control_input[c](),d.length&&(e.hideInput(),e.setActiveItem(d),b&&b.preventDefault())):e.setCaret(e.caretPos+a))},setCaret:function(b){var c=this;if(b="single"===c.settings.mode?c.items.length:Math.max(0,Math.min(c.items.length,b)),!c.isPending){var d,e,f,g;for(f=c.$control.children(":not(input)"),d=0,e=f.length;d
'+a.title+'×
'}},b),c.setup=function(){var d=c.setup;return function(){d.apply(c,arguments),c.$dropdown_header=a(b.html(b)),c.$dropdown.prepend(c.$dropdown_header)}}()}),M.define("optgroup_columns",function(b){var c=this;b=a.extend({equalizeWidth:!0,equalizeHeight:!0},b),this.getAdjacentOption=function(b,c){var d=b.closest("[data-group]").find("[data-selectable]"),e=d.index(b)+c;return e>=0&&e
',a=a.firstChild,c.body.appendChild(a),b=d.width=a.offsetWidth-a.clientWidth,c.body.removeChild(a)),b},e=function(){var e,f,g,h,i,j,k;if(k=a("[data-group]",c.$dropdown_content),f=k.length,f&&c.$dropdown_content.width()){if(b.equalizeHeight){for(g=0,e=0;e1&&(i=j-h*(f-1),k.eq(f-1).css({width:i})))}};(b.equalizeHeight||b.equalizeWidth)&&(B.after(this,"positionDropdown",e),B.after(this,"refreshOptions",e))}),M.define("remove_button",function(b){b=a.extend({label:"×",title:"Remove",className:"remove",append:!0},b);var c=function(b,c){c.className="remove-single";var d=b,e=''+c.label+"",f=function(a,b){return a+b};b.setup=function(){var g=d.setup;return function(){if(c.append){var h=a(d.$input.context).attr("id"),i=(a("#"+h),d.settings.render.item);d.settings.render.item=function(a){return f(i.apply(b,arguments),e)}}g.apply(b,arguments),b.$control.on("click","."+c.className,function(a){a.preventDefault(),d.isLocked||d.clear()})}}()},d=function(b,c){var d=b,e=''+c.label+"",f=function(a,b){var c=a.search(/(<\/[^>]+>\s*)$/);return a.substring(0,c)+b+a.substring(c)};b.setup=function(){var g=d.setup;return function(){if(c.append){var h=d.settings.render.item;d.settings.render.item=function(a){return f(h.apply(b,arguments),e)}}g.apply(b,arguments),b.$control.on("click","."+c.className,function(b){if(b.preventDefault(),!d.isLocked){var c=a(b.currentTarget).parent();d.setActiveItem(c),d.deleteSelection()&&d.setCaret(d.items.length)}})}}()};return"single"===this.settings.mode?void c(this,b):void d(this,b)}),M.define("restore_on_backspace",function(a){var b=this;a.text=a.text||function(a){return a[this.settings.labelField]},this.onKeyDown=function(){var c=b.onKeyDown;return function(b){var d,e;return b.keyCode===p&&""===this.$control_input.val()&&!this.$activeItems.length&&(d=this.caretPos-1,d>=0&&d\": \">\",\n '\"': \""\",\n \"'\": \"'\",\n \"/\": \"/\"\n };\n\n return str.replace(/[&<>'\"\\/]/g, function(m) {\n return escaped[m];\n });\n}\n\nfunction randomId() {\n return Math.floor(0x100000000 + (Math.random() * 0xF00000000)).toString(16);\n}\n\nfunction strToBool(str) {\n if (!str || !str.toLowerCase)\n return undefined;\n\n switch(str.toLowerCase()) {\n case 'true':\n return true;\n case 'false':\n return false;\n default:\n return undefined;\n }\n}\n\n// A wrapper for getComputedStyle that is compatible with older browsers.\n// This is significantly faster than jQuery's .css() function.\nfunction getStyle(el, styleProp) {\n var x;\n if (el.currentStyle)\n x = el.currentStyle[styleProp];\n else if (window.getComputedStyle) {\n // getComputedStyle can return null when we're inside a hidden iframe on\n // Firefox; don't attempt to retrieve style props in this case.\n // https://bugzilla.mozilla.org/show_bug.cgi?id=548397\n var style = document.defaultView.getComputedStyle(el, null);\n if (style)\n x = style.getPropertyValue(styleProp);\n }\n return x;\n}\n\n// Convert a number to a string with leading zeros\nfunction padZeros(n, digits) {\n var str = n.toString();\n while (str.length < digits)\n str = \"0\" + str;\n return str;\n}\n\n// Round to a specified number of significant digits.\nfunction roundSignif(x, digits = 1) {\n if (digits < 1)\n throw \"Significant digits must be at least 1.\";\n\n // This converts to a string and back to a number, which is inelegant, but\n // is less prone to FP rounding error than an alternate method which used\n // Math.round().\n return parseFloat(x.toPrecision(digits));\n}\n\n// Take a string with format \"YYYY-MM-DD\" and return a Date object.\n// IE8 and QTWebKit don't support YYYY-MM-DD, but they support YYYY/MM/DD\nfunction parseDate(dateString) {\n var date = new Date(dateString);\n if (isNaN(date))\n date = new Date(dateString.replace(/-/g, \"/\"));\n return date;\n}\n\n// Given a Date object, return a string in yyyy-mm-dd format, using the\n// UTC date. This may be a day off from the date in the local time zone.\nfunction formatDateUTC(date) {\n if (date instanceof Date) {\n return date.getUTCFullYear() + '-' +\n padZeros(date.getUTCMonth()+1, 2) + '-' +\n padZeros(date.getUTCDate(), 2);\n\n } else {\n return null;\n }\n}\n\n\n// Given an element and a function(width, height), returns a function(). When\n// the output function is called, it calls the input function with the offset\n// width and height of the input element--but only if the size of the element\n// is non-zero and the size is different than the last time the output\n// function was called.\n//\n// Basically we are trying to filter out extraneous calls to func, so that\n// when the window size changes or whatever, we don't run resize logic for\n// elements that haven't actually changed size or aren't visible anyway.\nfunction makeResizeFilter(el, func) {\n var lastSize = {};\n return function() {\n var size = { w: el.offsetWidth, h: el.offsetHeight };\n if (size.w === 0 && size.h === 0)\n return;\n if (size.w === lastSize.w && size.h === lastSize.h)\n return;\n lastSize = size;\n func(size.w, size.h);\n };\n}\n\nvar _BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder ||\n window.MozBlobBuilder || window.MSBlobBuilder;\n\nfunction makeBlob(parts) {\n\n // Browser compatibility is a mess right now. The code as written works in\n // a variety of modern browsers, but sadly gives a deprecation warning\n // message on the console in current versions (as of this writing) of\n // Chrome.\n\n // Safari 6.0 (8536.25) on Mac OS X 10.8.1:\n // Has Blob constructor but it doesn't work with ArrayBufferView args\n\n // Google Chrome 21.0.1180.81 on Xubuntu 12.04:\n // Has Blob constructor, accepts ArrayBufferView args, accepts ArrayBuffer\n // but with a deprecation warning message\n\n // Firefox 15.0 on Xubuntu 12.04:\n // Has Blob constructor, accepts both ArrayBuffer and ArrayBufferView args\n\n // Chromium 18.0.1025.168 (Developer Build 134367 Linux) on Xubuntu 12.04:\n // No Blob constructor. Has WebKitBlobBuilder.\n\n try {\n return new Blob(parts);\n }\n catch (e) {\n var blobBuilder = new _BlobBuilder();\n $.each(parts, function(i, part) {\n blobBuilder.append(part);\n });\n return blobBuilder.getBlob();\n }\n}\n\nfunction pixelRatio() {\n if (window.devicePixelRatio) {\n return window.devicePixelRatio;\n } else {\n return 1;\n }\n}\n\n// Takes a string expression and returns a function that takes an argument.\n//\n// When the function is executed, it will evaluate that expression using\n// \"with\" on the argument value, and return the result.\nfunction scopeExprToFunc(expr) {\n /*jshint evil: true */\n var expr_escaped = expr\n .replace(/[\\\\\"']/g, '\\\\$&')\n .replace(/\\u0000/g, '\\\\0')\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r')\n // \\b has a special meaning; need [\\b] to match backspace char.\n .replace(/[\\b]/g, '\\\\b');\n\n try {\n var func = new Function(\n `with (this) {\n try {\n return (${expr});\n } catch (e) {\n console.error('Error evaluating expression: ${expr_escaped}');\n throw e;\n }\n }`\n );\n } catch (e) {\n console.error(\"Error parsing expression: \" + expr);\n throw e;\n }\n\n\n return function(scope) {\n return func.call(scope);\n };\n}\n\nfunction asArray(value) {\n if (value === null || value === undefined)\n return [];\n if ($.isArray(value))\n return value;\n return [value];\n}\n\n// We need a stable sorting algorithm for ordering\n// bindings by priority and insertion order.\nfunction mergeSort(list, sortfunc) {\n function merge(sortfunc, a, b) {\n var ia = 0;\n var ib = 0;\n var sorted = [];\n while (ia < a.length && ib < b.length) {\n if (sortfunc(a[ia], b[ib]) <= 0) {\n sorted.push(a[ia++]);\n }\n else {\n sorted.push(b[ib++]);\n }\n }\n while (ia < a.length)\n sorted.push(a[ia++]);\n while (ib < b.length)\n sorted.push(b[ib++]);\n return sorted;\n }\n\n // Don't mutate list argument\n list = list.slice(0);\n\n for (var chunkSize = 1; chunkSize < list.length; chunkSize *= 2) {\n for (var i = 0; i < list.length; i += chunkSize * 2) {\n var listA = list.slice(i, i + chunkSize);\n var listB = list.slice(i + chunkSize, i + chunkSize * 2);\n var merged = merge(sortfunc, listA, listB);\n var args = [i, merged.length];\n Array.prototype.push.apply(args, merged);\n Array.prototype.splice.apply(list, args);\n }\n }\n\n return list;\n}\n\n// Escape jQuery selector metacharacters: !\"#$%&'()*+,./:;<=>?@[\\]^`{|}~\nvar $escape = exports.$escape = function(val) {\n return val.replace(/([!\"#$%&'()*+,.\\/:;<=>?@\\[\\\\\\]^`{|}~])/g, '\\\\$1');\n};\n\n// Maps a function over an object, preserving keys. Like the mapValues\n// function from lodash.\nfunction mapValues(obj, f) {\n const newObj = {};\n for (let key in obj) {\n if (obj.hasOwnProperty(key))\n newObj[key] = f(obj[key], key, obj);\n }\n return newObj;\n}\n\n// This is does the same as Number.isNaN, but that function unfortunately does\n// not exist in any version of IE.\nfunction isnan(x) {\n return typeof(x) === 'number' && isNaN(x);\n}\n\n// Binary equality function used by the equal function.\nfunction _equal(x, y) {\n if ($.type(x) === \"object\" && $.type(y) === \"object\") {\n if (Object.keys(x).length !== Object.keys(y).length) return false;\n for (let prop in x)\n if (!y.hasOwnProperty(prop) || !_equal(x[prop], y[prop]))\n return false;\n return true;\n } else if ($.type(x) === \"array\" && $.type(y) === \"array\") {\n if (x.length !== y.length) return false;\n for (let i = 0; i < x.length; i++)\n if (!_equal(x[i], y[i])) return false;\n return true;\n } else {\n return (x === y);\n }\n}\n\n// Structural or \"deep\" equality predicate. Tests two or more arguments for\n// equality, traversing arrays and objects (as determined by $.type) as\n// necessary.\n//\n// Objects other than objects and arrays are tested for equality using ===.\nfunction equal(...args) {\n if (args.length < 2) throw new Error(\"equal requires at least two arguments.\");\n for (let i = 0; i < args.length-1; i++) {\n if (!_equal(args[i], args[i+1]))\n return false;\n }\n return true;\n};\n\n// Compare version strings like \"1.0.1\", \"1.4-2\". `op` must be a string like\n// \"==\" or \"<\".\nexports.compareVersion = function(a, op, b) {\n function versionParts(ver) {\n return (ver + \"\")\n .replace(/-/, \".\")\n .replace(/(\\.0)+[^\\.]*$/, \"\")\n .split(\".\");\n }\n\n function cmpVersion(a, b) {\n a = versionParts(a);\n b = versionParts(b);\n var len = Math.min(a.length, b.length);\n var cmp;\n\n for(var i=0; i=\") return (diff >= 0);\n else if (op === \">\") return (diff > 0);\n else if (op === \"<=\") return (diff <= 0);\n else if (op === \"<\") return (diff < 0);\n else throw `Unknown operator: ${op}`;\n};\n\n\n// multimethod: Creates functions — \"multimethods\" — that are polymorphic on one\n// or more of their arguments.\n//\n// Multimethods can take any number of arguments. Arguments are passed to an\n// applicable function or \"method\", returning its result. By default, if no\n// method was applicable, an exception is thrown.\n//\n// Methods are searched in the order that they were added, and the first\n// applicable method found is the one used.\n//\n// A method is applicable when the \"dispatch value\" associated with it\n// corresponds to the value returned by the dispatch function. The dispatch\n// function defaults to the value of the first argument passed to the\n// multimethod.\n//\n// The correspondence between the value returned by the dispatch function and\n// any method's dispatch value is determined by the test function, which is\n// user-definable and defaults to `equal` or deep equality.\n//\n// # Chainable Functions\n//\n// The function returned by `multimethod()` exposes functions as properties.\n// These functions generally return the multimethod, and so can be chained.\n//\n// - dispatch([function newDispatch]): Sets the dispatch function. The dispatch\n// function can take any number of arguments, but must return a dispatch\n// value. The default dispatch function returns the first argument passed to\n// the multimethod.\n//\n// - test([function newTest]): Sets the test function. The test function takes\n// two arguments: the dispatch value produced by the dispatch function, and\n// the dispatch value associated with some method. It must return a boolean\n// indicating whether or not to select the method. The default test function\n// is `equal`.\n//\n// - when(object dispatchVal, function method): Adds a new dispatch value/method\n// combination.\n//\n// - whenAny(array dispatchVals, function method): Like `when`, but\n// associates the method with every dispatch value in the `dispatchVals`\n// array.\n//\n// - else(function newDefaultMethod): Sets the default function. This function\n// is invoked when no methods apply. If left unset, the multimethod will throw\n// an exception when no methods are applicable.\n//\n// - clone(): Returns a new, functionally-equivalent multimethod. This is a way\n// to extend an existing multimethod in a local context — such as inside a\n// function — without modifying the original. NOTE: The array of methods is\n// copied, but the dispatch values themselves are not.\n//\n// # Self-reference\n//\n// The multimethod function can be obtained inside its method bodies without\n// referring to it by name.\n//\n// This makes it possible for one method to call another, or to pass the\n// multimethod to other functions as a callback from within methods.\n//\n// The mechanism is: the multimethod itself is bound as `this` to methods when\n// they are called. Since arrow functions cannot be bound to objects, **self-reference\n// is only possible within methods created using the `function` keyword**.\n//\n// # Tail recursion\n//\n// A method can call itself in a way that will not overflow the stack by using\n// `this.recur`.\n//\n// `this.recur` is a function available in methods created using `function`.\n// When the return value of a call to `this.recur` is returned by a method, the\n// arguments that were supplied to `this.recur` are used to call the\n// multimethod.\n//\n// # Examples\n//\n// Handling events:\n//\n// var handle = multimethod()\n// .dispatch(e => [e.target.tagName.toLowerCase(), e.type])\n// .when([\"h1\", \"click\"], e => \"you clicked on an h1\")\n// .when([\"p\", \"mouseover\"], e => \"you moused over a p\"})\n// .else(e => {\n// let tag = e.target.tagName.toLowerCase();\n// return `you did ${e.type} to an ${tag}`;\n// });\n//\n// $(document).on(\"click mouseover mouseup mousedown\", e => console.log(handle(e)))\n//\n// Self-calls:\n//\n// var demoSelfCall = multimethod()\n// .when(0, function(n) {\n// this(1);\n// })\n// .when(1, function(n) {\n// doSomething(this);\n// })\n// .when(2, _ => console.log(\"tada\"));\n//\n// Using (abusing?) the test function:\n//\n// var fizzBuzz = multimethod()\n// .test((x, divs) => divs.map(d => x % d === 0).every(Boolean))\n// .when([3, 5], x => \"FizzBuzz\")\n// .when([3], x => \"Fizz\")\n// .when([5], x => \"Buzz\")\n// .else(x => x);\n//\n// for(let i = 0; i <= 100; i++) console.log(fizzBuzz(i));\n//\n// Getting carried away with tail recursion:\n//\n// var factorial = multimethod()\n// .when(0, () => 1)\n// .when(1, (_, prod = 1) => prod)\n// .else(function(n, prod = 1) {\n// return this.recur(n-1, n*prod);\n// });\n//\n// var fibonacci = multimethod()\n// .when(0, (_, a = 0) => a)\n// .else(function(n, a = 0, b = 1) {\n// return this.recur(n-1, b, a+b);\n// });\nfunction multimethod(dispatch = (firstArg) => firstArg,\n test = equal,\n defaultMethod = null,\n methods = []) {\n\n var trampolining = false;\n\n function Sentinel (args) { this.args = args; }\n\n function trampoline(f) {\n return (...args) => {\n trampolining = true;\n var ret = f.apply(invoke, args);\n while (ret instanceof Sentinel)\n ret = f.apply(invoke, ret.args);\n trampolining = false;\n return ret;\n };\n }\n\n let invoke = trampoline((...args) => {\n var dispatchVal = dispatch.apply(null, args);\n for (let i = 0; i < methods.length; i++) {\n let [methodVal, methodFn] = methods[i];\n if (test(dispatchVal, methodVal)) {\n return methodFn.apply(invoke, args);\n }\n }\n if (defaultMethod) {\n return defaultMethod.apply(invoke, args);\n } else {\n throw new Error(`No method for dispatch value ${dispatchVal}`);\n }\n });\n\n invoke.recur = (...args) => {\n if (!trampolining) throw new Error(\"recur can only be called inside a method\");\n return new Sentinel(args);\n };\n\n invoke.dispatch = (newDispatch) => {\n dispatch = newDispatch;\n return invoke;\n };\n\n invoke.test = (newTest) => {\n test = newTest;\n return invoke;\n };\n\n invoke.when = (dispatchVal, methodFn) => {\n methods = methods.concat([[dispatchVal, methodFn]]);\n return invoke;\n };\n\n invoke.whenAny = (dispatchVals, methodFn) => {\n return dispatchVals.reduce((self, val) => invoke.when(val, methodFn), invoke);\n };\n\n invoke.else = (newDefaultMethod = null) => {\n defaultMethod = newDefaultMethod;\n return invoke;\n };\n\n invoke.clone = () => {\n return multimethod(dispatch, test, defaultMethod, methods.slice());\n };\n\n return invoke;\n}\n","//---------------------------------------------------------------------\n// Source file: ../srcjs/browser.js\n\nvar browser = (function() {\n\n var isQt = false;\n // For easy handling of Qt quirks using CSS\n if (/\\bQt\\//.test(window.navigator.userAgent)) {\n $(document.documentElement).addClass('qt');\n isQt = true;\n }\n\n // Enable special treatment for Qt 5 quirks on Linux\n if (/\\bQt\\/5/.test(window.navigator.userAgent) &&\n /Linux/.test(window.navigator.userAgent)) {\n $(document.documentElement).addClass('qt5');\n }\n\n // Detect IE information\n var isIE = (navigator.appName === 'Microsoft Internet Explorer');\n\n function getIEVersion() {\n var rv = -1;\n if (isIE) {\n var ua = navigator.userAgent;\n var re = new RegExp(\"MSIE ([0-9]{1,}[\\\\.0-9]{0,})\");\n if (re.exec(ua) !== null)\n rv = parseFloat(RegExp.$1);\n }\n return rv;\n }\n\n return {\n isQt: isQt,\n isIE: isIE,\n IEVersion: getIEVersion()\n };\n\n})();\n","//---------------------------------------------------------------------\n// Source file: ../srcjs/input_rate.js\n\nvar Invoker = function(target, func) {\n this.target = target;\n this.func = func;\n};\n\n(function() {\n this.normalCall =\n this.immediateCall = function() {\n this.func.apply(this.target, arguments);\n };\n}).call(Invoker.prototype);\n\nvar Debouncer = function(target, func, delayMs) {\n this.target = target;\n this.func = func;\n this.delayMs = delayMs;\n\n this.timerId = null;\n this.args = null;\n};\n\n(function() {\n this.normalCall = function() {\n var self = this;\n\n this.$clearTimer();\n this.args = arguments;\n\n this.timerId = setTimeout(function() {\n // IE8 doesn't reliably clear timeout, so this additional\n // check is needed\n if (self.timerId === null)\n return;\n self.$clearTimer();\n self.$invoke();\n }, this.delayMs);\n };\n this.immediateCall = function() {\n this.$clearTimer();\n this.args = arguments;\n this.$invoke();\n };\n this.isPending = function() {\n return this.timerId !== null;\n };\n this.$clearTimer = function() {\n if (this.timerId !== null) {\n clearTimeout(this.timerId);\n this.timerId = null;\n }\n };\n this.$invoke = function() {\n this.func.apply(this.target, this.args);\n this.args = null;\n };\n}).call(Debouncer.prototype);\n\nvar Throttler = function(target, func, delayMs) {\n this.target = target;\n this.func = func;\n this.delayMs = delayMs;\n\n this.timerId = null;\n this.args = null;\n};\n\n(function() {\n this.normalCall = function() {\n var self = this;\n\n this.args = arguments;\n if (this.timerId === null) {\n this.$invoke();\n this.timerId = setTimeout(function() {\n // IE8 doesn't reliably clear timeout, so this additional\n // check is needed\n if (self.timerId === null)\n return;\n self.$clearTimer();\n if (self.args)\n self.normalCall.apply(self, self.args);\n }, this.delayMs);\n }\n };\n this.immediateCall = function() {\n this.$clearTimer();\n this.args = arguments;\n this.$invoke();\n };\n this.isPending = function() {\n return this.timerId !== null;\n };\n this.$clearTimer = function() {\n if (this.timerId !== null) {\n clearTimeout(this.timerId);\n this.timerId = null;\n }\n };\n this.$invoke = function() {\n this.func.apply(this.target, this.args);\n this.args = null;\n };\n}).call(Throttler.prototype);\n\n// Returns a debounced version of the given function.\n// Debouncing means that when the function is invoked,\n// there is a delay of `threshold` milliseconds before\n// it is actually executed, and if the function is\n// invoked again before that threshold has elapsed then\n// the clock starts over.\n//\n// For example, if a function is debounced with a\n// threshold of 1000ms, then calling it 17 times at\n// 900ms intervals will result in a single execution\n// of the underlying function, 1000ms after the 17th\n// call.\nfunction debounce(threshold, func) {\n var timerId = null;\n var self, args;\n return function() {\n self = this;\n args = arguments;\n if (timerId !== null) {\n clearTimeout(timerId);\n timerId = null;\n }\n timerId = setTimeout(function() {\n // IE8 doesn't reliably clear timeout, so this additional\n // check is needed\n if (timerId === null)\n return;\n timerId = null;\n func.apply(self, args);\n }, threshold);\n };\n}\n\n// Returns a throttled version of the given function.\n// Throttling means that the underlying function will\n// be executed no more than once every `threshold`\n// milliseconds.\n//\n// For example, if a function is throttled with a\n// threshold of 1000ms, then calling it 17 times at\n// 900ms intervals will result in something like 15\n// or 16 executions of the underlying function.\n// eslint-disable-next-line no-unused-vars\nfunction throttle(threshold, func) {\n var executionPending = false;\n var timerId = null;\n var self, args;\n\n function throttled() {\n self = null;\n args = null;\n if (timerId === null) {\n // Haven't seen a call recently. Execute now and\n // start a timer to buffer any subsequent calls.\n timerId = setTimeout(function() {\n // When time expires, clear the timer; and if\n // there has been a call in the meantime, repeat.\n timerId = null;\n if (executionPending) {\n executionPending = false;\n throttled.apply(self, args);\n }\n }, threshold);\n func.apply(this, arguments);\n }\n else {\n // Something executed recently. Don't do anything\n // except set up target/arguments to be called later\n executionPending = true;\n self = this;\n args = arguments;\n }\n }\n return throttled;\n}\n\n\n// Schedules data to be sent to shinyapp at the next setTimeout(0).\n// Batches multiple input calls into one websocket message.\nvar InputBatchSender = function(shinyapp) {\n this.shinyapp = shinyapp;\n this.timerId = null;\n this.pendingData = {};\n this.reentrant = false;\n this.lastChanceCallback = [];\n};\n(function() {\n this.setInput = function(name, value, opts) {\n this.pendingData[name] = value;\n\n if (!this.reentrant) {\n if (opts.priority === \"event\") {\n this.$sendNow();\n } else if (!this.timerId) {\n this.timerId = setTimeout(this.$sendNow.bind(this), 0);\n }\n }\n };\n\n this.$sendNow = function() {\n if (this.reentrant) {\n console.trace(\"Unexpected reentrancy in InputBatchSender!\");\n }\n\n this.reentrant = true;\n try {\n this.timerId = null;\n $.each(this.lastChanceCallback, (i, callback) => {\n callback();\n });\n var currentData = this.pendingData;\n this.pendingData = {};\n this.shinyapp.sendInput(currentData);\n } finally {\n this.reentrant = false;\n }\n };\n}).call(InputBatchSender.prototype);\n\n\nvar InputNoResendDecorator = function(target, initialValues) {\n this.target = target;\n this.lastSentValues = this.reset(initialValues);\n};\n(function() {\n this.setInput = function(name, value, opts) {\n const { name: inputName, inputType: inputType } = splitInputNameType(name);\n const jsonValue = JSON.stringify(value);\n\n if (opts.priority !== \"event\" &&\n this.lastSentValues[inputName] &&\n this.lastSentValues[inputName].jsonValue === jsonValue &&\n this.lastSentValues[inputName].inputType === inputType) {\n return;\n }\n this.lastSentValues[inputName] = { jsonValue, inputType };\n this.target.setInput(name, value, opts);\n };\n this.reset = function(values = {}) {\n // Given an object with flat name-value format:\n // { x: \"abc\", \"y.shiny.number\": 123 }\n // Create an object in cache format and save it:\n // { x: { jsonValue: '\"abc\"', inputType: \"\" },\n // y: { jsonValue: \"123\", inputType: \"shiny.number\" } }\n const cacheValues = {};\n\n for (let inputName in values) {\n if (values.hasOwnProperty(inputName)) {\n let { name, inputType } = splitInputNameType(inputName);\n cacheValues[name] = {\n jsonValue: JSON.stringify(values[inputName]),\n inputType: inputType\n };\n }\n }\n\n this.lastSentValues = cacheValues;\n };\n}).call(InputNoResendDecorator.prototype);\n\n\nvar InputEventDecorator = function(target) {\n this.target = target;\n};\n(function() {\n this.setInput = function(name, value, opts) {\n var evt = jQuery.Event(\"shiny:inputchanged\");\n\n const input = splitInputNameType(name);\n evt.name = input.name;\n evt.inputType = input.inputType;\n evt.value = value;\n evt.binding = opts.binding;\n evt.el = opts.el;\n evt.priority = opts.priority;\n\n $(document).trigger(evt);\n\n if (!evt.isDefaultPrevented()) {\n name = evt.name;\n if (evt.inputType !== '') name += ':' + evt.inputType;\n\n // Most opts aren't passed along to lower levels in the input decorator\n // stack.\n this.target.setInput(name, evt.value, { priority: opts.priority });\n }\n };\n}).call(InputEventDecorator.prototype);\n\n\nvar InputRateDecorator = function(target) {\n this.target = target;\n this.inputRatePolicies = {};\n};\n(function() {\n this.setInput = function(name, value, opts) {\n this.$ensureInit(name);\n\n if (opts.priority !== \"deferred\")\n this.inputRatePolicies[name].immediateCall(name, value, opts);\n else\n this.inputRatePolicies[name].normalCall(name, value, opts);\n };\n this.setRatePolicy = function(name, mode, millis) {\n if (mode === 'direct') {\n this.inputRatePolicies[name] = new Invoker(this, this.$doSetInput);\n }\n else if (mode === 'debounce') {\n this.inputRatePolicies[name] = new Debouncer(this, this.$doSetInput, millis);\n }\n else if (mode === 'throttle') {\n this.inputRatePolicies[name] = new Throttler(this, this.$doSetInput, millis);\n }\n };\n this.$ensureInit = function(name) {\n if (!(name in this.inputRatePolicies))\n this.setRatePolicy(name, 'direct');\n };\n this.$doSetInput = function(name, value, opts) {\n this.target.setInput(name, value, opts);\n };\n}).call(InputRateDecorator.prototype);\n\n\nvar InputDeferDecorator = function(target) {\n this.target = target;\n this.pendingInput = {};\n};\n(function() {\n this.setInput = function(name, value, opts) {\n if (/^\\./.test(name))\n this.target.setInput(name, value, opts);\n else\n this.pendingInput[name] = { value, opts };\n };\n this.submit = function() {\n for (var name in this.pendingInput) {\n if (this.pendingInput.hasOwnProperty(name)) {\n let input = this.pendingInput[name];\n this.target.setInput(name, input.value, input.opts);\n }\n }\n };\n}).call(InputDeferDecorator.prototype);\n\n\nconst InputValidateDecorator = function(target) {\n this.target = target;\n};\n(function() {\n this.setInput = function(name, value, opts) {\n if (!name)\n throw \"Can't set input with empty name.\";\n\n opts = addDefaultInputOpts(opts);\n\n this.target.setInput(name, value, opts);\n };\n}).call(InputValidateDecorator.prototype);\n\n\n// Merge opts with defaults, and return a new object.\nfunction addDefaultInputOpts(opts) {\n\n opts = $.extend({\n priority: \"immediate\",\n binding: null,\n el: null\n }, opts);\n\n if (opts && typeof(opts.priority) !== \"undefined\") {\n switch (opts.priority) {\n case \"deferred\":\n case \"immediate\":\n case \"event\":\n break;\n default:\n throw new Error(\"Unexpected input value mode: '\" + opts.priority + \"'\");\n }\n }\n\n return opts;\n}\n\n\nfunction splitInputNameType(name) {\n const name2 = name.split(':');\n return {\n name: name2[0],\n inputType: name2.length > 1 ? name2[1] : ''\n };\n}\n","//---------------------------------------------------------------------\n// Source file: ../srcjs/shinyapp.js\n\nvar ShinyApp = function() {\n this.$socket = null;\n\n // Cached input values\n this.$inputValues = {};\n\n // Input values at initialization (and reconnect)\n this.$initialInput = {};\n\n // Output bindings\n this.$bindings = {};\n\n // Cached values/errors\n this.$values = {};\n this.$errors = {};\n\n // Conditional bindings (show/hide element based on expression)\n this.$conditionals = {};\n\n this.$pendingMessages = [];\n this.$activeRequests = {};\n this.$nextRequestId = 0;\n\n this.$allowReconnect = false;\n};\n\n(function() {\n\n this.connect = function(initialInput) {\n if (this.$socket)\n throw \"Connect was already called on this application object\";\n\n this.$socket = this.createSocket();\n this.$initialInput = initialInput;\n $.extend(this.$inputValues, initialInput);\n\n this.$updateConditionals();\n };\n\n this.isConnected = function() {\n return !!this.$socket;\n };\n\n var scheduledReconnect = null;\n this.reconnect = function() {\n // This function can be invoked directly even if there's a scheduled\n // reconnect, so be sure to clear any such scheduled reconnects.\n clearTimeout(scheduledReconnect);\n\n if (this.isConnected())\n throw \"Attempted to reconnect, but already connected.\";\n\n this.$socket = this.createSocket();\n this.$initialInput = $.extend({}, this.$inputValues);\n this.$updateConditionals();\n };\n\n this.createSocket = function () {\n var self = this;\n\n var createSocketFunc = exports.createSocket || function() {\n var protocol = 'ws:';\n if (window.location.protocol === 'https:')\n protocol = 'wss:';\n\n var defaultPath = window.location.pathname;\n // some older WebKit browsers return the pathname already decoded;\n // if we find invalid URL characters in the path, encode them\n if (!/^([$#!&-;=?-[\\]_a-z~]|%[0-9a-fA-F]{2})+$/.test(defaultPath)) {\n defaultPath = encodeURI(defaultPath);\n // Bizarrely, QtWebKit requires us to encode these characters *twice*\n if (browser.isQt) {\n defaultPath = encodeURI(defaultPath);\n }\n }\n if (!/\\/$/.test(defaultPath))\n defaultPath += '/';\n defaultPath += 'websocket/';\n\n var ws = new WebSocket(protocol + '//' + window.location.host + defaultPath);\n ws.binaryType = 'arraybuffer';\n\n return ws;\n };\n\n var socket = createSocketFunc();\n var hasOpened = false;\n socket.onopen = function() {\n hasOpened = true;\n\n $(document).trigger({\n type: 'shiny:connected',\n socket: socket\n });\n\n self.onConnected();\n\n socket.send(JSON.stringify({\n method: 'init',\n data: self.$initialInput\n }));\n\n while (self.$pendingMessages.length) {\n var msg = self.$pendingMessages.shift();\n socket.send(msg);\n }\n };\n socket.onmessage = function(e) {\n self.dispatchMessage(e.data);\n };\n // Called when a successfully-opened websocket is closed, or when an\n // attempt to open a connection fails.\n socket.onclose = function() {\n // These things are needed only if we've successfully opened the\n // websocket.\n if (hasOpened) {\n $(document).trigger({\n type: 'shiny:disconnected',\n socket: socket\n });\n\n self.$notifyDisconnected();\n }\n\n self.onDisconnected(); // Must be run before self.$removeSocket()\n self.$removeSocket();\n };\n return socket;\n };\n\n this.sendInput = function(values) {\n var msg = JSON.stringify({\n method: 'update',\n data: values\n });\n\n this.$sendMsg(msg);\n\n $.extend(this.$inputValues, values);\n this.$updateConditionals();\n };\n\n this.$notifyDisconnected = function() {\n\n // function to normalize hostnames\n var normalize = function(hostname) {\n if (hostname === \"127.0.0.1\")\n return \"localhost\";\n else\n return hostname;\n };\n\n // Send a 'disconnected' message to parent if we are on the same domin\n var parentUrl = (parent !== window) ? document.referrer : null;\n if (parentUrl) {\n // parse the parent href\n var a = document.createElement('a');\n a.href = parentUrl;\n\n // post the disconnected message if the hostnames are the same\n if (normalize(a.hostname) === normalize(window.location.hostname)) {\n var protocol = a.protocol.replace(':',''); // browser compatability\n var origin = protocol + '://' + a.hostname;\n if (a.port)\n origin = origin + ':' + a.port;\n parent.postMessage('disconnected', origin);\n }\n }\n };\n\n this.$removeSocket = function() {\n this.$socket = null;\n };\n\n this.$scheduleReconnect = function(delay) {\n var self = this;\n scheduledReconnect = setTimeout(function() { self.reconnect(); }, delay);\n };\n\n // How long should we wait before trying the next reconnection?\n // The delay will increase with subsequent attempts.\n // .next: Return the time to wait for next connection, and increment counter.\n // .reset: Reset the attempt counter.\n var reconnectDelay = (function() {\n var attempts = 0;\n // Time to wait before each reconnection attempt. If we go through all of\n // these values, repeated use the last one. Add 500ms to each one so that\n // in the last 0.5s, it shows \"...\"\n var delays = [1500, 1500, 2500, 2500, 5500, 5500, 10500];\n\n return {\n next: function() {\n var i = attempts;\n // Instead of going off the end, use the last one\n if (i >= delays.length) {\n i = delays.length - 1;\n }\n\n attempts++;\n return delays[i];\n },\n reset: function() {\n attempts = 0;\n }\n };\n })();\n\n this.onDisconnected = function() {\n // Add gray-out overlay, if not already present\n var $overlay = $('#shiny-disconnected-overlay');\n if ($overlay.length === 0) {\n $(document.body).append('
');\n }\n\n // To try a reconnect, both the app (this.$allowReconnect) and the\n // server (this.$socket.allowReconnect) must allow reconnections, or\n // session$allowReconnect(\"force\") was called. The \"force\" option should\n // only be used for testing.\n if ((this.$allowReconnect === true && this.$socket.allowReconnect === true) ||\n this.$allowReconnect === \"force\")\n {\n var delay = reconnectDelay.next();\n exports.showReconnectDialog(delay);\n this.$scheduleReconnect(delay);\n }\n };\n\n this.onConnected = function() {\n $('#shiny-disconnected-overlay').remove();\n exports.hideReconnectDialog();\n reconnectDelay.reset();\n };\n\n // NB: Including blobs will cause IE to break!\n // TODO: Make blobs work with Internet Explorer\n //\n // Websocket messages are normally one-way--i.e. the client passes a\n // message to the server but there is no way for the server to provide\n // a response to that specific message. makeRequest provides a way to\n // do asynchronous RPC over websocket. Each request has a method name\n // and arguments, plus optionally one or more binary blobs can be\n // included as well. The request is tagged with a unique number that\n // the server will use to label the corresponding response.\n //\n // @param method A string that tells the server what logic to run.\n // @param args An array of objects that should also be passed to the\n // server in JSON-ified form.\n // @param onSuccess A function that will be called back if the server\n // responds with success. If the server provides a value in the\n // response, the function will be called with it as the only argument.\n // @param onError A function that will be called back if the server\n // responds with error, or if the request fails for any other reason.\n // The parameter to onError will be a string describing the error.\n // @param blobs Optionally, an array of Blob, ArrayBuffer, or string\n // objects that will be made available to the server as part of the\n // request. Strings will be encoded using UTF-8.\n this.makeRequest = function(method, args, onSuccess, onError, blobs) {\n var requestId = this.$nextRequestId;\n while (this.$activeRequests[requestId]) {\n requestId = (requestId + 1) % 1000000000;\n }\n this.$nextRequestId = requestId + 1;\n\n this.$activeRequests[requestId] = {\n onSuccess: onSuccess,\n onError: onError\n };\n\n var msg = JSON.stringify({\n method: method,\n args: args,\n tag: requestId\n });\n\n if (blobs) {\n // We have binary data to transfer; form a different kind of packet.\n // Start with a 4-byte signature, then for each blob, emit 4 bytes for\n // the length followed by the blob. The json payload is UTF-8 encoded\n // and used as the first blob.\n\n var uint32_to_buf = function(val) {\n var buffer = new ArrayBuffer(4);\n var view = new DataView(buffer);\n view.setUint32(0, val, true); // little-endian\n return buffer;\n };\n\n var payload = [];\n payload.push(uint32_to_buf(0x01020202)); // signature\n\n var jsonBuf = makeBlob([msg]);\n payload.push(uint32_to_buf(jsonBuf.size));\n payload.push(jsonBuf);\n\n for (var i = 0; i < blobs.length; i++) {\n payload.push(uint32_to_buf(blobs[i].byteLength || blobs[i].size || 0));\n payload.push(blobs[i]);\n }\n\n msg = makeBlob(payload);\n }\n\n this.$sendMsg(msg);\n };\n\n this.$sendMsg = function(msg) {\n if (!this.$socket.readyState) {\n this.$pendingMessages.push(msg);\n }\n else {\n this.$socket.send(msg);\n }\n };\n\n this.receiveError = function(name, error) {\n if (this.$errors[name] === error)\n return;\n\n this.$errors[name] = error;\n delete this.$values[name];\n\n var binding = this.$bindings[name];\n var evt = jQuery.Event('shiny:error');\n evt.name = name;\n evt.error = error;\n evt.binding = binding;\n $(binding ? binding.el : document).trigger(evt);\n if (!evt.isDefaultPrevented() && binding && binding.onValueError) {\n binding.onValueError(evt.error);\n }\n };\n\n this.receiveOutput = function(name, value) {\n var binding = this.$bindings[name];\n var evt = jQuery.Event('shiny:value');\n evt.name = name;\n evt.value = value;\n evt.binding = binding;\n\n if (this.$values[name] === value) {\n $(binding ? binding.el : document).trigger(evt);\n return undefined;\n }\n\n this.$values[name] = value;\n delete this.$errors[name];\n\n $(binding ? binding.el : document).trigger(evt);\n\n if (!evt.isDefaultPrevented() && binding) {\n binding.onValueChange(evt.value);\n }\n\n return value;\n };\n\n this.bindOutput = function(id, binding) {\n if (!id)\n throw \"Can't bind an element with no ID\";\n if (this.$bindings[id])\n throw \"Duplicate binding for ID \" + id;\n this.$bindings[id] = binding;\n\n if (this.$values[id] !== undefined)\n binding.onValueChange(this.$values[id]);\n else if (this.$errors[id] !== undefined)\n binding.onValueError(this.$errors[id]);\n\n return binding;\n };\n\n this.unbindOutput = function(id, binding) {\n if (this.$bindings[id] === binding) {\n delete this.$bindings[id];\n return true;\n }\n else {\n return false;\n }\n };\n\n\n // Narrows a scopeComponent -- an input or output object -- to one constrained\n // by nsPrefix. Returns a new object with keys removed and renamed as\n // necessary.\n function narrowScopeComponent(scopeComponent, nsPrefix) {\n return Object.keys(scopeComponent)\n .filter(k => k.indexOf(nsPrefix) === 0)\n .map(k => ({[k.substring(nsPrefix.length)]: scopeComponent[k]}))\n .reduce((obj, pair) => $.extend(obj, pair),\n {});\n }\n\n // Narrows a scope -- an object with input and output \"subComponents\" -- to\n // one constrained by the nsPrefix string.\n //\n // If nsPrefix is null or empty, returns scope without modification.\n //\n // Otherwise, returns a new object with keys in subComponents removed and\n // renamed as necessary.\n function narrowScope(scope, nsPrefix) {\n return nsPrefix ? {\n input: narrowScopeComponent(scope.input, nsPrefix),\n output: narrowScopeComponent(scope.output, nsPrefix)\n } : scope;\n }\n\n this.$updateConditionals = function() {\n $(document).trigger({\n type: 'shiny:conditional'\n });\n\n var inputs = {};\n\n // Input keys use \"name:type\" format; we don't want the user to\n // have to know about the type suffix when referring to inputs.\n for (var name in this.$inputValues) {\n if (this.$inputValues.hasOwnProperty(name)) {\n var shortName = name.replace(/:.*/, '');\n inputs[shortName] = this.$inputValues[name];\n }\n }\n\n var scope = {input: inputs, output: this.$values};\n\n var conditionals = $(document).find('[data-display-if]');\n for (var i = 0; i < conditionals.length; i++) {\n var el = $(conditionals[i]);\n var condFunc = el.data('data-display-if-func');\n\n if (!condFunc) {\n var condExpr = el.attr('data-display-if');\n condFunc = scopeExprToFunc(condExpr);\n el.data('data-display-if-func', condFunc);\n }\n\n var nsPrefix = el.attr('data-ns-prefix');\n var nsScope = narrowScope(scope, nsPrefix);\n var show = condFunc(nsScope);\n var showing = el.css(\"display\") !== \"none\";\n if (show !== showing) {\n if (show) {\n el.trigger('show');\n el.show();\n el.trigger('shown');\n }\n else {\n el.trigger('hide');\n el.hide();\n el.trigger('hidden');\n }\n }\n }\n };\n\n // Message handler management functions =================================\n\n // Records insertion order of handlers. Maps number to name. This is so\n // we can dispatch messages to handlers in the order that handlers were\n // added.\n var messageHandlerOrder = [];\n // Keep track of handlers by name. Maps name to handler function.\n var messageHandlers = {};\n\n // Two categories of message handlers: those that are from Shiny, and those\n // that are added by the user. The Shiny ones handle messages in\n // msgObj.values, msgObj.errors, and so on. The user ones handle messages\n // in msgObj.custom.foo and msgObj.custom.bar.\n var customMessageHandlerOrder = [];\n var customMessageHandlers = {};\n\n // Adds Shiny (internal) message handler\n function addMessageHandler(type, handler) {\n if (messageHandlers[type]) {\n throw('handler for message of type \"' + type + '\" already added.');\n }\n if (typeof(handler) !== 'function') {\n throw('handler must be a function.');\n }\n if (handler.length !== 1) {\n throw('handler must be a function that takes one argument.');\n }\n messageHandlerOrder.push(type);\n messageHandlers[type] = handler;\n }\n\n // Adds custom message handler - this one is exposed to the user\n function addCustomMessageHandler(type, handler) {\n // Remove any previously defined handlers so that only the most recent one\n // will be called\n if (customMessageHandlers[type]) {\n var typeIdx = customMessageHandlerOrder.indexOf(type);\n if (typeIdx !== -1) {\n customMessageHandlerOrder.splice(typeIdx, 1);\n delete customMessageHandlers[type];\n }\n }\n if (typeof(handler) !== 'function') {\n throw('handler must be a function.');\n }\n if (handler.length !== 1) {\n throw('handler must be a function that takes one argument.');\n }\n\n customMessageHandlerOrder.push(type);\n customMessageHandlers[type] = handler;\n }\n\n exports.addCustomMessageHandler = addCustomMessageHandler;\n\n this.dispatchMessage = function(data) {\n var msgObj = {};\n if(typeof data === \"string\") {\n msgObj = JSON.parse(data);\n } else { // data is arraybuffer\n var len = new DataView(data,0,1).getUint8(0);\n var typedv = new DataView(data,1,len);\n var typebuf = [];\n for(var i=0; i 0) {\n var el = $obj[0];\n var evt = jQuery.Event('shiny:updateinput');\n evt.message = message[i].message;\n evt.binding = inputBinding;\n $(el).trigger(evt);\n if (!evt.isDefaultPrevented())\n inputBinding.receiveMessage(el, evt.message);\n }\n }\n });\n\n addMessageHandler('javascript', function(message) {\n /*jshint evil: true */\n eval(message);\n });\n\n addMessageHandler('console', function(message) {\n for (var i = 0; i < message.length; i++) {\n if (console.log)\n console.log(message[i]);\n }\n });\n\n addMessageHandler('progress', function(message) {\n if (message.type && message.message) {\n var handler = progressHandlers[message.type];\n if (handler)\n handler.call(this, message.message);\n }\n });\n\n addMessageHandler('notification', function(message) {\n if (message.type === 'show')\n exports.notifications.show(message.message);\n else if (message.type === 'remove')\n exports.notifications.remove(message.message);\n else\n throw('Unkown notification type: ' + message.type);\n });\n\n addMessageHandler('modal', function(message) {\n if (message.type === 'show')\n exports.modal.show(message.message);\n else if (message.type === 'remove')\n exports.modal.remove(); // For 'remove', message content isn't used\n else\n throw('Unkown modal type: ' + message.type);\n });\n\n addMessageHandler('response', function(message) {\n var requestId = message.tag;\n var request = this.$activeRequests[requestId];\n if (request) {\n delete this.$activeRequests[requestId];\n if ('value' in message)\n request.onSuccess(message.value);\n else\n request.onError(message.error);\n }\n });\n\n addMessageHandler('allowReconnect', function(message) {\n if (message === true || message === false || message === \"force\") {\n this.$allowReconnect = message;\n } else {\n throw \"Invalid value for allowReconnect: \" + message;\n }\n });\n\n addMessageHandler('custom', function(message) {\n // For old-style custom messages - should deprecate and migrate to new\n // method\n if (exports.oncustommessage) {\n exports.oncustommessage(message);\n }\n\n // Send messages.foo and messages.bar to appropriate handlers\n this._sendMessagesToHandlers(message, customMessageHandlers,\n customMessageHandlerOrder);\n });\n\n addMessageHandler('config', function(message) {\n this.config = {workerId: message.workerId, sessionId: message.sessionId};\n if (message.user) exports.user = message.user;\n $(document).trigger('shiny:sessioninitialized');\n });\n\n addMessageHandler('busy', function(message) {\n if (message === 'busy') {\n $(document.documentElement).addClass('shiny-busy');\n $(document).trigger('shiny:busy');\n } else if (message === 'idle') {\n $(document.documentElement).removeClass('shiny-busy');\n $(document).trigger('shiny:idle');\n }\n });\n\n addMessageHandler('recalculating', function(message) {\n if (message.hasOwnProperty('name') && message.hasOwnProperty('status')) {\n var binding = this.$bindings[message.name];\n $(binding ? binding.el : null).trigger({\n type: 'shiny:' + message.status\n });\n }\n });\n\n addMessageHandler('reload', function(message) {\n window.location.reload();\n });\n\n addMessageHandler('shiny-insert-ui', function(message) {\n var targets = $(message.selector);\n if (targets.length === 0) {\n // render the HTML and deps to a null target, so\n // the side-effect of rendering the deps, singletons,\n // and still occur\n console.warn('The selector you chose (\"' + message.selector +\n '\") could not be found in the DOM.');\n exports.renderHtml(message.content.html, $([]), message.content.deps);\n } else {\n targets.each(function (i, target) {\n exports.renderContent(target, message.content, message.where);\n return message.multiple;\n });\n }\n });\n\n addMessageHandler('shiny-remove-ui', function(message) {\n var els = $(message.selector);\n els.each(function (i, el) {\n exports.unbindAll(el, true);\n $(el).remove();\n // If `multiple` is false, returning false terminates the function\n // and no other elements are removed; if `multiple` is true,\n // returning true continues removing all remaining elements.\n return message.multiple;\n });\n });\n\n function getTabset(id) {\n var $tabset = $(\"#\" + $escape(id));\n if ($tabset.length === 0)\n throw \"There is no tabsetPanel (or navbarPage or navlistPanel) \" +\n \"with id equal to '\" + id + \"'\";\n return $tabset;\n }\n\n function getTabContent($tabset) {\n var tabsetId = $tabset.attr(\"data-tabsetid\");\n var $tabContent = $(\"div.tab-content[data-tabsetid='\" +\n $escape(tabsetId) + \"']\");\n return $tabContent;\n }\n\n function getTargetTabs($tabset, $tabContent, target) {\n var dataValue = \"[data-value='\" + $escape(target) + \"']\";\n var $aTag = $tabset.find(\"a\" + dataValue);\n var $liTag = $aTag.parent();\n if ($liTag.length === 0) {\n throw \"There is no tabPanel (or navbarMenu) with value\" +\n \" (or menuName) equal to '\" + target + \"'\";\n }\n var $liTags = [];\n var $divTags = [];\n\n if ($aTag.attr(\"data-toggle\") === \"dropdown\") {\n // dropdown\n var $dropdownTabset = $aTag.find(\"+ ul.dropdown-menu\");\n var dropdownId = $dropdownTabset.attr(\"data-tabsetid\");\n\n var $dropdownLiTags = $dropdownTabset.find(\"a[data-toggle='tab']\").parent(\"li\");\n $dropdownLiTags.each(function (i, el) {\n $liTags.push($(el));\n });\n var selector = \"div.tab-pane[id^='tab-\" + $escape(dropdownId) + \"']\";\n var $dropdownDivs = $tabContent.find(selector);\n $dropdownDivs.each(function (i, el) {\n $divTags.push($(el));\n });\n\n }\n else {\n // regular tab\n $divTags.push($tabContent.find(\"div\" + dataValue));\n }\n return { $liTag: $liTag, $liTags: $liTags, $divTags: $divTags };\n }\n\n addMessageHandler(\"shiny-insert-tab\", function(message) {\n var $parentTabset = getTabset(message.inputId);\n var $tabset = $parentTabset;\n var $tabContent = getTabContent($tabset);\n var tabsetId = $parentTabset.attr(\"data-tabsetid\");\n\n var $divTag = $(message.divTag.html);\n var $liTag = $(message.liTag.html);\n var $aTag = $liTag.find(\"> a\");\n\n // Unless the item is being prepended/appended, the target tab\n // must be provided\n var target = null;\n var $targetLiTag = null;\n if (message.target !== null) {\n target = getTargetTabs($tabset, $tabContent, message.target);\n $targetLiTag = target.$liTag;\n }\n\n // If the item is to be placed inside a navbarMenu (dropdown),\n // change the value of $tabset from the parent's ul tag to the\n // dropdown's ul tag\n var dropdown = getDropdown();\n if (dropdown !== null) {\n if ($aTag.attr(\"data-toggle\") === \"dropdown\")\n throw \"Cannot insert a navbarMenu inside another one\";\n $tabset = dropdown.$tabset;\n tabsetId = dropdown.id;\n }\n\n // For regular tab items, fix the href (of the li > a tag)\n // and the id (of the div tag). This does not apply to plain\n // text items (which function as dividers and headers inside\n // navbarMenus) and whole navbarMenus (since those get\n // constructed from scratch on the R side and therefore\n // there are no ids that need matching)\n if ($aTag.attr(\"data-toggle\") === \"tab\") {\n var index = getTabIndex($tabset, tabsetId);\n var tabId = \"tab-\" + tabsetId + \"-\" + index;\n $liTag.find(\"> a\").attr(\"href\", \"#\" + tabId);\n $divTag.attr(\"id\", tabId);\n }\n\n // actually insert the item into the right place\n if (message.position === \"before\") {\n if ($targetLiTag) {\n $targetLiTag.before($liTag);\n } else {\n $tabset.append($liTag);\n }\n } else if (message.position === \"after\") {\n if ($targetLiTag) {\n $targetLiTag.after($liTag);\n } else {\n $tabset.prepend($liTag);\n }\n }\n\n exports.renderContent($liTag[0], {html: $liTag.html(), deps: message.liTag.deps});\n // jcheng 2017-07-28: This next part might look a little insane versus the\n // more obvious `$tabContent.append($divTag);`, but there's a method to the\n // madness.\n //\n // 1) We need to load the dependencies, and this needs to happen before\n // any scripts in $divTag get a chance to run.\n // 2) The scripts in $divTag need to run only once.\n // 3) The contents of $divTag need to be sent through renderContent so that\n // singletons may be registered and/or obeyed, and so that inputs/outputs\n // may be bound.\n //\n // Add to these constraints these facts:\n //\n // A) The (non-jQuery) DOM manipulation functions don't cause scripts to\n // run, but the jQuery functions all do.\n // B) renderContent must be called on an element that's attached to the\n // document.\n // C) $divTag may be of length > 1 (e.g. navbarMenu). I also noticed text\n // elements consisting of just \"\\n\" being included in the nodeset of\n // $divTag.\n // D) renderContent has a bug where only position \"replace\" (the default)\n // uses the jQuery functions, so other positions like \"beforeend\" will\n // prevent child script tags from running.\n //\n // In theory the same problem exists for $liTag but since that content is\n // much less likely to include arbitrary scripts, we're skipping it.\n //\n // This code could be nicer if we didn't use renderContent, but rather the\n // lower-level functions that renderContent uses. Like if we pre-process\n // the value of message.divTag.html for singletons, we could do that, then\n // render dependencies, then do $tabContent.append($divTag).\n exports.renderContent($tabContent[0], {html: \"\", deps: message.divTag.deps}, \"beforeend\");\n $divTag.get().forEach(el => {\n // Must not use jQuery for appending el to the doc, we don't want any\n // scripts to run (since they will run when renderContent takes a crack).\n $tabContent[0].appendChild(el);\n // If `el` itself is a script tag, this approach won't work (the script\n // won't be run), since we're only sending innerHTML through renderContent\n // and not the whole tag. That's fine in this case because we control the\n // R code that generates this HTML, and we know that the element is not\n // a script tag.\n exports.renderContent(el, el.innerHTML || el.textContent);\n });\n\n if (message.select) {\n $liTag.find(\"a\").tab(\"show\");\n }\n\n /* Barbara -- August 2017\n Note: until now, the number of tabs in a tabsetPanel (or navbarPage\n or navlistPanel) was always fixed. So, an easy way to give an id to\n a tab was simply incrementing a counter. (Just like it was easy to\n give a random 4-digit number to identify the tabsetPanel). Now that\n we're introducing dynamic tabs, we must retrieve these numbers and\n fix the dummy id given to the tab in the R side -- there, we always\n set the tab id (counter dummy) to \"id\" and the tabset id to \"tsid\")\n */\n function getTabIndex($tabset, tabsetId) {\n // The 0 is to ensure this works for empty tabsetPanels as well\n var existingTabIds = [0];\n var leadingHref = \"#tab-\" + tabsetId + \"-\";\n // loop through all existing tabs, find the one with highest id\n // (since this is based on a numeric counter), and increment\n $tabset.find(\"> li\").each(function() {\n var $tab = $(this).find(\"> a[data-toggle='tab']\");\n if ($tab.length > 0) {\n var index = $tab.attr(\"href\").replace(leadingHref, \"\");\n existingTabIds.push(Number(index));\n }\n });\n return Math.max.apply(null, existingTabIds) + 1;\n }\n\n // Finds out if the item will be placed inside a navbarMenu\n // (dropdown). If so, returns the dropdown tabset (ul tag)\n // and the dropdown tabsetid (to be used to fix the tab ID)\n function getDropdown() {\n if (message.menuName !== null) {\n // menuName is only provided if the user wants to prepend\n // or append an item inside a navbarMenu (dropdown)\n var $dropdownATag = $(\"a.dropdown-toggle[data-value='\" +\n $escape(message.menuName) + \"']\");\n if ($dropdownATag.length === 0) {\n throw \"There is no navbarMenu with menuName equal to '\" +\n message.menuName + \"'\";\n }\n var $dropdownTabset = $dropdownATag.find(\"+ ul.dropdown-menu\");\n var dropdownId = $dropdownTabset.attr(\"data-tabsetid\");\n return { $tabset: $dropdownTabset, id: dropdownId };\n\n } else if (message.target !== null) {\n // if our item is to be placed next to a tab that is inside\n // a navbarMenu, our item will also be inside\n var $uncleTabset = $targetLiTag.parent(\"ul\");\n if ($uncleTabset.hasClass(\"dropdown-menu\")) {\n var uncleId = $uncleTabset.attr(\"data-tabsetid\");\n return { $tabset: $uncleTabset, id: uncleId };\n }\n }\n return null;\n }\n });\n\n // If the given tabset has no active tabs, select the first one\n function ensureTabsetHasVisibleTab($tabset) {\n if ($tabset.find(\"li.active\").not(\".dropdown\").length === 0) {\n // Note: destTabValue may be null. We still want to proceed\n // through the below logic and setValue so that the input\n // value for the tabset gets updated (i.e. input$tabsetId\n // should be null if there are no tabs).\n let destTabValue = getFirstTab($tabset);\n let inputBinding = $tabset.data('shiny-input-binding');\n let evt = jQuery.Event('shiny:updateinput');\n evt.binding = inputBinding;\n $tabset.trigger(evt);\n inputBinding.setValue($tabset[0], destTabValue);\n }\n }\n\n // Given a tabset ul jquery object, return the value of the first tab\n // (in document order) that's visible and able to be selected.\n function getFirstTab($ul) {\n return $ul.find(\"li:visible a[data-toggle='tab']\")\n .first()\n .attr(\"data-value\") || null;\n }\n\n function tabApplyFunction(target, func, liTags = false) {\n $.each(target, function(key, el) {\n if (key === \"$liTag\") {\n // $liTag is always just one jQuery element\n func(el);\n }\n else if (key === \"$divTags\") {\n // $divTags is always an array (even if length = 1)\n $.each(el, function(i, div) { func(div); });\n\n } else if (liTags && key === \"$liTags\") {\n // $liTags is always an array (even if length = 0)\n $.each(el, function(i, div) { func(div); });\n }\n });\n }\n\n addMessageHandler(\"shiny-remove-tab\", function(message) {\n var $tabset = getTabset(message.inputId);\n var $tabContent = getTabContent($tabset);\n var target = getTargetTabs($tabset, $tabContent, message.target);\n\n tabApplyFunction(target, removeEl);\n\n ensureTabsetHasVisibleTab($tabset);\n\n function removeEl($el) {\n exports.unbindAll($el, true);\n $el.remove();\n }\n });\n\n addMessageHandler(\"shiny-change-tab-visibility\", function(message) {\n var $tabset = getTabset(message.inputId);\n var $tabContent = getTabContent($tabset);\n var target = getTargetTabs($tabset, $tabContent, message.target);\n\n tabApplyFunction(target, changeVisibility, true);\n\n ensureTabsetHasVisibleTab($tabset);\n\n function changeVisibility($el) {\n if (message.type === \"show\") $el.css(\"display\", \"\");\n else if (message.type === \"hide\") {\n $el.hide();\n $el.removeClass(\"active\");\n }\n }\n });\n\n addMessageHandler('updateQueryString', function(message) {\n\n // leave the bookmarking code intact\n if (message.mode === \"replace\") {\n window.history.replaceState(null, null, message.queryString);\n return;\n }\n\n var what = null;\n if (message.queryString.charAt(0) === \"#\") what = \"hash\";\n else if (message.queryString.charAt(0) === \"?\") what = \"query\";\n else throw \"The 'query' string must start with either '?' \" +\n \"(to update the query string) or with '#' (to \" +\n \"update the hash).\";\n\n var path = window.location.pathname;\n var oldQS = window.location.search;\n var oldHash = window.location.hash;\n\n /* Barbara -- December 2016\n Note: we could check if the new QS and/or hash are different\n from the old one(s) and, if not, we could choose not to push\n a new state (whether or not we would replace it is moot/\n inconsequential). However, I think that it is better to\n interpret each call to `updateQueryString` as representing\n new state (even if the message.queryString is the same), so\n that check isn't even performed as of right now.\n */\n\n var relURL = path;\n if (what === \"query\") relURL += message.queryString;\n else relURL += oldQS + message.queryString; // leave old QS if it exists\n window.history.pushState(null, null, relURL);\n\n // for the case when message.queryString has both a query string\n // and a hash (`what = \"hash\"` allows us to trigger the\n // hashchange event)\n if (message.queryString.indexOf(\"#\") !== -1) what = \"hash\";\n\n // for the case when there was a hash before, but there isn't\n // any hash now (e.g. for when only the query string is updated)\n if (window.location.hash !== oldHash) what = \"hash\";\n\n // This event needs to be triggered manually because pushState() never\n // causes a hashchange event to be fired,\n if (what === \"hash\") $(document).trigger(\"hashchange\");\n });\n\n addMessageHandler(\"resetBrush\", function(message) {\n exports.resetBrush(message.brushId);\n });\n\n // Progress reporting ====================================================\n\n var progressHandlers = {\n // Progress for a particular object\n binding: function(message) {\n var key = message.id;\n var binding = this.$bindings[key];\n if (binding) {\n $(binding.el).trigger({\n type: 'shiny:outputinvalidated',\n binding: binding,\n name: key\n });\n if (binding.showProgress) binding.showProgress(true);\n }\n },\n\n // Open a page-level progress bar\n open: function(message) {\n if (message.style === \"notification\") {\n // For new-style (starting in Shiny 0.14) progress indicators that use\n // the notification API.\n\n // Progress bar starts hidden; will be made visible if a value is provided\n // during updates.\n exports.notifications.show({\n html:\n `
` +\n '
' +\n '
' +\n 'message ' +\n '' +\n '
' +\n '
',\n id: message.id,\n duration: null\n });\n\n } else if (message.style === \"old\") {\n // For old-style (Shiny <=0.13.2) progress indicators.\n\n // Add progress container (for all progress items) if not already present\n var $container = $('.shiny-progress-container');\n if ($container.length === 0) {\n $container = $('
');\n $('body').append($container);\n }\n\n // Add div for just this progress ID\n var depth = $('.shiny-progress.open').length;\n // The 'bar' class is needed for backward compatibility with Bootstrap 2.\n var $progress = $('
' +\n '
' +\n '
' +\n 'message' +\n '' +\n '
' +\n '
'\n );\n\n $progress.attr('id', message.id);\n $container.append($progress);\n\n // Stack bars\n var $progressBar = $progress.find('.progress');\n $progressBar.css('top', depth * $progressBar.height() + 'px');\n\n // Stack text objects\n var $progressText = $progress.find('.progress-text');\n $progressText.css('top', 3 * $progressBar.height() +\n depth * $progressText.outerHeight() + 'px');\n\n $progress.hide();\n }\n\n },\n\n // Update page-level progress bar\n update: function(message) {\n if (message.style === \"notification\") {\n // For new-style (starting in Shiny 0.14) progress indicators that use\n // the notification API.\n var $progress = $('#shiny-progress-' + message.id);\n\n if ($progress.length === 0)\n return;\n\n if (typeof(message.message) !== 'undefined') {\n $progress.find('.progress-message').text(message.message);\n }\n if (typeof(message.detail) !== 'undefined') {\n $progress.find('.progress-detail').text(message.detail);\n }\n if (typeof(message.value) !== 'undefined' && message.value !== null) {\n $progress.find('.progress').show();\n $progress.find('.progress-bar').width((message.value*100) + '%');\n }\n\n } else if (message.style === \"old\") {\n // For old-style (Shiny <=0.13.2) progress indicators.\n\n var $progress = $('#' + message.id + '.shiny-progress');\n if (typeof(message.message) !== 'undefined') {\n $progress.find('.progress-message').text(message.message);\n }\n if (typeof(message.detail) !== 'undefined') {\n $progress.find('.progress-detail').text(message.detail);\n }\n if (typeof(message.value) !== 'undefined' && message.value !== null) {\n $progress.find('.progress').show();\n $progress.find('.bar').width((message.value*100) + '%');\n }\n\n $progress.fadeIn();\n }\n\n },\n\n // Close page-level progress bar\n close: function(message) {\n if (message.style === \"notification\") {\n exports.notifications.remove(message.id);\n\n } else if (message.style === \"old\") {\n var $progress = $('#' + message.id + '.shiny-progress');\n $progress.removeClass('open');\n\n $progress.fadeOut({\n complete: function() {\n $progress.remove();\n\n // If this was the last shiny-progress, remove container\n if ($('.shiny-progress').length === 0)\n $('.shiny-progress-container').remove();\n }\n });\n }\n }\n };\n\n exports.progressHandlers = progressHandlers;\n\n // Returns a URL which can be queried to get values from inside the server\n // function. This is enabled with `options(shiny.testmode=TRUE)`.\n this.getTestSnapshotBaseUrl = function({ fullUrl = true } = {})\n {\n const loc = window.location;\n let url = \"\";\n\n if (fullUrl) {\n // Strip off everything after last slash in path, like dirname() in R\n url = loc.origin + loc.pathname.replace(/\\/[^/]*$/, \"\");\n }\n url += \"/session/\" +\n encodeURIComponent(this.config.sessionId) +\n \"/dataobj/shinytest?w=\" +\n encodeURIComponent(this.config.workerId) +\n \"&nonce=\" + randomId();\n\n return url;\n };\n\n}).call(ShinyApp.prototype);\n\n\n\nexports.showReconnectDialog = (function() {\n var reconnectTime = null;\n\n function updateTime() {\n var $time = $(\"#shiny-reconnect-time\");\n // If the time has been removed, exit and don't reschedule this function.\n if ($time.length === 0) return;\n\n var seconds = Math.floor((reconnectTime - new Date().getTime()) / 1000);\n if (seconds > 0) {\n $time.text(\" in \" + seconds + \"s\");\n } else {\n $time.text(\"...\");\n }\n\n // Reschedule this function after 1 second\n setTimeout(updateTime, 1000);\n }\n\n\n return function(delay) {\n reconnectTime = new Date().getTime() + delay;\n\n // If there's already a reconnect dialog, don't add another\n if ($('#shiny-reconnect-text').length > 0)\n return;\n\n var html = 'Attempting to reconnect' +\n '';\n var action = 'Try now';\n\n exports.notifications.show({\n id: \"reconnect\",\n html: html,\n action: action,\n duration: null,\n closeButton: false,\n type: 'warning'\n });\n\n updateTime();\n };\n})();\n\nexports.hideReconnectDialog = function() {\n exports.notifications.remove(\"reconnect\");\n};\n","//---------------------------------------------------------------------\n// Source file: ../srcjs/notifications.js\n\nexports.notifications = (function() {\n\n // Milliseconds to fade in or out\n const fadeDuration = 250;\n\n function show({ html='', action='', deps=[], duration=5000,\n id=null, closeButton=true, type=null } = {})\n {\n if (!id)\n id = randomId();\n\n // Create panel if necessary\n _createPanel();\n\n // Get existing DOM element for this ID, or create if needed.\n let $notification = _get(id);\n if ($notification.length === 0)\n $notification = _create(id);\n\n // Render html and dependencies\n const newHtml = `
${html}
` +\n `
${action}
`;\n const $content = $notification.find('.shiny-notification-content');\n exports.renderContent($content, { html: newHtml, deps: deps });\n\n // Remove any existing classes of the form 'shiny-notification-xxxx'.\n // The xxxx would be strings like 'warning'.\n const classes = $notification.attr('class')\n .split(/\\s+/)\n .filter(cls => cls.match(/^shiny-notification-/))\n .join(' ');\n $notification.removeClass(classes);\n\n // Add class. 'default' means no additional CSS class.\n if (type && type !== 'default')\n $notification.addClass('shiny-notification-' + type);\n\n\n // Make sure that the presence/absence of close button matches with value\n // of `closeButton`.\n const $close = $notification.find('.shiny-notification-close');\n if (closeButton && $close.length === 0) {\n $notification.append('
×
');\n } else if (!closeButton && $close.length !== 0) {\n $close.remove();\n }\n\n // If duration was provided, schedule removal. If not, clear existing\n // removal callback (this happens if a message was first added with\n // a duration, and then updated with no duration).\n if (duration)\n _addRemovalCallback(id, duration);\n else\n _clearRemovalCallback(id);\n\n return id;\n }\n\n function remove(id) {\n _get(id).fadeOut(fadeDuration, function() {\n\n exports.unbindAll(this);\n $(this).remove();\n\n // If no more notifications, remove the panel from the DOM.\n if (_ids().length === 0) {\n _getPanel().remove();\n }\n });\n }\n\n // Returns an individual notification DOM object (wrapped in jQuery).\n function _get(id) {\n if (!id)\n return null;\n return _getPanel().find('#shiny-notification-' + $escape(id));\n }\n\n // Return array of all notification IDs\n function _ids() {\n return _getPanel()\n .find('.shiny-notification')\n .map(function() { return this.id.replace(/shiny-notification-/, ''); })\n .get();\n }\n\n // Returns the notification panel DOM object (wrapped in jQuery).\n function _getPanel() {\n return $('#shiny-notification-panel');\n }\n\n // Create notifications panel and return the jQuery object. If the DOM\n // element already exists, just return it.\n function _createPanel() {\n let $panel = _getPanel();\n\n if ($panel.length > 0)\n return $panel;\n\n $('body').append('
');\n\n return $panel;\n }\n\n // Create a notification DOM element and return the jQuery object. If the\n // DOM element already exists for the ID, just return it without creating.\n function _create(id) {\n let $notification = _get(id);\n\n if ($notification.length === 0) {\n $notification = $(\n `
` +\n '
×
' +\n '
' +\n '
'\n );\n\n $notification.find('.shiny-notification-close').on('click', e => {\n e.preventDefault();\n e.stopPropagation();\n remove(id);\n });\n\n _getPanel().append($notification);\n }\n\n return $notification;\n }\n\n // Add a callback to remove a notification after a delay in ms.\n function _addRemovalCallback(id, delay) {\n // If there's an existing removalCallback, clear it before adding the new\n // one.\n _clearRemovalCallback(id);\n\n // Attach new removal callback\n const removalCallback = setTimeout(function() { remove(id); }, delay);\n _get(id).data('removalCallback', removalCallback);\n }\n\n // Clear a removal callback from a notification, if present.\n function _clearRemovalCallback(id) {\n const $notification = _get(id);\n const oldRemovalCallback = $notification.data('removalCallback');\n if (oldRemovalCallback) {\n clearTimeout(oldRemovalCallback);\n }\n }\n\n return {\n show,\n remove\n };\n})();\n","//---------------------------------------------------------------------\n// Source file: ../srcjs/modal.js\n\nexports.modal = {\n\n // Show a modal dialog. This is meant to handle two types of cases: one is\n // that the content is a Bootstrap modal dialog, and the other is that the\n // content is non-Bootstrap. Bootstrap modals require some special handling,\n // which is coded in here.\n show: function({ html='', deps=[] } = {}) {\n\n // If there was an existing Bootstrap modal, then there will be a modal-\n // backdrop div that was added outside of the modal wrapper, and it must be\n // removed; otherwise there can be multiple of these divs.\n $('.modal-backdrop').remove();\n\n // Get existing wrapper DOM element, or create if needed.\n let $modal = $('#shiny-modal-wrapper');\n if ($modal.length === 0) {\n $modal = $('
');\n $('body').append($modal);\n\n // If the wrapper's content is a Bootstrap modal, then when the inner\n // modal is hidden, remove the entire thing, including wrapper.\n $modal.on('hidden.bs.modal', function(e) {\n if (e.target === $(\"#shiny-modal\")[0]) {\n exports.unbindAll($modal);\n $modal.remove();\n }\n });\n }\n\n $modal.on('keydown.shinymodal', function(e) {\n // If we're listening for Esc, don't let the event propagate. See\n // https://github.com/rstudio/shiny/issues/1453. The value of\n // data(\"keyboard\") needs to be checked inside the handler, because at\n // the time that $modal.on() is called, the $(\"#shiny-modal\") div doesn't\n // yet exist.\n if ($(\"#shiny-modal\").data(\"keyboard\") === false)\n return;\n\n if (e.keyCode === 27) {\n e.stopPropagation();\n e.preventDefault();\n }\n });\n\n // Set/replace contents of wrapper with html.\n exports.renderContent($modal, { html: html, deps: deps });\n },\n\n remove: function() {\n const $modal = $('#shiny-modal-wrapper');\n\n $modal.off('keydown.shinymodal');\n\n // Look for a Bootstrap modal and if present, trigger hide event. This will\n // trigger the hidden.bs.modal callback that we set in show(), which unbinds\n // and removes the element.\n if ($modal.find('.modal').length > 0) {\n $modal.find('.modal').modal('hide');\n\n } else {\n // If not a Bootstrap modal dialog, simply unbind and remove it.\n exports.unbindAll($modal);\n $modal.remove();\n }\n }\n};\n","//---------------------------------------------------------------------\n// Source file: ../srcjs/file_processor.js\n\n// Generic driver class for doing chunk-wise asynchronous processing of a\n// FileList object. Subclass/clone it and override the `on*` functions to\n// make it do something useful.\nvar FileProcessor = function(files) {\n this.files = files;\n this.fileIndex = -1;\n // Currently need to use small chunk size because R-Websockets can't\n // handle continuation frames\n this.aborted = false;\n this.completed = false;\n\n // TODO: Register error/abort callbacks\n\n this.$run();\n};\n(function() {\n // Begin callbacks. Subclassers/cloners may override any or all of these.\n this.onBegin = function(files, cont) {\n setTimeout(cont, 0);\n };\n this.onFile = function(file, cont) {\n setTimeout(cont, 0);\n };\n this.onComplete = function() {\n };\n this.onAbort = function() {\n };\n // End callbacks\n\n // Aborts processing, unless it's already completed\n this.abort = function() {\n if (this.completed || this.aborted)\n return;\n\n this.aborted = true;\n this.onAbort();\n };\n\n // Returns a bound function that will call this.$run one time.\n this.$getRun = function() {\n var self = this;\n var called = false;\n return function() {\n if (called)\n return;\n called = true;\n self.$run();\n };\n };\n\n // This function will be called multiple times to advance the process.\n // It relies on the state of the object's fields to know what to do next.\n this.$run = function() {\n\n if (this.aborted || this.completed)\n return;\n\n if (this.fileIndex < 0) {\n // Haven't started yet--begin\n this.fileIndex = 0;\n this.onBegin(this.files, this.$getRun());\n return;\n }\n\n if (this.fileIndex === this.files.length) {\n // Just ended\n this.completed = true;\n this.onComplete();\n return;\n }\n\n // If we got here, then we have a file to process, or we are\n // in the middle of processing a file, or have just finished\n // processing a file.\n\n var file = this.files[this.fileIndex++];\n this.onFile(file, this.$getRun());\n };\n}).call(FileProcessor.prototype);\n","//---------------------------------------------------------------------\n// Source file: ../srcjs/binding_registry.js\n\nvar BindingRegistry = function() {\n this.bindings = [];\n this.bindingNames = {};\n};\n(function() {\n this.register = function(binding, bindingName, priority) {\n var bindingObj = {binding: binding, priority: priority || 0};\n this.bindings.unshift(bindingObj);\n if (bindingName) {\n this.bindingNames[bindingName] = bindingObj;\n binding.name = bindingName;\n }\n };\n this.setPriority = function(bindingName, priority) {\n var bindingObj = this.bindingNames[bindingName];\n if (!bindingObj)\n throw \"Tried to set priority on unknown binding \" + bindingName;\n bindingObj.priority = priority || 0;\n };\n this.getPriority = function(bindingName) {\n var bindingObj = this.bindingNames[bindingName];\n if (!bindingObj)\n return false;\n return bindingObj.priority;\n };\n this.getBindings = function() {\n // Sort the bindings. The ones with higher priority are consulted\n // first; ties are broken by most-recently-registered.\n return mergeSort(this.bindings, function(a, b) {\n return b.priority - a.priority;\n });\n };\n}).call(BindingRegistry.prototype);\n\n\nvar inputBindings = exports.inputBindings = new BindingRegistry();\nvar outputBindings = exports.outputBindings = new BindingRegistry();\n","//---------------------------------------------------------------------\n// Source file: ../srcjs/output_binding.js\n\nvar OutputBinding = exports.OutputBinding = function() {};\n(function() {\n // Returns a jQuery object or element array that contains the\n // descendants of scope that match this binding\n this.find = function(scope) { throw \"Not implemented\"; };\n\n this.getId = function(el) {\n return el['data-input-id'] || el.id;\n };\n\n this.onValueChange = function(el, data) {\n this.clearError(el);\n this.renderValue(el, data);\n };\n this.onValueError = function(el, err) {\n this.renderError(el, err);\n };\n this.renderError = function(el, err) {\n this.clearError(el);\n if (err.message === '') {\n // not really error, but we just need to wait (e.g. action buttons)\n $(el).empty();\n return;\n }\n var errClass = 'shiny-output-error';\n if (err.type !== null) {\n // use the classes of the error condition as CSS class names\n errClass = errClass + ' ' + $.map(asArray(err.type), function(type) {\n return errClass + '-' + type;\n }).join(' ');\n }\n $(el).addClass(errClass).text(err.message);\n };\n this.clearError = function(el) {\n $(el).attr('class', function(i, c) {\n return c.replace(/(^|\\s)shiny-output-error\\S*/g, '');\n });\n };\n this.showProgress = function(el, show) {\n var RECALC_CLASS = 'recalculating';\n if (show)\n $(el).addClass(RECALC_CLASS);\n else\n $(el).removeClass(RECALC_CLASS);\n };\n}).call(OutputBinding.prototype);\n","//---------------------------------------------------------------------\n// Source file: ../srcjs/output_binding_text.js\n\nvar textOutputBinding = new OutputBinding();\n$.extend(textOutputBinding, {\n find: function(scope) {\n return $(scope).find('.shiny-text-output');\n },\n renderValue: function(el, data) {\n $(el).text(data);\n }\n});\noutputBindings.register(textOutputBinding, 'shiny.textOutput');\n\n","//---------------------------------------------------------------------\n// Source file: ../srcjs/output_binding_image.js\n\nvar imageOutputBinding = new OutputBinding();\n$.extend(imageOutputBinding, {\n find: function(scope) {\n return $(scope).find('.shiny-image-output, .shiny-plot-output');\n },\n renderValue: function(el, data) {\n // The overall strategy:\n // * Clear out existing image and event handlers.\n // * Create new image.\n // * Create various event handlers.\n // * Bind those event handlers to events.\n // * Insert the new image.\n\n var outputId = this.getId(el);\n\n var $el = $(el);\n var img;\n\n // Get existing img element if present.\n var $img = $el.find('img');\n\n if ($img.length === 0) {\n // If a img element is not already present, that means this is either\n // the first time renderValue() has been called, or this is after an\n // error.\n img = document.createElement('img');\n $el.append(img);\n $img = $(img);\n } else {\n // Trigger custom 'reset' event for any existing images in the div\n img = $img[0];\n $img.trigger('reset');\n }\n\n if (!data) {\n $el.empty();\n return;\n }\n\n // If value is undefined, return alternate. Sort of like ||, except it won't\n // return alternate for other falsy values (0, false, null).\n function OR(value, alternate) {\n if (value === undefined) return alternate;\n return value;\n }\n\n var opts = {\n clickId: $el.data('click-id'),\n clickClip: OR(strToBool($el.data('click-clip')), true),\n\n dblclickId: $el.data('dblclick-id'),\n dblclickClip: OR(strToBool($el.data('dblclick-clip')), true),\n dblclickDelay: OR($el.data('dblclick-delay'), 400),\n\n hoverId: $el.data('hover-id'),\n hoverClip: OR(strToBool($el.data('hover-clip')), true),\n hoverDelayType: OR($el.data('hover-delay-type'), 'debounce'),\n hoverDelay: OR($el.data('hover-delay'), 300),\n hoverNullOutside: OR(strToBool($el.data('hover-null-outside')), false),\n\n brushId: $el.data('brush-id'),\n brushClip: OR(strToBool($el.data('brush-clip')), true),\n brushDelayType: OR($el.data('brush-delay-type'), 'debounce'),\n brushDelay: OR($el.data('brush-delay'), 300),\n brushFill: OR($el.data('brush-fill'), '#666'),\n brushStroke: OR($el.data('brush-stroke'), '#000'),\n brushOpacity: OR($el.data('brush-opacity'), 0.3),\n brushDirection: OR($el.data('brush-direction'), 'xy'),\n brushResetOnNew: OR(strToBool($el.data('brush-reset-on-new')), false),\n\n coordmap: data.coordmap\n };\n\n // Copy items from data to img. Don't set the coordmap as an attribute.\n $.each(data, function(key, value) {\n if (value === null || key === 'coordmap') {\n return;\n }\n img.setAttribute(key, value);\n });\n\n // Unset any attributes in the current img that were not provided in the\n // new data.\n for (var i=0; i max)\n newval = max;\n else if (newval < min)\n newval = min;\n }\n return newval;\n }\n\n // Create scale and inverse-scale functions for a single direction (x or y).\n function scaler1D(domainMin, domainMax, rangeMin, rangeMax, logbase) {\n return {\n scale: function(val, clip) {\n if (logbase)\n val = Math.log(val) / Math.log(logbase);\n return mapLinear(val, domainMin, domainMax, rangeMin, rangeMax, clip);\n },\n\n scaleInv: function(val, clip) {\n var res = mapLinear(val, rangeMin, rangeMax, domainMin, domainMax, clip);\n if (logbase)\n res = Math.pow(logbase, res);\n return res;\n }\n };\n }\n\n // Modify panel, adding scale and inverse-scale functions that take objects\n // like {x:1, y:3}, and also add clip function.\n function addScaleFuns(panel) {\n var d = panel.domain;\n var r = panel.range;\n var xlog = (panel.log && panel.log.x) ? panel.log.x : null;\n var ylog = (panel.log && panel.log.y) ? panel.log.y : null;\n var xscaler = scaler1D(d.left, d.right, r.left, r.right, xlog);\n var yscaler = scaler1D(d.bottom, d.top, r.bottom, r.top, ylog);\n\n // Given an object of form {x:1, y:2}, or {x:1, xmin:2:, ymax: 3}, convert\n // from data coordinates to img. Whether a value is converted as x or y\n // depends on the first character of the key.\n panel.scaleDataToImg = function(val, clip) {\n return mapValues(val, (value, key) => {\n const prefix = key.substring(0, 1);\n if (prefix === \"x\") {\n return xscaler.scale(value, clip);\n } else if (prefix === \"y\") {\n return yscaler.scale(value, clip);\n }\n return null;\n });\n };\n\n panel.scaleImgToData = function(val, clip) {\n return mapValues(val, (value, key) => {\n const prefix = key.substring(0, 1);\n if (prefix === \"x\") {\n return xscaler.scaleInv(value, clip);\n } else if (prefix === \"y\") {\n return yscaler.scaleInv(value, clip);\n }\n return null;\n });\n };\n\n // Given a scaled offset (in img pixels), clip it to the nearest panel region.\n panel.clipImg = function(offset_img) {\n var newOffset = {\n x: offset_img.x,\n y: offset_img.y\n };\n\n var bounds = panel.range;\n\n if (offset_img.x > bounds.right) newOffset.x = bounds.right;\n else if (offset_img.x < bounds.left) newOffset.x = bounds.left;\n\n if (offset_img.y > bounds.bottom) newOffset.y = bounds.bottom;\n else if (offset_img.y < bounds.top) newOffset.y = bounds.top;\n\n return newOffset;\n };\n }\n\n // Add the functions to each panel object.\n for (var i=0; i (not including padding\n// and border).\n// 2. img: The pixel coordinates of the image data. A common case is on a\n// HiDPI device, where the source PNG image could be 1000 pixels wide but\n// be displayed in 500 CSS pixels. Another case is when the image has\n// additional scaling due to CSS transforms or width.\n// 3. data: The coordinates in the data space. This is a bit more complicated\n// than the other two, because there can be multiple panels (as in facets).\nimageutils.initCoordmap = function($el, coordmap) {\n const el = $el[0];\n const $img = $el.find(\"img\");\n\n // If we didn't get any panels, create a dummy one where the domain and range\n // are simply the pixel dimensions.\n // that we modify.\n if (coordmap.panels.length === 0) {\n let bounds = {\n top: 0,\n left: 0,\n right: el.clientWidth - 1,\n bottom: el.clientHeight - 1\n };\n\n coordmap.panels[0] = {\n domain: bounds,\n range: bounds,\n mapping: {}\n };\n }\n\n // Add scaling functions to each panel\n imageutils.initPanelScales(coordmap.panels);\n\n\n // This returns the offset of the mouse in CSS pixels relative to the img,\n // but not including the padding or border, if present.\n coordmap.mouseOffsetCss = function(mouseEvent) {\n const img_origin = findOrigin($img);\n\n // The offset of the mouse from the upper-left corner of the img, in\n // pixels.\n return {\n x: mouseEvent.pageX - img_origin.x,\n y: mouseEvent.pageY - img_origin.y\n };\n };\n\n // Given an offset in an img in CSS pixels, return the corresponding offset\n // in source image pixels. The offset_css can have properties like \"x\",\n // \"xmin\", \"y\", and \"ymax\" -- anything that starts with \"x\" and \"y\". If the\n // img content is 1000 pixels wide, but is scaled to 400 pixels on screen,\n // and the input is x:400, then this will return x:1000.\n coordmap.scaleCssToImg = function(offset_css) {\n const pixel_scaling = coordmap.imgToCssScalingRatio();\n\n const result = mapValues(offset_css, (value, key) => {\n const prefix = key.substring(0, 1);\n \n if (prefix === \"x\") {\n return offset_css[key] / pixel_scaling.x;\n } else if (prefix === \"y\") {\n return offset_css[key] / pixel_scaling.y;\n }\n return null;\n });\n\n return result;\n };\n\n // Given an offset in an img, in source image pixels, return the\n // corresponding offset in CSS pixels. If the img content is 1000 pixels\n // wide, but is scaled to 400 pixels on screen, and the input is x:1000,\n // then this will return x:400.\n coordmap.scaleImgToCss = function(offset_img) {\n const pixel_scaling = coordmap.imgToCssScalingRatio();\n\n const result = mapValues(offset_img, (value, key) => {\n const prefix = key.substring(0, 1);\n \n if (prefix === \"x\") {\n return offset_img[key] * pixel_scaling.x;\n } else if (prefix === \"y\") {\n return offset_img[key] * pixel_scaling.y;\n }\n return null;\n });\n\n return result;\n };\n\n // Returns the x and y ratio the image content is scaled to on screen. If\n // the image data is 1000 pixels wide and is scaled to 300 pixels on screen,\n // then this returns 0.3. (Note the 300 pixels refers to CSS pixels.)\n coordmap.imgToCssScalingRatio = function() {\n const img_dims = findDims($img);\n return {\n x: img_dims.x / coordmap.dims.width,\n y: img_dims.y / coordmap.dims.height\n };\n };\n\n coordmap.cssToImgScalingRatio = function() {\n const res = coordmap.imgToCssScalingRatio();\n return {\n x: 1 / res.x,\n y: 1 / res.y\n };\n };\n\n // Given an offset in css pixels, return an object representing which panel\n // it's in. The `expand` argument tells it to expand the panel area by that\n // many pixels. It's possible for an offset to be within more than one\n // panel, because of the `expand` value. If that's the case, find the\n // nearest panel.\n coordmap.getPanelCss = function(offset_css, expand = 0) {\n const offset_img = coordmap.scaleCssToImg(offset_css);\n const x = offset_img.x;\n const y = offset_img.y;\n\n // Convert expand from css pixels to img pixels\n const cssToImgRatio = coordmap.cssToImgScalingRatio();\n const expand_img = {\n x: expand * cssToImgRatio.x,\n y: expand * cssToImgRatio.y\n };\n\n const matches = []; // Panels that match\n const dists = []; // Distance of offset to each matching panel\n let b;\n for (var i=0; i= b.left - expand_img.x &&\n y <= b.bottom + expand_img.y &&\n y >= b.top - expand_img.y)\n {\n matches.push(coordmap.panels[i]);\n\n // Find distance from edges for x and y\n var xdist = 0;\n var ydist = 0;\n if (x > b.right && x <= b.right + expand_img.x) {\n xdist = x - b.right;\n } else if (x < b.left && x >= b.left - expand_img.x) {\n xdist = x - b.left;\n }\n if (y > b.bottom && y <= b.bottom + expand_img.y) {\n ydist = y - b.bottom;\n } else if (y < b.top && y >= b.top - expand_img.y) {\n ydist = y - b.top;\n }\n\n // Cartesian distance\n dists.push(Math.sqrt( Math.pow(xdist, 2) + Math.pow(ydist, 2) ));\n }\n }\n\n if (matches.length) {\n // Find shortest distance\n var min_dist = Math.min.apply(null, dists);\n for (i=0; i max) {\n shiftAmount = max - maxval;\n } else if (minval < min) {\n shiftAmount = min - minval;\n }\n\n var newvals = [];\n for (var i=0; i 2 ||\n Math.abs(pending_e.offsetY - e.offsetY) > 2) {\n\n triggerPendingMousedown2();\n scheduleMousedown2(e);\n\n } else {\n // The second click was close to the first one. If it happened\n // within specified delay, trigger our custom 'dblclick2' event.\n pending_e = null;\n triggerEvent('dblclick2', e);\n }\n }\n }\n\n // IE8 needs a special hack because when you do a double-click it doesn't\n // trigger the click event twice - it directly triggers dblclick.\n function dblclickIE8(e) {\n e.which = 1; // In IE8, e.which is 0 instead of 1. ???\n triggerEvent('dblclick2', e);\n }\n\n return {\n mousedown: mousedown,\n dblclickIE8: dblclickIE8\n };\n};\n\n\n// ----------------------------------------------------------\n// Handler creators for click, hover, brush.\n// Each of these returns an object with a few public members. These public\n// members are callbacks that are meant to be bound to events on $el with\n// the same name (like 'mousedown').\n// ----------------------------------------------------------\n\nimageutils.createClickHandler = function(inputId, clip, coordmap) {\n var clickInfoSender = coordmap.mouseCoordinateSender(inputId, clip);\n\n return {\n mousedown: function(e) {\n // Listen for left mouse button only\n if (e.which !== 1) return;\n clickInfoSender(e);\n },\n onResetImg: function() { clickInfoSender(null); },\n onResize: null\n };\n};\n\n\nimageutils.createHoverHandler = function(inputId, delay, delayType, clip,\n nullOutside, coordmap)\n{\n var sendHoverInfo = coordmap.mouseCoordinateSender(inputId, clip, nullOutside);\n\n var hoverInfoSender;\n if (delayType === 'throttle')\n hoverInfoSender = new Throttler(null, sendHoverInfo, delay);\n else\n hoverInfoSender = new Debouncer(null, sendHoverInfo, delay);\n\n // What to do when mouse exits the image\n var mouseout;\n if (nullOutside)\n mouseout = function() { hoverInfoSender.normalCall(null); };\n else\n mouseout = function() {};\n\n return {\n mousemove: function(e) { hoverInfoSender.normalCall(e); },\n mouseout: mouseout,\n onResetImg: function() { hoverInfoSender.immediateCall(null); },\n onResize: null\n };\n};\n\n\n// Returns a brush handler object. This has three public functions:\n// mousedown, mousemove, and onResetImg.\nimageutils.createBrushHandler = function(inputId, $el, opts, coordmap, outputId) {\n // Parameter: expand the area in which a brush can be started, by this\n // many pixels in all directions. (This should probably be a brush option)\n var expandPixels = 20;\n\n // Represents the state of the brush\n var brush = imageutils.createBrush($el, opts, coordmap, expandPixels);\n\n // Brush IDs can span multiple image/plot outputs. When an output is brushed,\n // if a brush with the same ID is active on a different image/plot, it must\n // be dismissed (but without sending any data to the server). We implement\n // this by sending the shiny-internal:brushed event to all plots, and letting\n // each plot decide for itself what to do.\n //\n // The decision to have the event sent to each plot (as opposed to a single\n // event triggered on, say, the document) was made to make cleanup easier;\n // listening on an event on the document would prevent garbage collection\n // of plot outputs that are removed from the document.\n $el.on(\"shiny-internal:brushed.image_output\", function(e, coords) {\n // If the new brush shares our ID but not our output element ID, we\n // need to clear our brush (if any).\n if (coords.brushId === inputId && coords.outputId !== outputId) {\n $el.data(\"mostRecentBrush\", false);\n brush.reset();\n }\n });\n\n // Set cursor to one of 7 styles. We need to set the cursor on the whole\n // el instead of the brush div, because the brush div has\n // 'pointer-events:none' so that it won't intercept pointer events.\n // If `style` is null, don't add a cursor style.\n function setCursorStyle(style) {\n $el.removeClass('crosshair grabbable grabbing ns-resize ew-resize nesw-resize nwse-resize');\n\n if (style) $el.addClass(style);\n }\n\n function sendBrushInfo() {\n var coords = brush.boundsData();\n\n // We're in a new or reset state\n if (isNaN(coords.xmin)) {\n exports.setInputValue(inputId, null);\n // Must tell other brushes to clear.\n imageOutputBinding.find(document).trigger(\"shiny-internal:brushed\", {\n brushId: inputId, outputId: null\n });\n return;\n }\n\n var panel = brush.getPanel();\n\n // Add the panel (facet) variables, if present\n $.extend(coords, panel.panel_vars);\n\n coords.pixelratio = coordmap.cssToImgScalingRatio();\n\n // Add variable name mappings\n coords.mapping = panel.mapping;\n\n // Add scaling information\n coords.domain = panel.domain;\n coords.range = panel.range;\n coords.log = panel.log;\n\n coords.direction = opts.brushDirection;\n\n coords.brushId = inputId;\n coords.outputId = outputId;\n\n // Send data to server\n exports.setInputValue(inputId, coords);\n\n $el.data(\"mostRecentBrush\", true);\n imageOutputBinding.find(document).trigger(\"shiny-internal:brushed\", coords);\n }\n\n var brushInfoSender;\n if (opts.brushDelayType === 'throttle') {\n brushInfoSender = new Throttler(null, sendBrushInfo, opts.brushDelay);\n } else {\n brushInfoSender = new Debouncer(null, sendBrushInfo, opts.brushDelay);\n }\n\n function mousedown(e) {\n // This can happen when mousedown inside the graphic, then mouseup\n // outside, then mousedown inside. Just ignore the second\n // mousedown.\n if (brush.isBrushing() || brush.isDragging() || brush.isResizing()) return;\n\n // Listen for left mouse button only\n if (e.which !== 1) return;\n\n // In general, brush uses css pixels, and coordmap uses img pixels.\n const offset_css = coordmap.mouseOffsetCss(e);\n\n // Ignore mousedown events outside of plotting region, expanded by\n // a number of pixels specified in expandPixels.\n if (opts.brushClip && !coordmap.isInPanelCss(offset_css, expandPixels))\n return;\n\n brush.up({ x: NaN, y: NaN });\n brush.down(offset_css);\n\n\n if (brush.isInResizeArea(offset_css)) {\n brush.startResizing(offset_css);\n\n // Attach the move and up handlers to the window so that they respond\n // even when the mouse is moved outside of the image.\n $(document)\n .on('mousemove.image_brush', mousemoveResizing)\n .on('mouseup.image_brush', mouseupResizing);\n\n } else if (brush.isInsideBrush(offset_css)) {\n brush.startDragging(offset_css);\n setCursorStyle('grabbing');\n\n // Attach the move and up handlers to the window so that they respond\n // even when the mouse is moved outside of the image.\n $(document)\n .on('mousemove.image_brush', mousemoveDragging)\n .on('mouseup.image_brush', mouseupDragging);\n\n } else {\n const panel = coordmap.getPanelCss(offset_css, expandPixels);\n brush.startBrushing(panel.clipImg(coordmap.scaleCssToImg(offset_css)));\n\n // Attach the move and up handlers to the window so that they respond\n // even when the mouse is moved outside of the image.\n $(document)\n .on('mousemove.image_brush', mousemoveBrushing)\n .on('mouseup.image_brush', mouseupBrushing);\n }\n }\n\n // This sets the cursor style when it's in the el\n function mousemove(e) {\n // In general, brush uses css pixels, and coordmap uses img pixels.\n const offset_css = coordmap.mouseOffsetCss(e);\n\n if (!(brush.isBrushing() || brush.isDragging() || brush.isResizing())) {\n // Set the cursor depending on where it is\n if (brush.isInResizeArea(offset_css)) {\n const r = brush.whichResizeSides(offset_css);\n\n if ((r.left && r.top) || (r.right && r.bottom)) {\n setCursorStyle('nwse-resize');\n } else if ((r.left && r.bottom) || (r.right && r.top)) {\n setCursorStyle('nesw-resize');\n } else if (r.left || r.right) {\n setCursorStyle('ew-resize');\n } else if (r.top || r.bottom) {\n setCursorStyle('ns-resize');\n }\n } else if (brush.isInsideBrush(offset_css)) {\n setCursorStyle('grabbable');\n } else if (coordmap.isInPanelCss(offset_css, expandPixels)) {\n setCursorStyle('crosshair');\n } else {\n setCursorStyle(null);\n }\n }\n }\n\n // mousemove handlers while brushing or dragging\n function mousemoveBrushing(e) {\n brush.brushTo(coordmap.mouseOffsetCss(e));\n brushInfoSender.normalCall();\n }\n\n function mousemoveDragging(e) {\n brush.dragTo(coordmap.mouseOffsetCss(e));\n brushInfoSender.normalCall();\n }\n\n function mousemoveResizing(e) {\n brush.resizeTo(coordmap.mouseOffsetCss(e));\n brushInfoSender.normalCall();\n }\n\n // mouseup handlers while brushing or dragging\n function mouseupBrushing(e) {\n // Listen for left mouse button only\n if (e.which !== 1) return;\n\n $(document)\n .off('mousemove.image_brush')\n .off('mouseup.image_brush');\n\n brush.up(coordmap.mouseOffsetCss(e));\n\n brush.stopBrushing();\n setCursorStyle('crosshair');\n\n // If the brush didn't go anywhere, hide the brush, clear value,\n // and return.\n if (brush.down().x === brush.up().x && brush.down().y === brush.up().y) {\n brush.reset();\n brushInfoSender.immediateCall();\n return;\n }\n\n // Send info immediately on mouseup, but only if needed. If we don't\n // do the pending check, we might send the same data twice (with\n // with difference nonce).\n if (brushInfoSender.isPending())\n brushInfoSender.immediateCall();\n }\n\n function mouseupDragging(e) {\n // Listen for left mouse button only\n if (e.which !== 1) return;\n\n $(document)\n .off('mousemove.image_brush')\n .off('mouseup.image_brush');\n\n brush.up(coordmap.mouseOffsetCss(e));\n\n brush.stopDragging();\n setCursorStyle('grabbable');\n\n if (brushInfoSender.isPending())\n brushInfoSender.immediateCall();\n }\n\n function mouseupResizing(e) {\n // Listen for left mouse button only\n if (e.which !== 1) return;\n\n $(document)\n .off('mousemove.image_brush')\n .off('mouseup.image_brush');\n\n brush.up(coordmap.mouseOffsetCss(e));\n brush.stopResizing();\n\n if (brushInfoSender.isPending())\n brushInfoSender.immediateCall();\n\n }\n\n // Brush maintenance: When an image is re-rendered, the brush must either\n // be removed (if brushResetOnNew) or imported (if !brushResetOnNew). The\n // \"mostRecentBrush\" bit is to ensure that when multiple outputs share the\n // same brush ID, inactive brushes don't send null values up to the server.\n\n // This should be called when the img (not the el) is reset\n function onResetImg() {\n if (opts.brushResetOnNew) {\n if ($el.data(\"mostRecentBrush\")) {\n brush.reset();\n brushInfoSender.immediateCall();\n }\n }\n }\n\n if (!opts.brushResetOnNew) {\n if ($el.data(\"mostRecentBrush\")) {\n // Importing an old brush must happen after the image data has loaded\n // and the DOM element has the updated size. If importOldBrush()\n // is called before this happens, then the css-img coordinate mappings\n // will give the wrong result, and the brush will have the wrong\n // position.\n $el.find(\"img\").one(\"load.shiny-image-interaction\", function() {\n brush.importOldBrush();\n brushInfoSender.immediateCall();\n });\n }\n }\n\n function onResize() {\n brush.onResize();\n brushInfoSender.immediateCall();\n }\n\n return {\n mousedown: mousedown,\n mousemove: mousemove,\n onResetImg: onResetImg,\n onResize: onResize\n };\n};\n\n// Returns an object that represents the state of the brush. This gets wrapped\n// in a brushHandler, which provides various event listeners.\nimageutils.createBrush = function($el, opts, coordmap, expandPixels) {\n // Number of pixels outside of brush to allow start resizing\n var resizeExpand = 10;\n\n var el = $el[0];\n var $div = null; // The div representing the brush\n\n var state = {};\n\n // Aliases for conciseness\n const cssToImg = coordmap.scaleCssToImg;\n const imgToCss = coordmap.scaleImgToCss;\n\n reset();\n\n function reset() {\n // Current brushing/dragging/resizing state\n state.brushing = false;\n state.dragging = false;\n state.resizing = false;\n\n // Offset of last mouse down and up events (in CSS pixels)\n state.down = { x: NaN, y: NaN };\n state.up = { x: NaN, y: NaN };\n\n // Which side(s) we're currently resizing\n state.resizeSides = {\n left: false,\n right: false,\n top: false,\n bottom: false\n };\n\n // Bounding rectangle of the brush, in CSS pixel and data dimensions. We\n // need to record data dimensions along with pixel dimensions so that when\n // a new plot is sent, we can re-draw the brush div with the appropriate\n // coords.\n state.boundsCss = {\n xmin: NaN,\n xmax: NaN,\n ymin: NaN,\n ymax: NaN\n };\n state.boundsData = {\n xmin: NaN,\n xmax: NaN,\n ymin: NaN,\n ymax: NaN\n };\n\n // Panel object that the brush is in\n state.panel = null;\n\n // The bounds at the start of a drag/resize (in CSS pixels)\n state.changeStartBounds = {\n xmin: NaN,\n xmax: NaN,\n ymin: NaN,\n ymax: NaN\n };\n\n if ($div)\n $div.remove();\n }\n\n // If there's an existing brush div, use that div to set the new brush's\n // settings, provided that the x, y, and panel variables have the same names,\n // and there's a panel with matching panel variable values.\n function importOldBrush() {\n var oldDiv = $el.find('#' + el.id + '_brush');\n if (oldDiv.length === 0)\n return;\n\n var oldBoundsData = oldDiv.data('bounds-data');\n var oldPanel = oldDiv.data('panel');\n\n if (!oldBoundsData || !oldPanel)\n return;\n\n // Find a panel that has matching vars; if none found, we can't restore.\n // The oldPanel and new panel must match on their mapping vars, and the\n // values.\n for (var i=0; i= bounds.xmin &&\n offset_css.y <= bounds.ymax && offset_css.y >= bounds.ymin;\n }\n\n // Return true if offset is inside a region to start a resize\n function isInResizeArea(offset_css) {\n var sides = whichResizeSides(offset_css);\n return sides.left || sides.right || sides.top || sides.bottom;\n }\n\n // Return an object representing which resize region(s) the cursor is in.\n function whichResizeSides(offset_css) {\n const b = state.boundsCss;\n // Bounds with expansion\n const e = {\n xmin: b.xmin - resizeExpand,\n xmax: b.xmax + resizeExpand,\n ymin: b.ymin - resizeExpand,\n ymax: b.ymax + resizeExpand\n };\n const res = {\n left: false,\n right: false,\n top: false,\n bottom: false\n };\n\n if ((opts.brushDirection === 'xy' || opts.brushDirection === 'x') &&\n (offset_css.y <= e.ymax && offset_css.y >= e.ymin))\n {\n if (offset_css.x < b.xmin && offset_css.x >= e.xmin)\n res.left = true;\n else if (offset_css.x > b.xmax && offset_css.x <= e.xmax)\n res.right = true;\n }\n\n if ((opts.brushDirection === 'xy' || opts.brushDirection === 'y') &&\n (offset_css.x <= e.xmax && offset_css.x >= e.xmin))\n {\n if (offset_css.y < b.ymin && offset_css.y >= e.ymin)\n res.top = true;\n else if (offset_css.y > b.ymax && offset_css.y <= e.ymax)\n res.bottom = true;\n }\n\n return res;\n }\n\n\n // Sets the bounds of the brush (in CSS pixels), given a box and optional\n // panel. This will fit the box bounds into the panel, so we don't brush\n // outside of it. This knows whether we're brushing in the x, y, or xy\n // directions, and sets bounds accordingly. If no box is passed in, just\n // return current bounds.\n function boundsCss(box_css) {\n if (box_css === undefined) {\n return $.extend({}, state.boundsCss);\n }\n\n let min_css = { x: box_css.xmin, y: box_css.ymin };\n let max_css = { x: box_css.xmax, y: box_css.ymax };\n\n const panel = state.panel;\n const panelBounds_img = panel.range;\n\n if (opts.brushClip) {\n min_css = imgToCss(panel.clipImg(cssToImg(min_css)));\n max_css = imgToCss(panel.clipImg(cssToImg(max_css)));\n }\n\n if (opts.brushDirection === 'xy') {\n // No change\n\n } else if (opts.brushDirection === 'x') {\n // Extend top and bottom of plotting area\n min_css.y = imgToCss({y: panelBounds_img.top }).y;\n max_css.y = imgToCss({y: panelBounds_img.bottom}).y;\n\n } else if (opts.brushDirection === 'y') {\n min_css.x = imgToCss({x: panelBounds_img.left }).x;\n max_css.x = imgToCss({x: panelBounds_img.right}).x;\n }\n\n state.boundsCss = {\n xmin: min_css.x,\n xmax: max_css.x,\n ymin: min_css.y,\n ymax: max_css.y\n };\n\n // Positions in data space\n const min_data = state.panel.scaleImgToData(cssToImg(min_css));\n const max_data = state.panel.scaleImgToData(cssToImg(max_css));\n // For reversed scales, the min and max can be reversed, so use findBox\n // to ensure correct order.\n state.boundsData = imageutils.findBox(min_data, max_data);\n // Round to 14 significant digits to avoid spurious changes in FP values\n // (#1634).\n state.boundsData = mapValues(state.boundsData, val => roundSignif(val, 14));\n\n // We also need to attach the data bounds and panel as data attributes, so\n // that if the image is re-sent, we can grab the data bounds to create a new\n // brush. This should be fast because it doesn't actually modify the DOM.\n $div.data('bounds-data', state.boundsData);\n $div.data('panel', state.panel);\n return undefined;\n }\n\n // Get or set the bounds of the brush using coordinates in the data space.\n function boundsData(box_data) {\n if (box_data === undefined) {\n return $.extend({}, state.boundsData);\n }\n\n const box_css = imgToCss(state.panel.scaleDataToImg(box_data));\n\n // The scaling function can reverse the direction of the axes, so we need to\n // find the min and max again.\n boundsCss({\n xmin: Math.min(box_css.xmin, box_css.xmax),\n xmax: Math.max(box_css.xmin, box_css.xmax),\n ymin: Math.min(box_css.ymin, box_css.ymax),\n ymax: Math.max(box_css.ymin, box_css.ymax)\n });\n return undefined;\n }\n\n function getPanel() {\n return state.panel;\n }\n\n // Add a new div representing the brush.\n function addDiv() {\n if ($div) $div.remove();\n\n // Start hidden; we'll show it when movement occurs\n $div = $(document.createElement('div'))\n .attr('id', el.id + '_brush')\n .css({\n 'background-color': opts.brushFill,\n 'opacity': opts.brushOpacity,\n 'pointer-events': 'none',\n 'position': 'absolute'\n })\n .hide();\n\n var borderStyle = '1px solid ' + opts.brushStroke;\n if (opts.brushDirection === 'xy') {\n $div.css({\n 'border': borderStyle\n });\n } else if (opts.brushDirection === 'x') {\n $div.css({\n 'border-left': borderStyle,\n 'border-right': borderStyle\n });\n } else if (opts.brushDirection === 'y') {\n $div.css({\n 'border-top': borderStyle,\n 'border-bottom': borderStyle\n });\n }\n\n $el.append($div);\n $div.offset({x:0, y:0}).width(0).outerHeight(0);\n }\n\n // Update the brush div to reflect the current brush bounds.\n function updateDiv() {\n // Need parent offset relative to page to calculate mouse offset\n // relative to page.\n const img_offset_css = findOrigin($el.find(\"img\"));\n const b = state.boundsCss;\n\n $div.offset({\n top: img_offset_css.y + b.ymin,\n left: img_offset_css.x + b.xmin\n })\n .outerWidth(b.xmax - b.xmin + 1)\n .outerHeight(b.ymax - b.ymin + 1);\n }\n\n function down(offset_css) {\n if (offset_css === undefined)\n return state.down;\n\n state.down = offset_css;\n return undefined;\n }\n\n function up(offset_css) {\n if (offset_css === undefined)\n return state.up;\n\n state.up = offset_css;\n return undefined;\n }\n\n function isBrushing() {\n return state.brushing;\n }\n\n function startBrushing() {\n state.brushing = true;\n addDiv();\n state.panel = coordmap.getPanelCss(state.down, expandPixels);\n\n boundsCss(imageutils.findBox(state.down, state.down));\n updateDiv();\n }\n\n function brushTo(offset_css) {\n boundsCss(imageutils.findBox(state.down, offset_css));\n $div.show();\n updateDiv();\n }\n\n function stopBrushing() {\n state.brushing = false;\n // Save the final bounding box of the brush\n boundsCss(imageutils.findBox(state.down, state.up));\n }\n\n function isDragging() {\n return state.dragging;\n }\n\n function startDragging() {\n state.dragging = true;\n state.changeStartBounds = $.extend({}, state.boundsCss);\n }\n\n function dragTo(offset_css) {\n // How far the brush was dragged\n const dx = offset_css.x - state.down.x;\n const dy = offset_css.y - state.down.y;\n\n // Calculate what new positions would be, before clipping.\n const start = state.changeStartBounds;\n let newBounds_css = {\n xmin: start.xmin + dx,\n xmax: start.xmax + dx,\n ymin: start.ymin + dy,\n ymax: start.ymax + dy\n };\n\n // Clip to the plotting area\n if (opts.brushClip) {\n const panelBounds_img = state.panel.range;\n const newBounds_img = cssToImg(newBounds_css);\n\n // Convert to format for shiftToRange\n let xvals_img = [ newBounds_img.xmin, newBounds_img.xmax ];\n let yvals_img = [ newBounds_img.ymin, newBounds_img.ymax ];\n\n xvals_img = imageutils.shiftToRange(xvals_img, panelBounds_img.left, panelBounds_img.right);\n yvals_img = imageutils.shiftToRange(yvals_img, panelBounds_img.top, panelBounds_img.bottom);\n\n // Convert back to bounds format\n newBounds_css = imgToCss({\n xmin: xvals_img[0],\n xmax: xvals_img[1],\n ymin: yvals_img[0],\n ymax: yvals_img[1]\n });\n }\n\n boundsCss(newBounds_css);\n updateDiv();\n }\n\n function stopDragging() {\n state.dragging = false;\n }\n\n function isResizing() {\n return state.resizing;\n }\n\n function startResizing() {\n state.resizing = true;\n state.changeStartBounds = $.extend({}, state.boundsCss);\n state.resizeSides = whichResizeSides(state.down);\n }\n\n function resizeTo(offset_css) {\n // How far the brush was dragged\n const d_css = {\n x: offset_css.x - state.down.x,\n y: offset_css.y - state.down.y\n };\n\n const d_img = cssToImg(d_css);\n\n // Calculate what new positions would be, before clipping.\n const b_img = cssToImg(state.changeStartBounds);\n const panelBounds_img = state.panel.range;\n\n if (state.resizeSides.left) {\n const xmin_img = imageutils.shiftToRange(b_img.xmin + d_img.x, panelBounds_img.left, b_img.xmax)[0];\n b_img.xmin = xmin_img;\n } else if (state.resizeSides.right) {\n const xmax_img = imageutils.shiftToRange(b_img.xmax + d_img.x, b_img.xmin, panelBounds_img.right)[0];\n b_img.xmax = xmax_img;\n }\n\n if (state.resizeSides.top) {\n const ymin_img = imageutils.shiftToRange(b_img.ymin + d_img.y, panelBounds_img.top, b_img.ymax)[0];\n b_img.ymin = ymin_img;\n } else if (state.resizeSides.bottom) {\n const ymax_img = imageutils.shiftToRange(b_img.ymax + d_img.y, b_img.ymin, panelBounds_img.bottom)[0];\n b_img.ymax = ymax_img;\n }\n\n boundsCss(imgToCss(b_img));\n updateDiv();\n }\n\n function stopResizing() {\n state.resizing = false;\n }\n\n return {\n reset: reset,\n\n importOldBrush: importOldBrush,\n isInsideBrush: isInsideBrush,\n isInResizeArea: isInResizeArea,\n whichResizeSides: whichResizeSides,\n\n onResize: onResize, // A callback when the wrapper div or img is resized.\n\n boundsCss: boundsCss,\n boundsData: boundsData,\n getPanel: getPanel,\n\n down: down,\n up: up,\n\n isBrushing: isBrushing,\n startBrushing: startBrushing,\n brushTo: brushTo,\n stopBrushing: stopBrushing,\n\n isDragging: isDragging,\n startDragging: startDragging,\n dragTo: dragTo,\n stopDragging: stopDragging,\n\n isResizing: isResizing,\n startResizing: startResizing,\n resizeTo: resizeTo,\n stopResizing: stopResizing\n };\n};\n\nexports.resetBrush = function(brushId) {\n exports.setInputValue(brushId, null);\n imageOutputBinding.find(document).trigger(\"shiny-internal:brushed\", {\n brushId: brushId, outputId: null\n });\n};\n\n\n// -----------------------------------------------------------------------\n// Utility functions for finding dimensions and locations of DOM elements\n// -----------------------------------------------------------------------\n\n// Returns the ratio that an element has been scaled (for example, by CSS\n// transforms) in the x and y directions.\nfunction findScalingRatio($el) {\n const boundingRect = $el[0].getBoundingClientRect();\n return {\n x: boundingRect.width / $el.outerWidth(),\n y: boundingRect.height / $el.outerHeight()\n };\n}\n\nfunction findOrigin($el) {\n const offset = $el.offset();\n const scaling_ratio = findScalingRatio($el);\n\n // Find the size of the padding and border, for the top and left. This is\n // before any transforms.\n const paddingBorder = {\n left: parseInt($el.css(\"border-left-width\")) + parseInt($el.css(\"padding-left\")),\n top: parseInt($el.css(\"border-top-width\")) + parseInt($el.css(\"padding-top\"))\n };\n\n // offset() returns the upper left corner of the element relative to the\n // page, but it includes padding and border. Here we find the upper left\n // of the element, not including padding and border.\n return {\n x: offset.left + scaling_ratio.x * paddingBorder.left,\n y: offset.top + scaling_ratio.y * paddingBorder.top\n };\n}\n\n// Find the dimensions of a tag, after transforms, and without padding and\n// border.\nfunction findDims($el) {\n // If there's any padding/border, we need to find the ratio of the actual\n // element content compared to the element plus padding and border.\n const content_ratio = {\n x: $el.width() / $el.outerWidth(),\n y: $el.height() / $el.outerHeight()\n };\n\n // Get the dimensions of the element _after_ any CSS transforms. This\n // includes the padding and border.\n const bounding_rect = $el[0].getBoundingClientRect();\n\n // Dimensions of the element after any CSS transforms, and without\n // padding/border.\n return {\n x: content_ratio.x * bounding_rect.width,\n y: content_ratio.y * bounding_rect.height\n };\n}\n","//---------------------------------------------------------------------\n// Source file: ../srcjs/output_binding_html.js\n\nvar htmlOutputBinding = new OutputBinding();\n$.extend(htmlOutputBinding, {\n find: function(scope) {\n return $(scope).find('.shiny-html-output');\n },\n onValueError: function(el, err) {\n exports.unbindAll(el);\n this.renderError(el, err);\n },\n renderValue: function(el, data) {\n exports.renderContent(el, data);\n }\n});\noutputBindings.register(htmlOutputBinding, 'shiny.htmlOutput');\n\nvar renderDependencies = exports.renderDependencies = function(dependencies) {\n if (dependencies) {\n $.each(dependencies, function(i, dep) {\n renderDependency(dep);\n });\n }\n};\n\n// Render HTML in a DOM element, add dependencies, and bind Shiny\n// inputs/outputs. `content` can be null, a string, or an object with\n// properties 'html' and 'deps'.\nexports.renderContent = function(el, content, where=\"replace\") {\n if (where === \"replace\") {\n exports.unbindAll(el);\n }\n\n var html;\n var dependencies = [];\n if (content === null) {\n html = '';\n } else if (typeof(content) === 'string') {\n html = content;\n } else if (typeof(content) === 'object') {\n html = content.html;\n dependencies = content.deps || [];\n }\n\n exports.renderHtml(html, el, dependencies, where);\n\n var scope = el;\n if (where === \"replace\") {\n exports.initializeInputs(el);\n exports.bindAll(el);\n } else {\n var $parent = $(el).parent();\n if ($parent.length > 0) {\n scope = $parent;\n if (where === \"beforeBegin\" || where === \"afterEnd\") {\n var $grandparent = $parent.parent();\n if ($grandparent.length > 0) scope = $grandparent;\n }\n }\n exports.initializeInputs(scope);\n exports.bindAll(scope);\n }\n};\n\n// Render HTML in a DOM element, inserting singletons into head as needed\nexports.renderHtml = function(html, el, dependencies, where = 'replace') {\n renderDependencies(dependencies);\n return singletons.renderHtml(html, el, where);\n};\n\nvar htmlDependencies = {};\nfunction registerDependency(name, version) {\n htmlDependencies[name] = version;\n}\n\n// Client-side dependency resolution and rendering\nfunction renderDependency(dep) {\n if (htmlDependencies.hasOwnProperty(dep.name))\n return false;\n\n registerDependency(dep.name, dep.version);\n\n var href = dep.src.href;\n\n var $head = $(\"head\").first();\n\n if (dep.meta) {\n var metas = $.map(asArray(dep.meta), function(obj, idx) {\n // only one named pair is expected in obj as it's already been decomposed\n var name = Object.keys(obj)[0];\n return $(\"\").attr(\"name\", name).attr(\"content\", obj[name]);\n });\n $head.append(metas);\n }\n\n if (dep.stylesheet) {\n var stylesheets = $.map(asArray(dep.stylesheet), function(stylesheet) {\n return $(\"\")\n .attr(\"href\", href + \"/\" + encodeURI(stylesheet));\n });\n $head.append(stylesheets);\n }\n\n if (dep.script) {\n var scripts = $.map(asArray(dep.script), function(scriptName) {\n return $(\"