Меню для выбора селектов (Selectionator)

Разработка Меню для выбора селектов (Selectionator)

Нет прав для скачивания
Меню для выбора селектов (Selectionator).
Пишем HTML:
HTML:
<div class="container">
  <div id="select" ng-model=""></div>
</div>
Пишем стиль:
CSS:
@import url('//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css');
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 100;
  src: url(https://fonts.gstatic.com/s/roboto/v29/KFOkCnqEu92Fr1MmgVxIIzc.ttf) format('truetype');
}
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmSU5fBBc9.ttf) format('truetype');
}
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 400;
  src: url(https://fonts.gstatic.com/s/roboto/v29/KFOmCnqEu92Fr1Mu4mxP.ttf) format('truetype');
}
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 700;
  src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmWUlfBBc9.ttf) format('truetype');
}
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 900;
  src: url(https://fonts.gstatic.com/s/roboto/v29/KFOlCnqEu92Fr1MmYUtfBBc9.ttf) format('truetype');
}
body {
  font-family: 'Roboto';
  padding: 0;
  margin: 0;
  background: linear-gradient(-45deg, #183850 0, #183850 25%, #192c46 50%, #22254c 75%, #22254c 100%);
  background-repeat: no-repeat;
  background-attachment: fixed;
  margin-top: 100px;
  margin-left: 20px;
  color: #ecf0f1;
}
.container {
  margin: 0 auto;
  display: table;
}
/* selecionator */
.selectionator {
  position: relative;
  border-radius: 2px;
  background-color: #2c3e50;
  color: #95a5a6;
  perspective: 800px;
  width: 200px;
  /*
  &:before {
  content: "";
  background-color: transparent;
  width: 100%;
  height: 2.5em;
  position: absolute;
  background-image: linear-gradient(top, #000, rgba(0,0,0,0));
}
  */
}
.selectionator .search {
  position: relative;
  display: block;
  border: 0px;
  width: 100%;
  padding: 1em;
  outline: none;
  color: #FFF;
  background-color: #16a085;
  box-sizing: border-box;
  transform-style: preserve-3d;
  transform-origin: 50% 0%;
  transition: transform 0.3s;
  border-radius: 2px;
  z-index: 99;
}
.selectionator .search .overlay {
  width: 100%;
  background-color: #f00;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.35) 0%, rgba(0, 0, 0, 0.1) 100%);
  opacity: 0;
}
.selectionator .search .shadow {
  position: absolute;
  height: 15px;
  width: 100%;
  left: 0;
  bottom: -15px;
  transform-origin: center bottom;
  transform: scale(0.95, 1) translate3d(0, 0px, 0);
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0) 100%);
  opacity: 0;
}
.selectionator .search:before {
  content: "\f078";
  display: inline-block;
  font-family: FontAwesome;
  font-style: normal;
  font-weight: normal;
  line-height: 1.5;
  float: right;
  vertical-align: middle;
}
.selectionator:hover .search,
.selectionator.opened .search {
  transform: rotate3d(1, 0, 0, 60deg);
}
.selectionator:hover .search .overlay,
.selectionator.opened .search .overlay,
.selectionator:hover .search .shadow,
.selectionator.opened .search .shadow {
  opacity: 1;
}
.selectionator:hover .menu,
.selectionator.opened .menu {
  height: 200px;
  opacity: 1;
}
.selectionator .menu {
  overflow: hidden;
  position: absolute;
  width: 100%;
  top: 50%;
  height: 0px;
  border-radius: 0px;
  background-color: #2c3e50;
  transition: all 0.3s ease;
  opacity: 0;
  border: 1px solid #16a085;
  border-top: none;
}
.selectionator ul.list {
  list-style: none;
  padding: 0px;
  margin: 0px;
  overflow: hidden;
  overflow-y: scroll;
  height: 0px;
  -webkit-backface-visibility: hidden;
          backface-visibility: hidden;
  transition: all 0.3s ease;
  opacity: 0.75;
  width: 100%;
  height: 100%;
}
.selectionator ul.list > li span.header {
  display: block;
  padding: 6px;
  background-color: #34495e;
  font-weight: 200;
  color: #fff;
}
.selectionator ul.optgroup {
  list-style: none;
  padding: 0px;
  margin: 0px;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
      user-select: none;
}
.selectionator ul.optgroup li:hover {
  background-color: #16a085;
  color: #fff;
}
.selectionator ul.optgroup li input[type="checkbox"] {
  display: none;
  margin: 6px;
}
.selectionator ul.optgroup li input[type="checkbox"]:checked {
  background-color: #1abc9c;
}
.selectionator ul.optgroup li input[type="checkbox"]:checked ~ label {
  background-color: #2980b9;
  color: #fff;
}
.selectionator ul.optgroup li input[type="checkbox"]:checked ~ label:before {
  content: "\f14a";
}
.selectionator ul.optgroup li label {
  font-weight: 100;
  display: block;
  padding-left: 15px;
  line-height: 2em;
  transition: all 0.3s ease;
}
.selectionator ul.optgroup li label:before {
  content: "\f096";
  display: inline-block;
  font-family: FontAwesome;
  font-style: normal;
  font-weight: normal;
  line-height: 1;
  margin-right: 8px;
  vertical-align: middle;
}
Пишем Jquery:
JavaScript:
$(document).ready(function () {
  "use strict";
  var pluginName = "selectionator";
  var defaults = {
    propertyName: "selectionator",
    src: null,
    orgElement: null,
    checkedItems: [],
    // custom callback events
    onError: function(error) {}
  };
  function Plugin(element, options) {
    this.element = element;
    this.selector = null;
    this.options = $.extend({}, defaults, options);
    this._defaults = defaults;
    this._name = pluginName;
    this.init();
  }
  Plugin.prototype = {
    init: function () {
      console.log("options: ", this.options);
      var that = this;
      var self = $(that.element);
      that.options.src = that.element.getAttribute('data-src');
      that.selector = that.createFromJson(that.options.data);
      that.options.orgElement = that.element.parentNode.replaceChild(that.selector, that.element);
      $(that.selector).addClass(that._name);
    },
    createFromJson: function(options) {
      var that = this;
      var select = document.createElement('select');
      var popup = document.createElement('div');
      var header = document.createElement('div');
      var search = document.createElement('span');
      var overlay = document.createElement('span');
      overlay.className = 'overlay';
      var shadow = document.createElement('span');
      shadow.className = 'shadow';
      var placeholder = document.createTextNode('Options');
      search.className = 'search';
      search.appendChild(shadow);     
      search.appendChild(overlay);   
      search.appendChild(placeholder);   
      popup.appendChild(search);
      var menu = document.createElement('ul');
      select.style.display = 'none';
      menu.className = 'list';
      var box = document.createElement('div');
      box.className = 'menu';
      box.appendChild(menu);
      popup.appendChild(box);
      console.log("optgroup", options.optgroups);
      options.optgroups.forEach(function(optgroup, index) {


        var menuItem = document.createElement('li');
        //menuItem.className('header');
        var header = document.createElement('span');
        header.className = 'header';
        var caption = document.createTextNode(optgroup.label);
        header.appendChild(caption);
        menuItem.appendChild(header);
        var menuItems = document.createElement('ul');
        menuItems.className = 'optgroup';
        menuItem.appendChild(menuItems);
        menu.appendChild(menuItem);

        optgroup.options.forEach(function(option, index) {
          var opt = new Option(option.text, option.value, option.defaultSelected, option.selected);
          select.options.add(opt);
          var item = document.createElement('li');
          var label = document.createElement('label');
          label.setAttribute("for", option.value);
          var checkbox = document.createElement('input');
          $(checkbox).data(option);
          checkbox.setAttribute('type', 'checkbox');

          checkbox.addEventListener('change', function(event){
            var checkbox = event.target;
            var $el = $(event.srcElement);
            if (checkbox.checked) {
              that.options.checkedItems.push(event.srcElement);
              placeholder.nodeValue = "Selected: " + that.options.checkedItems.length + " out of " + $(that.selector).find('input[type="checkbox"]').length;

            } else {
              that.options.checkedItems.pop();
              that.options.checkedItems = that.options.checkedItems.filter(function(items, index){
                return items.value != $el.data().value;
              });
              placeholder.nodeValue = "Selected: " + that.options.checkedItems.length + " out of " + $(that.selector).find('input[type="checkbox"]').length;
            }
            console.log("data: ", that.options.checkedItems);
          });
          checkbox.id = option.value;
          var caption = document.createTextNode(option.text);
          label.appendChild(caption);
          item.appendChild(checkbox);
          item.appendChild(label);
          menuItems.appendChild(item);
        });
      });
      return popup;
    },
    onAddFriend: function(data) {
      var that = this;
      return that.options.onAddFriend(that, data);
    },
    onRemoveFriend: function(data){
      var that = this;
      var self = $(that.element);
      return that.options.onRemoveFriend(data);
    },
    destroy: function() {
      var that = this;
      $(that.element).unbind("destroyed", that.teardown);
      that.teardown();
    },
    teardown: function() {
      var that = this;
      $(that.element).removeClass(that._name);
      $(that.selector).replaceWith(that.options.orgElement);
      $(that.element).removeData(that._name);
      that.unbind();
      that.element = null;
    },
    bind: function() { },
    unbind: function() { }
  };
  $.fn[pluginName] = function (options) {
    return this.each(function () {
      if (!$.data(this, pluginName)) {
        $.data(this, pluginName, new Plugin(this, options));
      }
    });
  };
});
//Attach plugin to all matching element
$(document).ready(function () {
  $('#select').selectionator({
    data: {
      optgroups: [{
        label: 'Marketing',
        options: [{
          value: 0,
          text: 'Steve',
          defaultSelected: true,
          selected: false
        }, {
          value: 345,
          text: 'mike',
          defaultSelected: false,
          selected: false
        }, {
          value: 111,
          text: "pepe",
          defaultSelected: false,
          selected: false
        }, {
          value: 433,
          text: "anna",
          defaultSelected: false,
          selected: true
        }]
      }, {
        label: 'Sales',
        options: [{
          value: 555,
          text: 'linda',
          defaultSelected: false,
          selected: false
        }, {
          value: 333,
          text: "mike",
          defaultSelected: false,
          selected: false
        }]
      }]
    }
  });
  setTimeout(function(){
    $(".selectionator").addClass('opened');
  }, 500);
  setTimeout(function(){
    $(".selectionator").removeClass('opened');
  }, 1250);
});
Получаем следующий результат:
dfr53.gif
Автор
baltun
Скачиваний
0
Просмотры
326
Первый выпуск
Обновление
Рейтинг
0.00 звёзд Оценок: 0

Ещё ресурсы от baltun

Назад
Верх Низ