@@ -3452,12 +3452,25 @@ var string = (function() {
3452
3452
* first in editable.prefix in order for it to be the only externally visible
3453
3453
* variable.
3454
3454
*
3455
+ * @param {Object } configuration for this editable instance.
3456
+ * window: The window where to attach the editable events.
3457
+ * defaultBehavior: {Boolean} Load default-behavior.js.
3458
+ * mouseMoveSelectionChanges: {Boolean} Whether to get cursor and selection events on mousemove.
3459
+ * browserSpellcheck: {Boolean} Set the spellcheck attribute on editable elements
3460
+ *
3455
3461
* @class Editable
3456
3462
*/
3457
- Editable = function ( userConfig ) {
3458
- this . config = $ . extend ( true , { } , config , userConfig ) ;
3459
- this . win = this . config . window || window ;
3460
- this . editableSelector = '.' + this . config . editableClass ;
3463
+ Editable = function ( instanceConfig ) {
3464
+ var defaultInstanceConfig = {
3465
+ window : window ,
3466
+ defaultBehavior : true ,
3467
+ mouseMoveSelectionChanges : false ,
3468
+ browserSpellcheck : true
3469
+ } ;
3470
+
3471
+ this . config = $ . extend ( defaultInstanceConfig , instanceConfig ) ;
3472
+ this . win = this . config . window ;
3473
+ this . editableSelector = '.' + config . editableClass ;
3461
3474
3462
3475
if ( ! rangy . initialized ) {
3463
3476
rangy . init ( ) ;
@@ -3469,6 +3482,25 @@ Editable = function(userConfig) {
3469
3482
}
3470
3483
} ;
3471
3484
3485
+
3486
+ /**
3487
+ * Set configuration options that affect all editable
3488
+ * instances.
3489
+ *
3490
+ * @param {Object } global configuration options (defaults are defined in config.js)
3491
+ * log: {Boolean}
3492
+ * logErrors: {Boolean}
3493
+ * editableClass: {String} e.g. 'js-editable'
3494
+ * editableDisabledClass: {String} e.g. 'js-editable-disabled'
3495
+ * pastingAttribute: {String} default: e.g. 'data-editable-is-pasting'
3496
+ * boldTag: e.g. '<strong>'
3497
+ * italicTag: e.g. '<em>'
3498
+ */
3499
+ Editable . globalConfig = function ( globalConfig ) {
3500
+ $ . extend ( config , globalConfig ) ;
3501
+ } ;
3502
+
3503
+
3472
3504
/**
3473
3505
* Adds the Editable.JS API to the given target elements.
3474
3506
* Opposite of {{#crossLink "Editable/remove"}}{{/crossLink}}.
@@ -3478,14 +3510,10 @@ Editable = function(userConfig) {
3478
3510
* @param {HTMLElement|Array(HTMLElement)|String } target A HTMLElement, an
3479
3511
* array of HTMLElement or a query selector representing the target where
3480
3512
* the API should be added on.
3481
- * @param {Object } [elementConfiguration={}] Configuration options override.
3482
3513
* @chainable
3483
3514
*/
3484
- Editable . prototype . add = function ( target , elementConfiguration ) {
3485
- var elemConfig = $ . extend ( true , { } , config , elementConfiguration ) ;
3486
- // todo: store element configuration
3515
+ Editable . prototype . add = function ( target ) {
3487
3516
this . enable ( $ ( target ) ) ;
3488
-
3489
3517
// todo: check css whitespace settings
3490
3518
return this ;
3491
3519
} ;
@@ -3523,6 +3551,7 @@ Editable.prototype.disable = function($elem) {
3523
3551
$elem = $elem || $ ( '.' + config . editableClass , body ) ;
3524
3552
$elem
3525
3553
. removeAttr ( 'contenteditable' )
3554
+ . removeAttr ( 'spellcheck' )
3526
3555
. removeClass ( config . editableClass )
3527
3556
. addClass ( config . editableDisabledClass ) ;
3528
3557
@@ -3544,6 +3573,7 @@ Editable.prototype.enable = function($elem, normalize) {
3544
3573
$elem = $elem || $ ( '.' + config . editableDisabledClass , body ) ;
3545
3574
$elem
3546
3575
. attr ( 'contenteditable' , true )
3576
+ . attr ( 'spellcheck' , this . config . browserSpellcheck )
3547
3577
. removeClass ( config . editableDisabledClass )
3548
3578
. addClass ( config . editableClass ) ;
3549
3579
@@ -3811,10 +3841,8 @@ var config = {
3811
3841
editableClass : 'js-editable' ,
3812
3842
editableDisabledClass : 'js-editable-disabled' ,
3813
3843
pastingAttribute : 'data-editable-is-pasting' ,
3814
- mouseMoveSelectionChanges : false ,
3815
3844
boldTag : '<strong>' ,
3816
- italicTag : '<em>' ,
3817
- defaultBehavior : true
3845
+ italicTag : '<em>'
3818
3846
} ;
3819
3847
3820
3848
@@ -4959,10 +4987,10 @@ Dispatcher.prototype.unload = function() {
4959
4987
Dispatcher . prototype . setupElementEvents = function ( ) {
4960
4988
var _this = this ;
4961
4989
this . $document . on ( 'focus.editable' , _this . editableSelector , function ( event ) {
4962
- if ( this . getAttribute ( _this . config . pastingAttribute ) ) return ;
4990
+ if ( this . getAttribute ( config . pastingAttribute ) ) return ;
4963
4991
_this . notify ( 'focus' , this ) ;
4964
4992
} ) . on ( 'blur.editable' , _this . editableSelector , function ( event ) {
4965
- if ( this . getAttribute ( _this . config . pastingAttribute ) ) return ;
4993
+ if ( this . getAttribute ( config . pastingAttribute ) ) return ;
4966
4994
_this . notify ( 'blur' , this ) ;
4967
4995
} ) . on ( 'copy.editable' , _this . editableSelector , function ( event ) {
4968
4996
log ( 'Copy' ) ;
0 commit comments