[Javascript] Đóng mở Category

Xem chủ đề cũ hơn Xem chủ đề mới hơn Go down

Yêu thích [Javascript] Đóng mở Category

Bài gửi by HelpsFMvi Tue Mar 15, 2016 11:49 pm


Demo:

[You must be registered and logged in to see this link.]

Hướng dẫn:

Tạo 1 javascript mới:

Title: đóng mở box
Placement: In the homepage
Codes:
Code:

/***
 * Application: toggle Category
 * Description: Show/hide categories!
 * Version: 0.02632015-jq1.9.1
 *         RC1 (Release candidate 1!) - Invision
 * Author: JScript - 2015/03/26 - based on Invision.js
 * This work is free. You can redistribute it and/or modify it
 * under the terms of the WTFPL, Version 2
 */
$(function() {
   ("JScript <jscriptbrasil at live dot com>, based on Invision.js");
   var style = document.createElement("style"),
      /* Versions:|phpBB2----------------------------------------|  |phpBB3-------------|    |PunBB-----------------|   |Invision already have it!| */
      oCat = $('#content-container .three-col td:eq(1) .forumline, #main-content .forabg, #main-content .main-head'),
      oThis = null,
      oTemp = null,
      sEval = '';
 
   style.type = "text/css";
   style.innerHTML =
      '.contract, .expand {' +
      '  background: url("http://2img.net/i/fa/invision/exp_minus.gif") no-repeat scroll 50% 50% rgba(0, 0, 0, 0);' +
      '  cursor: pointer;' +
      '  float: right;' +
      '  margin-top: 3px;' +
      '}' +
      '.expand {' +
      '  background: url("http://2img.net/i/fa/invision/exp_plus.gif") no-repeat scroll 50% 50% rgba(0, 0, 0, 0);' +
      '}';
   document.getElementsByTagName("head")[0].appendChild(style);
 
   switch (oCat[0].className) {
      case 'forumline': //phpBB2
         sEval = "oTemp = oThis.find('tr').first();oTemp.addClass('title-bar');" +
            "oTemp.find('th:last').append('<div onclick=\"toggleCategory(\\'c' + i + '\\');\" id=\"bc' + i + '\" class=\"contract\" style=\"margin-top: -15px;\">&nbsp;&nbsp;&nbsp;</div>');" +
            "oThis.find('tr').not('.title-bar').addClass('c' + i);";
         break;
      case 'forabg': //phpBB3
         sEval = "oThis.find('ul.topiclist:first dl.icon').append('<div onclick=\"toggleCategory(\\'c' + i + '\\');\" id=\"bc' + i + '\" class=\"contract\">&nbsp;&nbsp;&nbsp;</div>');" +
            "oThis.find('ul.topiclist.forums').attr('id', 'c' + i);";
         break;
      case 'main-head': //PunBB
         sEval = "oThis.find('h2').append('<div onclick=\"toggleCategory(\\'c' + i + '\\');\" id=\"bc' + i + '\" class=\"contract\">&nbsp;&nbsp;&nbsp;</div>');" +
            "oThis.next().attr('id', 'c' + i);";
         break;
   }
   for (var i = 0, len = oCat.length; i < len; i++) {
      oThis = $(oCat[i]);
      eval(sEval);
   }
 
   initCategories();
});
// by invision.js
function initCategories() {
   var id;
   cookies = document.cookie.split('; ');
   for (var i = 0; i < cookies.length; i++) {
      if (cookies[i].charAt(0) == '_') {
         cookie = cookies[i].split('=');
         if (cookie[1] == '1') {
            id = cookie[0].substring(1);
            if (document.getElementById(id)) {
               toggleCategory(id)
            }
         }
      }
   }
}
// by invision.js, modified by JScript
function toggleCategory(id) {
   var obj = document.getElementById(id);
   var button = document.getElementById('b' + id);
   if (obj) {
      var toggle = obj.style.display == 'none';
      obj.style.display = toggle ? '' : 'none';
   } else {
      var elems = document.getElementsByClassName(id);
      for (var i = 0, len = elems.length; i < len; i++) {
         var toggle = elems[i].style.display == 'none';
         elems[i].style.display = toggle ? '' : 'none';
      }
   }
   button.className = toggle ? 'contract' : 'expand';
   my_setcookie('_' + id, toggle ? '' : '1', true);
   return false
}
 
/*
▲ -> contract
▼ -> expand
*/

[You must be registered and logged in to see this link.]

HelpsFMvi
HelpsFMvi
Ban Quản Trị FMvi
Ban Quản Trị FMvi


Số bài : 104
HelpsPoints : 15318
Likes : 33
Ngày tham gia : 10/03/2016
Trạng thái :
Online
Offline

Tuổi : 26
Location : Ninh Thuận
Google Chrome
Phpbb3

[Click để xem tài sản HelpsFMvi]

https://helps.forumvi.com

Về Đầu Trang Go down

Xem chủ đề cũ hơn Xem chủ đề mới hơn Về Đầu Trang

- Similar topics

 
Permissions in this forum:
Bạn không có quyền trả lời bài viết
Free forum | ©phpBB | Free forum support | Báo cáo lạm dụng | Thảo luận mới nhất
Stylish responsive footer | Script Tutorials