Moved to data() store of options for item (inspired by bs js plugins).
This commit is contained in:
parent
043bcd9a55
commit
354c8a8634
4 changed files with 24 additions and 12 deletions
|
@ -59,7 +59,7 @@ class App.WidgetOrganization extends App.Controller
|
||||||
###
|
###
|
||||||
|
|
||||||
update: (e) =>
|
update: (e) =>
|
||||||
note = $(e.target).ceg({ mode: 'textonly' })
|
note = $(e.target).ceg()
|
||||||
organization = App.Organization.find( @organization_id )
|
organization = App.Organization.find( @organization_id )
|
||||||
if organization.note isnt note
|
if organization.note isnt note
|
||||||
organization.updateAttributes( note: note )
|
organization.updateAttributes( note: note )
|
||||||
|
|
|
@ -86,7 +86,7 @@ class App.WidgetUser extends App.Controller
|
||||||
)
|
)
|
||||||
|
|
||||||
update: (e) =>
|
update: (e) =>
|
||||||
note = $(e.target).ceg({ mode: 'textonly' })
|
note = $(e.target).ceg()
|
||||||
user = App.User.find( @user_id )
|
user = App.User.find( @user_id )
|
||||||
if user.note isnt note
|
if user.note isnt note
|
||||||
user.updateAttributes( note: note )
|
user.updateAttributes( note: note )
|
||||||
|
|
|
@ -39,12 +39,12 @@
|
||||||
85: true, // u
|
85: true, // u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var OPTIONS = {}
|
|
||||||
|
|
||||||
// add/remove placeholder
|
// add/remove placeholder
|
||||||
var updatePlaceholder = function(target, type) {
|
var updatePlaceholder = function(target, type) {
|
||||||
|
var options = target.data('ce.options')
|
||||||
var text = target.text().trim()
|
var text = target.text().trim()
|
||||||
var placeholder = '<span class="placeholder">' + OPTIONS.placeholder + '</span>'
|
var placeholder = '<span class="placeholder">' + options.placeholder + '</span>'
|
||||||
|
|
||||||
// add placholder if no text exists
|
// add placholder if no text exists
|
||||||
if ( type === 'add') {
|
if ( type === 'add') {
|
||||||
|
@ -55,7 +55,7 @@
|
||||||
|
|
||||||
// empty placeholder text
|
// empty placeholder text
|
||||||
else {
|
else {
|
||||||
if ( text === OPTIONS.placeholder ) {
|
if ( text === options.placeholder ) {
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
document.execCommand('selectAll', false, '');
|
document.execCommand('selectAll', false, '');
|
||||||
document.execCommand('delete', false, '');
|
document.execCommand('delete', false, '');
|
||||||
|
@ -68,11 +68,16 @@
|
||||||
|
|
||||||
// max length check
|
// max length check
|
||||||
var maxLengthOk = function(field, typeAhead) {
|
var maxLengthOk = function(field, typeAhead) {
|
||||||
|
var options = field.data('ce.options')
|
||||||
|
if (!options) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
var length = field.text().length
|
var length = field.text().length
|
||||||
if (typeAhead) {
|
if (typeAhead) {
|
||||||
length = length + 1
|
length = length + 1
|
||||||
}
|
}
|
||||||
if ( length > OPTIONS.maxlength ) {
|
if ( length > options.maxlength ) {
|
||||||
field.addClass('invalid')
|
field.addClass('invalid')
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
field.removeClass('invalid')
|
field.removeClass('invalid')
|
||||||
|
@ -84,10 +89,12 @@
|
||||||
|
|
||||||
// check if key is allowed, even if length limit is reached
|
// check if key is allowed, even if length limit is reached
|
||||||
var allowKey = function(e) {
|
var allowKey = function(e) {
|
||||||
if ( OPTIONS.allowKey[ e.keyCode ] ) {
|
var options = $(e.target).data('ce.options')
|
||||||
|
|
||||||
|
if ( options.allowKey[ e.keyCode ] ) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if ( ( e.ctrlKey || e.metaKey ) && OPTIONS.extraAllowKey[ e.keyCode ] ) {
|
if ( ( e.ctrlKey || e.metaKey ) && options.extraAllowKey[ e.keyCode ] ) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -95,7 +102,9 @@
|
||||||
|
|
||||||
// check if rich text key is pressed
|
// check if rich text key is pressed
|
||||||
var richTextKey = function(e) {
|
var richTextKey = function(e) {
|
||||||
if ( ( e.ctrlKey || e.metaKey ) && OPTIONS.richTextFormatKey[ e.keyCode ] ) {
|
var options = $(e.target).data('ce.options')
|
||||||
|
|
||||||
|
if ( ( e.ctrlKey || e.metaKey ) && options.richTextFormatKey[ e.keyCode ] ) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -103,7 +112,8 @@
|
||||||
|
|
||||||
// get correct val if textbox
|
// get correct val if textbox
|
||||||
$.fn.ceg = function(option) {
|
$.fn.ceg = function(option) {
|
||||||
var options = $.extend({}, DEFAULTS, option)
|
var options = this.data('ce.options')
|
||||||
|
|
||||||
updatePlaceholder( this, 'remove' )
|
updatePlaceholder( this, 'remove' )
|
||||||
|
|
||||||
// get text
|
// get text
|
||||||
|
@ -125,7 +135,9 @@
|
||||||
$.fn.ce = function(option) {
|
$.fn.ce = function(option) {
|
||||||
var options = $.extend({}, DEFAULTS, option)
|
var options = $.extend({}, DEFAULTS, option)
|
||||||
options.placeholder = options.placeholder || this.data('placeholder')
|
options.placeholder = options.placeholder || this.data('placeholder')
|
||||||
OPTIONS = options
|
|
||||||
|
// store options
|
||||||
|
this.data('ce.options', options)
|
||||||
|
|
||||||
// process placeholder
|
// process placeholder
|
||||||
if ( options.placeholder ) {
|
if ( options.placeholder ) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<h1><span contenteditable="true" class="ticket-title-update" data-placeholder="<%= @T('Enter Ticket Title...') %>"><%= @P( @ticket.title ) %></span></h1>
|
<h1><span contenteditable="true" class="ticket-title-update" data-placeholder="<%= @T('Enter Title...') %>"><%= @P( @ticket.title ) %></span></h1>
|
||||||
|
|
||||||
<small class="task-subline">
|
<small class="task-subline">
|
||||||
<%- @C('ticket_hook') %> <span class="ticket-number"><%- @ticket.number %></span> - <%- @T('created') %> <span class="humanTimeFromNow" data-time="<%- @ticket.created_at %>">?</span> <% if !@isCustomer && @ticket.escalation_time: %> - <%- @T('escalation') %> <span class="humanTimeFromNow escalation" data-time="<%- @ticket.escalation_time %>">?</span><% end %>
|
<%- @C('ticket_hook') %> <span class="ticket-number"><%- @ticket.number %></span> - <%- @T('created') %> <span class="humanTimeFromNow" data-time="<%- @ticket.created_at %>">?</span> <% if !@isCustomer && @ticket.escalation_time: %> - <%- @T('escalation') %> <span class="humanTimeFromNow escalation" data-time="<%- @ticket.escalation_time %>">?</span><% end %>
|
||||||
|
|
Loading…
Reference in a new issue