Advertisement
Guest User

Untitled

a guest
Nov 24th, 2011
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.75 KB | None | 0 0
  1. <link rel="stylesheet" type="text/css" href="<?=media_base_url()?>css/new_buttons.css" />
  2.  
  3.  
  4. <div id="container2"> <!-- container2 -->
  5.  
  6. <div class="isci_po_kategoriji">
  7. <!-- <div>
  8. <span>išči po kategoriji</span>
  9. </div> -->
  10.  
  11. <form method="GET">
  12. <table>
  13. <tbody>
  14. <tr>
  15. <td class="first">
  16. <input title="Išči v tej kategoriji..." value="" class="search_top1" id="inputString_company" name="niz" type="text" />
  17. <a title="Počisti iskalni niz" href="<?=current_url()?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
  18. </td>
  19. <td>
  20. <input class="button" type="submit" value=" " />
  21. </td>
  22. </tr>
  23. </tbody>
  24. </table>
  25. </form>
  26. </div>
  27.  
  28. <?=br(1)?>
  29.  
  30.  
  31.  
  32. <!-- LEFT -->
  33. <div id="left1">
  34. TEST
  35. </div>
  36.  
  37.  
  38.  
  39. <!-- CONTENT -->
  40. <div id="right1">
  41.  
  42. <!-- ADS CONTENT -->
  43.  
  44. <img src="<?=media_base_url()?>css/images/ajax-loader.gif" id="loader" style="display:none;" />
  45.  
  46. <form id="hiddenFields">
  47. <input type="hidden" name="orderBy" value="" />
  48. <input type="hidden" name="orderWay" value="" />
  49. <input type="hidden" name="perPage" value="" />
  50. </form>
  51.  
  52.  
  53. <section id="pagination"></section>
  54. <section id="toolbar"></section>
  55. <div class="lnsep"></div>
  56. <section id="ads"></section>
  57.  
  58. </div>
  59.  
  60. <!--
  61. <div class="actions newbutton-container">
  62. <a class="newbuttonempty" title="Osveži oglase"><span class="reload gIcon"></span></a>
  63.  
  64. <div class="newbutton-group">
  65. <a class="newbutton icon reload">Osveži</a>
  66. </div>
  67. </div>
  68. -->
  69.  
  70.  
  71. <div id="clear"></div>
  72.  
  73.  
  74.  
  75. </div><!-- container2 -->
  76.  
  77. <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
  78. <script type="text/javascript" src="/style/js/jquery.cookie.js"></script>
  79. <script type="text/javascript" src="/style/js/jquery.loadmask.js"></script>
  80. <script type="text/javascript">
  81. function get_data(currentUrl, extraDatas)
  82. {
  83. // REQUEST
  84. var request = $.ajax({
  85. url: "/server/ads/ads_list",
  86. type: "POST",
  87. dataType: "json",
  88. data: {currentUrl:currentUrl, extra:extraDatas },
  89. beforeSend: function( xhr ) {
  90. _loading.show();
  91. _ads_listing.mask("Nalagam...");
  92. }
  93. });
  94. request.done(function(data) {
  95. if( data )
  96. echo_data(data)
  97. _loading.hide();
  98. _ads_listing.unmask();
  99. });
  100. request.fail(function(jqXHR, textStatus) {
  101. _ads_listing.html(textStatus);
  102. _loading.hide();
  103. _ads_listing.unmask();
  104. });
  105. };
  106. function echo_data(data)
  107. {
  108. var length = data.count;
  109. var length_all = data.count_all;
  110.  
  111. // Prebuild
  112. _pagination.html(data.pagination_links);
  113. _toolbar.html(data.per_page+data.ordering_links);
  114.  
  115.  
  116. var data = data.ads;
  117. var appendHtml = [];
  118.  
  119. for(var i = 0; i < length; i += 1)
  120. {
  121. var info = data[i];
  122. var html = "";
  123.  
  124. html = "<div class='listing second' rel='caption'>";
  125.  
  126. // Image
  127. html += "<div class='item-picture'>"+info['image']+"</div>";
  128. // Title
  129. html += "<div class='item-title'><a href='/oglas/ogled/"+info['id']+"/"+info['slug']+"'>"+info['title']+"</a></div>";
  130. // Description
  131. html += "<div class='item-desc'>"+info['desc']+"</div>";
  132. // Price
  133. html += "<div class='item-price'>"+info['price']+"</div>";
  134.  
  135.  
  136.  
  137. html += "</div>";
  138.  
  139. appendHtml[i] = html;
  140. }
  141. _ads_listing.html(appendHtml.join(''));
  142. }
  143.  
  144. //Variables
  145. var _loading = $("#loader");
  146. var _ads_listing = $("#ads");
  147. var _pagination = $("#pagination");
  148. var _toolbar = $("#toolbar");
  149. //Ajax variables
  150. var length = 0;
  151. var length_all = 0;
  152.  
  153. jQuery(function($) {
  154.  
  155. var _currentPage = 1;
  156. var _currentUrl = window.location.hash;
  157.  
  158. var extraData = new Array();
  159.  
  160. // Click on pagination
  161. _pagination.find('a').live('click',function() {
  162. var goalPage = $(this).attr('page');
  163.  
  164. if( goalPage )
  165. {
  166. var _temp_url = _currentUrl.replace("#","");
  167. var _temp_url2 = _temp_url.split(",");
  168.  
  169. var contain = containsRegex(_temp_url2, /stran/);
  170.  
  171. if( contain !== null )
  172. {
  173. var pageNr = "stran="+goalPage;
  174. _temp_url2[contain[0]] = pageNr;
  175. }
  176. else
  177. {
  178. if( _temp_url2.length > 0 )
  179. _temp_url2[_temp_url2.length] = ",stran="+goalPage;
  180. else
  181. _temp_url2[0] = "#stran="+goalPage;
  182. }
  183. extraData = $("#hiddenFields").serialize();
  184.  
  185. _currentUrl = "#" + _temp_url2.join(",");
  186. var f = get_data(_currentUrl, extraData);
  187. }
  188. });
  189.  
  190. // Click on sorting
  191. _toolbar.find('a').live('click',function() {
  192. var orderBy = $(this).attr('orderBy');
  193. var orderWay = $(this).attr('orderWay');
  194.  
  195. if( orderBy && orderWay )
  196. {
  197. $("input[name=orderBy]").val(orderBy);
  198. $("input[name=orderWay]").val(orderWay);
  199.  
  200. // Save ordering in cookie
  201. $.cookie("pw_listing_ordering_by", orderBy);
  202. $.cookie("pw_listing_ordering_way", orderWay);
  203.  
  204. extraData = $("#hiddenFields").serialize();
  205.  
  206. var f = get_data(_currentUrl, extraData);
  207. }
  208. });
  209.  
  210. // Click on show Per Page
  211. $("#changePerPage > li").live('click',function() {
  212. $("#changePerPage").hide();
  213. var perPageValue = $(this).val();
  214. $(".currentPerPage").text(perPageValue);
  215. if( perPageValue )
  216. {
  217. // Save results per page to cookie
  218. $.cookie("pw_listing_perPage", perPageValue);
  219. $("input[name=perPage]").val(perPageValue);
  220.  
  221. // Set page to first one
  222. var _temp_url = _currentUrl.replace("#","");
  223. var _temp_url2 = _temp_url.split(",");
  224.  
  225. var contain = containsRegex(_temp_url2, /stran/);
  226.  
  227. if( contain !== null )
  228. {
  229. _temp_url2[contain[0]] = "stran=1";
  230. }
  231. else
  232. {
  233. if( _temp_url2.length > 0 )
  234. _temp_url2[_temp_url2.length] = ",stran=1";
  235. else
  236. _temp_url2[0] = "#stran=1";
  237. }
  238.  
  239. extraData = $("#hiddenFields").serialize();
  240. _currentUrl = "#" + _temp_url2.join(",");
  241. var f = get_data(_currentUrl, extraData);
  242. }
  243. });
  244.  
  245.  
  246. // DATA
  247. var cookies = [];
  248. cookies['ordering_by'] = $.cookie("pw_listing_ordering_by");
  249. cookies['ordering_way'] = $.cookie("pw_listing_ordering_way");
  250. console.log(cookies);
  251. if( cookies['ordering_by'] && cookies['ordering_way'] )
  252. {
  253. $("input[name=orderBy]").val($.cookie("pw_listing_ordering_by"));
  254. $("input[name=orderWay]").val($.cookie("pw_listing_ordering_way"));
  255. extraData = $("#hiddenFields").serialize();
  256. var f = get_data(_currentUrl,extraData);
  257. }else if( $.cookie("pw_listing_perPage") ){
  258. $("input[name=perPage]").val($.cookie("pw_listing_perPage"));
  259. extraData = $("#hiddenFields").serialize();
  260. var f = get_data(_currentUrl,extraData);
  261. }
  262. else
  263. {
  264. var f = get_data(_currentUrl);
  265. }
  266.  
  267.  
  268.  
  269. $(".toolbarPerPage").find('span').live('click',function() {
  270. $("#changePerPage").toggle();
  271. });
  272. });
  273.  
  274. function containsRegex(a, regex){
  275. for(var i = 0; i < a.length; i++) {
  276. var pos = a[i].search(regex);
  277. if(pos > -1){
  278. return [i, pos];
  279. }
  280. }
  281. return null;
  282. }
  283. </script>
  284.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement