Improved default checkbox value handling in the Inspector. Imrpovements in the Redactor figure toolbar support.

This commit is contained in:
alekseybobkov 2015-01-14 19:39:53 -08:00
parent 3499bbf063
commit f5aee22110
8 changed files with 15697 additions and 17 deletions

File diff suppressed because one or more lines are too long

View File

@ -1532,9 +1532,9 @@ properties[matches[1]]=attribute.value}
this.propertyValues=properties}else{var propertyValuesStr=$.trim(this.propertyValuesField.val())
this.propertyValues=propertyValuesStr.length===0?{}:$.parseJSON(propertyValuesStr)}
try{this.originalPropertyValues=$.extend(true,{},this.propertyValues)}catch(err){throw new Error('Error parsing the Inspector property values string. '+err)}}
Inspector.prototype.readProperty=function(property){if(this.propertyValues[property]!==undefined)
Inspector.prototype.readProperty=function(property,returnUndefined){if(this.propertyValues[property]!==undefined)
return this.propertyValues[property]
return null}
return returnUndefined?undefined:null}
Inspector.prototype.writeProperty=function(property,value,noChangedStatusUpdate){this.propertyValues[property]=value
if(this.propertyValuesField.length)
this.propertyValuesField.val(JSON.stringify(this.propertyValues))
@ -1631,12 +1631,14 @@ this.selector='#'+this.editorId+' input'
var self=this
$(document).on('change',this.selector,function(){self.applyValue()})}
InspectorEditorCheckbox.prototype.applyValue=function(){this.inspector.writeProperty(this.fieldDef.property,$(this.selector).get(0).checked?1:0)}
InspectorEditorCheckbox.prototype.renderEditor=function(){var data={id:this.editorId,cbId:this.editorId+'-cb',title:this.fieldDef.title}
InspectorEditorCheckbox.prototype.renderEditor=function(){var self=this,data={id:this.editorId,cbId:this.editorId+'-cb',title:this.fieldDef.title}
return Mustache.render(this.getTemplate(),data)}
InspectorEditorCheckbox.prototype.init=function(){var isChecked=this.inspector.readProperty(this.fieldDef.property)
if(isChecked=='0'||isChecked=='false')
isChecked=false
InspectorEditorCheckbox.prototype.init=function(){var isChecked=this.inspector.readProperty(this.fieldDef.property,true)
if(isChecked===undefined){if(this.fieldDef.placeholder!==undefined){isChecked=this.normalizeCheckedValue(this.fieldDef.placeholder)}}else{isChecked=this.normalizeCheckedValue(isChecked)}
$(this.selector).prop('checked',isChecked)}
InspectorEditorCheckbox.prototype.normalizeCheckedValue=function(value){if(value=='0'||value=='false')
return false
return value}
InspectorEditorCheckbox.prototype.focus=function(){$(this.selector).closest('div').focus()}
InspectorEditorCheckbox.prototype.getTemplate=function(){return' \
<td id="{{id}}"> \

View File

@ -602,11 +602,11 @@
}
}
Inspector.prototype.readProperty = function(property) {
Inspector.prototype.readProperty = function(property, returnUndefined) {
if (this.propertyValues[property] !== undefined)
return this.propertyValues[property]
return null
return returnUndefined ? undefined : null
}
Inspector.prototype.writeProperty = function(property, value, noChangedStatusUpdate) {
@ -864,7 +864,8 @@
}
InspectorEditorCheckbox.prototype.renderEditor = function() {
var data = {
var self = this,
data = {
id: this.editorId,
cbId: this.editorId + '-cb',
title: this.fieldDef.title
@ -874,14 +875,26 @@
}
InspectorEditorCheckbox.prototype.init = function() {
var isChecked = this.inspector.readProperty(this.fieldDef.property)
var isChecked = this.inspector.readProperty(this.fieldDef.property, true)
if (isChecked == '0' || isChecked == 'false')
isChecked = false
if (isChecked === undefined) {
if (this.fieldDef.placeholder !== undefined) {
isChecked = this.normalizeCheckedValue(this.fieldDef.placeholder)
}
} else {
isChecked = this.normalizeCheckedValue(isChecked)
}
$(this.selector).prop('checked', isChecked)
}
InspectorEditorCheckbox.prototype.normalizeCheckedValue = function(value) {
if (value == '0' || value == 'false')
return false
return value
}
InspectorEditorCheckbox.prototype.focus = function() {
$(this.selector).closest('div').focus()
}

View File

@ -337,7 +337,10 @@ div.control-popover {
font-weight: 400!important;
}
div.custom-select.select2-container .select2-choice {
height: 36px;
line-height: 36px;
}
}
}
}

View File

@ -1026,6 +1026,25 @@ body .redactor-box-fullscreen {
.redactor-box figure:hover .oc-figure-controls {
display: block;
}
.redactor-box .oc-figure-controls.bottom {
bottom: -50px;
top: auto;
}
.redactor-box .oc-figure-controls.bottom:after {
bottom: auto;
top: -10px;
}
.redactor-box .oc-figure-controls.bottom:before {
content: '' !important;
display: block !important;
width: 0 !important;
height: 0 !important;
border-left: 8.5px solid transparent !important;
border-right: 8.5px solid transparent !important;
border-bottom: 9px solid #2b3e50 !important;
border-top: none;
top: -8px;
}
.redactor-box .oc-figure-controls span {
display: inline-block;
border: none;

View File

@ -86,7 +86,7 @@
},
hideToolbar: function (event) {
$(event.currentTarget).find('.oc-figure-controls').appendTo(this.redactor.$box).hide()
$(event.currentTarget).find('.oc-figure-controls').appendTo(this.redactor.$box).hide()
},
observeToolbars: function () {

View File

@ -63,7 +63,7 @@
blurCallback: function() { self.$el.removeClass('editor-focus') },
keydownCallback: function(e) { return self.keydown(e, this.$editor) },
enterCallback: function(e) { return self.enter(e, this.$editor) },
initCallback: function() { self.build() },
initCallback: function() { self.build(this) },
changeCallback: function() {
self.sanityCheckContent(this.$editor)
this.$editor.trigger('mutate')
@ -87,13 +87,20 @@
this.$textarea.redactor(redactorOptions)
}
RichEditor.prototype.build = function() {
RichEditor.prototype.build = function(redactor) {
this.updateLayout()
$(window).resize($.proxy(this.updateLayout, this))
$(window).on('oc.updateUi', $.proxy(this.updateLayout, this))
this.$textarea.trigger('init.oc.richeditor', [this.$el])
var self = this
redactor.default = {
onShow: function($figure, $toolbar) {
self.onShowFigureToolbar($figure, $toolbar)
}
}
}
RichEditor.prototype.updateLayout = function() {
@ -149,6 +156,14 @@
return false
}
RichEditor.prototype.onShowFigureToolbar = function($figure, $toolbar) {
// Deal with the case when the toolbar top has negative
// value
var toolbarTop = $figure.position().top - $toolbar.height() - 10
$toolbar.toggleClass('bottom', toolbarTop < 0)
}
// RICHEDITOR PLUGIN DEFINITION
// ============================

View File

@ -172,6 +172,22 @@
display: block;
}
.oc-figure-controls.bottom {
bottom: -50px;
top: auto;
&:after {
bottom: auto;
top: -10px;
}
&:before {
.triangle(up, 17px, 9px, #2b3e50)!important;
border-top: none;
top: -8px;
}
}
.oc-figure-controls span {
display: inline-block;
border: none;