PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/App/Presentation/Content/themes/default/js/jquery.selectbox-0.6.1.js

http://century.codeplex.com
JavaScript | 135 lines | 117 code | 2 blank | 16 comment | 15 complexity | a977734a26bd5b3df8d51efb400384c8 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * jQuery custom selectboxes
  3. *
  4. * Copyright (c) 2008 Krzysztof Suszy?„ski (suszynski.org)
  5. * Licensed under the MIT License:
  6. * http://www.opensource.org/licenses/mit-license.php
  7. *
  8. * @version 0.6.1
  9. * @category visual
  10. * @package jquery
  11. * @subpakage ui.selectbox
  12. * @author Krzysztof Suszy?&#x201E;ski <k.suszynski@wit.edu.pl>
  13. **/
  14. jQuery.fn.selectbox = function (options) {
  15. /* Default settings */
  16. var settings = {
  17. className: 'jquery-selectbox',
  18. animationSpeed: "fast",
  19. replaceInvisible: true
  20. };
  21. var commonClass = 'jquery-custom-selectboxes-replaced';
  22. var listOpen = false;
  23. var showList = function (listObj) {
  24. var selectbox = listObj.parents('.' + settings.className + '');
  25. listObj.slideDown(settings.animationSpeed, function () {
  26. listOpen = true;
  27. });
  28. selectbox.addClass('selecthover');
  29. jQuery(document).bind('click', onBlurList);
  30. return listObj;
  31. }
  32. var hideList = function (listObj) {
  33. var selectbox = listObj.parents('.' + settings.className + '');
  34. listObj.slideUp(settings.animationSpeed, function () {
  35. listOpen = false;
  36. jQuery(this).parents('.' + settings.className + '').removeClass('selecthover');
  37. });
  38. jQuery(document).unbind('click', onBlurList);
  39. return listObj;
  40. }
  41. var onBlurList = function (e) {
  42. var trgt = e.target;
  43. var currentListElements = jQuery('.' + settings.className + '-list:visible').parent().find('*').andSelf();
  44. if (jQuery.inArray(trgt, currentListElements) < 0 && listOpen) {
  45. hideList(jQuery('.' + commonClass + '-list'));
  46. }
  47. return false;
  48. }
  49. /* Processing settings */
  50. settings = jQuery.extend(settings, options || {});
  51. /* Wrapping all passed elements */
  52. return this.each(function () {
  53. var _this = jQuery(this);
  54. if (_this.filter(':visible').length == 0 && !settings.replaceInvisible)
  55. return;
  56. var replacement = jQuery(
  57. '<div class="' + settings.className + ' ' + commonClass + '">' +
  58. '<div class="' + settings.className + '-moreButton" />' +
  59. '<div class="' + settings.className + '-list ' + commonClass + '-list" />' +
  60. '<span class="' + settings.className + '-currentItem" />' +
  61. '</div>'
  62. );
  63. jQuery('option', _this).each(function (k, v) {
  64. var v = jQuery(v);
  65. var listElement = jQuery('<span class="' + settings.className + '-item value-' + v.val() + ' item-' + k + '">' + v.text() + '</span>');
  66. listElement.click(function () {
  67. var thisListElement = jQuery(this);
  68. var thisReplacment = thisListElement.parents('.' + settings.className);
  69. var thisIndex = thisListElement[0].className.split(' ');
  70. for (k1 in thisIndex) {
  71. if (/^item-[0-9]+$/.test(thisIndex[k1])) {
  72. thisIndex = parseInt(thisIndex[k1].replace('item-', ''), 10);
  73. break;
  74. }
  75. };
  76. var thisValue = thisListElement[0].className.split(' ');
  77. for (k1 in thisValue) {
  78. if (/^value-.+$/.test(thisValue[k1])) {
  79. thisValue = thisValue[k1].replace('value-', '');
  80. break;
  81. }
  82. };
  83. thisReplacment
  84. .find('.' + settings.className + '-currentItem')
  85. .text(thisListElement.text());
  86. thisReplacment
  87. .find('select')
  88. .val(thisValue)
  89. .triggerHandler('change');
  90. var thisSublist = thisReplacment.find('.' + settings.className + '-list');
  91. if (thisSublist.filter(":visible").length > 0) {
  92. hideList(thisSublist);
  93. } else {
  94. showList(thisSublist);
  95. }
  96. })
  97. .bind('mouseenter', function () {
  98. jQuery(this).addClass('listelementhover');
  99. }).bind('mouseleave', function () {
  100. jQuery(this).removeClass('listelementhover');
  101. });
  102. jQuery('.' + settings.className + '-list', replacement).append(listElement);
  103. if (v.filter(':selected').length > 0) {
  104. jQuery('.' + settings.className + '-currentItem', replacement).text(v.text());
  105. }
  106. });
  107. replacement.find('.' + settings.className + '-moreButton').click(function () {
  108. var thisMoreButton = jQuery(this);
  109. var otherLists = jQuery('.' + settings.className + '-list')
  110. .not(thisMoreButton.siblings('.' + settings.className + '-list'));
  111. hideList(otherLists);
  112. var thisList = thisMoreButton.siblings('.' + settings.className + '-list');
  113. if (thisList.filter(":visible").length > 0) {
  114. hideList(thisList);
  115. } else {
  116. showList(thisList);
  117. }
  118. }).bind('mouseenter', function () {
  119. jQuery(this).addClass('morebuttonhover');
  120. }).bind('mouseleave', function () {
  121. jQuery(this).removeClass('morebuttonhover');
  122. });
  123. _this.hide().replaceWith(replacement).appendTo(replacement);
  124. var thisListBox = replacement.find('.' + settings.className + '-list');
  125. });
  126. }
  127. jQuery.fn.unselectbox = function () {
  128. var commonClass = 'jquery-custom-selectboxes-replaced';
  129. return this.each(function () {
  130. var selectToRemove = jQuery(this).filter('.' + commonClass);
  131. selectToRemove.replaceWith(selectToRemove.find('select').show());
  132. });
  133. }