jquery.validator.themes.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /* ========================================================================
  2. * for nice validate themes
  3. * @since K'naan (xknaan@163.com)
  4. * ======================================================================== */
  5. +function ($) {
  6. 'use strict';
  7. function fixedLeft($msgbox) {
  8. var $input = $msgbox.prev(),
  9. $btngroup = $msgbox.next(),
  10. $icheck = $msgbox.closest('[data-icheck]'),
  11. $ichecks = $icheck.siblings('[data-icheck="'+ $icheck.data('icheck') +'"]').andSelf(),
  12. $upload = $msgbox.closest('.bjui-upload')
  13. var offLeft = 0
  14. if (($input && $input.isTag('select') && $input.is(':hidden')) && ($btngroup && $btngroup.hasClass('bootstrap-select'))) {
  15. var $btngroup = $msgbox.next()
  16. offLeft += $btngroup.outerWidth()
  17. }
  18. if ($icheck.length) {
  19. $ichecks.each(function() {
  20. offLeft += $(this).outerWidth()
  21. })
  22. $msgbox.children().css('top', -4)
  23. }
  24. if ($upload.length) {
  25. offLeft += $upload.find('.bjui-upload-select').outerWidth()
  26. }
  27. return offLeft
  28. }
  29. var TPL_ARROW = '<span class="n-arrow"><b>◆</b><i>◆</i></span>'
  30. $.validator.setTheme({
  31. 'simple_right': {
  32. formClass: 'n-simple',
  33. msgClass: 'n-right',
  34. msgShow: function($msgbox, type) {
  35. var $el = $msgbox.children()
  36. var $el = $msgbox.children()
  37. var $form = $msgbox.closest('form'),
  38. fW = $form.width(),
  39. fL = $form.offset().left,
  40. eL = $msgbox.offset().left,
  41. mw = $el.outerWidth()
  42. var offLeft = fixedLeft($msgbox)
  43. if ((fW - (eL - fL)) < (mw + offLeft + 8)) {
  44. $msgbox.find('> .msg-wrap').addClass('wrap').width(fW - (eL - fL) - offLeft - 8)
  45. .find('> .n-msg').width(fW - (eL - fL) - offLeft - 8 - 30)
  46. }
  47. $el.css({
  48. left: offLeft,
  49. opacity: 1
  50. }).fadeIn(200)
  51. },
  52. msgHide: function($msgbox, type) {
  53. $msgbox.hide()
  54. }
  55. },
  56. 'simple_bottom': {
  57. formClass: 'n-simple',
  58. msgClass: 'n-bottom'
  59. },
  60. 'yellow_top': {
  61. formClass: 'n-yellow',
  62. msgClass: 'n-top',
  63. msgArrow: TPL_ARROW
  64. },
  65. 'yellow_right': {
  66. formClass: 'n-yellow',
  67. msgClass: 'n-right',
  68. msgArrow: TPL_ARROW,
  69. msgShow: function($msgbox, type) {
  70. var $el = $msgbox.children()
  71. var $el = $msgbox.children()
  72. var $form = $msgbox.closest('form'),
  73. fW = $form.width(),
  74. fL = $form.offset().left,
  75. eL = $msgbox.offset().left,
  76. mw = $el.outerWidth()
  77. var offLeft = fixedLeft($msgbox)
  78. if ((fW - (eL - fL)) < (mw + offLeft + 8)) {
  79. $msgbox.find('> .msg-wrap').addClass('wrap').width(fW - (eL - fL) - offLeft - 8)
  80. .find('> .n-msg').width(fW - (eL - fL) - offLeft - 8 - 30)
  81. }
  82. $el.css({
  83. left: offLeft,
  84. opacity: 1
  85. }).fadeIn(200)
  86. },
  87. msgHide: function($msgbox, type) {
  88. $msgbox.hide()
  89. }
  90. },
  91. 'yellow_right_effect': {
  92. formClass: 'n-yellow',
  93. msgClass: 'n-right',
  94. msgArrow: TPL_ARROW,
  95. msgShow: function($msgbox, type) {
  96. var $el = $msgbox.children()
  97. var $el = $msgbox.children()
  98. var $form = $msgbox.closest('form'),
  99. fW = $form.width(),
  100. fL = $form.offset().left,
  101. eL = $msgbox.offset().left,
  102. mw = $el.outerWidth()
  103. var offLeft = fixedLeft($msgbox)
  104. if ((fW - (eL - fL)) < (mw + offLeft + 8)) {
  105. $msgbox.find('> .msg-wrap').addClass('wrap').width(fW - (eL - fL) - offLeft - 8)
  106. .find('> .n-msg').width(fW - (eL - fL) - offLeft - 8 - 30)
  107. }
  108. if ($el.is(':animated')) return
  109. if (type === 'error') {
  110. $el.css({
  111. left: offLeft + 20,
  112. opacity: 0
  113. }).delay(100).show().stop().animate({
  114. left: offLeft - 4,
  115. opacity: 1
  116. }, 150).animate({
  117. left: offLeft + 3
  118. }, 80).animate({
  119. left: offLeft
  120. }, 80)
  121. } else {
  122. $el.css({
  123. left: offLeft,
  124. opacity: 1
  125. }).fadeIn(200)
  126. }
  127. },
  128. msgHide: function($msgbox, type) {
  129. var $el = $msgbox.children()
  130. $el.stop().delay(100).show().animate({
  131. left: '20px',
  132. opacity: 0
  133. }, 300, function(){
  134. $msgbox.hide()
  135. })
  136. }
  137. },
  138. 'red_right_effect': {
  139. formClass: 'n-red',
  140. msgClass: 'n-right',
  141. msgArrow: TPL_ARROW,
  142. msgShow: function($msgbox, type) {
  143. var $el = $msgbox.children()
  144. var $form = $msgbox.closest('form'),
  145. fW = $form.width(),
  146. fL = $form.offset().left,
  147. eL = $msgbox.offset().left,
  148. mw = $el.outerWidth()
  149. var offLeft = fixedLeft($msgbox)
  150. var $wrap = $msgbox.find('> .msg-wrap')
  151. var $icon = $msgbox.find('.n-icon')
  152. if ((fW - (eL - fL)) < (mw + offLeft + 8)) {
  153. $wrap.addClass('wrap').width(fW - (eL - fL) - offLeft - 8)
  154. .find('> .n-msg').width(fW - (eL - fL) - offLeft - 8 - 30)
  155. }
  156. if ($wrap.hasClass('n-error'))
  157. $icon.removeClass('n-icon').addClass('glyphicon glyphicon-remove-circle').css({top:-1, 'font-size':'14px', 'vertical-align':'middle'})
  158. else if ($wrap.hasClass('n-tip'))
  159. $icon.removeClass('n-icon').addClass('glyphicon glyphicon-info-sign').css({top:-1, 'font-size':'14px', 'vertical-align':'middle'})
  160. else if ($wrap.hasClass('n-ok'))
  161. $icon.removeClass('n-icon').addClass('glyphicon glyphicon-ok-circle').css({top:-1, 'font-size':'14px', 'vertical-align':'middle'})
  162. if ($el.is(':animated')) return
  163. if (type === 'error') {
  164. $el.css({
  165. left: offLeft + 20,
  166. opacity: 0
  167. }).delay(100).show().stop().animate({
  168. left: offLeft - 4,
  169. opacity: 1
  170. }, 150).animate({
  171. left: offLeft + 3
  172. }, 80).animate({
  173. left: offLeft
  174. }, 80)
  175. } else {
  176. $el.css({
  177. left: offLeft,
  178. opacity: 1
  179. }).fadeIn(200)
  180. }
  181. },
  182. msgHide: function($msgbox, type){
  183. var $el = $msgbox.children()
  184. $el.stop().delay(100).show().animate({
  185. left: '20px',
  186. opacity: 0
  187. }, 300, function(){
  188. $msgbox.hide()
  189. })
  190. }
  191. },
  192. 'red_bottom_effect_grid': {
  193. formClass: 'n-red',
  194. msgClass: 'n-right',
  195. msgArrow: TPL_ARROW,
  196. msgShow: function($msgbox, type) {
  197. var $el = $msgbox.children()
  198. /*
  199. var $form = $msgbox.closest('form'),
  200. fW = $form.width(),
  201. fL = $form.offset().left,
  202. eL = $msgbox.offset().left,
  203. mw = $el.outerWidth()
  204. */
  205. var offLeft = fixedLeft($msgbox)
  206. var $wrap = $msgbox.find('> .msg-wrap')
  207. var $icon = $msgbox.find('.n-icon')
  208. /*if ((fW - (eL - fL)) < (mw + offLeft + 8)) {
  209. $wrap.addClass('wrap').width(fW - (eL - fL) - offLeft - 8)
  210. .find('> .n-msg').width(fW - (eL - fL) - offLeft - 8 - 30)
  211. }*/
  212. if ($wrap.hasClass('n-error'))
  213. $icon.removeClass('n-icon').addClass('glyphicon glyphicon-remove-circle').css({top:-1, 'font-size':'14px', 'vertical-align':'middle'})
  214. else if ($wrap.hasClass('n-tip'))
  215. $icon.removeClass('n-icon').addClass('glyphicon glyphicon-info-sign').css({top:-1, 'font-size':'14px', 'vertical-align':'middle'})
  216. else if ($wrap.hasClass('n-ok'))
  217. $icon.removeClass('n-icon').addClass('glyphicon glyphicon-ok-circle').css({top:-1, 'font-size':'14px', 'vertical-align':'middle'})
  218. if ($el.is(':animated')) return
  219. if (type === 'error') {
  220. $el.css({
  221. left: offLeft + 20,
  222. opacity: 0
  223. }).delay(100).show().stop().animate({
  224. left: offLeft - 4,
  225. opacity: 1
  226. }, 150).animate({
  227. left: offLeft + 3
  228. }, 80).animate({
  229. left: offLeft
  230. }, 80)
  231. } else {
  232. $el.css({
  233. left: offLeft,
  234. opacity: 1
  235. }).fadeIn(200)
  236. }
  237. },
  238. msgHide: function($msgbox, type) {
  239. var $el = $msgbox.children()
  240. $el.stop().delay(100).show().animate({
  241. left: '20px',
  242. opacity: 0
  243. }, 300, function(){
  244. $msgbox.hide()
  245. })
  246. }
  247. }
  248. })
  249. $.validator.config({
  250. theme : 'red_right_effect',
  251. formClass : 'n-red'
  252. })
  253. }(jQuery);