使用方法
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof module === 'object' && module.exports) {
// Node/CommonJS
module.exports = function(root, jQuery) {
if (jQuery === undefined) {
// require('jQuery') returns a factory that requires window to
// build a jQuery instance, we normalize how we use modules
// that require this pattern but the window provided is a noop
// if it's defined (how jquery works)
if (typeof window !== 'undefined') {
jQuery = require('jquery');
}
else {
jQuery = require('jquery')(root);
}
}
factory(jQuery);
return jQuery;
};
} else {
// Browser globals
factory(jQuery);
}
}(function($) {
var Comments = {
// Instance variables
// ==================
$el: null,
commentsById: {},
dataFetched: false,
currentSortKey: '',
options: {},
events: {
// Close dropdowns
'click': 'closeDropdowns',
// Paste attachments
'paste' : 'preSavePastedAttachments',
// Save comment on keydown
'keydown [contenteditable]' : 'saveOnKeydown',
// Listening changes in contenteditable fields (due to input event not working with IE)
'focus [contenteditable]' : 'saveEditableContent',
'keyup [contenteditable]' : 'checkEditableContentForChange',
'paste [contenteditable]' : 'checkEditableContentForChange',
'input [contenteditable]' : 'checkEditableContentForChange',
'blur [contenteditable]' : 'checkEditableContentForChange',
// Navigation
'click .navigation li[data-sort-key]' : 'navigationElementClicked',
'click .navigation li.title' : 'toggleNavigationDropdown',
// Main comenting field
'click .commenting-field.main .textarea': 'showMainCommentingField',
'click .commenting-field.main .close' : 'hideMainCommentingField',
// All commenting fields
'click .commenting-field .textarea' : 'increaseTextareaHeight',
'change .commenting-field .textarea' : 'increaseTextareaHeight textareaContentChanged',
'click .commenting-field:not(.main) .close' : 'removeCommentingField',
// Edit mode actions
'click .commenting-field .send.enabled' : 'postComment',
'click .commenting-field .update.enabled' : 'putComment',
'click .commenting-field .delete.enabled' : 'deleteComment',
'click .commenting-field .attachments .attachment .delete' : 'preDeleteAttachment',
'change .commenting-field .upload.enabled input[type="file"]' : 'fileInputChanged',
// Other actions
'click li.comment button.upvote' : 'upvoteComment',
'click li.comment button.delete.enabled' : 'deleteComment',
'click li.comment .hashtag' : 'hashtagClicked',
'click li.comment .ping' : 'pingClicked',
// Other
'click li.comment ul.child-comments .toggle-all': 'toggleReplies',
'click li.comment button.reply': 'replyButtonClicked',
'click li.comment button.edit': 'editButtonClicked',
// Drag & dropping attachments
'dragenter' : 'showDroppableOverlay',
'dragenter .droppable-overlay' : 'handleDragEnter',
'dragleave .droppable-overlay' : 'handleDragLeaveForOverlay',
'dragenter .droppable-overlay .droppable' : 'handleDragEnter',
'dragleave .droppable-overlay .droppable' : 'handleDragLeaveForDroppable',
'dragover .droppable-overlay' : 'handleDragOverForOverlay',
'drop .droppable-overlay' : 'handleDrop',
// Prevent propagating the click event into buttons under the autocomplete dropdown
'click .dropdown.autocomplete': 'stopPropagation',
'mousedown .dropdown.autocomplete': 'stopPropagation',
'touchstart .dropdown.autocomplete': 'stopPropagation',
},
// Default options
// ===============
getDefaultOptions: function() {
return {
// User
profilePictureURL: '',
currentUserIsAdmin: false,
currentUserId: null,
// Font awesome icon overrides
spinnerIconURL: '',
upvoteIconURL: '',
replyIconURL: '',
uploadIconURL: '',
attachmentIconURL: '',
noCommentsIconURL: '',
closeIconURL: '',
// Strings to be formatted (for example localization)
textareaPlaceholderText: '添加一条评论',
newestText: '最新评论',
oldestText: '历史评论',
popularText: '热门评论',
attachmentsText: '附件',
sendText: '发送',
replyText: '回复',
editText: '编辑',
editedText: '已编辑',
youText: '自己',
saveText: '保存',
deleteText: '删除',
newText: '最新',
viewAllRepliesText: '查看所有 __replyCount__ 回复',
hideRepliesText: '隐藏回复',
noCommentsText: '没有评论',
noAttachmentsText: '没有附件',
attachmentDropText: '拖拽文件到这里',
textFormatter: function(text) {return text},
// Functionalities
enableReplying: true,
enableEditing: true,
enableUpvoting: true,
enableDeleting: true,
enableAttachments: false,
enableHashtags: false,
enablePinging: false,
enableDeletingCommentWithReplies: false,
enableNavigation: true,
postCommentOnEnter: false,
forceResponsive: false,
readOnly: false,
defaultNavigationSortKey: 'newest',
// Colors
highlightColor: '#2793e6',
deleteButtonColor: '#C9302C',
scrollContainer: this.$el,
roundProfilePictures: false,
textareaRows: 2,
textareaRowsOnFocus: 2,
textareaMaxRows: 5,
maxRepliesVisible: 2,
fieldMappings: {
id: 'id',
parent: 'parent',
created: 'created',
modified: 'modified',
content: 'content',
attachments: 'attachments',
pings: 'pings',
creator: 'creator',
fullname: 'fullname',
profilePictureURL: 'profile_picture_url',
isNew: 'is_new',
createdByAdmin: 'created_by_admin',
createdByCurrentUser: 'created_by_current_user',
upvoteCount: 'upvote_count',
userHasUpvoted: 'user_has_upvoted'
},
searchUsers: function(term, success, error) {success([])},
getComments: function(success, error) {success([])},
postComment: function(commentJSON, success, error) {success(commentJSON)},
putComment: function(commentJSON, success, error) {success(commentJSON)},
deleteComment: function(commentJSON, success, error) {success()},
upvoteComment: function(commentJSON, success, error) {success(commentJSON)},
validateAttachments: function(attachments, callback) {return callback(attachments)},
hashtagClicked: function(hashtag) {},
pingClicked: function(userId) {},
refresh: function() {},
timeFormatter: function(time) {return new Date(time).toLocaleDateString()}
}
},
// Initialization
// ==============
init: function(options, el) {
this.$el = $(el);
this.$el.addClass('jquery-comments');
this.undelegateEvents();
this.delegateEvents();
}
}
站长提示:
1. 苦力吧素材官方QQ群:
950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励
2K币。
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服