Moved to this.log().

This commit is contained in:
Martin Edenhofer 2015-02-17 16:25:22 +01:00
parent aacb930094
commit dfe7d33bd1
2 changed files with 37 additions and 18 deletions

View file

@ -10,6 +10,7 @@
var pluginName = 'ce', var pluginName = 'ce',
defaults = { defaults = {
debug: false,
mode: 'richtext', mode: 'richtext',
multiline: true, multiline: true,
allowKey: { allowKey: {
@ -68,9 +69,9 @@
// handle enter // handle enter
this.$element.on('keydown', function (e) { this.$element.on('keydown', function (e) {
console.log('keydown', e.keyCode) _this.log('keydown', e.keyCode)
if ( _this.preventInput ) { if ( _this.preventInput ) {
console.log('preventInput', _this.preventInput) this.log('preventInput', _this.preventInput)
return return
} }
@ -95,7 +96,7 @@
// just paste text // just paste text
this.$element.on('paste', function (e) { this.$element.on('paste', function (e) {
console.log('paste') _this.log('paste')
// check existing + paste text for limit // check existing + paste text for limit
var text var text
@ -136,6 +137,7 @@
// disable rich text b/u/i // disable rich text b/u/i
if ( this.options.mode === 'textonly' ) { if ( this.options.mode === 'textonly' ) {
this.$element.on('keydown', function (e) { this.$element.on('keydown', function (e) {
var _this = this
if ( _this.richTextKey(e) ) { if ( _this.richTextKey(e) ) {
e.preventDefault() e.preventDefault()
} }
@ -179,7 +181,7 @@
if (typeAhead) { if (typeAhead) {
length = length + typeAhead length = length + typeAhead
} }
console.log('maxLengthOk', length, this.options.maxlength) this.log('maxLengthOk', length, this.options.maxlength)
if ( length > this.options.maxlength ) { if ( length > this.options.maxlength ) {
// try to set error on framework form // try to set error on framework form
@ -234,6 +236,13 @@
return this.$element.html().trim() return this.$element.html().trim()
} }
// log method
Plugin.prototype.log = function() {
if (this.options.debug) {
console.log(this._name, arguments)
}
}
$.fn[pluginName] = function ( options ) { $.fn[pluginName] = function ( options ) {
return this.each(function () { return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) { if (!$.data(this, 'plugin_' + pluginName)) {

View file

@ -10,7 +10,9 @@
*/ */
var pluginName = 'textmodule', var pluginName = 'textmodule',
defaults = {} defaults = {
debug: false
}
function Plugin( element, options ) { function Plugin( element, options ) {
this.element = element this.element = element
@ -110,7 +112,7 @@
// backspace + buffer === :: -> close textmodule // backspace + buffer === :: -> close textmodule
if ( _this.buffer === '::' ) { if ( _this.buffer === '::' ) {
_this.close() _this.close(true)
e.preventDefault() e.preventDefault()
return return
} }
@ -118,14 +120,14 @@
// reduce buffer and show new result // reduce buffer and show new result
var length = _this.buffer.length var length = _this.buffer.length
_this.buffer = _this.buffer.substr( 0, length-1 ) _this.buffer = _this.buffer.substr( 0, length-1 )
console.log('BS backspace', _this.buffer) _this.log( 'BS backspace', _this.buffer )
_this.result( _this.buffer.substr( 2, length-1 ) ) _this.result( _this.buffer.substr( 2, length-1 ) )
} }
}) })
// build buffer // build buffer
this.$element.on('keypress', function (e) { this.$element.on('keypress', function (e) {
console.log('BUFF', _this.buffer, e.keyCode, String.fromCharCode(e.which) ) _this.log('BUFF', _this.buffer, e.keyCode, String.fromCharCode(e.which) )
// shift // shift
if ( e.keyCode === 16 ) return if ( e.keyCode === 16 ) return
@ -156,9 +158,9 @@
var sign = String.fromCharCode(e.which) var sign = String.fromCharCode(e.which)
if ( sign && sign !== ':' && e.which != 8 ) { // 8 == backspace if ( sign && sign !== ':' && e.which != 8 ) { // 8 == backspace
_this.buffer = _this.buffer + sign _this.buffer = _this.buffer + sign
//console.log('BUFF ADD', sign, this.buffer, sign.length, e.which) //_this.log('BUFF ADD', sign, this.buffer, sign.length, e.which)
} }
console.log('BUFF HINT', _this.buffer, _this.buffer.length, e.which, String.fromCharCode(e.which)) _this.log('BUFF HINT', _this.buffer, _this.buffer.length, e.which, String.fromCharCode(e.which))
b = $.proxy(function() { b = $.proxy(function() {
this.result( this.buffer.substr(2,this.buffer.length) ) this.result( this.buffer.substr(2,this.buffer.length) )
@ -228,11 +230,12 @@
} }
// close widget // close widget
Plugin.prototype.close = function() { Plugin.prototype.close = function(cutInput) {
this.$widget.removeClass('open') this.$widget.removeClass('open')
if ( this.active ) { if ( cutInput && this.active ) {
this.cutInput(true) this.cutInput(true)
} }
this.buffer = ''
this.active = false this.active = false
} }
@ -281,7 +284,7 @@
start = start - 1 start = start - 1
} }
} }
//console.log('CUT FOR', string, "-"+clone.toString()+"-", start, range.startOffset) //this.log('CUT FOR', string, "-"+clone.toString()+"-", start, range.startOffset)
clone.setStart(range.startContainer, start) clone.setStart(range.startContainer, start)
clone.setEnd(range.startContainer, range.startOffset) clone.setEnd(range.startContainer, range.startOffset)
clone.deleteContents() clone.deleteContents()
@ -304,7 +307,7 @@
// select text module and insert into text // select text module and insert into text
Plugin.prototype.take = function(id) { Plugin.prototype.take = function(id) {
if (!id) { if (!id) {
this.close() this.close(true)
return return
} }
for (var i = 0; i < this.collection.length; i++) { for (var i = 0; i < this.collection.length; i++) {
@ -313,7 +316,7 @@
var content = item.content var content = item.content
this.cutInput() this.cutInput()
this.paste(content) this.paste(content)
this.close() this.close(true)
return return
} }
} }
@ -348,7 +351,7 @@
}) })
this.$widget.find('ul').html('') this.$widget.find('ul').html('')
console.log('result', term, result) this.log('result', term, result)
for (var i = 0; i < result.length; i++) { for (var i = 0; i < result.length; i++) {
var item = result[i] var item = result[i]
var template = "<li><a href=\"#\" class=\"u-textTruncate\" data-id=" + item.id + ">" + App.Utils.htmlEscape(item.name) var template = "<li><a href=\"#\" class=\"u-textTruncate\" data-id=" + item.id + ">" + App.Utils.htmlEscape(item.name)
@ -372,6 +375,13 @@
this.movePosition() this.movePosition()
} }
// log method
Plugin.prototype.log = function() {
if (this.options.debug) {
console.log(this._name, arguments)
}
}
$.fn[pluginName] = function ( options ) { $.fn[pluginName] = function ( options ) {
return this.each(function () { return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) { if (!$.data(this, 'plugin_' + pluginName)) {