diff --git a/README.md b/README.md index 258a4d5..b14986b 100644 --- a/README.md +++ b/README.md @@ -298,6 +298,43 @@ Example: } ``` +#### Components + +##### Selectbox + +Creates a styled jQuery selectbox. This will create a div to hold the selected value and +a ul list of options to select from. User the following to style: + +***HTML*** + +```html +
+ +
+``` + +***JAVASCRIPT*** +```javascript +sbox = SelectBox.new({ + container: $(".selector"), + scrollBreak: 2 // not required but can change how big the options menu is relative to the screen size +}) +``` + +***SCSS*** + +```scss +.selector { + // If any of these default variables are set, then it will adopt those values + // $base-body-color, $base-font-color, $base-border-color, $base-border-radius + + @include select($height, $padding, $background-color, $color, $border, $border-radius, $arrow-color) +} +``` + ## Contributing 1. Fork it diff --git a/app/assets/javascripts/codelation/components/selectbox.js b/app/assets/javascripts/codelation/components/selectbox.js new file mode 100644 index 0000000..7e61f5a --- /dev/null +++ b/app/assets/javascripts/codelation/components/selectbox.js @@ -0,0 +1,71 @@ +/* +Required Args: container (a reference to a node) +Optional Args: + - scrollBreak: (int) Determines how big the options menu is compaired to the screen size +*/ + +var SelectBox = function(args) { + if ($(args.container).has("select")){ + var selectboxObj = $(args.container).find("select"); + + $(selectboxObj).each(function(){ + var $this = $(this), numberOfOptions = $(this).children('option').length; + + $this.wrap('
'); + $this.after('
'); + + //Set the selected item + var $styledSelect = $this.next('div.ca-selectbox-styled'); + var selectedValue = $this.children('option').eq(0).text(); + $this.children('option').each(function () { + if ($(this).attr("selected")) { + selectedValue = $(this).text(); + } + }); + $styledSelect.text(selectedValue); + + + var $list = $('