chat client: autoGrow - add scroll after maxHeight
This commit is contained in:
parent
f4efdf931b
commit
faea9d3936
3 changed files with 156 additions and 140 deletions
|
@ -1,3 +1,149 @@
|
|||
/*!
|
||||
* ----------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <jevin9@gmail.com> wrote this file. As long as you retain this notice you
|
||||
* can do whatever you want with this stuff. If we meet some day, and you think
|
||||
* this stuff is worth it, you can buy me a beer in return. Jevin O. Sewaruth
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* Autogrow Textarea Plugin Version v3.0
|
||||
* http://www.technoreply.com/autogrow-textarea-plugin-3-0
|
||||
*
|
||||
* THIS PLUGIN IS DELIVERD ON A PAY WHAT YOU WHANT BASIS. IF THE PLUGIN WAS USEFUL TO YOU, PLEASE CONSIDER BUYING THE PLUGIN HERE :
|
||||
* https://sites.fastspring.com/technoreply/instant/autogrowtextareaplugin
|
||||
*
|
||||
* Date: October 15, 2012
|
||||
*
|
||||
* Zammad modification: remove overflow:hidden when maximum height is reached
|
||||
*
|
||||
*/
|
||||
|
||||
jQuery.fn.autoGrow = function(options) {
|
||||
return this.each(function() {
|
||||
var settings = jQuery.extend({
|
||||
extraLine: true,
|
||||
}, options);
|
||||
|
||||
var createMirror = function(textarea) {
|
||||
jQuery(textarea).after('<div class="autogrow-textarea-mirror"></div>');
|
||||
return jQuery(textarea).next('.autogrow-textarea-mirror')[0];
|
||||
}
|
||||
|
||||
var sendContentToMirror = function (textarea) {
|
||||
mirror.innerHTML = String(textarea.value)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/ /g, ' ')
|
||||
.replace(/\n/g, '<br />') +
|
||||
(settings.extraLine? '.<br/>.' : '')
|
||||
;
|
||||
|
||||
if (jQuery(textarea).height() != jQuery(mirror).height()) {
|
||||
jQuery(textarea).height(jQuery(mirror).height());
|
||||
|
||||
var maxHeight = parseInt(jQuery(textarea).css('max-height'), 10);
|
||||
var overflow = jQuery(mirror).height() > maxHeight ? '' : 'hidden'
|
||||
jQuery(textarea).css('overflow', overflow);
|
||||
}
|
||||
}
|
||||
|
||||
var growTextarea = function () {
|
||||
sendContentToMirror(this);
|
||||
}
|
||||
|
||||
// Create a mirror
|
||||
var mirror = createMirror(this);
|
||||
|
||||
// Style the mirror
|
||||
mirror.style.display = 'none';
|
||||
mirror.style.wordWrap = 'break-word';
|
||||
mirror.style.whiteSpace = 'normal';
|
||||
mirror.style.padding = jQuery(this).css('paddingTop') + ' ' +
|
||||
jQuery(this).css('paddingRight') + ' ' +
|
||||
jQuery(this).css('paddingBottom') + ' ' +
|
||||
jQuery(this).css('paddingLeft');
|
||||
|
||||
mirror.style.width = jQuery(this).css('width');
|
||||
mirror.style.fontFamily = jQuery(this).css('font-family');
|
||||
mirror.style.fontSize = jQuery(this).css('font-size');
|
||||
mirror.style.lineHeight = jQuery(this).css('line-height');
|
||||
|
||||
// Style the textarea
|
||||
this.style.overflow = "hidden";
|
||||
this.style.minHeight = this.rows+"em";
|
||||
|
||||
// Bind the textarea's event
|
||||
this.onkeyup = growTextarea;
|
||||
|
||||
// Fire the event for text already present
|
||||
sendContentToMirror(this);
|
||||
|
||||
});
|
||||
};
|
||||
if (!window.zammadChatTemplates) {
|
||||
window.zammadChatTemplates = {};
|
||||
}
|
||||
window.zammadChatTemplates["agent"] = function (__obj) {
|
||||
if (!__obj) __obj = {};
|
||||
var __out = [], __capture = function(callback) {
|
||||
var out = __out, result;
|
||||
__out = [];
|
||||
callback.call(this);
|
||||
result = __out.join('');
|
||||
__out = out;
|
||||
return __safe(result);
|
||||
}, __sanitize = function(value) {
|
||||
if (value && value.ecoSafe) {
|
||||
return value;
|
||||
} else if (typeof value !== 'undefined' && value != null) {
|
||||
return __escape(value);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
|
||||
__safe = __obj.safe = function(value) {
|
||||
if (value && value.ecoSafe) {
|
||||
return value;
|
||||
} else {
|
||||
if (!(typeof value !== 'undefined' && value != null)) value = '';
|
||||
var result = new String(value);
|
||||
result.ecoSafe = true;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
if (!__escape) {
|
||||
__escape = __obj.escape = function(value) {
|
||||
return ('' + value)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
};
|
||||
}
|
||||
(function() {
|
||||
(function() {
|
||||
if (this.agent.avatar) {
|
||||
__out.push('\n<img class="zammad-chat-agent-avatar" src="');
|
||||
__out.push(__sanitize(this.agent.avatar));
|
||||
__out.push('">\n');
|
||||
}
|
||||
|
||||
__out.push('\n<span class="zammad-chat-agent-sentence">\n <span class="zammad-chat-agent-name">');
|
||||
|
||||
__out.push(__sanitize(this.agent.name));
|
||||
|
||||
__out.push('</span>\n</span>');
|
||||
|
||||
}).call(this);
|
||||
|
||||
}).call(__obj);
|
||||
__obj.safe = __objSafe, __obj.escape = __escape;
|
||||
return __out.join('');
|
||||
};
|
||||
|
||||
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
slice = [].slice;
|
||||
|
||||
|
@ -789,144 +935,6 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
|
|||
return window.ZammadChat = ZammadChat;
|
||||
})(window.jQuery, window);
|
||||
|
||||
if (!window.zammadChatTemplates) {
|
||||
window.zammadChatTemplates = {};
|
||||
}
|
||||
window.zammadChatTemplates["agent"] = function (__obj) {
|
||||
if (!__obj) __obj = {};
|
||||
var __out = [], __capture = function(callback) {
|
||||
var out = __out, result;
|
||||
__out = [];
|
||||
callback.call(this);
|
||||
result = __out.join('');
|
||||
__out = out;
|
||||
return __safe(result);
|
||||
}, __sanitize = function(value) {
|
||||
if (value && value.ecoSafe) {
|
||||
return value;
|
||||
} else if (typeof value !== 'undefined' && value != null) {
|
||||
return __escape(value);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
|
||||
__safe = __obj.safe = function(value) {
|
||||
if (value && value.ecoSafe) {
|
||||
return value;
|
||||
} else {
|
||||
if (!(typeof value !== 'undefined' && value != null)) value = '';
|
||||
var result = new String(value);
|
||||
result.ecoSafe = true;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
if (!__escape) {
|
||||
__escape = __obj.escape = function(value) {
|
||||
return ('' + value)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
};
|
||||
}
|
||||
(function() {
|
||||
(function() {
|
||||
if (this.agent.avatar) {
|
||||
__out.push('\n<img class="zammad-chat-agent-avatar" src="');
|
||||
__out.push(__sanitize(this.agent.avatar));
|
||||
__out.push('">\n');
|
||||
}
|
||||
|
||||
__out.push('\n<span class="zammad-chat-agent-sentence">\n <span class="zammad-chat-agent-name">');
|
||||
|
||||
__out.push(__sanitize(this.agent.name));
|
||||
|
||||
__out.push('</span>\n</span>');
|
||||
|
||||
}).call(this);
|
||||
|
||||
}).call(__obj);
|
||||
__obj.safe = __objSafe, __obj.escape = __escape;
|
||||
return __out.join('');
|
||||
};
|
||||
|
||||
/*!
|
||||
* ----------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <jevin9@gmail.com> wrote this file. As long as you retain this notice you
|
||||
* can do whatever you want with this stuff. If we meet some day, and you think
|
||||
* this stuff is worth it, you can buy me a beer in return. Jevin O. Sewaruth
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* Autogrow Textarea Plugin Version v3.0
|
||||
* http://www.technoreply.com/autogrow-textarea-plugin-3-0
|
||||
*
|
||||
* THIS PLUGIN IS DELIVERD ON A PAY WHAT YOU WHANT BASIS. IF THE PLUGIN WAS USEFUL TO YOU, PLEASE CONSIDER BUYING THE PLUGIN HERE :
|
||||
* https://sites.fastspring.com/technoreply/instant/autogrowtextareaplugin
|
||||
*
|
||||
* Date: October 15, 2012
|
||||
*/
|
||||
|
||||
jQuery.fn.autoGrow = function(options) {
|
||||
return this.each(function() {
|
||||
var settings = jQuery.extend({
|
||||
extraLine: true,
|
||||
}, options);
|
||||
|
||||
var createMirror = function(textarea) {
|
||||
jQuery(textarea).after('<div class="autogrow-textarea-mirror"></div>');
|
||||
return jQuery(textarea).next('.autogrow-textarea-mirror')[0];
|
||||
}
|
||||
|
||||
var sendContentToMirror = function (textarea) {
|
||||
mirror.innerHTML = String(textarea.value)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/ /g, ' ')
|
||||
.replace(/\n/g, '<br />') +
|
||||
(settings.extraLine? '.<br/>.' : '')
|
||||
;
|
||||
|
||||
if (jQuery(textarea).height() != jQuery(mirror).height())
|
||||
jQuery(textarea).height(jQuery(mirror).height());
|
||||
}
|
||||
|
||||
var growTextarea = function () {
|
||||
sendContentToMirror(this);
|
||||
}
|
||||
|
||||
// Create a mirror
|
||||
var mirror = createMirror(this);
|
||||
|
||||
// Style the mirror
|
||||
mirror.style.display = 'none';
|
||||
mirror.style.wordWrap = 'break-word';
|
||||
mirror.style.whiteSpace = 'normal';
|
||||
mirror.style.padding = jQuery(this).css('paddingTop') + ' ' +
|
||||
jQuery(this).css('paddingRight') + ' ' +
|
||||
jQuery(this).css('paddingBottom') + ' ' +
|
||||
jQuery(this).css('paddingLeft');
|
||||
|
||||
mirror.style.width = jQuery(this).css('width');
|
||||
mirror.style.fontFamily = jQuery(this).css('font-family');
|
||||
mirror.style.fontSize = jQuery(this).css('font-size');
|
||||
mirror.style.lineHeight = jQuery(this).css('line-height');
|
||||
|
||||
// Style the textarea
|
||||
this.style.overflow = "hidden";
|
||||
this.style.minHeight = this.rows+"em";
|
||||
|
||||
// Bind the textarea's event
|
||||
this.onkeyup = growTextarea;
|
||||
|
||||
// Fire the event for text already present
|
||||
sendContentToMirror(this);
|
||||
|
||||
});
|
||||
};
|
||||
if (!window.zammadChatTemplates) {
|
||||
window.zammadChatTemplates = {};
|
||||
}
|
||||
|
|
2
public/assets/chat/chat.min.js
vendored
2
public/assets/chat/chat.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -13,6 +13,9 @@
|
|||
* https://sites.fastspring.com/technoreply/instant/autogrowtextareaplugin
|
||||
*
|
||||
* Date: October 15, 2012
|
||||
*
|
||||
* Zammad modification: remove overflow:hidden when maximum height is reached
|
||||
*
|
||||
*/
|
||||
|
||||
jQuery.fn.autoGrow = function(options) {
|
||||
|
@ -38,8 +41,13 @@ jQuery.fn.autoGrow = function(options) {
|
|||
(settings.extraLine? '.<br/>.' : '')
|
||||
;
|
||||
|
||||
if (jQuery(textarea).height() != jQuery(mirror).height())
|
||||
if (jQuery(textarea).height() != jQuery(mirror).height()) {
|
||||
jQuery(textarea).height(jQuery(mirror).height());
|
||||
|
||||
var maxHeight = parseInt(jQuery(textarea).css('max-height'), 10);
|
||||
var overflow = jQuery(mirror).height() > maxHeight ? '' : 'hidden'
|
||||
jQuery(textarea).css('overflow', overflow);
|
||||
}
|
||||
}
|
||||
|
||||
var growTextarea = function () {
|
||||
|
|
Loading…
Reference in a new issue