Your IP : 18.219.40.177
/**
* Module for report about mistake in content
* @param {object} window global object
* @param {function} $ jQuery library
* @param {object} EventMgr EventMgr library
* @param {object} App Application
* @return {object} api
*/
App.ContentMistake = function(window, $, EventMgr, App) {
'use strict';
var CTRLKEY = 17,
ENTERKEY = 13,
mistakeObject = {};
function showForm(mistakeObject) {
$('body').addClass('active_mistake_form');
$('#modal_mistake_textarea').val(mistakeObject.content);
$('#modal_mistake_input').val(mistakeObject.msgName + ', ' +
mistakeObject.funcName);
}
function closeForm() {
$('body').removeClass('active_mistake_form');
$('#modal_mistake_textarea').val('');
$('#modal_mistake_input').val('');
$('#reportmistakebox').val('on');
}
function submitForm() {
var content = $('#modal_mistake_textarea').val(),
devReport = $('#reportmistakebox').val();
if (content !== mistakeObject.content) {
EventMgr.trigger('ajaxRequest', {
param: {
msg: mistakeObject.msgName,
module: mistakeObject.funcName,
content: content,
func: 'editmsg',
notify: devReport
},
type: 'get',
outtype: 'json',
trfunc: 'DoNothing',
queue: 'noqueue'
});
if (mistakeObject.node) {
mistakeObject.node.innerHTML = content;
}
}
closeForm();
}
function detectTextSelection() {
mistakeObject = {};
var content, node, msgName, selection, funcName, selectedContent,
targetNode;
if (typeof window.getSelection !== 'undefined') {
selection = window.getSelection();
selectedContent = selection.toString();
if (selectedContent === '') { return true; }
//try to find
if (selection.rangeCount > 0) {
node = selection.getRangeAt(0).startContainer.parentNode;
if (node) {
msgName = node.getAttribute('data-mn');
funcName = node.getAttribute('data-fn');
content = node.innerHTML;
targetNode = node;
//try to find in children
if (!msgName) {
$(node).children().each(function() {
if (this.getAttribute('data-mn')) {
msgName = this.getAttribute('data-mn');
funcName = this.getAttribute('data-fn');
content = this.innerHTML;
targetNode = node;
return false;
}
});
}
//try to find in parents
if (!msgName) {
var $parentNode = $(node).closest('[data-mn]');
msgName = $parentNode.attr('data-mn');
if (msgName && $parentNode.length) {
content = $parentNode[0].innerHTML;
}
}
if (msgName && !funcName) {
funcName = $(node).closest('.tab-content').attr('data-func');
}
if (!funcName) {
funcName = $('.tab-content_st_active').attr('data-func');
}
}
}
}
mistakeObject.content = content;
mistakeObject.msgName = msgName;
mistakeObject.funcName = funcName;
mistakeObject.node = targetNode;
if (!msgName) {
EventMgr.trigger('showAlert', { 'msg': pageInfo.mistakeNosel });
} else {
showForm(mistakeObject);
}
}
function keyUpHandler(e) {
var codeKey = e.which || e.keyCode;
if (codeKey === ENTERKEY && (e.ctrlKey || e.metaKey)) {
detectTextSelection();
}
}
function init() {
if (pageInfo.userLevel - 0 >= 29) {
EventMgr.obind($(document), 'keyup', keyUpHandler);
EventMgr.obind('#modal_mistake_cancel', 'click', closeForm);
EventMgr.obind('#modal_mistake_ok', 'click', submitForm);
}
}
var api = {
init: init
};
return api;
} (window, $, EventMgr, App);