init.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. define(['jquery', 'jquery.gcjs', 'foxui', 'tpl'], function ($, gc, FoxUI, tpl) {
  2. tpl.helper("timeformat", function (content) {
  3. if (isNaN(content)) {
  4. return content;
  5. }
  6. return $.format( new Date(content), true);
  7. });
  8. $.formatDate = function (now, hasTime) {
  9. var year = now.getYear();
  10. var month = now.getMonth() + 1;
  11. var date = now.getDate();
  12. var hour = now.getHours();
  13. var minute = now.getMinutes();
  14. if (hasTime) {
  15. return year + "-" + month + "-" + date + " " + hour + ":" + minute;
  16. }
  17. return year + "-" + month + "-" + date;
  18. };
  19. $.urlencode = function (clearString)
  20. {
  21. var output = '';
  22. var x = 0;
  23. clearString = utf16to8(clearString.toString());
  24. var regex = /(^[a-zA-Z0-9-_.]*)/;
  25. while (x < clearString.length)
  26. {
  27. var match = regex.exec(clearString.substr(x));
  28. if (match != null && match.length > 1 && match[1] != '')
  29. {
  30. output += match[1];
  31. x += match[1].length;
  32. }
  33. else
  34. {
  35. if (clearString[x] == ' ')
  36. {
  37. output += '+';
  38. }
  39. else
  40. {
  41. var charCode = clearString.charCodeAt(x);
  42. var hexVal = charCode.toString(16);
  43. output += '%' + (hexVal.length < 2 ? '0' : '') + hexVal.toUpperCase();
  44. }
  45. x++;
  46. }
  47. };
  48. function utf16to8(str) {
  49. var out, i, len, c;
  50. out = "";
  51. len = str.length;
  52. for (i = 0; i < len; i++)
  53. {
  54. c = str.charCodeAt(i);
  55. if ((c >= 0x0001) && (c <= 0x007F))
  56. {
  57. out += str.charAt(i);
  58. }
  59. else if (c > 0x07FF)
  60. {
  61. out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
  62. out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
  63. out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
  64. }
  65. else
  66. {
  67. out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
  68. out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
  69. }
  70. }
  71. return out;
  72. }
  73. return output;
  74. };
  75. $.urldecode = function (encodedString)
  76. {
  77. var output = encodedString;
  78. var binVal, thisString;
  79. var myregexp = /(%[^%]{2})/;
  80. function utf8to16(str)
  81. {
  82. var out, i, len, c;
  83. var char2, char3;
  84. out = "";
  85. len = str.length;
  86. i = 0;
  87. while (i < len)
  88. {
  89. c = str.charCodeAt(i++);
  90. switch (c >> 4)
  91. {
  92. case 0:
  93. case 1:
  94. case 2:
  95. case 3:
  96. case 4:
  97. case 5:
  98. case 6:
  99. case 7:
  100. out += str.charAt(i - 1);
  101. break;
  102. case 12:
  103. case 13:
  104. char2 = str.charCodeAt(i++);
  105. out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
  106. break;
  107. case 14:
  108. char2 = str.charCodeAt(i++);
  109. char3 = str.charCodeAt(i++);
  110. out += String.fromCharCode(((c & 0x0F) << 12) |
  111. ((char2 & 0x3F) << 6) |
  112. ((char3 & 0x3F) << 0));
  113. break;
  114. }
  115. }
  116. return out;
  117. }
  118. while ((match = myregexp.exec(output)) != null
  119. && match.length > 1
  120. && match[1] != '')
  121. {
  122. binVal = parseInt(match[1].substr(1), 16);
  123. thisString = String.fromCharCode(binVal);
  124. output = output.replace(match[1], thisString);
  125. }
  126. output = output.replace(/\\+/g, " ");
  127. output = utf8to16(output);
  128. return output;
  129. };
  130. //商品组
  131. if ($('.fui-goods-group').length) {
  132. var resizeImages = function () {
  133. $('.fui-goods-group img').not(".exclude").each(function () {
  134. $(this).height($(this).width());
  135. })
  136. };
  137. window.onload = resizeImages;
  138. window.resize = resizeImages;
  139. }
  140. FoxUI.init();
  141. });