x-editable-rails 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,7 @@
1
- /*! X-editable - v1.4.6
1
+ /*! X-editable - v1.5.0
2
2
  * In-place editing with Twitter Bootstrap, jQuery UI or pure jQuery
3
3
  * http://github.com/vitalets/x-editable
4
4
  * Copyright (c) 2013 Vitaliy Potapov; Licensed MIT */
5
-
6
5
  /**
7
6
  Form with single input element, two buttons and two states: normal/loading.
8
7
  Applied as jQuery method to DIV tag (not to form tag!). This is because form can be in loading state when spinner shown.
@@ -33,6 +32,9 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
33
32
  //set initial value
34
33
  //todo: may be add check: typeof str === 'string' ?
35
34
  this.value = this.input.str2value(this.options.value);
35
+
36
+ //prerender: get input.$input
37
+ this.input.prerender();
36
38
  },
37
39
  initTemplate: function() {
38
40
  this.$form = $($.fn.editableform.template);
@@ -80,9 +82,8 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
80
82
  this.initInput();
81
83
 
82
84
  //append input to form
83
- this.input.prerender();
84
85
  this.$form.find('div.editable-input').append(this.input.$tpl);
85
-
86
+
86
87
  //append form to container
87
88
  this.$div.append(this.$form);
88
89
 
@@ -620,6 +621,9 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
620
621
 
621
622
  //error class attached to editable-error-block
622
623
  $.fn.editableform.errorBlockClass = 'editable-error';
624
+
625
+ //engine
626
+ $.fn.editableform.engine = 'jquery';
623
627
  }(window.jQuery));
624
628
 
625
629
  /**
@@ -898,6 +902,8 @@ Applied as jQuery method.
898
902
  containerDataName: null, //object name in element's .data()
899
903
  innerCss: null, //tbd in child class
900
904
  containerClass: 'editable-container editable-popup', //css class applied to container element
905
+ defaults: {}, //container itself defaults
906
+
901
907
  init: function(element, options) {
902
908
  this.$element = $(element);
903
909
  //since 1.4.1 container do not use data-* directly as they already merged into options.
@@ -975,10 +981,9 @@ Applied as jQuery method.
975
981
  throw new Error(this.containerName + ' not found. Have you included corresponding js file?');
976
982
  }
977
983
 
978
- var cDef = $.fn[this.containerName].defaults;
979
984
  //keys defined in container defaults go to container, others go to form
980
985
  for(var k in this.options) {
981
- if(k in cDef) {
986
+ if(k in this.defaults) {
982
987
  this.containerOptions[k] = this.options[k];
983
988
  } else {
984
989
  this.formOptions[k] = this.options[k];
@@ -1727,13 +1732,12 @@ Makes editable any HTML element on the page. Applied as jQuery method.
1727
1732
  this.isEmpty = isEmpty;
1728
1733
  } else {
1729
1734
  //detect empty
1730
- if($.trim(this.$element.html()) === '') {
1731
- this.isEmpty = true;
1732
- } else if($.trim(this.$element.text()) !== '') {
1733
- this.isEmpty = false;
1735
+ //for some inputs we need more smart check
1736
+ //e.g. wysihtml5 may have <br>, <p></p>, <img>
1737
+ if(typeof(this.input.isEmpty) === 'function') {
1738
+ this.isEmpty = this.input.isEmpty(this.$element);
1734
1739
  } else {
1735
- //e.g. '<img>'
1736
- this.isEmpty = !this.$element.height() || !this.$element.width();
1740
+ this.isEmpty = $.trim(this.$element.html()) === '';
1737
1741
  }
1738
1742
  }
1739
1743
 
@@ -2249,7 +2253,7 @@ Makes editable any HTML element on the page. Applied as jQuery method.
2249
2253
  @since 1.4.5
2250
2254
  @default #FFFF80
2251
2255
  **/
2252
- highlight: '#FFFF80'
2256
+ highlight: '#FFFF80'
2253
2257
  };
2254
2258
 
2255
2259
  }(window.jQuery));
@@ -2308,7 +2312,7 @@ To create your own input you can inherit from this class.
2308
2312
  @param {DOMElement} element
2309
2313
  **/
2310
2314
  value2html: function(value, element) {
2311
- $(element).text($.trim(value));
2315
+ $(element)[this.options.escape ? 'text' : 'html']($.trim(value));
2312
2316
  },
2313
2317
 
2314
2318
  /**
@@ -2415,7 +2419,7 @@ To create your own input you can inherit from this class.
2415
2419
  },
2416
2420
 
2417
2421
  // -------- helper functions --------
2418
- setClass: function() {
2422
+ setClass: function() {
2419
2423
  if(this.options.inputclass) {
2420
2424
  this.$input.addClass(this.options.inputclass);
2421
2425
  }
@@ -2447,9 +2451,22 @@ To create your own input you can inherit from this class.
2447
2451
 
2448
2452
  @property inputclass
2449
2453
  @type string
2450
- @default input-medium
2454
+ @default null
2451
2455
  **/
2452
- inputclass: 'input-medium',
2456
+ inputclass: null,
2457
+
2458
+ /**
2459
+ If `true` - html will be escaped in content of element via $.text() method.
2460
+ If `false` - html will not be escaped, $.html() used.
2461
+ When you use own `display` function, this option obviosly has no effect.
2462
+
2463
+ @property escape
2464
+ @type boolean
2465
+ @since 1.5.0
2466
+ @default true
2467
+ **/
2468
+ escape: true,
2469
+
2453
2470
  //scope for external methods (e.g. source defined as function)
2454
2471
  //for internal use only
2455
2472
  scope: null,
@@ -2581,8 +2598,8 @@ List - abstract class for inputs that have source option loaded from js array or
2581
2598
  }
2582
2599
  }
2583
2600
 
2584
- //loading sourceData from server
2585
- $.ajax({
2601
+ //ajaxOptions for source. Can be overwritten bt options.sourceOptions
2602
+ var ajaxOptions = $.extend({
2586
2603
  url: source,
2587
2604
  type: 'get',
2588
2605
  cache: false,
@@ -2617,7 +2634,11 @@ List - abstract class for inputs that have source option loaded from js array or
2617
2634
  $.each(cache.err_callbacks, function () { this.call(); });
2618
2635
  }
2619
2636
  }, this)
2620
- });
2637
+ }, this.options.sourceOptions);
2638
+
2639
+ //loading sourceData from server
2640
+ $.ajax(ajaxOptions);
2641
+
2621
2642
  } else { //options as json/array
2622
2643
  this.sourceData = this.makeArray(source);
2623
2644
 
@@ -2777,7 +2798,17 @@ List - abstract class for inputs that have source option loaded from js array or
2777
2798
  @default true
2778
2799
  @since 1.2.0
2779
2800
  **/
2780
- sourceCache: true
2801
+ sourceCache: true,
2802
+ /**
2803
+ Additional ajax options to be used in $.ajax() when loading list from server.
2804
+ Useful to send extra parameters (`data` key) or change request method (`type` key).
2805
+
2806
+ @property sourceOptions
2807
+ @type object|function
2808
+ @default null
2809
+ @since 1.5.0
2810
+ **/
2811
+ sourceOptions: null
2781
2812
  });
2782
2813
 
2783
2814
  $.fn.editabletypes.list = List;
@@ -3038,7 +3069,7 @@ Select (dropdown)
3038
3069
  @extends list
3039
3070
  @final
3040
3071
  @example
3041
- <a href="#" id="status" data-type="select" data-pk="1" data-url="/post" data-original-title="Select status"></a>
3072
+ <a href="#" id="status" data-type="select" data-pk="1" data-url="/post" data-title="Select status"></a>
3042
3073
  <script>
3043
3074
  $(function(){
3044
3075
  $('#status').editable({
@@ -3105,7 +3136,8 @@ $(function(){
3105
3136
  text = items[0].text;
3106
3137
  }
3107
3138
 
3108
- $(element).text(text);
3139
+ //$(element).text(text);
3140
+ $.fn.editabletypes.abstractinput.prototype.value2html.call(this, text, element);
3109
3141
  },
3110
3142
 
3111
3143
  autosubmit: function() {
@@ -3135,7 +3167,7 @@ Internally value stored as javascript array of values.
3135
3167
  @extends list
3136
3168
  @final
3137
3169
  @example
3138
- <a href="#" id="options" data-type="checklist" data-pk="1" data-url="/post" data-original-title="Select options"></a>
3170
+ <a href="#" id="options" data-type="checklist" data-pk="1" data-url="/post" data-title="Select options"></a>
3139
3171
  <script>
3140
3172
  $(function(){
3141
3173
  $('#options').editable({
@@ -3229,10 +3261,14 @@ $(function(){
3229
3261
  //collect text of checked boxes
3230
3262
  value2htmlFinal: function(value, element) {
3231
3263
  var html = [],
3232
- checked = $.fn.editableutils.itemsByValue(value, this.sourceData);
3264
+ checked = $.fn.editableutils.itemsByValue(value, this.sourceData),
3265
+ escape = this.options.escape;
3233
3266
 
3234
3267
  if(checked.length) {
3235
- $.each(checked, function(i, v) { html.push($.fn.editableutils.escape(v.text)); });
3268
+ $.each(checked, function(i, v) {
3269
+ var text = escape ? $.fn.editableutils.escape(v.text) : v.text;
3270
+ html.push(text);
3271
+ });
3236
3272
  $(element).html(html.join('<br>'));
3237
3273
  } else {
3238
3274
  $(element).empty();
@@ -3502,7 +3538,7 @@ Time
3502
3538
  /**
3503
3539
  Select2 input. Based on amazing work of Igor Vaynberg https://github.com/ivaynberg/select2.
3504
3540
  Please see [original select2 docs](http://ivaynberg.github.com/select2) for detailed description and options.
3505
- Compatible **select2 version is 3.4.1**!
3541
+
3506
3542
  You should manually download and include select2 distributive:
3507
3543
 
3508
3544
  <link href="select2/select2.css" rel="stylesheet" type="text/css"></link>
@@ -3643,9 +3679,11 @@ $(function(){
3643
3679
  $.extend(Constructor.prototype, {
3644
3680
  render: function() {
3645
3681
  this.setClass();
3646
-
3647
- //apply select2
3648
- this.$input.select2(this.options.select2);
3682
+
3683
+ //can not apply select2 here as it calls initSelection
3684
+ //over input that does not have correct value yet.
3685
+ //apply select2 only in value2input
3686
+ //this.$input.select2(this.options.select2);
3649
3687
 
3650
3688
  //when data is loaded via ajax, we need to know when it's done to populate listData
3651
3689
  if(this.isRemote) {
@@ -3673,7 +3711,8 @@ $(function(){
3673
3711
  } else if(this.sourceData) {
3674
3712
  data = $.fn.editableutils.itemsByValue(value, this.sourceData, this.idFunc);
3675
3713
  } else {
3676
- //can not get list of possible values (e.g. autotext for select2 with ajax source)
3714
+ //can not get list of possible values
3715
+ //(e.g. autotext for select2 with ajax source)
3677
3716
  }
3678
3717
 
3679
3718
  //data may be array (when multiple values allowed)
@@ -3689,7 +3728,8 @@ $(function(){
3689
3728
 
3690
3729
  text = $.isArray(text) ? text.join(this.options.viewseparator) : text;
3691
3730
 
3692
- $(element).text(text);
3731
+ //$(element).text(text);
3732
+ Constructor.superclass.value2html.call(this, text, element);
3693
3733
  },
3694
3734
 
3695
3735
  html2value: function(html) {
@@ -3708,8 +3748,14 @@ $(function(){
3708
3748
  }
3709
3749
  */
3710
3750
 
3711
- //for remote source just set value, text is updated by initSelection
3712
- this.$input.val(value).trigger('change', true); //second argument needed to separate initial change from user's click (for autosubmit)
3751
+ //for remote source just set value, text is updated by initSelection
3752
+ if(!this.$input.data('select2')) {
3753
+ this.$input.val(value);
3754
+ this.$input.select2(this.options.select2);
3755
+ } else {
3756
+ //second argument needed to separate initial change from user's click (for autosubmit)
3757
+ this.$input.val(value).trigger('change', true);
3758
+ }
3713
3759
 
3714
3760
  //if remote source AND no user's initSelection provided --> try to use element's text
3715
3761
  if(this.isRemote && !this.isMultiple && !this.options.select2.initSelection) {
@@ -3717,7 +3763,7 @@ $(function(){
3717
3763
  customText = this.options.select2.formatSelection;
3718
3764
  if(!customId && !customText) {
3719
3765
  var data = {id: value, text: $(this.options.scope).text()};
3720
- this.$input.select2('data', data);
3766
+ this.$input.select2('data', data);
3721
3767
  }
3722
3768
  }
3723
3769
  },
@@ -3806,7 +3852,7 @@ $(function(){
3806
3852
  E.g. `[{id: 1, text: "text1"}, {id: 2, text: "text2"}, ...]`.
3807
3853
 
3808
3854
  @property source
3809
- @type array
3855
+ @type array|string|function
3810
3856
  @default null
3811
3857
  **/
3812
3858
  source: null,
@@ -3817,7 +3863,7 @@ $(function(){
3817
3863
  @type string
3818
3864
  @default ', '
3819
3865
  **/
3820
- viewseparator: ', '
3866
+ viewseparator: ', '
3821
3867
  });
3822
3868
 
3823
3869
  $.fn.editabletypes.select2 = Constructor;
@@ -4297,7 +4343,7 @@ Internally value stored as `momentjs` object.
4297
4343
  @final
4298
4344
  @since 1.4.0
4299
4345
  @example
4300
- <a href="#" id="dob" data-type="combodate" data-pk="1" data-url="/post" data-value="1984-05-15" data-original-title="Select date"></a>
4346
+ <a href="#" id="dob" data-type="combodate" data-pk="1" data-url="/post" data-value="1984-05-15" data-title="Select date"></a>
4301
4347
  <script>
4302
4348
  $(function(){
4303
4349
  $('#dob').editable({
@@ -4343,7 +4389,14 @@ $(function(){
4343
4389
  $.extend(Constructor.prototype, {
4344
4390
  render: function () {
4345
4391
  this.$input.combodate(this.options.combodate);
4392
+
4393
+ if($.fn.editableform.engine === 'bs3') {
4394
+ this.$input.siblings().find('select').addClass('form-control');
4395
+ }
4346
4396
 
4397
+ if(this.options.inputclass) {
4398
+ this.$input.siblings().find('select').addClass(this.options.inputclass);
4399
+ }
4347
4400
  //"clear" link
4348
4401
  /*
4349
4402
  if(this.options.clear) {
@@ -4360,7 +4413,8 @@ $(function(){
4360
4413
 
4361
4414
  value2html: function(value, element) {
4362
4415
  var text = value ? value.format(this.options.viewformat) : '';
4363
- $(element).text(text);
4416
+ //$(element).text(text);
4417
+ Constructor.superclass.value2html.call(this, text, element);
4364
4418
  },
4365
4419
 
4366
4420
  html2value: function(html) {
@@ -4479,6 +4533,7 @@ $(function(){
4479
4533
  $.extend($.fn.editableContainer.Popup.prototype, {
4480
4534
  containerName: 'poshytip',
4481
4535
  innerCss: 'div.tip-inner',
4536
+ defaults: $.fn.poshytip.defaults,
4482
4537
 
4483
4538
  initContainer: function(){
4484
4539
  this.handlePlacement();
@@ -4683,7 +4738,7 @@ For **i18n** you should include js file from here: https://github.com/jquery/jqu
4683
4738
  @extends abstractinput
4684
4739
  @final
4685
4740
  @example
4686
- <a href="#" id="dob" data-type="date" data-pk="1" data-url="/post" data-original-title="Select date">15/05/1984</a>
4741
+ <a href="#" id="dob" data-type="date" data-pk="1" data-url="/post" data-title="Select date">15/05/1984</a>
4687
4742
  <script>
4688
4743
  $(function(){
4689
4744
  $('#dob').editable({
@@ -4742,7 +4797,7 @@ $(function(){
4742
4797
 
4743
4798
  value2html: function(value, element) {
4744
4799
  var text = $.datepicker.formatDate(this.options.viewformat, value);
4745
- DateUI.superclass.value2html(text, element);
4800
+ DateUI.superclass.value2html.call(this, text, element);
4746
4801
  },
4747
4802
 
4748
4803
  html2value: function(html) {
@@ -1,8 +1,7 @@
1
- /*! X-editable - v1.4.6
1
+ /*! X-editable - v1.5.0
2
2
  * In-place editing with Twitter Bootstrap, jQuery UI or pure jQuery
3
3
  * http://github.com/vitalets/x-editable
4
4
  * Copyright (c) 2013 Vitaliy Potapov; Licensed MIT */
5
-
6
5
  /**
7
6
  Form with single input element, two buttons and two states: normal/loading.
8
7
  Applied as jQuery method to DIV tag (not to form tag!). This is because form can be in loading state when spinner shown.
@@ -33,6 +32,9 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
33
32
  //set initial value
34
33
  //todo: may be add check: typeof str === 'string' ?
35
34
  this.value = this.input.str2value(this.options.value);
35
+
36
+ //prerender: get input.$input
37
+ this.input.prerender();
36
38
  },
37
39
  initTemplate: function() {
38
40
  this.$form = $($.fn.editableform.template);
@@ -80,9 +82,8 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
80
82
  this.initInput();
81
83
 
82
84
  //append input to form
83
- this.input.prerender();
84
85
  this.$form.find('div.editable-input').append(this.input.$tpl);
85
-
86
+
86
87
  //append form to container
87
88
  this.$div.append(this.$form);
88
89
 
@@ -620,6 +621,9 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
620
621
 
621
622
  //error class attached to editable-error-block
622
623
  $.fn.editableform.errorBlockClass = 'editable-error';
624
+
625
+ //engine
626
+ $.fn.editableform.engine = 'jquery';
623
627
  }(window.jQuery));
624
628
 
625
629
  /**
@@ -898,6 +902,8 @@ Applied as jQuery method.
898
902
  containerDataName: null, //object name in element's .data()
899
903
  innerCss: null, //tbd in child class
900
904
  containerClass: 'editable-container editable-popup', //css class applied to container element
905
+ defaults: {}, //container itself defaults
906
+
901
907
  init: function(element, options) {
902
908
  this.$element = $(element);
903
909
  //since 1.4.1 container do not use data-* directly as they already merged into options.
@@ -975,10 +981,9 @@ Applied as jQuery method.
975
981
  throw new Error(this.containerName + ' not found. Have you included corresponding js file?');
976
982
  }
977
983
 
978
- var cDef = $.fn[this.containerName].defaults;
979
984
  //keys defined in container defaults go to container, others go to form
980
985
  for(var k in this.options) {
981
- if(k in cDef) {
986
+ if(k in this.defaults) {
982
987
  this.containerOptions[k] = this.options[k];
983
988
  } else {
984
989
  this.formOptions[k] = this.options[k];
@@ -1727,13 +1732,12 @@ Makes editable any HTML element on the page. Applied as jQuery method.
1727
1732
  this.isEmpty = isEmpty;
1728
1733
  } else {
1729
1734
  //detect empty
1730
- if($.trim(this.$element.html()) === '') {
1731
- this.isEmpty = true;
1732
- } else if($.trim(this.$element.text()) !== '') {
1733
- this.isEmpty = false;
1735
+ //for some inputs we need more smart check
1736
+ //e.g. wysihtml5 may have <br>, <p></p>, <img>
1737
+ if(typeof(this.input.isEmpty) === 'function') {
1738
+ this.isEmpty = this.input.isEmpty(this.$element);
1734
1739
  } else {
1735
- //e.g. '<img>'
1736
- this.isEmpty = !this.$element.height() || !this.$element.width();
1740
+ this.isEmpty = $.trim(this.$element.html()) === '';
1737
1741
  }
1738
1742
  }
1739
1743
 
@@ -2249,7 +2253,7 @@ Makes editable any HTML element on the page. Applied as jQuery method.
2249
2253
  @since 1.4.5
2250
2254
  @default #FFFF80
2251
2255
  **/
2252
- highlight: '#FFFF80'
2256
+ highlight: '#FFFF80'
2253
2257
  };
2254
2258
 
2255
2259
  }(window.jQuery));
@@ -2308,7 +2312,7 @@ To create your own input you can inherit from this class.
2308
2312
  @param {DOMElement} element
2309
2313
  **/
2310
2314
  value2html: function(value, element) {
2311
- $(element).text($.trim(value));
2315
+ $(element)[this.options.escape ? 'text' : 'html']($.trim(value));
2312
2316
  },
2313
2317
 
2314
2318
  /**
@@ -2415,7 +2419,7 @@ To create your own input you can inherit from this class.
2415
2419
  },
2416
2420
 
2417
2421
  // -------- helper functions --------
2418
- setClass: function() {
2422
+ setClass: function() {
2419
2423
  if(this.options.inputclass) {
2420
2424
  this.$input.addClass(this.options.inputclass);
2421
2425
  }
@@ -2447,9 +2451,22 @@ To create your own input you can inherit from this class.
2447
2451
 
2448
2452
  @property inputclass
2449
2453
  @type string
2450
- @default input-medium
2454
+ @default null
2451
2455
  **/
2452
- inputclass: 'input-medium',
2456
+ inputclass: null,
2457
+
2458
+ /**
2459
+ If `true` - html will be escaped in content of element via $.text() method.
2460
+ If `false` - html will not be escaped, $.html() used.
2461
+ When you use own `display` function, this option obviosly has no effect.
2462
+
2463
+ @property escape
2464
+ @type boolean
2465
+ @since 1.5.0
2466
+ @default true
2467
+ **/
2468
+ escape: true,
2469
+
2453
2470
  //scope for external methods (e.g. source defined as function)
2454
2471
  //for internal use only
2455
2472
  scope: null,
@@ -2581,8 +2598,8 @@ List - abstract class for inputs that have source option loaded from js array or
2581
2598
  }
2582
2599
  }
2583
2600
 
2584
- //loading sourceData from server
2585
- $.ajax({
2601
+ //ajaxOptions for source. Can be overwritten bt options.sourceOptions
2602
+ var ajaxOptions = $.extend({
2586
2603
  url: source,
2587
2604
  type: 'get',
2588
2605
  cache: false,
@@ -2617,7 +2634,11 @@ List - abstract class for inputs that have source option loaded from js array or
2617
2634
  $.each(cache.err_callbacks, function () { this.call(); });
2618
2635
  }
2619
2636
  }, this)
2620
- });
2637
+ }, this.options.sourceOptions);
2638
+
2639
+ //loading sourceData from server
2640
+ $.ajax(ajaxOptions);
2641
+
2621
2642
  } else { //options as json/array
2622
2643
  this.sourceData = this.makeArray(source);
2623
2644
 
@@ -2777,7 +2798,17 @@ List - abstract class for inputs that have source option loaded from js array or
2777
2798
  @default true
2778
2799
  @since 1.2.0
2779
2800
  **/
2780
- sourceCache: true
2801
+ sourceCache: true,
2802
+ /**
2803
+ Additional ajax options to be used in $.ajax() when loading list from server.
2804
+ Useful to send extra parameters (`data` key) or change request method (`type` key).
2805
+
2806
+ @property sourceOptions
2807
+ @type object|function
2808
+ @default null
2809
+ @since 1.5.0
2810
+ **/
2811
+ sourceOptions: null
2781
2812
  });
2782
2813
 
2783
2814
  $.fn.editabletypes.list = List;
@@ -3038,7 +3069,7 @@ Select (dropdown)
3038
3069
  @extends list
3039
3070
  @final
3040
3071
  @example
3041
- <a href="#" id="status" data-type="select" data-pk="1" data-url="/post" data-original-title="Select status"></a>
3072
+ <a href="#" id="status" data-type="select" data-pk="1" data-url="/post" data-title="Select status"></a>
3042
3073
  <script>
3043
3074
  $(function(){
3044
3075
  $('#status').editable({
@@ -3105,7 +3136,8 @@ $(function(){
3105
3136
  text = items[0].text;
3106
3137
  }
3107
3138
 
3108
- $(element).text(text);
3139
+ //$(element).text(text);
3140
+ $.fn.editabletypes.abstractinput.prototype.value2html.call(this, text, element);
3109
3141
  },
3110
3142
 
3111
3143
  autosubmit: function() {
@@ -3135,7 +3167,7 @@ Internally value stored as javascript array of values.
3135
3167
  @extends list
3136
3168
  @final
3137
3169
  @example
3138
- <a href="#" id="options" data-type="checklist" data-pk="1" data-url="/post" data-original-title="Select options"></a>
3170
+ <a href="#" id="options" data-type="checklist" data-pk="1" data-url="/post" data-title="Select options"></a>
3139
3171
  <script>
3140
3172
  $(function(){
3141
3173
  $('#options').editable({
@@ -3229,10 +3261,14 @@ $(function(){
3229
3261
  //collect text of checked boxes
3230
3262
  value2htmlFinal: function(value, element) {
3231
3263
  var html = [],
3232
- checked = $.fn.editableutils.itemsByValue(value, this.sourceData);
3264
+ checked = $.fn.editableutils.itemsByValue(value, this.sourceData),
3265
+ escape = this.options.escape;
3233
3266
 
3234
3267
  if(checked.length) {
3235
- $.each(checked, function(i, v) { html.push($.fn.editableutils.escape(v.text)); });
3268
+ $.each(checked, function(i, v) {
3269
+ var text = escape ? $.fn.editableutils.escape(v.text) : v.text;
3270
+ html.push(text);
3271
+ });
3236
3272
  $(element).html(html.join('<br>'));
3237
3273
  } else {
3238
3274
  $(element).empty();
@@ -3502,7 +3538,7 @@ Time
3502
3538
  /**
3503
3539
  Select2 input. Based on amazing work of Igor Vaynberg https://github.com/ivaynberg/select2.
3504
3540
  Please see [original select2 docs](http://ivaynberg.github.com/select2) for detailed description and options.
3505
- Compatible **select2 version is 3.4.1**!
3541
+
3506
3542
  You should manually download and include select2 distributive:
3507
3543
 
3508
3544
  <link href="select2/select2.css" rel="stylesheet" type="text/css"></link>
@@ -3643,9 +3679,11 @@ $(function(){
3643
3679
  $.extend(Constructor.prototype, {
3644
3680
  render: function() {
3645
3681
  this.setClass();
3646
-
3647
- //apply select2
3648
- this.$input.select2(this.options.select2);
3682
+
3683
+ //can not apply select2 here as it calls initSelection
3684
+ //over input that does not have correct value yet.
3685
+ //apply select2 only in value2input
3686
+ //this.$input.select2(this.options.select2);
3649
3687
 
3650
3688
  //when data is loaded via ajax, we need to know when it's done to populate listData
3651
3689
  if(this.isRemote) {
@@ -3673,7 +3711,8 @@ $(function(){
3673
3711
  } else if(this.sourceData) {
3674
3712
  data = $.fn.editableutils.itemsByValue(value, this.sourceData, this.idFunc);
3675
3713
  } else {
3676
- //can not get list of possible values (e.g. autotext for select2 with ajax source)
3714
+ //can not get list of possible values
3715
+ //(e.g. autotext for select2 with ajax source)
3677
3716
  }
3678
3717
 
3679
3718
  //data may be array (when multiple values allowed)
@@ -3689,7 +3728,8 @@ $(function(){
3689
3728
 
3690
3729
  text = $.isArray(text) ? text.join(this.options.viewseparator) : text;
3691
3730
 
3692
- $(element).text(text);
3731
+ //$(element).text(text);
3732
+ Constructor.superclass.value2html.call(this, text, element);
3693
3733
  },
3694
3734
 
3695
3735
  html2value: function(html) {
@@ -3708,8 +3748,14 @@ $(function(){
3708
3748
  }
3709
3749
  */
3710
3750
 
3711
- //for remote source just set value, text is updated by initSelection
3712
- this.$input.val(value).trigger('change', true); //second argument needed to separate initial change from user's click (for autosubmit)
3751
+ //for remote source just set value, text is updated by initSelection
3752
+ if(!this.$input.data('select2')) {
3753
+ this.$input.val(value);
3754
+ this.$input.select2(this.options.select2);
3755
+ } else {
3756
+ //second argument needed to separate initial change from user's click (for autosubmit)
3757
+ this.$input.val(value).trigger('change', true);
3758
+ }
3713
3759
 
3714
3760
  //if remote source AND no user's initSelection provided --> try to use element's text
3715
3761
  if(this.isRemote && !this.isMultiple && !this.options.select2.initSelection) {
@@ -3717,7 +3763,7 @@ $(function(){
3717
3763
  customText = this.options.select2.formatSelection;
3718
3764
  if(!customId && !customText) {
3719
3765
  var data = {id: value, text: $(this.options.scope).text()};
3720
- this.$input.select2('data', data);
3766
+ this.$input.select2('data', data);
3721
3767
  }
3722
3768
  }
3723
3769
  },
@@ -3806,7 +3852,7 @@ $(function(){
3806
3852
  E.g. `[{id: 1, text: "text1"}, {id: 2, text: "text2"}, ...]`.
3807
3853
 
3808
3854
  @property source
3809
- @type array
3855
+ @type array|string|function
3810
3856
  @default null
3811
3857
  **/
3812
3858
  source: null,
@@ -3817,7 +3863,7 @@ $(function(){
3817
3863
  @type string
3818
3864
  @default ', '
3819
3865
  **/
3820
- viewseparator: ', '
3866
+ viewseparator: ', '
3821
3867
  });
3822
3868
 
3823
3869
  $.fn.editabletypes.select2 = Constructor;
@@ -4297,7 +4343,7 @@ Internally value stored as `momentjs` object.
4297
4343
  @final
4298
4344
  @since 1.4.0
4299
4345
  @example
4300
- <a href="#" id="dob" data-type="combodate" data-pk="1" data-url="/post" data-value="1984-05-15" data-original-title="Select date"></a>
4346
+ <a href="#" id="dob" data-type="combodate" data-pk="1" data-url="/post" data-value="1984-05-15" data-title="Select date"></a>
4301
4347
  <script>
4302
4348
  $(function(){
4303
4349
  $('#dob').editable({
@@ -4343,7 +4389,14 @@ $(function(){
4343
4389
  $.extend(Constructor.prototype, {
4344
4390
  render: function () {
4345
4391
  this.$input.combodate(this.options.combodate);
4392
+
4393
+ if($.fn.editableform.engine === 'bs3') {
4394
+ this.$input.siblings().find('select').addClass('form-control');
4395
+ }
4346
4396
 
4397
+ if(this.options.inputclass) {
4398
+ this.$input.siblings().find('select').addClass(this.options.inputclass);
4399
+ }
4347
4400
  //"clear" link
4348
4401
  /*
4349
4402
  if(this.options.clear) {
@@ -4360,7 +4413,8 @@ $(function(){
4360
4413
 
4361
4414
  value2html: function(value, element) {
4362
4415
  var text = value ? value.format(this.options.viewformat) : '';
4363
- $(element).text(text);
4416
+ //$(element).text(text);
4417
+ Constructor.superclass.value2html.call(this, text, element);
4364
4418
  },
4365
4419
 
4366
4420
  html2value: function(html) {
@@ -4495,6 +4549,8 @@ Editableform based on jQuery UI
4495
4549
  //error classes
4496
4550
  $.fn.editableform.errorGroupClass = null;
4497
4551
  $.fn.editableform.errorBlockClass = 'ui-state-error';
4552
+ //engine
4553
+ $.fn.editableform.engine = 'jquery-ui';
4498
4554
 
4499
4555
  }(window.jQuery));
4500
4556
  /**
@@ -4511,6 +4567,7 @@ Editableform based on jQuery UI
4511
4567
  //object name in element's .data()
4512
4568
  containerDataName: 'ui-tooltip',
4513
4569
  innerCss: '.ui-tooltip-content',
4570
+ defaults: $.ui.tooltip.prototype.options,
4514
4571
 
4515
4572
  //split options on containerOptions and formOptions
4516
4573
  splitOptions: function() {
@@ -4522,10 +4579,10 @@ Editableform based on jQuery UI
4522
4579
  $.error('Please use jQueryUI with "tooltip" widget! http://jqueryui.com/download');
4523
4580
  return;
4524
4581
  }
4582
+
4525
4583
  //defaults for tooltip
4526
- var cDef = $.ui[this.containerName].prototype.options;
4527
4584
  for(var k in this.options) {
4528
- if(k in cDef) {
4585
+ if(k in this.defaults) {
4529
4586
  this.containerOptions[k] = this.options[k];
4530
4587
  } else {
4531
4588
  this.formOptions[k] = this.options[k];
@@ -4628,7 +4685,7 @@ For **i18n** you should include js file from here: https://github.com/jquery/jqu
4628
4685
  @extends abstractinput
4629
4686
  @final
4630
4687
  @example
4631
- <a href="#" id="dob" data-type="date" data-pk="1" data-url="/post" data-original-title="Select date">15/05/1984</a>
4688
+ <a href="#" id="dob" data-type="date" data-pk="1" data-url="/post" data-title="Select date">15/05/1984</a>
4632
4689
  <script>
4633
4690
  $(function(){
4634
4691
  $('#dob').editable({
@@ -4687,7 +4744,7 @@ $(function(){
4687
4744
 
4688
4745
  value2html: function(value, element) {
4689
4746
  var text = $.datepicker.formatDate(this.options.viewformat, value);
4690
- DateUI.superclass.value2html(text, element);
4747
+ DateUI.superclass.value2html.call(this, text, element);
4691
4748
  },
4692
4749
 
4693
4750
  html2value: function(html) {