admincp.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // JavaScript Document
  2. //自定义radio样式
  3. $(document).ready( function(){
  4. $(".cb-enable").click(function(){
  5. var parent = $(this).parents('.onoff');
  6. $('.cb-disable',parent).removeClass('selected');
  7. $(this).addClass('selected');
  8. $('.checkbox',parent).attr('checked', true);
  9. });
  10. $(".cb-disable").click(function(){
  11. var parent = $(this).parents('.onoff');
  12. $('.cb-enable',parent).removeClass('selected');
  13. $(this).addClass('selected');
  14. $('.checkbox',parent).attr('checked', false);
  15. });
  16. });
  17. //图片比例缩放控制
  18. function DrawImage(ImgD, FitWidth, FitHeight) {
  19. var image = new Image();
  20. image.src = ImgD.src;
  21. if (image.width > 0 && image.height > 0) {
  22. if (image.width / image.height >= FitWidth / FitHeight) {
  23. if (image.width > FitWidth) {
  24. ImgD.width = FitWidth;
  25. ImgD.height = (image.height * FitWidth) / image.width;
  26. } else {
  27. ImgD.width = image.width;
  28. ImgD.height = image.height;
  29. }
  30. } else {
  31. if (image.height > FitHeight) {
  32. ImgD.height = FitHeight;
  33. ImgD.width = (image.width * FitHeight) / image.height;
  34. } else {
  35. ImgD.width = image.width;
  36. ImgD.height = image.height;
  37. }
  38. }
  39. }
  40. }
  41. $(function(){
  42. // 显示隐藏预览图 start
  43. $('.show_image').hover(
  44. function(){
  45. $(this).next().css('display','block');
  46. },
  47. function(){
  48. $(this).next().css('display','none');
  49. }
  50. );
  51. // 全选 start
  52. $('.checkall').click(function(){
  53. $('.checkall').attr('checked',$(this).attr('checked') == 'checked');
  54. $('.checkitem').each(function(){
  55. $(this).attr('checked',$('.checkall').attr('checked') == 'checked');
  56. });
  57. });
  58. // 表格鼠标悬停变色 start
  59. $("tbody tr").hover(
  60. function(){
  61. $(this).css({background:"#FBFBFB"} );
  62. },
  63. function(){
  64. $(this).css({background:"#FFF"} );
  65. });
  66. // 可编辑列(input)变色
  67. $('.editable').hover(
  68. function(){
  69. $(this).removeClass('editable').addClass('editable2');
  70. },
  71. function(){
  72. $(this).removeClass('editable2').addClass('editable');
  73. }
  74. );
  75. // 提示操作 展开与隐藏
  76. $("#prompt tr:odd").addClass("odd");
  77. $("#prompt tr:not(.odd)").hide();
  78. $("#prompt tr:first-child").show();
  79. $("#prompt tr.odd").click(function(){
  80. $(this).next("tr").toggle();
  81. $(this).find(".title").toggleClass("ac");
  82. $(this).find(".arrow").toggleClass("up");
  83. });
  84. // 可编辑列(area)变色
  85. $('.editable-tarea').hover(
  86. function(){
  87. $(this).removeClass('editable-tarea').addClass('editable-tarea2');
  88. },
  89. function(){
  90. $(this).removeClass('editable-tarea2').addClass('editable-tarea');
  91. }
  92. );
  93. });
  94. /* 火狐下取本地全路径 */
  95. function getFullPath(obj)
  96. {
  97. if(obj)
  98. {
  99. // ie
  100. if (window.navigator.userAgent.indexOf("MSIE")>=1)
  101. {
  102. obj.select();
  103. if(window.navigator.userAgent.indexOf("MSIE") == 25){
  104. obj.blur();
  105. }
  106. return document.selection.createRange().text;
  107. }
  108. // firefox
  109. else if(window.navigator.userAgent.indexOf("Firefox")>=1)
  110. {
  111. if(obj.files)
  112. {
  113. //return obj.files.item(0).getAsDataURL();
  114. return window.URL.createObjectURL(obj.files.item(0));
  115. }
  116. return obj.value;
  117. }
  118. return obj.value;
  119. }
  120. }
  121. /* AJAX选择品牌 */
  122. (function($) {
  123. $.fn.brandinit = function(options){
  124. var brand_container = $(this);
  125. //根据首字母查询
  126. $(this).find('.letter[nctype="letter"]').find('a[data-letter]').click(function(){
  127. var _url = $(this).parents('.brand-index:first').attr('data-url');
  128. var _letter = $(this).attr('data-letter');
  129. var _search = $(this).html();
  130. $.getJSON(_url, {type : 'letter', letter : _letter}, function(data){
  131. $(brand_container).insertBrand({param:data,search:_search});
  132. });
  133. });
  134. // 根据关键字查询
  135. $(this).find('.search[nctype="search"]').find('a').click(function(){
  136. var _url = $(this).parents('.brand-index:first').attr('data-url');
  137. var _keyword = $('#search_brand_keyword').val();
  138. $.getJSON(_url, {type : 'keyword', keyword : _keyword}, function(data){
  139. $(brand_container).insertBrand({param:data,search:_keyword});
  140. });
  141. });
  142. // 选择品牌
  143. $(this).find('ul[nctype="brand_list"]').on('click', 'li', function(){
  144. $('#b_id').val($(this).attr('data-id'));
  145. $('#b_name').val($(this).attr('data-name'));
  146. });
  147. //搜索品牌列表滚条绑定
  148. $(this).find('div[nctype="brandList"]').perfectScrollbar();
  149. }
  150. $.fn.insertBrand = function(options) {
  151. //品牌搜索容器
  152. var dataContainer = $(this);
  153. $(dataContainer).find('div[nctype="brandList"]').show();
  154. $(dataContainer).find('div[nctype="noBrandList"]').hide();
  155. var _ul = $(dataContainer).find('ul[nctype="brand_list"]');
  156. _ul.html('');
  157. if ($.isEmptyObject(options.param)) {
  158. $(dataContainer).find('div[nctype="brandList"]').hide();
  159. $(dataContainer).find('div[nctype="noBrandList"]').show().find('strong').html(options.search);
  160. return false;
  161. }
  162. $.each(options.param, function(i, n){
  163. $('<li data-id="' + n.brand_id + '" data-name="' + n.brand_name + '"><em>' + n.brand_initial + '</em>' + n.brand_name + '</li>').appendTo(_ul);
  164. });
  165. //搜索品牌列表滚条绑定
  166. $(dataContainer).find('div[nctype="brandList"]').perfectScrollbar('update');
  167. };
  168. })(jQuery);