From 829d10c74ba09752cfa5e035a40a3c3a52385d6d Mon Sep 17 00:00:00 2001 From: Jake Humphrey Date: Fri, 5 Feb 2016 11:31:58 -0600 Subject: [PATCH 1/4] Adding custom select box to assets --- README.md | 46 ++++++++ .../codelation/components/selectbox.js | 58 ++++++++++ app/assets/stylesheets/codelation.scss | 1 + .../codelation/components/selectbox.scss | 100 ++++++++++++++++++ 4 files changed, 205 insertions(+) create mode 100644 app/assets/javascripts/codelation/components/selectbox.js create mode 100644 app/assets/stylesheets/codelation/components/selectbox.scss diff --git a/README.md b/README.md index 258a4d5..8ffc292 100644 --- a/README.md +++ b/README.md @@ -298,6 +298,52 @@ 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 + +``` + +***SCSS*** + +```scss +//override these variable to change its basic style +$select-background-color: $color; +$select-border: 1px solid $color; +$select-arrow-color: $color; +$select-border-radius: $radius; +$select-height: $height; +$select-width: $width; + +//To add more styles +.select { + //style the selectbox container +} + +.select-styled { + //style the selectbox selected value +} + +.select-options { + //style the selectbox options container + + li { + //style the selectbox options + } +} + +``` + ## 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..1c82fe9 --- /dev/null +++ b/app/assets/javascripts/codelation/components/selectbox.js @@ -0,0 +1,58 @@ +(function() { + "use strict"; + + App.register('component').enter(function() { + $('select.custom').each(function(){ + var $this = $(this), numberOfOptions = $(this).children('option').length; + + $this.addClass('select-hidden'); + $this.wrap('
'); + $this.after('
'); + + //Set the selected item + var $styledSelect = $this.next('div.select-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 = $('