Guest User

Untitled

a guest
Oct 20th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.20 KB | None | 0 0
  1. <head>
  2. <script src="//cdnjs.cloudflare.com/ajax/libs/less.js/3.7.1/less.min.js" ></script>
  3. </head>
  4. <div class="container">
  5. <div id="select" ng-model=""></div>
  6. </div>
  7.  
  8. <style>
  9. @import url('https://fonts.googleapis.com/css?family=Roboto:400,100,300,700,900');
  10. @import url('//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css');
  11.  
  12. body {
  13. font-family: 'Roboto';
  14. padding: 0;
  15. margin: 0;
  16. background: linear-gradient(-45deg, #183850 0, #183850 25%, #192c46 50%, #22254c 75%, #22254c 100%);
  17. background-repeat: no-repeat;
  18. background-attachment: fixed;
  19. margin-top: 100px;
  20. margin-left: 20px;
  21. color: #ecf0f1;
  22. }
  23.  
  24. .container {
  25. margin: 0 auto;
  26. display: table;
  27. }
  28. /* selecionator */
  29. .selectionator {
  30. position: relative;
  31. border-radius: 2px;
  32. background-color: #2c3e50;
  33. color: #95a5a6;
  34. perspective: 800px;
  35. width: 200px;
  36. /*
  37. &:before {
  38. content: "";
  39. background-color: transparent;
  40. width: 100%;
  41. height: 2.5em;
  42. position: absolute;
  43. background-image: linear-gradient(top, #000, rgba(0,0,0,0));
  44. }
  45. */
  46.  
  47. .search {
  48. position: relative;
  49. display: block;
  50. border: 0px;
  51. width: 100%;
  52. padding: 1em;
  53. outline: none;
  54. color: #FFF;
  55. background-color: #16a085;
  56. box-sizing: border-box;
  57. transform-style: preserve-3d;
  58. transform-origin: 50% 0%;
  59. transition: transform .3s;
  60. border-radius: 2px;
  61. z-index: 99;
  62. .overlay {
  63. width: 100%;
  64. background-color: #f00;
  65. height: 100%;
  66. position: absolute;
  67. left: 0;
  68. top: 0px;
  69. background: linear-gradient(to bottom, rgba(0, 0, 0, 0.35) 0%, rgba(0, 0, 0, 0.1) 100%);
  70. opacity: 0;
  71. }
  72. .shadow {
  73. position: absolute;
  74. height: 15px;
  75. width: 100%;
  76. left: 0;
  77. bottom: -15px;
  78. transform-origin: center bottom;
  79. transform: scale(0.95, 1) translate3d(0, 0px, 0);
  80. background: linear-gradient(to bottom, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0) 100%);
  81. opacity: 0;
  82. }
  83. &:before {
  84. content: "f078";
  85. display: inline-block;
  86. font-family: FontAwesome;
  87. font-style: normal;
  88. font-weight: normal;
  89. line-height: 1.5;
  90. float: right;
  91. vertical-align: middle;
  92. }
  93. }
  94. &:hover, &.opened {
  95. .search {
  96. transform: rotate3d(1,0,0,60deg);
  97. .overlay, .shadow {
  98. opacity: 1;
  99. }
  100. }
  101. .menu {
  102. height: 200px;
  103. opacity: 1;
  104. }
  105. }
  106. .menu {
  107. overflow: hidden;
  108. position: absolute;
  109. width: 100%;
  110. top: 50%;
  111. height: 0px;
  112. border-radius: 0px;
  113. background-color: #2c3e50;
  114. transition: all 0.3s ease;
  115. opacity: 0;
  116. border: 1px solid #16a085;
  117. border-top: none;
  118. }
  119. ul.list {
  120. list-style: none;
  121. padding: 0px;
  122. margin: 0px;
  123. overflow:hidden;
  124. overflow-y: scroll;
  125. height: 0px;
  126. backface-visibility: hidden;
  127. transition: all 0.3s ease;
  128. opacity: 0.75;
  129. width: 100%;
  130. height: 100%;
  131. > li span.header {
  132. display: block;
  133. padding: 6px;
  134. background-color: #34495e;
  135. font-weight: 200;
  136. color: #fff;
  137. }
  138. }
  139. ul.optgroup {
  140. list-style: none;
  141. padding: 0px;
  142. margin: 0px;
  143. -webkit-touch-callout: none;
  144. -webkit-user-select: none;
  145. -moz-user-select: none;
  146. user-select: none;
  147. li {
  148. &:hover {
  149. background-color: #16a085;
  150. color: #fff;
  151. }
  152. input[type="checkbox"] {
  153. display: none;
  154. margin: 6px;
  155. &:checked {
  156. background-color: #1abc9c;
  157. ~ label {
  158. background-color: #2980b9;
  159. color: #fff;
  160. &:before {
  161. content: "f14a";
  162. }
  163. }
  164. }
  165. }
  166.  
  167. label {
  168. font-weight: 100;
  169. display: block;
  170. //margin: 0px 0px 0px 15px;
  171. padding-left: 15px;
  172. line-height: 2em;
  173. transition: all 0.3s ease;
  174. &:before {
  175. content: "f096";
  176. display: inline-block;
  177. font-family: FontAwesome;
  178. font-style: normal;
  179. font-weight: normal;
  180. line-height: 1;
  181. margin-right: 8px;
  182. vertical-align: middle;
  183. }
  184. }
  185. }
  186. }
  187. }
  188. </style>
  189.  
  190. <script>
  191. /*
  192. * library dependencies:
  193. * jquery
  194. */
  195.  
  196. // plugin 1.0
  197.  
  198.  
  199. $(document).ready(function () {
  200. "use strict";
  201. var pluginName = "selectionator";
  202. var defaults = {
  203. propertyName: "selectionator",
  204. src: null,
  205. orgElement: null,
  206. checkedItems: [],
  207. // custom callback events
  208. onError: function(error) {}
  209. };
  210. function Plugin(element, options) {
  211. this.element = element;
  212. this.selector = null;
  213. this.options = $.extend({}, defaults, options);
  214. this._defaults = defaults;
  215. this._name = pluginName;
  216. this.init();
  217. }
  218. Plugin.prototype = {
  219. init: function () {
  220. console.log("options: ", this.options);
  221. var that = this;
  222. var self = $(that.element);
  223. that.options.src = that.element.getAttribute('data-src');
  224. that.selector = that.createFromJson(that.options.data);
  225. that.options.orgElement = that.element.parentNode.replaceChild(that.selector, that.element);
  226. $(that.selector).addClass(that._name);
  227. },
  228. createFromJson: function(options) {
  229. var that = this;
  230. var select = document.createElement('select');
  231. var popup = document.createElement('div');
  232. var header = document.createElement('div');
  233. var search = document.createElement('span');
  234. var overlay = document.createElement('span');
  235. overlay.className = 'overlay';
  236. var shadow = document.createElement('span');
  237. shadow.className = 'shadow';
  238. var placeholder = document.createTextNode('Options');
  239. search.className = 'search';
  240. search.appendChild(shadow);
  241. search.appendChild(overlay);
  242. search.appendChild(placeholder);
  243. popup.appendChild(search);
  244. var menu = document.createElement('ul');
  245. select.style.display = 'none';
  246. menu.className = 'list';
  247. var box = document.createElement('div');
  248. box.className = 'menu';
  249. box.appendChild(menu);
  250. popup.appendChild(box);
  251. console.log("optgroup", options.optgroups);
  252. options.optgroups.forEach(function(optgroup, index) {
  253.  
  254.  
  255. var menuItem = document.createElement('li');
  256. //menuItem.className('header');
  257. var header = document.createElement('span');
  258. header.className = 'header';
  259. var caption = document.createTextNode(optgroup.label);
  260. header.appendChild(caption);
  261. menuItem.appendChild(header);
  262. var menuItems = document.createElement('ul');
  263. menuItems.className = 'optgroup';
  264. menuItem.appendChild(menuItems);
  265. menu.appendChild(menuItem);
  266.  
  267. optgroup.options.forEach(function(option, index) {
  268. var opt = new Option(option.text, option.value, option.defaultSelected, option.selected);
  269. select.options.add(opt);
  270. var item = document.createElement('li');
  271. var label = document.createElement('label');
  272. label.setAttribute("for", option.value);
  273. var checkbox = document.createElement('input');
  274. $(checkbox).data(option);
  275. checkbox.setAttribute('type', 'checkbox');
  276.  
  277. checkbox.addEventListener('change', function(event){
  278. var checkbox = event.target;
  279. var $el = $(event.srcElement);
  280. if (checkbox.checked) {
  281. that.options.checkedItems.push(event.srcElement);
  282. placeholder.nodeValue = "Selected: " + that.options.checkedItems.length + " out of " + $(that.selector).find('input[type="checkbox"]').length;
  283.  
  284. } else {
  285. that.options.checkedItems.pop();
  286. that.options.checkedItems = that.options.checkedItems.filter(function(items, index){
  287. return items.value != $el.data().value;
  288. });
  289. placeholder.nodeValue = "Selected: " + that.options.checkedItems.length + " out of " + $(that.selector).find('input[type="checkbox"]').length;
  290. }
  291. console.log("data: ", that.options.checkedItems);
  292. });
  293. checkbox.id = option.value;
  294. var caption = document.createTextNode(option.text);
  295. label.appendChild(caption);
  296. item.appendChild(checkbox);
  297. item.appendChild(label);
  298. menuItems.appendChild(item);
  299. });
  300. });
  301. return popup;
  302. },
  303. onAddFriend: function(data) {
  304. var that = this;
  305. return that.options.onAddFriend(that, data);
  306. },
  307. onRemoveFriend: function(data){
  308. var that = this;
  309. var self = $(that.element);
  310. return that.options.onRemoveFriend(data);
  311. },
  312. destroy: function() {
  313. var that = this;
  314. $(that.element).unbind("destroyed", that.teardown);
  315. that.teardown();
  316. },
  317. teardown: function() {
  318. var that = this;
  319. $(that.element).removeClass(that._name);
  320. $(that.selector).replaceWith(that.options.orgElement);
  321. $(that.element).removeData(that._name);
  322. that.unbind();
  323. that.element = null;
  324. },
  325. bind: function() { },
  326. unbind: function() { }
  327. };
  328. $.fn[pluginName] = function (options) {
  329. return this.each(function () {
  330. if (!$.data(this, pluginName)) {
  331. $.data(this, pluginName, new Plugin(this, options));
  332. }
  333. });
  334. };
  335. });
  336. //Attach plugin to all matching element
  337. $(document).ready(function () {
  338. $('#select').selectionator({
  339. data: {
  340. optgroups: [{
  341. label: 'Marketing',
  342. options: [{
  343. value: 0,
  344. text: 'Steve',
  345. defaultSelected: true,
  346. selected: false
  347. }, {
  348. value: 345,
  349. text: 'mike',
  350. defaultSelected: false,
  351. selected: false
  352. }, {
  353. value: 111,
  354. text: "pepe",
  355. defaultSelected: false,
  356. selected: false
  357. }, {
  358. value: 433,
  359. text: "anna",
  360. defaultSelected: false,
  361. selected: true
  362. }]
  363. }, {
  364. label: 'Sales',
  365. options: [{
  366. value: 555,
  367. text: 'linda',
  368. defaultSelected: false,
  369. selected: false
  370. }, {
  371. value: 333,
  372. text: "mike",
  373. defaultSelected: false,
  374. selected: false
  375. }]
  376. }]
  377. }
  378. });
  379. setTimeout(function(){
  380. $(".selectionator").addClass('opened');
  381. }, 500);
  382. setTimeout(function(){
  383. $(".selectionator").removeClass('opened');
  384. }, 1250);
  385. });
  386.  
  387. </script>
Add Comment
Please, Sign In to add comment