[Javascript] Trích dẫn nhanh (Quick Quote)

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

Chủ đề [Javascript] Trích dẫn nhanh (Quick Quote)

Bài gửi by HelpsFMvi Tue Mar 15, 2016 9:14 pm


Demo:

Khi bấm vào nút quote:
[You must be registered and logged in to see this link.]
Kết quả:
[You must be registered and logged in to see this link.]

Hướng dẫn:

- Tạo 1 trang js mới

Title: Quick Quote
Placement: In all the pages
Codes:
Code:
$(function(){
  var forum_version = 1,
  new_button = false,
  quote_image = 'http://icons.iconarchive.com/icons/fatcow/farm-fresh/16/document-quote-icon.png';
 
  if (forum_version == 0) n = [".postbody div",".name strong a"];
  if (forum_version == 1) n = [".postbody .content div",".postprofile dl dt strong a"];
  if (forum_version == 2) n = [".entry-content div",".username a"];
  if (forum_version == 3) n = [".post-entry div",".postprofile-details dt a + br + a"];
  if (new_button == true) { q = ".quickquote"; $(forum_version==1?"li:has(.i_icon_quote)":"a:has(.i_icon_quote)").after($('<li style="display:inline-block;list-style:none;"><a href="#quick_reply"><img src="'+quote_image+'" class="quickquote" alt="Trích dẫn nhanh" title="Trích dẫn nhanh" /></a></li>')) }
  if (new_button == false) { q = "a:has(.i_icon_quote)"; $("a:has(.i_icon_quote)").attr("href", "#quick_reply"); $(".i_icon_quote").attr("title", "Reply with quote") }
  
  $(document).on('mouseup',n[0],function(e){
    qtext = $(this).parents(".post");
    if (window.getSelection) theSelection = window.getSelection().toString();
    else if (document.getSelection) theSelection = document.getSelection();
    else if (document.selection) theSelection = document.selection.createRange().text;
  });  
  
  $(q).click(function () {
    if (typeof qtext == 'undefined') return;
    uname = qtext.find(n[1]).text();
    $("div.sceditor-toolbar + iframe").contents().find("body").append('<blockquote><cite>' + uname + '</cite>' + theSelection + '</blockquote> <br />');
    $('.sceditor-container textarea')[0].value += '[quote="' + uname + '"]' + theSelection + '[/quote]'
  });
  var n,q;
});

- Chọn phiên bản để code có thể hoạt động:

tìm
Code:
 var forum_version = 1,
sửa số 1 thành số phiên bản mà bạn đang sử dụng (VD: diễn đàn bạn sử dụng phiên bản punbb thì thay số 1 thành số 2)
0 = phpbb2
1 = phpbb3
2 = punbb
3 = invision

Tùy biến button và hình ảnh button:

new_button :
true = tạo 1 nút trích dẫn nhanh
false = sử dụng nút trích dẫn mặc định

Ở code trên mình đã edit link ảnh cho phù hợp các bạn chỉ cần sửa phiên bản và có sử dụng button hay ko thôi Very Happy

*Chú ý: - Các bạn nên bôi đen đoạn cần trích dẫn trước khi sử dụng
- Ở demo trên mình đã mở button quick quote nên mới có thêm một button như v Very Happy
[You must be registered and logged in to see this image.]

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


Số bài : 104
HelpsPoints : 15428
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