Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bselect

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bselect - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

93

bselect.js
/*!
* BSelect v0.2.2 - 2013-03-04
* BSelect v0.2.3 - 2013-03-08
*

@@ -79,2 +79,4 @@ * Created by Gustavo Henke <gustavo@injoin.com.br>

bselect.find(".bselect-search-input").attr( "aria-expanded", "true" );
return this;

@@ -96,2 +98,4 @@ },

bselect.find(".bselect-search-input").attr( "aria-expanded", "false" );
return this;

@@ -115,6 +119,15 @@ },

// Remove the highlighted status from any previously selected item...
bselect.find("li").removeClass("active");
var index = bselect.find("li")
.removeClass("active")
.attr( "aria-selected", "false" )
.index( $elem );
var option = this.find("option[value!='']").get( index );
// Trigger the selected event
this.trigger( "bselectselect", [ option ] );
// ...and add to the new selected item :)
val = $elem.addClass("active").data("value");
$elem.attr( "aria-selected", "true" );

@@ -128,5 +141,3 @@ bselect.find(".bselect-label").text( $elem.text() );

// Trigger the selected event
if ( typeof options.selected === "function" ) {
options.selected.call( this, val, $elem );
}
this.trigger( "bselectselected", [ val, option ] );

@@ -157,9 +168,13 @@ return this;

var results = $();
listItems = bselect.find("li").hide();
for ( i = 0; i < listItems.length; i++ ) {
if ( listItems[ i ].textContent.toLowerCase().indexOf( searched.toLowerCase() ) > -1 ) {
$( listItems[ i ] ).show();
results.add( $( listItems[ i ] ).show() );
}
}
this.trigger( "bselectsearch", [ searched, results ] );
adjustDropdownHeight( listItems.end() );

@@ -183,3 +198,3 @@ return this;

var bselect = _callMethod( this, "element" ),
html = "";
optionList = bselect.find(".bselect-option-list").empty();

@@ -191,8 +206,11 @@ this.find("option").each(function() {

html += "<li class='bselect-option' data-value='" + this.value + "'>" +
"<a href='#'>" + this.text + "</a>" +
"</li>";
var li = $( "<li class='bselect-option' />" ).attr({
role: "option",
"aria-selected": "false"
}).data( "value", this.value );
li.append( "<a href='#'>" + this.text + "</a>" );
li.appendTo( optionList );
});
bselect.find(".bselect-option-list").html( html );
return this;

@@ -266,20 +284,37 @@ },

function setup( elem, options ) {
var caret, label, container, html;
var caret, label, container, id, dropdown;
var $elem = $( elem );
// First of, let's build the base HTML of BSelect
html = "<div class='bselect' id='bselect-" + ( ++elements ) + "'>";
html += "<div class='bselect-dropdown'>";
id = ++elements;
container = $( "<div class='bselect' />", {
id: "bselect-" + id
});
dropdown = $("<div class='bselect-dropdown' />");
if ( options.searchInput === true ) {
html += "<div class='bselect-search'>" +
"<input type='text' class='bselect-search-input' />" +
"<span class='bselect-search-icon'><i class='icon-search'></i></span>" +
"</div>";
var search = $("<div class='bselect-search' />");
$("<input type='text' class='bselect-search-input' />").attr({
role: "combobox",
"aria-expanded": "false",
"aria-owns": "bselect-option-list-" + id
// The W3C documentation says that role="combobox" should have aria-autocomplete,
// but the validator tells us that this is invalid. Very strange.
//"aria-autocomplete": "list"
}).appendTo( search );
$("<span class='bselect-search-icon'><i class='icon-search' /></span>").appendTo( search );
search.appendTo( dropdown );
}
html += "<ul class='bselect-option-list'></ul>";
html += "</div></div>";
$("<ul class='bselect-option-list' />").attr({
id: "bselect-option-list-" + id,
role: "listbox"
}).appendTo( dropdown );
container = $elem.after( html ).next();
container.append( dropdown ).insertAfter( $elem );

@@ -295,2 +330,6 @@ // Save some precious data in the original select now, as we have the container in the DOM

$elem.bind( "bselectselect", options.select );
$elem.bind( "bselectselected", options.selected );
$elem.bind( "bselectsearch", options.search );
label = $("<span />").addClass("bselect-label").text( getPlaceholder( $elem ) );

@@ -318,9 +357,16 @@ caret = $("<button type='button' />").addClass("bselect-caret").html("<span class='caret'></span>");

$.fn.bselect = function( arg ) {
if ( typeof arg === "string" && this[ 0 ] && $.isPlainObject( $( this[ 0 ] ).data("bselect") ) ) {
if ( methods[ arg ] !== undefined ) {
if ( typeof arg === "string" && this[ 0 ] ) {
if ( $.isPlainObject( $( this[ 0 ] ).data("bselect") ) && methods[ arg ] !== undefined ) {
return methods[ arg ].apply( $( this[ 0 ] ), Array.prototype.slice.call( arguments, 1 ) );
}
return this;
}
return this.each(function() {
// #8 - avoid creating bselect again on the same element
if ( $.isPlainObject( $( this ).data("bselect") ) ) {
return;
}
arg = $.isPlainObject( arg ) ? arg : {};

@@ -341,2 +387,3 @@ arg = $.extend( {}, $.bselect.defaults, arg );

searchInput: true,
search: null,
select: null,

@@ -343,0 +390,0 @@ selected: null

/*!
* BSelect v0.2.2 - 2013-03-04
* BSelect v0.2.3 - 2013-03-08
*

@@ -7,2 +7,2 @@ * Created by Gustavo Henke <gustavo@injoin.com.br>

*/
(function(e,t){"use strict";function n(e,n){return o[n]!==t?o[n].apply(e,Array.prototype.slice.call(arguments,2)):e}function i(t){return n(t,"option","placeholder")||t.data("placeholder")||e.bselect.i18n.selectAnOption}function s(e){var t=e.find(".bselect-option-list"),n=t.find("li:visible").length;t.innerHeight(1.5*parseInt(t.css("line-height"),10)*(5>n?n:5))}function l(t,i,s){var l=n(t,"element");e.each(i,function(t,n){if(s[t]!==n&&"size"===t){var i;i=e.map(r.slice(0),function(e){return"bselect-"+e}).join(" "),l.removeClass(i),r.indexOf(s.size)>-1&&l.addClass("bselect-"+s.size)}})}function a(t,s){var a,r,h,d,u=e(t);d="<div class='bselect' id='bselect-"+ ++c+"'>",d+="<div class='bselect-dropdown'>",s.searchInput===!0&&(d+="<div class='bselect-search'><input type='text' class='bselect-search-input' /><span class='bselect-search-icon'><i class='icon-search'></i></span></div>"),d+="<ul class='bselect-option-list'></ul>",d+="</div></div>",h=u.after(d).next(),u.data("bselect",{options:s,element:h}),l(u,e.bselect.defaults,s),n(u,"refresh"),r=e("<span />").addClass("bselect-label").text(i(u)),a=e("<button type='button' />").addClass("bselect-caret").html("<span class='caret'></span>"),h.prepend(a).prepend(r),r.outerWidth(u.outerWidth()-a.outerWidth()),u.hide(),e(document).click(function(t){h.find(".bselect-dropdown").is(":visible")&&!e(".bselect-dropdown, .bselect-dropdown *",h).find(t.target).length&&n(u,"hide")}),h.find(".bselect-search-input").keyup(e.proxy(o.search,u)),h.on("click",".bselect-option",e.proxy(o.select,u)),h.on("click",".bselect-caret, .bselect-label",e.proxy(o.toggle,u))}var c=0,o={option:function(n,i){var s=this.data("bselect").options||{},a=e.extend({},s);return"string"==typeof n&&"_"!==n[0]?i===t?s[n]:(s[n]=i,l(this,a,s),this):(e.isPlainObject(n)&&(e.extend(s,n),l(this,a,s),this.data("bselect").options=s),s)},element:function(){return this.data("bselect").element},toggle:function(t){var i=n(this,"element");if(t instanceof e.Event){var s=n(this,"option","showOn");if(t.stopPropagation(),e(t.target).is(".bselect-label")&&"both"!==s)return this}return i.find(".bselect-dropdown").is(":hidden")?n(this,"show"):n(this,"hide"),this},show:function(){var e,t=n(this,"element"),i=t.find(".bselect-dropdown");return i.css("left","-9999em").show(),s(t),i.hide().css("left","auto"),i.slideDown(n(this,"option","animationDuration")),t.addClass("open"),e=t.find(".bselect-search-input"),e.innerWidth(e.parent().width()-e.next().outerWidth()),this},hide:function(e){var i=n(this,"option"),s=n(this,"element");return e=e===t?!0:e,s.find(".bselect-dropdown").slideUp(i.animationDuration),s.removeClass("open"),e&&i.clearSearchOnExit&&n(this,"clearSearch"),this},select:function(t){var i,s,l=n(this,"option"),a=n(this,"element");if(t instanceof e.Event)i=e(t.currentTarget);else if(i=a.find("li").eq(t),!i.length)return this;return a.find("li").removeClass("active"),s=i.addClass("active").data("value"),a.find(".bselect-label").text(i.text()),n(this,"hide"),this.val(s),"function"==typeof l.selected&&l.selected.call(this,s,i),this},search:function(t){var i,l,a=n(this,"option"),c=t instanceof e.Event?t.target.value:t,o=n(this,"element");if(""===c&&n(this,"clearSearch"),t instanceof e.Event||o.find(".bselect-search").val(c),!(c===a.lastSearch||c.length<a.minSearchInput)){for(i=o.find("li").hide(),l=0;i.length>l;l++)i[l].textContent.toLowerCase().indexOf(c.toLowerCase())>-1&&e(i[l]).show();return s(i.end()),this}},clearSearch:function(){var e=n(this,"element");return e.find(".bselect-search").val(""),e.find("li").show(),s(e),this},refresh:function(){var e=n(this,"element"),t="";return this.find("option").each(function(){this.value&&(t+="<li class='bselect-option' data-value='"+this.value+"'>"+"<a href='#'>"+this.text+"</a>"+"</li>")}),e.find(".bselect-option-list").html(t),this},destroy:function(){var e=n(this,"element");this.data("bselect",null),e.remove(),this.show()}},r=["mini","small","large"];e.fn.bselect=function(n){return"string"==typeof n&&this[0]&&e.isPlainObject(e(this[0]).data("bselect"))&&o[n]!==t?o[n].apply(e(this[0]),Array.prototype.slice.call(arguments,1)):this.each(function(){n=e.isPlainObject(n)?n:{},n=e.extend({},e.bselect.defaults,n),a(this,n)})},e.bselect={defaults:{size:"normal",showOn:"both",clearSearchOnExit:!0,minSearchInput:0,animationDuration:300,searchInput:!0,select:null,selected:null},i18n:{selectAnOption:"Select an option"}}})(jQuery);
(function(e,t){"use strict";function s(e,s){return c[s]!==t?c[s].apply(e,Array.prototype.slice.call(arguments,2)):e}function i(t){return s(t,"option","placeholder")||t.data("placeholder")||e.bselect.i18n.selectAnOption}function n(e){var t=e.find(".bselect-option-list"),s=t.find("li:visible").length;t.innerHeight(1.5*parseInt(t.css("line-height"),10)*(5>s?s:5))}function a(t,i,n){var a=s(t,"element");e.each(i,function(t,s){if(n[t]!==s&&"size"===t){var i;i=e.map(o.slice(0),function(e){return"bselect-"+e}).join(" "),a.removeClass(i),o.indexOf(n.size)>-1&&a.addClass("bselect-"+n.size)}})}function l(t,n){var l,o,d,h,p,u=e(t);if(h=++r,d=e("<div class='bselect' />",{id:"bselect-"+h}),p=e("<div class='bselect-dropdown' />"),n.searchInput===!0){var f=e("<div class='bselect-search' />");e("<input type='text' class='bselect-search-input' />").attr({role:"combobox","aria-expanded":"false","aria-owns":"bselect-option-list-"+h}).appendTo(f),e("<span class='bselect-search-icon'><i class='icon-search' /></span>").appendTo(f),f.appendTo(p)}e("<ul class='bselect-option-list' />").attr({id:"bselect-option-list-"+h,role:"listbox"}).appendTo(p),d.append(p).insertAfter(u),u.data("bselect",{options:n,element:d}),a(u,e.bselect.defaults,n),s(u,"refresh"),u.bind("bselectselect",n.select),u.bind("bselectselected",n.selected),u.bind("bselectsearch",n.search),o=e("<span />").addClass("bselect-label").text(i(u)),l=e("<button type='button' />").addClass("bselect-caret").html("<span class='caret'></span>"),d.prepend(l).prepend(o),o.outerWidth(u.outerWidth()-l.outerWidth()),u.hide(),e(document).click(function(t){d.find(".bselect-dropdown").is(":visible")&&!e(".bselect-dropdown, .bselect-dropdown *",d).find(t.target).length&&s(u,"hide")}),d.find(".bselect-search-input").keyup(e.proxy(c.search,u)),d.on("click",".bselect-option",e.proxy(c.select,u)),d.on("click",".bselect-caret, .bselect-label",e.proxy(c.toggle,u))}var r=0,c={option:function(s,i){var n=this.data("bselect").options||{},l=e.extend({},n);return"string"==typeof s&&"_"!==s[0]?i===t?n[s]:(n[s]=i,a(this,l,n),this):(e.isPlainObject(s)&&(e.extend(n,s),a(this,l,n),this.data("bselect").options=n),n)},element:function(){return this.data("bselect").element},toggle:function(t){var i=s(this,"element");if(t instanceof e.Event){var n=s(this,"option","showOn");if(t.stopPropagation(),e(t.target).is(".bselect-label")&&"both"!==n)return this}return i.find(".bselect-dropdown").is(":hidden")?s(this,"show"):s(this,"hide"),this},show:function(){var e,t=s(this,"element"),i=t.find(".bselect-dropdown");return i.css("left","-9999em").show(),n(t),i.hide().css("left","auto"),i.slideDown(s(this,"option","animationDuration")),t.addClass("open"),e=t.find(".bselect-search-input"),e.innerWidth(e.parent().width()-e.next().outerWidth()),t.find(".bselect-search-input").attr("aria-expanded","true"),this},hide:function(e){var i=s(this,"option"),n=s(this,"element");return e=e===t?!0:e,n.find(".bselect-dropdown").slideUp(i.animationDuration),n.removeClass("open"),e&&i.clearSearchOnExit&&s(this,"clearSearch"),n.find(".bselect-search-input").attr("aria-expanded","false"),this},select:function(t){var i,n,a=(s(this,"option"),s(this,"element"));if(t instanceof e.Event)i=e(t.currentTarget);else if(i=a.find("li").eq(t),!i.length)return this;var l=a.find("li").removeClass("active").attr("aria-selected","false").index(i),r=this.find("option[value!='']").get(l);return this.trigger("bselectselect",[r]),n=i.addClass("active").data("value"),i.attr("aria-selected","true"),a.find(".bselect-label").text(i.text()),s(this,"hide"),this.val(n),this.trigger("bselectselected",[n,r]),this},search:function(t){var i,a,l=s(this,"option"),r=t instanceof e.Event?t.target.value:t,c=s(this,"element");if(""===r&&s(this,"clearSearch"),t instanceof e.Event||c.find(".bselect-search").val(r),!(r===l.lastSearch||r.length<l.minSearchInput)){var o=e();for(i=c.find("li").hide(),a=0;i.length>a;a++)i[a].textContent.toLowerCase().indexOf(r.toLowerCase())>-1&&o.add(e(i[a]).show());return this.trigger("bselectsearch",[r,o]),n(i.end()),this}},clearSearch:function(){var e=s(this,"element");return e.find(".bselect-search").val(""),e.find("li").show(),n(e),this},refresh:function(){var t=s(this,"element"),i=t.find(".bselect-option-list").empty();return this.find("option").each(function(){if(this.value){var t=e("<li class='bselect-option' />").attr({role:"option","aria-selected":"false"}).data("value",this.value);t.append("<a href='#'>"+this.text+"</a>"),t.appendTo(i)}}),this},destroy:function(){var e=s(this,"element");this.data("bselect",null),e.remove(),this.show()}},o=["mini","small","large"];e.fn.bselect=function(s){return"string"==typeof s&&this[0]?e.isPlainObject(e(this[0]).data("bselect"))&&c[s]!==t?c[s].apply(e(this[0]),Array.prototype.slice.call(arguments,1)):this:this.each(function(){e.isPlainObject(e(this).data("bselect"))||(s=e.isPlainObject(s)?s:{},s=e.extend({},e.bselect.defaults,s),l(this,s))})},e.bselect={defaults:{size:"normal",showOn:"both",clearSearchOnExit:!0,minSearchInput:0,animationDuration:300,searchInput:!0,search:null,select:null,selected:null},i18n:{selectAnOption:"Select an option"}}})(jQuery);
{
"name": "bselect",
"version": "0.2.2",
"version": "0.2.3",
"main": ["./bselect.js", "./bselect.css"],

@@ -5,0 +5,0 @@ "dependencies": {

/*!
* BSelect v0.2.2 - 2013-03-04
* BSelect v0.2.3 - 2013-03-08
*

@@ -4,0 +4,0 @@ * Created by Gustavo Henke <gustavo@injoin.com.br>

{
"name": "bselect",
"title": "BSelect",
"version": "0.2.2",
"version": "0.2.3",
"homepage": "http://gustavohenke.github.com/bselect/",

@@ -6,0 +6,0 @@ "author": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc