function.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // JavaScript Document
  2. String.prototype.trim = function () {
  3. var str = this,
  4. str = str.replace(/^\s+/, '');
  5. for (var i = str.length - 1; i >= 0; i--) {
  6. if (/\S/.test(str.charAt(i))) {
  7. str = str.substring(0, i + 1);
  8. break;
  9. }
  10. }
  11. return str;
  12. }
  13. Array.prototype.Contain = function (item) {
  14. var array = this;
  15. for (var i = array.length - 1; i >= 0; i--) {
  16. if (array[i] == item)
  17. return true;
  18. }
  19. return false;
  20. }
  21. /*取cookies*/
  22. var getCookie = function (c_name) {
  23. if (document.cookie.length > 0) {
  24. c_start = document.cookie.indexOf(c_name + "=");
  25. if (c_start != -1) {
  26. c_start = c_start + c_name.length + 1;
  27. c_end = document.cookie.indexOf(";", c_start);
  28. if (c_end == -1) c_end = document.cookie.length;
  29. return decodeURIComponent(document.cookie.substring(c_start, c_end));
  30. }
  31. }
  32. return "";
  33. }
  34. //设为首页
  35. var sethomepage = function (url) {
  36. if (document.all) {
  37. document.body.style.behavior = 'url(#default#homepage)';
  38. document.body.setHomePage(window.location.href);
  39. } else if (window.sidebar) {
  40. if (window.netscape) {
  41. try {
  42. netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  43. } catch (e) {
  44. alert("该操作被浏览器拒绝,如果想启用该功能,请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
  45. }
  46. }
  47. var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
  48. prefs.setCharPref('browser.startup.homepage', window.location.href);
  49. } else {
  50. alert('您的浏览器不支持自动设置首页, 请使用浏览器菜单手动设置!');
  51. }
  52. }
  53. //加入收藏
  54. var addfav = function () {
  55. if (document.all) {
  56. try {
  57. window.external.addFavorite(window.location.href, document.title);
  58. } catch (e) {
  59. alert("加入收藏失败,请使用Ctrl+D进行添加");
  60. }
  61. } else if (window.sidebar) {
  62. window.sidebar.addPanel(document.title, window.location.href, "");
  63. } else {
  64. alert("加入收藏失败,请使用Ctrl+D进行添加");
  65. }
  66. }
  67. //图片缩放 参数(图片,允许的宽度,允许的高度)
  68. function DrawImage(ImgD, iwidth, iheight) {
  69. var image = new Image();
  70. image.src = ImgD.src;
  71. if (image.width > 0 && image.height > 0) {
  72. if (0==iheight||(image.width / image.height) >= (iwidth / iheight)) {
  73. if (image.width > iwidth) {
  74. ImgD.width = iwidth;
  75. ImgD.height = (image.height * iwidth) / image.width;
  76. } else {
  77. ImgD.width = image.width;
  78. ImgD.height = image.height;
  79. }
  80. }
  81. else {
  82. if (image.height > iheight) {
  83. ImgD.height = iheight;
  84. ImgD.width = (image.width * iheight) / image.height;
  85. } else {
  86. ImgD.width = image.width;
  87. ImgD.height = image.height;
  88. }
  89. }
  90. }
  91. }
  92. /*********瀑布流图片展示***********/
  93. //var config = {
  94. // CellCount:3,
  95. // CellSeparated:0,
  96. // CellWidth:320,
  97. // RowSepareted:0,
  98. // BoxId:"",
  99. // Item:"",
  100. // More_bottom:"",
  101. // More_url:""
  102. //};
  103. var flowImage = function (config)
  104. {
  105. var _cell = new Array(config.CellCount);
  106. var _box = $(config.BoxId);
  107. var _index = 0;
  108. var _itemIndex = 0;
  109. var pageIndex = 2;
  110. var Init = function ()
  111. {
  112. var _cellItem = { left: 0,top: 0 };
  113. _cell[0] = { left: 0,top: 0 };
  114. for (var i = 1; i < config.CellCount; i++)
  115. {
  116. _cell[i] = { left: _cell[i - 1].left + config.CellSeparated + config.CellWidth,top: 0 };
  117. }
  118. _index = GetCell(); _itemIndex = 0; _pageIndex = 1;
  119. };
  120. var Flow = function ()
  121. {
  122. InitItem(_box.children(config.Item));
  123. _box.height(GetMaxCellTop());
  124. };
  125. var InitItem = function (list)
  126. {
  127. for (var i = _itemIndex; i < list.length; i++)
  128. {
  129. var $this = list.eq(i);
  130. var $img = $this.find("img");
  131. DrawImage($img[0],312,0);
  132. $this.css({ top: _cell[_index].top,left: _cell[_index].left,position: "absolute",display: "block" });
  133. _cell[_index].top = _cell[_index].top + $img.height() + 70 + config.RowSepareted;
  134. _index = GetCell();
  135. }
  136. _itemIndex = list.length;
  137. };
  138. var GetCell = function ()
  139. {
  140. var top = _cell[0].top,index = 0;
  141. if (0 == top) { return 0; }
  142. for (var i = 1; i < _cell.length; i++)
  143. {
  144. if (0 == _cell[i].top) { index = i; break; }
  145. if (_cell[i].top < top) { top = _cell[i].top; index = i; }
  146. }
  147. return index;
  148. };
  149. var GetMaxCellTop = function ()
  150. {
  151. var top = _cell[0].top;
  152. for (var i = 1; i < _cell.length; i++)
  153. {
  154. if (_cell[i].top > top) { top = _cell[i].top; }
  155. }
  156. return top;
  157. };
  158. Init(); Flow();
  159. $(config.More_bottom).click(function ()
  160. {
  161. var url = config.More_url;
  162. if (url.indexOf("?") == -1)
  163. {
  164. url = url + "?page=" + pageIndex;
  165. }
  166. else
  167. {
  168. url = url + "&page=" + pageIndex;
  169. }
  170. $.ajax({
  171. type: "GET",
  172. url: url,
  173. dataType: "html",
  174. cache: false,
  175. success: function (html)
  176. {
  177. _box.append(html);
  178. Flow();
  179. }
  180. });
  181. pageIndex++;
  182. });
  183. }