Search found 4 matches for template

 21.12.15 16:01

Trong forum về code như Devs forumvi thì vấn đề màu mè cho khung code luôn được đặt lên hàng đầu. :D

Trước đây, mình đã có hướng dẫn vài cách ứng dụng các plugin syntax highlighter cho forum, mỗi cái có ưu và nhược điểm riêng, tạm kể ra vài tội như:
- Google Code Prettify: Tự nhận diện ngôn ngữ nhưng không chính xác lắm, xử lý rất chậm khi gặp code dài, kích thước file js lớn.
- Prismjs: Lỗi ở một số mã Regexp phức tạp, không tự nhận diện ngôn ngữ.
- CodeMirror: Không tự nhận diện ngôn ngữ, kích thước file js khá lớn.

Hôm nay mình sẽ hướng dẫn cách dùng highlightjs, một plugin syntax highlighter khắc phục được các nhược điểm trên.


Demo


Topics tagged under template on DEVs forumvi 2xpXfbr
Ảnh minh họa highlight code với ngôn ngữ PHP


Tính năng


  1. Hỗ trợ 146 ngôn ngữ và 66 giao diện (Xem ví dụ).
  2. Tự động nhận diện ngôn ngữ.
  3. Kích thước file js nhỏ ~17Kb.
  4. Sao chép nhanh dùng Clipboard.


Hạn chế


  1. Không hỗ trợ phpBB2. Do cấu trúc phpBB2 khác biệt với 3 mã nguồn còn lại, và ít người dùng nên mình không làm.
  2. Làm nổi bật cú pháp không chi tiết bằng 3 plugin mình giới thiệu trước đây.
  3. Không có các tính năng phụ như: số dòng, tìm dòng, chọn giao diện, chọn toàn bộ (đã thay bằng nút copy). Mình thấy các tính năng này ít dùng, lại làm chậm xử lý nên bỏ bớt cho nó nuột.



Hướng dẫn


ACP >> Display >> QLTT >> overall_header

Tìm:
Code:
<script src="{JQUERY_PATH}" type="text/javascript"></script>
<script src="{JS_DIR}{L_LANG}.js" type="text/javascript"></script>


Và thêm vào bên dưới nó, code sau:
Code:
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/styles/github-gist.min.css">
<style>
/* Zzhljs - http://devs.forumvi.com */
dl.codebox:not(.spoiler) dt {
    display: none;
}
dl.codebox:not(.spoiler) dd {
    border: 0 none;
    background: #f8f8f8;
    position: relative;
    max-height: 100%;
}
.clipboard {
    display: block;
    color: #333;
    position: absolute;
    right: 4px;
    top: 4px;
    background: url(http://i.imgur.com/o9NOYtH.png) no-repeat center center #eee;
    border: 1px solid #D5D5D5;
    width: 30px;
    height: 30px;
    text-align: center;
    border-radius: 3px;
    transition: opacity 0.3s ease-in-out 0s;
    opacity: 0;
    -webkit-user-select:none;
    -moz-user-select:none;
    -ms-user-select:none;
    user-select:none;
    -webkit-appearance:none;
    cursor: pointer;
}
.clipboard.check-circle {
    background-image: url(http://i.imgur.com/CBEkyLH.png);
}
.clipboard.exclamation-triangle {
    background-image: url(http://i.imgur.com/QQkE9Wj.png);
}
dl.codebox:not(.spoiler) dd:hover .clipboard {
    opacity: 1;
}
.clipboard:hover {
    background-color:#ddd;
    border-color:#ccc;
}
.hljs {
    background: #f8f8f8;
}
dl.codebox:not(.spoiler) code,
.codebox:not(.spoiler) dd.cont_code {
    max-height: 100%;
    margin: 0;
}
.codebox:not(.spoiler) {
    background-color: transparent;
    border: 0 none;
    margin: 0;
}
</style>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/highlight.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.5.5/clipboard.min.js"></script>
<script>
/* Zzhljs - http://devs.forumvi.com */
jQuery(function($){
    var $code = $("code");
    if ($code.length) {
        hljs.configure({
            useBR: true
        });
        $code.each(function (i, block) {
            hljs.highlightBlock(block);
        });

        function fallbackMessage(action) {
            var actionMsg = '';
            var actionKey = (action === 'cut' ? 'X' : 'C');

            if (/iPhone|iPad/i.test(navigator.userAgent)) {
                actionMsg = 'No support!';
            } else if (/Mac/i.test(navigator.userAgent)) {
                actionMsg = 'Press ⌘-' + actionKey + ' to ' + action;
            } else {
                actionMsg = 'Press Ctrl-' + actionKey + ' to ' + action;
            }

            return actionMsg;
        }

        function afterClipboard(ele) {
            setTimeout(function(){
                ele.className = 'clipboard clipboard';
            }, 400);
        }

        var snippets = document.querySelectorAll('.codebox:not(.spoiler) > dd');

        [].forEach.call(snippets, function (snippet) {
            snippet.firstChild.insertAdjacentHTML('beforebegin', '<i class="clipboard clipboard" data-clipboard></i>');
        });

        var clipboardSnippets = new Clipboard('[data-clipboard]', {
            target: function (trigger) {
                return trigger.nextElementSibling;
            }
        });

        clipboardSnippets.on('success', function (e) {
            e.clearSelection();
            e.trigger.className = 'clipboard check-circle';
            afterClipboard(e.trigger);
        });

        clipboardSnippets.on('error', function (e) {
            e.trigger.className = 'clipboard exclamation-triangle';
            afterClipboard(e.trigger);
            alert(fallbackMessage(e.action));
        });
    }
});
</script>



Tài nguyên

Icon từ FlatIcon.
Javascript plugin HighlightJs và ClipboardJs.
Ứng dụng cho Forumotion viết bởi Zzbaivong.
Tags: #mod #template #tutorial #highlight #clipboard #hljs

[Add-ons] Forumotion backup templates

Diễn đàn: Add-onsTrả lời: 26Lượt xem: 9130

 23.05.15 11:18

Forumotion Backup Templates



Giới thiệu


Tiện ích này sẽ giúp bạn lưu trữ và cài đặt tất cả Template trong Forumotion một cách nhanh chóng và chính xác.


  • Tất cả Template sẽ được nén vào một tệp zip nên rất thuận tiện lưu trữ và chia sẻ.
  • Cài đặt tệp zip lưu trữ từ máy sẽ có đủ thông tin và được cảnh báo về phiên bản giúp tránh nhầm lẫn.
  • Chế độ One-Click: Đơn giản hóa thao tác với 1 click, sử dụng khi cần cài đặt và lưu trữ toàn bộ Template.
  • Thông báo trên màn hình khi tiến trình hoàn tất, bạn chỉ cần giữ tab mở trong lúc tiện ích đang xử lý và làm việc khác.
  • Để đảm bảo bạn không vô tình tắt trình duyệt khi tiến trình đang chạy, một cảnh báo đã được thêm vào.


Cài đặt


Google Chrome: [You must be registered and logged in to see this link.]
Sau khi tải xong, bạn mở tab chrome://extensions/ và kéo thả file cxr vừa tải vào để cài đặt.
Firefox: [You must be registered and logged in to see this link.]
Opera: [You must be registered and logged in to see this link.]

Phiên bản Userscript cho các trình duyệt khác: [You must be registered and logged in to see this link.].


Ảnh chụp màn hình


[You must be [You must be registered and logged in to see this link.] and [You must be registered and logged in to see this link.] to see this image.]
Tiện ích vừa hoàn tất lưu trữ toàn bộ Template

Xem thêm ảnh chụp màn hình khác tại đây.


Video hướng dẫn


Google Chrome: [You must be registered and logged in to see this link.]
Firefox: [You must be registered and logged in to see this link.]
Opera: [You must be registered and logged in to see this link.]


Mã nguồn


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

Tài nguyên

jsZip (v2.5.0) By StuartKnightley
jszip-utils (v0.0.2) By Stuart Knightley, David Duponchel
FileSaver (2015-05-07.2) By Eli Grey
ForumotionBackupTemplates (v2.0.1) By [You must be registered and logged in to see this link.]


Tác giả


[You must be registered and logged in to see this link.] (https://devs.forumvi.com)
Tags: [You must be registered and logged in to see this link.]

 06.05.14 18:24

CodeMirror là một Text editor, viết bằng Javascript hoạt động trên trình duyệt, được dùng trong dev tool của Chrome, Firefox và nhiều Text editor khác như Brackets,  Light Table, ... Trong forumotion, nó được dùng làm công cụ chỉnh sửa CSS, Templates, trang html.
Ở bài này mình sẽ ứng dụng nó để làm nổi bật cú pháp trong code. Xét về dung lượng, nó có vẻ hơi khủng nếu đem so với 2 cách dùng plugin Google Code Prettify và Prismjs mà mình giới thiệu trước đây. Tuy nhiên, trái với vẻ bề ngoài nặng nề, nó có tốc độ xử lý rất nhanh và ổn định.


Chức năng


Ưu điểm


  • Chức năng di chuyển nhanh bằng cách nhập số dòng. Nhập 0 để chuyển đến dòng cuối.
  • Hỗ trợ chọn nhanh toàn bộ code.
  • Xử lý nhanh chóng, phân biệt rõ cú pháp trong code.
  • 30 giao diện thoải mái lựa chọn.
  • Hỗ trợ rất nhiều Add-on và API nếu bạn muốn tùy chỉnh thêm.

Nhược điểm


  • Chỉ áp dụng cho 3 loại ngôn ngữ HTML-CSS-JS.
  • Một số mã regexp không được xác định đúng.

Cập nhật: Sử dụng phiên bản mới nhất cho các addon (21/6/2015), và thay thế core của codemirror bằng addon stand-alone, giúp giảm dung lượng từ 192kb xuống còn 48kb.

Demo

[You must be [You must be registered and logged in to see this link.] and [You must be registered and logged in to see this link.] to see this image.]
Giao diện zzCodeMirror


Hướng dẫn


Tạo file javascript zzCodeMirror
Title * : zzCodeMirror
Placement : In all the pages
Javascript Code * :
Code:
$(function() {
    window.codeTranslate = {
        gotoLineOffsetTop: 5
    };
    $("code").length && $.getScript("http://baivong.github.io/cdn/devsforumvi/js/35300.js");
});

Trong code trên, gotoLineOffsetTop là tham số khoảng cách của dòng code với mép trên trình duyệt. Nếu bạn sử dụng Toolbar của forumotion thì thay số 5 bằng 35.

Chú ý:
zzCodeMirror không sử dụng được cho phpBB2.
Gỡ bỏ các mod, plugin liên quan đến khung code trước khi sử dụng.
Nên upload lại file CSS và Javascript lên host của riêng bạn khi sử dụng, ví dụ như Google. Xem hướng dẫn [You must be registered and logged in to see this link.].
zzCodeMirror được tùy biến để nhận dạng 3 ngôn ngữ HTML - CSS - Javascript, đây là phần mình viết thêm nên nếu gặp lỗi thì gửi báo cáo ngay tại chủ đề này. Thử nghiệm tại [You must be registered and logged in to see this link.]


Phiên bản áp dụng

phpBB3, punBB, Invision


Source code


CSS

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

Javascript

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


Nguồn


Zzbaivong (devs.forumvi.com)
Tags: [You must be registered and logged in to see this link.]

 07.03.14 18:56

Tạo nhóm các chuyên mục con trong một dropdown-menu theo phong cách Xenforo.

Topics tagged under template on DEVs forumvi UuNaWvc


ACP >> Display >> Homepage >> Structure and hierarchy >> Hierarchy:
Sub-level links on index : Yes

ACP >> Display >> Templates >> QLTT >> Index_box:
Tìm:
Code:
{catrow.forumrow.L_LINKS}{catrow.forumrow.LINKS}
<strong>{forumrow.L_SUBFORUM_STR}</strong> {forumrow.SUBFORUMS}

Thay bằng:
Code:
<span class="sub4r stat4r">{catrow.forumrow.LINKS}</span>


Đặt ở cuối index_box
Code:
<script type="text/javascript">
//<![CDATA[
/* subForum by Zzbaivong - devs.forumvi.com */
$(".sub4r.stat4r").each(function() {
    var sub = $(this);
    if (!sub.is(":empty")) {
        sub.contents().filter(function() {
            return this.nodeType === 3;
        }).remove().end().filter("a").wrap("<li></li>");
        sub.wrapInner('<ul class="subLink"></ul>').append("Diễn đàn con: <strong>" + sub.find("a").length + "</strong>");
    }
});
//]]>
</script>


ACP >> Display >> Pictures and Colors >> CSS Stylesheet:
Thêm vào CSS:
Code:
/* subForum by Zzbaivong - devs.forumvi.com */
.pun table .tcl{overflow:auto}
.stat4r{color:#888;font-size:12px;padding-right:10px}
.stat4r > strong{color:#333}
.sub4r.stat4r{position:relative}
.subLink{padding:0!important;position:absolute;display:none;left:0;list-style:none;background:#FFF;top:13px;z-index:30;min-width:97px;border:2px solid #666}
.sub4r.stat4r:hover .subLink{display:block}
.stat4r .subLink + strong{padding-right:15px;background:url(//i56.servimg.com/u/f56/18/59/49/93/arrow_10.png) no-repeat right center transparent}
.subLink li a{white-space:nowrap;height:20px;line-height:20px;display:block;padding:0 7px}
.subLink li a:hover{background:#f2f2f2}



Zzbaivong

Tags: #mod #template #xenforo #sub-forum


Back to top