jsuites 4.10.3 → 4.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -116,8 +116,6 @@ div[data-before]:before {
116
116
  cursor: pointer;
117
117
  box-sizing: border-box;
118
118
  width: 100%;
119
- max-height: 100%;
120
- min-height: 180px;
121
119
  display: flex;
122
120
  align-items: center;
123
121
  justify-content: center;
@@ -967,10 +965,6 @@ div[data-before]:before {
967
965
  display: inline-block;
968
966
  }
969
967
 
970
- .jdropdown-header::placeholder {
971
- color:#000;
972
- }
973
-
974
968
  .jdropdown-backdrop {
975
969
  position:fixed;
976
970
  top:0px;
@@ -1919,7 +1913,7 @@ div[data-before]:before {
1919
1913
  }
1920
1914
 
1921
1915
  .jtabs .jtabs-headers > div:not(.jtabs-border) {
1922
- padding: 6px;
1916
+ padding: 8px;
1923
1917
  padding-left: 20px;
1924
1918
  padding-right: 20px;
1925
1919
  margin-left: 1px;
@@ -2170,6 +2164,7 @@ div[data-before]:before {
2170
2164
  background-position: top 50% right 0px;
2171
2165
  display: flex;
2172
2166
  align-items: center;
2167
+ font-size: 0.9em;
2173
2168
  }
2174
2169
 
2175
2170
  .jtoolbar .jpicker-content > div {
@@ -17,7 +17,7 @@
17
17
 
18
18
  var jSuites = function(options) {
19
19
  var obj = {}
20
- var version = '4.10.3';
20
+ var version = '4.11.0';
21
21
 
22
22
  var find = function(DOMElement, component) {
23
23
  if (DOMElement[component.type] && DOMElement[component.type] == component) {
@@ -4880,6 +4880,7 @@ jSuites.editor = (function(el, options) {
4880
4880
  onkeyup: null,
4881
4881
  onkeydown: null,
4882
4882
  onchange: null,
4883
+ userSearch: null,
4883
4884
  };
4884
4885
 
4885
4886
  // Loop through our object
@@ -4958,7 +4959,7 @@ jSuites.editor = (function(el, options) {
4958
4959
  if (obj.options.value) {
4959
4960
  var value = obj.options.value;
4960
4961
  } else {
4961
- var value = el.innerHTML ? el.innerHTML : '';
4962
+ var value = el.innerHTML ? el.innerHTML : '';
4962
4963
  }
4963
4964
 
4964
4965
  if (! value) {
@@ -4969,7 +4970,7 @@ jSuites.editor = (function(el, options) {
4969
4970
  * Onchange event controllers
4970
4971
  */
4971
4972
  var change = function(e) {
4972
- if (typeof(obj.options.onchange) == 'function') {
4973
+ if (typeof(obj.options.onchange) == 'function') {
4973
4974
  obj.options.onchange(el, obj, e);
4974
4975
  }
4975
4976
 
@@ -4989,6 +4990,25 @@ jSuites.editor = (function(el, options) {
4989
4990
  }
4990
4991
  }
4991
4992
 
4993
+ // Create node
4994
+ var createUserSearchNode = function() {
4995
+ // Get coordinates from caret
4996
+ var sel = window.getSelection ? window.getSelection() : document.selection;
4997
+ var range = sel.getRangeAt(0);
4998
+ range.deleteContents();
4999
+ // Append text node
5000
+ var input = document.createElement('a');
5001
+ input.innerText = '@';
5002
+ input.searchable = true;
5003
+ range.insertNode(input);
5004
+ var node = range.getBoundingClientRect();
5005
+ range.collapse(false);
5006
+ // Position
5007
+ userSearch.style.position = 'fixed';
5008
+ userSearch.style.top = node.top + node.height + 10 + 'px';
5009
+ userSearch.style.left = node.left + 2 + 'px';
5010
+ }
5011
+
4992
5012
  /**
4993
5013
  * Extract images from a HTML string
4994
5014
  */
@@ -5019,10 +5039,10 @@ jSuites.editor = (function(el, options) {
5019
5039
  range = sel.getRangeAt(0);
5020
5040
  var selectedText = range.toString();
5021
5041
  range.deleteContents();
5022
- range.insertNode(newNode);
5042
+ range.insertNode(newNode);
5023
5043
  // move the cursor after element
5024
5044
  range.setStartAfter(newNode);
5025
- range.setEndAfter(newNode);
5045
+ range.setEndAfter(newNode);
5026
5046
  sel.removeAllRanges();
5027
5047
  sel.addRange(range);
5028
5048
  }
@@ -5104,7 +5124,7 @@ jSuites.editor = (function(el, options) {
5104
5124
  var html = editor.innerHTML.replace(/\n/g, ' ');
5105
5125
  var container = document.createElement('div');
5106
5126
  container.innerHTML = html;
5107
- var text = container.innerText;
5127
+ var text = container.innerText;
5108
5128
  var url = jSuites.editor.detectUrl(text);
5109
5129
 
5110
5130
  if (url) {
@@ -5177,8 +5197,12 @@ jSuites.editor = (function(el, options) {
5177
5197
  /**
5178
5198
  * Set editor value
5179
5199
  */
5180
- obj.setData = function(html) {
5181
- editor.innerHTML = html;
5200
+ obj.setData = function(o) {
5201
+ if (typeof(o) == 'object') {
5202
+ editor.innerHTML = o.content;
5203
+ } else {
5204
+ editor.innerHTML = o;
5205
+ }
5182
5206
 
5183
5207
  if (obj.options.focus) {
5184
5208
  jSuites.editor.setCursor(editor, true);
@@ -5246,8 +5270,31 @@ jSuites.editor = (function(el, options) {
5246
5270
  }
5247
5271
  }
5248
5272
 
5273
+ // Users
5274
+ if (userSearch) {
5275
+ // Get tag users
5276
+ var tagged = editor.querySelectorAll('a[data-user]');
5277
+ if (tagged.length) {
5278
+ data.users = [];
5279
+ for (var i = 0; i < tagged.length; i++) {
5280
+ var userId = tagged[i].getAttribute('data-user');
5281
+ if (userId) {
5282
+ data.users.push(userId);
5283
+ }
5284
+ }
5285
+ data.users = data.users.join(',');
5286
+ }
5287
+ }
5288
+
5249
5289
  // Get content
5250
- var text = editor.innerHTML;
5290
+ var d = document.createElement('div');
5291
+ d.innerHTML = editor.innerHTML;
5292
+ var s = d.querySelector('.jsnippet');
5293
+ if (s) {
5294
+ s.remove();
5295
+ }
5296
+
5297
+ var text = d.innerHTML;
5251
5298
  text = text.replace(/<br>/g, "\n");
5252
5299
  text = text.replace(/<\/div>/g, "<\/div>\n");
5253
5300
  text = text.replace(/<(?:.|\n)*?>/gm, "");
@@ -5406,13 +5453,8 @@ jSuites.editor = (function(el, options) {
5406
5453
  editor.removeEventListener('dragover', editorDragOver);
5407
5454
  editor.removeEventListener('drop', editorDrop);
5408
5455
  editor.removeEventListener('paste', editorPaste);
5409
-
5410
- if (typeof(obj.options.onblur) == 'function') {
5411
- editor.removeEventListener('blur', editorBlur);
5412
- }
5413
- if (typeof(obj.options.onfocus) == 'function') {
5414
- editor.removeEventListener('focus', editorFocus);
5415
- }
5456
+ editor.removeEventListener('blur', editorBlur);
5457
+ editor.removeEventListener('focus', editorFocus);
5416
5458
 
5417
5459
  el.editor = null;
5418
5460
  el.classList.remove('jeditor-container');
@@ -5476,7 +5518,7 @@ jSuites.editor = (function(el, options) {
5476
5518
  } else {
5477
5519
  editorAction = true;
5478
5520
  }
5479
- } else {
5521
+ } else {
5480
5522
  if (e.target.classList.contains('jsnippet')) {
5481
5523
  close(e.target);
5482
5524
  } else if (e.target.parentNode.classList.contains('jsnippet')) {
@@ -5545,7 +5587,23 @@ jSuites.editor = (function(el, options) {
5545
5587
  editor.innerHTML = '<div><br></div>';
5546
5588
  }
5547
5589
 
5548
- if (typeof(obj.options.onkeyup) == 'function') {
5590
+ if (userSearch) {
5591
+ var t = jSuites.getNode();
5592
+ if (t) {
5593
+ if (t.searchable === true) {
5594
+ if (t.innerText && t.innerText.substr(0,1) == '@') {
5595
+ userSearchInstance(t.innerText.substr(1));
5596
+ }
5597
+ } else if (t.searchable === false) {
5598
+ if (t.innerText !== t.getAttribute('data-label')) {
5599
+ t.searchable = true;
5600
+ t.removeAttribute('href');
5601
+ }
5602
+ }
5603
+ }
5604
+ }
5605
+
5606
+ if (typeof(obj.options.onkeyup) == 'function') {
5549
5607
  obj.options.onkeyup(el, obj, e);
5550
5608
  }
5551
5609
  }
@@ -5557,7 +5615,18 @@ jSuites.editor = (function(el, options) {
5557
5615
  verifyEditor();
5558
5616
  }
5559
5617
 
5560
- if (typeof(obj.options.onkeydown) == 'function') {
5618
+ if (userSearch) {
5619
+ if (e.key == '@') {
5620
+ createUserSearchNode(editor);
5621
+ e.preventDefault();
5622
+ } else {
5623
+ if (userSearchInstance.isOpened()) {
5624
+ userSearchInstance.keydown(e);
5625
+ }
5626
+ }
5627
+ }
5628
+
5629
+ if (typeof(obj.options.onkeydown) == 'function') {
5561
5630
  obj.options.onkeydown(el, obj, e);
5562
5631
  }
5563
5632
 
@@ -5649,7 +5718,7 @@ jSuites.editor = (function(el, options) {
5649
5718
  var span = document.createElement('span');
5650
5719
  span.innerHTML = d.firstChild.innerHTML;
5651
5720
  return span;
5652
- }
5721
+ }
5653
5722
 
5654
5723
  var editorPaste = function(e) {
5655
5724
  if (obj.options.filterPaste == true) {
@@ -5743,7 +5812,7 @@ jSuites.editor = (function(el, options) {
5743
5812
  var html = (e.originalEvent || e).dataTransfer.getData('text/html');
5744
5813
  var text = (e.originalEvent || e).dataTransfer.getData('text/plain');
5745
5814
  var file = (e.originalEvent || e).dataTransfer.files;
5746
-
5815
+
5747
5816
  if (file.length) {
5748
5817
  obj.addFile(file);
5749
5818
  } else if (text) {
@@ -5756,6 +5825,10 @@ jSuites.editor = (function(el, options) {
5756
5825
  }
5757
5826
 
5758
5827
  var editorBlur = function(e) {
5828
+ if (userSearch && userSearchInstance.isOpened()) {
5829
+ userSearchInstance.close();
5830
+ }
5831
+
5759
5832
  // Blur
5760
5833
  if (typeof(obj.options.onblur) == 'function') {
5761
5834
  obj.options.onblur(el, obj, e);
@@ -5817,6 +5890,33 @@ jSuites.editor = (function(el, options) {
5817
5890
  });
5818
5891
  }
5819
5892
 
5893
+ // Add user search
5894
+ var userSearch = null;
5895
+ var userSearchInstance = null;
5896
+ if (obj.options.userSearch) {
5897
+ userSearch = document.createElement('div');
5898
+ el.appendChild(userSearch);
5899
+
5900
+ // Component
5901
+ userSearchInstance = jSuites.search(userSearch, {
5902
+ data: obj.options.userSearch,
5903
+ placeholder: jSuites.translate('Type the name a user'),
5904
+ onselect: function(a,b,c,d) {
5905
+ if (userSearchInstance.isOpened()) {
5906
+ var t = jSuites.getNode();
5907
+ if (t && t.searchable == true && (t.innerText.trim() && t.innerText.substr(1))) {
5908
+ t.innerText = '@' + c;
5909
+ t.href = '/' + c;
5910
+ t.setAttribute('data-user', d);
5911
+ t.setAttribute('data-label', t.innerText);
5912
+ t.searchable = false;
5913
+ jSuites.focus(t);
5914
+ }
5915
+ }
5916
+ }
5917
+ });
5918
+ }
5919
+
5820
5920
  // Focus to the editor
5821
5921
  if (obj.options.focus) {
5822
5922
  jSuites.editor.setCursor(editor, obj.options.focus == 'initial' ? true : false);
@@ -8040,8 +8140,11 @@ jSuites.mask = (function() {
8040
8140
  type = getType.call(options, options.mask);
8041
8141
  }
8042
8142
 
8143
+ if (type === 'general') {
8144
+ var o = obj(v, options, true);
8043
8145
 
8044
- if (type === 'datetime') {
8146
+ value = v;
8147
+ } else if (type === 'datetime') {
8045
8148
  if (v instanceof Date) {
8046
8149
  var t = jSuites.calendar.getDateString(value, options.mask);
8047
8150
  }
@@ -8661,7 +8764,7 @@ jSuites.picker = (function(el, options) {
8661
8764
  obj.setValue(item.k);
8662
8765
  // Call method
8663
8766
  if (typeof(obj.options.onchange) == 'function') {
8664
- obj.options.onchange.call(obj, el, obj, item.v, item.v, item.k);
8767
+ obj.options.onchange.call(obj, el, obj, item.v, item.v, item.k, e);
8665
8768
  }
8666
8769
  }
8667
8770
  }
package/dist/jsuites.css CHANGED
@@ -116,8 +116,6 @@ div[data-before]:before {
116
116
  cursor: pointer;
117
117
  box-sizing: border-box;
118
118
  width: 100%;
119
- max-height: 100%;
120
- min-height: 180px;
121
119
  display: flex;
122
120
  align-items: center;
123
121
  justify-content: center;
@@ -967,10 +965,6 @@ div[data-before]:before {
967
965
  display: inline-block;
968
966
  }
969
967
 
970
- .jdropdown-header::placeholder {
971
- color:#000;
972
- }
973
-
974
968
  .jdropdown-backdrop {
975
969
  position:fixed;
976
970
  top:0px;
@@ -2423,7 +2417,7 @@ div[data-before]:before {
2423
2417
  }
2424
2418
 
2425
2419
  .jtabs .jtabs-headers > div:not(.jtabs-border) {
2426
- padding: 6px;
2420
+ padding: 8px;
2427
2421
  padding-left: 20px;
2428
2422
  padding-right: 20px;
2429
2423
  margin-left: 1px;
@@ -2740,6 +2734,7 @@ div[data-before]:before {
2740
2734
  background-position: top 50% right 0px;
2741
2735
  display: flex;
2742
2736
  align-items: center;
2737
+ font-size: 0.9em;
2743
2738
  }
2744
2739
 
2745
2740
  .jtoolbar .jpicker-content > div {
package/dist/jsuites.js CHANGED
@@ -17,7 +17,7 @@
17
17
 
18
18
  var jSuites = function(options) {
19
19
  var obj = {}
20
- var version = '4.10.3';
20
+ var version = '4.11.0';
21
21
 
22
22
  var find = function(DOMElement, component) {
23
23
  if (DOMElement[component.type] && DOMElement[component.type] == component) {
@@ -4891,6 +4891,7 @@ jSuites.editor = (function(el, options) {
4891
4891
  onkeyup: null,
4892
4892
  onkeydown: null,
4893
4893
  onchange: null,
4894
+ userSearch: null,
4894
4895
  };
4895
4896
 
4896
4897
  // Loop through our object
@@ -4969,7 +4970,7 @@ jSuites.editor = (function(el, options) {
4969
4970
  if (obj.options.value) {
4970
4971
  var value = obj.options.value;
4971
4972
  } else {
4972
- var value = el.innerHTML ? el.innerHTML : '';
4973
+ var value = el.innerHTML ? el.innerHTML : '';
4973
4974
  }
4974
4975
 
4975
4976
  if (! value) {
@@ -4980,7 +4981,7 @@ jSuites.editor = (function(el, options) {
4980
4981
  * Onchange event controllers
4981
4982
  */
4982
4983
  var change = function(e) {
4983
- if (typeof(obj.options.onchange) == 'function') {
4984
+ if (typeof(obj.options.onchange) == 'function') {
4984
4985
  obj.options.onchange(el, obj, e);
4985
4986
  }
4986
4987
 
@@ -5000,6 +5001,25 @@ jSuites.editor = (function(el, options) {
5000
5001
  }
5001
5002
  }
5002
5003
 
5004
+ // Create node
5005
+ var createUserSearchNode = function() {
5006
+ // Get coordinates from caret
5007
+ var sel = window.getSelection ? window.getSelection() : document.selection;
5008
+ var range = sel.getRangeAt(0);
5009
+ range.deleteContents();
5010
+ // Append text node
5011
+ var input = document.createElement('a');
5012
+ input.innerText = '@';
5013
+ input.searchable = true;
5014
+ range.insertNode(input);
5015
+ var node = range.getBoundingClientRect();
5016
+ range.collapse(false);
5017
+ // Position
5018
+ userSearch.style.position = 'fixed';
5019
+ userSearch.style.top = node.top + node.height + 10 + 'px';
5020
+ userSearch.style.left = node.left + 2 + 'px';
5021
+ }
5022
+
5003
5023
  /**
5004
5024
  * Extract images from a HTML string
5005
5025
  */
@@ -5030,10 +5050,10 @@ jSuites.editor = (function(el, options) {
5030
5050
  range = sel.getRangeAt(0);
5031
5051
  var selectedText = range.toString();
5032
5052
  range.deleteContents();
5033
- range.insertNode(newNode);
5053
+ range.insertNode(newNode);
5034
5054
  // move the cursor after element
5035
5055
  range.setStartAfter(newNode);
5036
- range.setEndAfter(newNode);
5056
+ range.setEndAfter(newNode);
5037
5057
  sel.removeAllRanges();
5038
5058
  sel.addRange(range);
5039
5059
  }
@@ -5115,7 +5135,7 @@ jSuites.editor = (function(el, options) {
5115
5135
  var html = editor.innerHTML.replace(/\n/g, ' ');
5116
5136
  var container = document.createElement('div');
5117
5137
  container.innerHTML = html;
5118
- var text = container.innerText;
5138
+ var text = container.innerText;
5119
5139
  var url = jSuites.editor.detectUrl(text);
5120
5140
 
5121
5141
  if (url) {
@@ -5188,8 +5208,12 @@ jSuites.editor = (function(el, options) {
5188
5208
  /**
5189
5209
  * Set editor value
5190
5210
  */
5191
- obj.setData = function(html) {
5192
- editor.innerHTML = html;
5211
+ obj.setData = function(o) {
5212
+ if (typeof(o) == 'object') {
5213
+ editor.innerHTML = o.content;
5214
+ } else {
5215
+ editor.innerHTML = o;
5216
+ }
5193
5217
 
5194
5218
  if (obj.options.focus) {
5195
5219
  jSuites.editor.setCursor(editor, true);
@@ -5257,8 +5281,31 @@ jSuites.editor = (function(el, options) {
5257
5281
  }
5258
5282
  }
5259
5283
 
5284
+ // Users
5285
+ if (userSearch) {
5286
+ // Get tag users
5287
+ var tagged = editor.querySelectorAll('a[data-user]');
5288
+ if (tagged.length) {
5289
+ data.users = [];
5290
+ for (var i = 0; i < tagged.length; i++) {
5291
+ var userId = tagged[i].getAttribute('data-user');
5292
+ if (userId) {
5293
+ data.users.push(userId);
5294
+ }
5295
+ }
5296
+ data.users = data.users.join(',');
5297
+ }
5298
+ }
5299
+
5260
5300
  // Get content
5261
- var text = editor.innerHTML;
5301
+ var d = document.createElement('div');
5302
+ d.innerHTML = editor.innerHTML;
5303
+ var s = d.querySelector('.jsnippet');
5304
+ if (s) {
5305
+ s.remove();
5306
+ }
5307
+
5308
+ var text = d.innerHTML;
5262
5309
  text = text.replace(/<br>/g, "\n");
5263
5310
  text = text.replace(/<\/div>/g, "<\/div>\n");
5264
5311
  text = text.replace(/<(?:.|\n)*?>/gm, "");
@@ -5417,13 +5464,8 @@ jSuites.editor = (function(el, options) {
5417
5464
  editor.removeEventListener('dragover', editorDragOver);
5418
5465
  editor.removeEventListener('drop', editorDrop);
5419
5466
  editor.removeEventListener('paste', editorPaste);
5420
-
5421
- if (typeof(obj.options.onblur) == 'function') {
5422
- editor.removeEventListener('blur', editorBlur);
5423
- }
5424
- if (typeof(obj.options.onfocus) == 'function') {
5425
- editor.removeEventListener('focus', editorFocus);
5426
- }
5467
+ editor.removeEventListener('blur', editorBlur);
5468
+ editor.removeEventListener('focus', editorFocus);
5427
5469
 
5428
5470
  el.editor = null;
5429
5471
  el.classList.remove('jeditor-container');
@@ -5487,7 +5529,7 @@ jSuites.editor = (function(el, options) {
5487
5529
  } else {
5488
5530
  editorAction = true;
5489
5531
  }
5490
- } else {
5532
+ } else {
5491
5533
  if (e.target.classList.contains('jsnippet')) {
5492
5534
  close(e.target);
5493
5535
  } else if (e.target.parentNode.classList.contains('jsnippet')) {
@@ -5556,7 +5598,23 @@ jSuites.editor = (function(el, options) {
5556
5598
  editor.innerHTML = '<div><br></div>';
5557
5599
  }
5558
5600
 
5559
- if (typeof(obj.options.onkeyup) == 'function') {
5601
+ if (userSearch) {
5602
+ var t = jSuites.getNode();
5603
+ if (t) {
5604
+ if (t.searchable === true) {
5605
+ if (t.innerText && t.innerText.substr(0,1) == '@') {
5606
+ userSearchInstance(t.innerText.substr(1));
5607
+ }
5608
+ } else if (t.searchable === false) {
5609
+ if (t.innerText !== t.getAttribute('data-label')) {
5610
+ t.searchable = true;
5611
+ t.removeAttribute('href');
5612
+ }
5613
+ }
5614
+ }
5615
+ }
5616
+
5617
+ if (typeof(obj.options.onkeyup) == 'function') {
5560
5618
  obj.options.onkeyup(el, obj, e);
5561
5619
  }
5562
5620
  }
@@ -5568,7 +5626,18 @@ jSuites.editor = (function(el, options) {
5568
5626
  verifyEditor();
5569
5627
  }
5570
5628
 
5571
- if (typeof(obj.options.onkeydown) == 'function') {
5629
+ if (userSearch) {
5630
+ if (e.key == '@') {
5631
+ createUserSearchNode(editor);
5632
+ e.preventDefault();
5633
+ } else {
5634
+ if (userSearchInstance.isOpened()) {
5635
+ userSearchInstance.keydown(e);
5636
+ }
5637
+ }
5638
+ }
5639
+
5640
+ if (typeof(obj.options.onkeydown) == 'function') {
5572
5641
  obj.options.onkeydown(el, obj, e);
5573
5642
  }
5574
5643
 
@@ -5660,7 +5729,7 @@ jSuites.editor = (function(el, options) {
5660
5729
  var span = document.createElement('span');
5661
5730
  span.innerHTML = d.firstChild.innerHTML;
5662
5731
  return span;
5663
- }
5732
+ }
5664
5733
 
5665
5734
  var editorPaste = function(e) {
5666
5735
  if (obj.options.filterPaste == true) {
@@ -5754,7 +5823,7 @@ jSuites.editor = (function(el, options) {
5754
5823
  var html = (e.originalEvent || e).dataTransfer.getData('text/html');
5755
5824
  var text = (e.originalEvent || e).dataTransfer.getData('text/plain');
5756
5825
  var file = (e.originalEvent || e).dataTransfer.files;
5757
-
5826
+
5758
5827
  if (file.length) {
5759
5828
  obj.addFile(file);
5760
5829
  } else if (text) {
@@ -5767,6 +5836,10 @@ jSuites.editor = (function(el, options) {
5767
5836
  }
5768
5837
 
5769
5838
  var editorBlur = function(e) {
5839
+ if (userSearch && userSearchInstance.isOpened()) {
5840
+ userSearchInstance.close();
5841
+ }
5842
+
5770
5843
  // Blur
5771
5844
  if (typeof(obj.options.onblur) == 'function') {
5772
5845
  obj.options.onblur(el, obj, e);
@@ -5828,6 +5901,33 @@ jSuites.editor = (function(el, options) {
5828
5901
  });
5829
5902
  }
5830
5903
 
5904
+ // Add user search
5905
+ var userSearch = null;
5906
+ var userSearchInstance = null;
5907
+ if (obj.options.userSearch) {
5908
+ userSearch = document.createElement('div');
5909
+ el.appendChild(userSearch);
5910
+
5911
+ // Component
5912
+ userSearchInstance = jSuites.search(userSearch, {
5913
+ data: obj.options.userSearch,
5914
+ placeholder: jSuites.translate('Type the name a user'),
5915
+ onselect: function(a,b,c,d) {
5916
+ if (userSearchInstance.isOpened()) {
5917
+ var t = jSuites.getNode();
5918
+ if (t && t.searchable == true && (t.innerText.trim() && t.innerText.substr(1))) {
5919
+ t.innerText = '@' + c;
5920
+ t.href = '/' + c;
5921
+ t.setAttribute('data-user', d);
5922
+ t.setAttribute('data-label', t.innerText);
5923
+ t.searchable = false;
5924
+ jSuites.focus(t);
5925
+ }
5926
+ }
5927
+ }
5928
+ });
5929
+ }
5930
+
5831
5931
  // Focus to the editor
5832
5932
  if (obj.options.focus) {
5833
5933
  jSuites.editor.setCursor(editor, obj.options.focus == 'initial' ? true : false);
@@ -8465,8 +8565,11 @@ jSuites.mask = (function() {
8465
8565
  type = getType.call(options, options.mask);
8466
8566
  }
8467
8567
 
8568
+ if (type === 'general') {
8569
+ var o = obj(v, options, true);
8468
8570
 
8469
- if (type === 'datetime') {
8571
+ value = v;
8572
+ } else if (type === 'datetime') {
8470
8573
  if (v instanceof Date) {
8471
8574
  var t = jSuites.calendar.getDateString(value, options.mask);
8472
8575
  }
@@ -8769,6 +8872,24 @@ jSuites.modal = (function(el, options) {
8769
8872
  });
8770
8873
 
8771
8874
  document.addEventListener('mouseup', function(e) {
8875
+ var item = jSuites.findElement(e.target, 'jmodal');
8876
+ if (item) {
8877
+ // Get target info
8878
+ var rect = item.getBoundingClientRect();
8879
+
8880
+ if (e.changedTouches && e.changedTouches[0]) {
8881
+ var x = e.changedTouches[0].clientX;
8882
+ var y = e.changedTouches[0].clientY;
8883
+ } else {
8884
+ var x = e.clientX;
8885
+ var y = e.clientY;
8886
+ }
8887
+
8888
+ if (rect.width - (x - rect.left) < 50 && (y - rect.top) < 50) {
8889
+ item.parentNode.modal.close();
8890
+ }
8891
+ }
8892
+
8772
8893
  if (tracker) {
8773
8894
  tracker.element.style.cursor = 'auto';
8774
8895
  tracker = null;
@@ -8790,7 +8911,7 @@ jSuites.modal = (function(el, options) {
8790
8911
  }
8791
8912
 
8792
8913
  if (rect.width - (x - rect.left) < 50 && (y - rect.top) < 50) {
8793
- item.parentNode.modal.close();
8914
+ // Do nothing
8794
8915
  } else {
8795
8916
  if (e.target.getAttribute('title') && (y - rect.top) < 50) {
8796
8917
  if (document.selection) {
@@ -9315,7 +9436,7 @@ jSuites.picker = (function(el, options) {
9315
9436
  obj.setValue(item.k);
9316
9437
  // Call method
9317
9438
  if (typeof(obj.options.onchange) == 'function') {
9318
- obj.options.onchange.call(obj, el, obj, item.v, item.v, item.k);
9439
+ obj.options.onchange.call(obj, el, obj, item.v, item.v, item.k, e);
9319
9440
  }
9320
9441
  }
9321
9442
  }
@@ -9760,8 +9881,10 @@ jSuites.search = (function(el, options) {
9760
9881
  obj.options = {
9761
9882
  data: options.data || null,
9762
9883
  input: options.input || null,
9884
+ searchByNode: options.searchByNode || null,
9763
9885
  onselect: options.onselect || null,
9764
9886
  forceSelect: options.forceSelect,
9887
+ onbeforesearch: options.onbeforesearch || null,
9765
9888
  };
9766
9889
 
9767
9890
  obj.selectIndex = function(item) {
@@ -9835,15 +9958,33 @@ jSuites.search = (function(el, options) {
9835
9958
  }
9836
9959
 
9837
9960
  obj.keyup = function(e) {
9838
- if (obj.options.input) {
9839
- obj(obj.options.input.value);
9961
+ if (! obj.options.searchByNode) {
9962
+ if (obj.options.input.tagName === 'DIV') {
9963
+ var terms = obj.options.input.innerText;
9964
+ } else {
9965
+ var terms = obj.options.input.value;
9966
+ }
9840
9967
  } else {
9841
9968
  // Current node
9842
9969
  var node = jSuites.getNode();
9843
9970
  if (node) {
9844
- obj(node.innerText);
9971
+ var terms = node.innerText;
9845
9972
  }
9846
9973
  }
9974
+
9975
+ if (typeof(obj.options.onbeforesearch) == 'function') {
9976
+ var ret = obj.options.onbeforesearch(obj, terms);
9977
+ if (ret) {
9978
+ terms = ret;
9979
+ } else {
9980
+ if (ret === false) {
9981
+ // Ignore event
9982
+ return;
9983
+ }
9984
+ }
9985
+ }
9986
+
9987
+ obj(terms);
9847
9988
  }
9848
9989
 
9849
9990
  // Add events
@@ -10774,6 +10915,7 @@ jSuites.tags = (function(el, options) {
10774
10915
  search: null,
10775
10916
  placeholder: null,
10776
10917
  validation: null,
10918
+ onbeforepaste: null,
10777
10919
  onbeforechange: null,
10778
10920
  onlimit: null,
10779
10921
  onchange: null,
@@ -11290,6 +11432,19 @@ jSuites.tags = (function(el, options) {
11290
11432
  }
11291
11433
 
11292
11434
  var data = extractTags(text);
11435
+
11436
+ if (typeof(obj.options.onbeforepaste) == 'function') {
11437
+ var ret = obj.options.onbeforepaste(el, obj, data);
11438
+ if (ret === false) {
11439
+ e.preventDefault();
11440
+ return false;
11441
+ } else {
11442
+ if (ret) {
11443
+ data = ret;
11444
+ }
11445
+ }
11446
+ }
11447
+
11293
11448
  if (data.length > 1) {
11294
11449
  obj.add(data, true);
11295
11450
  e.preventDefault();
@@ -11687,136 +11842,202 @@ jSuites.toolbar = (function(el, options) {
11687
11842
  return obj;
11688
11843
  });
11689
11844
 
11690
- jSuites.validations = function(value, options) {
11691
- if (typeof(jSuites.validations[options.type]) === 'function') {
11692
- return jSuites.validations[options.type](value, options);
11693
- }
11694
- return null;
11695
- };
11845
+ jSuites.validations = (function() {
11846
+ /**
11847
+ * Options: Object,
11848
+ * Properties:
11849
+ * Constraint,
11850
+ * Reference,
11851
+ * Value
11852
+ */
11696
11853
 
11697
- // Legacy
11698
- jSuites.validations.email = function(data) {
11699
- var pattern = new RegExp(/^[^\s@]+@[^\s@]+\.[^\s@]+$/);
11700
- return data && pattern.test(data) ? true : false;
11701
- }
11854
+ var isNumeric = function(num) {
11855
+ return !isNaN(num) && num !== null && num !== '';
11856
+ }
11702
11857
 
11703
- jSuites.validations.required = function(data) {
11704
- return data.trim() ? true : false;
11705
- }
11858
+ var numberCriterias = {
11859
+ 'between': function(value, range) {
11860
+ return value >= range[0] && value <= range[1];
11861
+ },
11862
+ 'not between': function(value, range) {
11863
+ return value < range[0] || value > range[1];
11864
+ },
11865
+ '<': function(value, range) {
11866
+ return value < range[0];
11867
+ },
11868
+ '<=': function(value, range) {
11869
+ return value <= range[0];
11870
+ },
11871
+ '>': function(value, range) {
11872
+ return value > range[0];
11873
+ },
11874
+ '>=': function(value, range) {
11875
+ return value >= range[0];
11876
+ },
11877
+ '=': function(value, range) {
11878
+ return value === range[0];
11879
+ },
11880
+ '!=': function(value, range) {
11881
+ return value !== range[0];
11882
+ },
11883
+ }
11706
11884
 
11707
- jSuites.validations.number = function(data) {
11708
- return jSuites.isNumber(data);
11709
- }
11885
+ var dateCriterias = {
11886
+ 'valid date': function() {
11887
+ return true;
11888
+ },
11889
+ '=': function(value, range) {
11890
+ return value === range[0];
11891
+ },
11892
+ '<': function(value, range) {
11893
+ return value < range[0];
11894
+ },
11895
+ '<=': function(value, range) {
11896
+ return value <= range[0];
11897
+ },
11898
+ '>': function(value, range) {
11899
+ return value > range[0];
11900
+ },
11901
+ '>=': function(value, range) {
11902
+ return value >= range[0];
11903
+ },
11904
+ 'between': function(value, range) {
11905
+ return value >= range[0] && value <= range[1];
11906
+ },
11907
+ 'not between': function(value, range) {
11908
+ return value < range[0] || value > range[1];
11909
+ },
11910
+ }
11710
11911
 
11711
- jSuites.validations.login = function(data) {
11712
- var pattern = new RegExp(/^[a-zA-Z0-9\_\-\.\s+]+$/);
11713
- return data && pattern.test(data) ? true : false;
11714
- }
11912
+ var textCriterias = {
11913
+ 'contains': function(value, range) {
11914
+ return value.includes(range[0]);
11915
+ },
11916
+ 'not contains': function(value, range) {
11917
+ return !value.includes(range[0]);
11918
+ },
11919
+ '=': function(value, range) {
11920
+ return value === range[0];
11921
+ },
11922
+ 'valid email': function(value) {
11923
+ var pattern = new RegExp(/^[^\s@]+@[^\s@]+\.[^\s@]+$/);
11715
11924
 
11716
- /**
11717
- * Options: Object,
11718
- * Properties:
11719
- * Constraint,
11720
- * Reference,
11721
- * Value
11722
- */
11925
+ return pattern.test(value);
11926
+ },
11927
+ 'valid url': function(value) {
11928
+ var pattern = new RegExp(/(((https?:\/\/)|(www\.))[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]+)/ig);
11723
11929
 
11724
- var valueComparisons = function(data, options) {
11725
- if (options.constraint === '=') {
11726
- return data === options.reference;
11727
- }
11728
- if (options.constraint === '<') {
11729
- return data < options.reference;
11730
- }
11731
- if (options.constraint === '<=') {
11732
- return data <= options.reference;
11930
+ return pattern.test(value);
11931
+ },
11733
11932
  }
11734
- if (options.constraint === '>') {
11735
- return data > options.reference;
11933
+
11934
+ // Component router
11935
+ var component = function(value, options) {
11936
+ if (typeof(component[options.type]) === 'function') {
11937
+ if (options.allowBlank && value === '') {
11938
+ return true;
11939
+ }
11940
+
11941
+ return component[options.type](value, options);
11942
+ }
11943
+ return null;
11736
11944
  }
11737
- if (options.constraint === '>=') {
11738
- return data >= options.reference;
11945
+
11946
+ component.url = function() {
11947
+ var pattern = new RegExp(/(((https?:\/\/)|(www\.))[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]+)/ig);
11948
+ return pattern.test(data) ? true : false;
11739
11949
  }
11740
- if (options.constraint === 'between') {
11741
- return data >= options.reference[0] && data <= options.reference[1];
11950
+
11951
+ component.email = function(data) {
11952
+ var pattern = new RegExp(/^[^\s@]+@[^\s@]+\.[^\s@]+$/);
11953
+ return data && pattern.test(data) ? true : false;
11742
11954
  }
11743
- if (options.constraint === 'not between') {
11744
- return data < options.reference[0] || data > options.reference[1];
11955
+
11956
+ component.required = function(data) {
11957
+ return data.trim() ? true : false;
11745
11958
  }
11959
+
11960
+ component.number = function(data, options) {
11961
+ if (! isNumeric(data)) {
11962
+ return false;
11963
+ }
11746
11964
 
11747
- return null;
11748
- }
11965
+ if (!options || !options.criteria) {
11966
+ return true;
11967
+ }
11749
11968
 
11750
- jSuites.validations.number = function(data, options) {
11751
- if (!jSuites.isNumeric(data)) {
11752
- return false;
11753
- }
11969
+ if (!numberCriterias[options.criteria]) {
11970
+ return false;
11971
+ }
11972
+
11973
+ return numberCriterias[options.criteria](
11974
+ data,
11975
+ options.value.map(function(num) {
11976
+ return parseFloat(num);
11977
+ }),
11978
+ );
11979
+ };
11754
11980
 
11755
- if (options === undefined || options.constraint === undefined) {
11756
- return true;
11981
+ component.login = function(data) {
11982
+ var pattern = new RegExp(/^[a-zA-Z0-9\_\-\.\s+]+$/);
11983
+ return data && pattern.test(data) ? true : false;
11757
11984
  }
11758
11985
 
11759
- return valueComparisons(data, options);
11760
- }
11986
+ component.list = function(data, options) {
11987
+ var dataType = typeof data;
11988
+ if (dataType !== 'string' && dataType !== 'number') {
11989
+ return false;
11990
+ }
11761
11991
 
11762
- jSuites.validations.date = function(data, options) {
11763
- if (new Date(data) == 'Invalid Date') {
11764
- return false;
11992
+ var validOption = options.value[0].split(',').findIndex(function name(item) {
11993
+ return item == data;
11994
+ });
11995
+
11996
+ return validOption > -1;
11765
11997
  }
11766
11998
 
11767
- if (options === undefined || options.constraint === undefined) {
11768
- return true;
11769
- } else if (typeof(options) === 'object') {
11770
- data = new Date(data).getTime();
11999
+ component.date = function(data, options) {
12000
+ if (new Date(data) == 'Invalid Date') {
12001
+ return false;
12002
+ }
11771
12003
 
11772
- if (Array.isArray(options.reference)) {
11773
- options.reference = options.reference.map(function(reference) {
11774
- return new Date(reference).getTime();
11775
- });
11776
- } else {
11777
- options.reference = new Date(options.reference).getTime();
12004
+ if (!options || !options.criteria) {
12005
+ return true;
11778
12006
  }
11779
12007
 
11780
- return valueComparisons(data, options);
12008
+ if (!dateCriterias[options.criteria]) {
12009
+ return false;
12010
+ }
12011
+
12012
+ return dateCriterias[options.criteria](
12013
+ new Date(data).getTime(),
12014
+ options.value.map(function(date) {
12015
+ return new Date(date).getTime();
12016
+ }),
12017
+ );
11781
12018
  }
11782
- return null;
11783
- }
11784
12019
 
11785
- jSuites.validations.itemList = function(data, options) {
11786
- return options.reference.some(function(reference) {
11787
- return reference == data;
11788
- });
11789
- }
12020
+ component.text = function(data, options) {
12021
+ if (typeof data !== 'string') {
12022
+ return false;
12023
+ }
11790
12024
 
11791
- jSuites.validations.text = function(data, options) {
11792
- if (typeof data !== 'string') {
11793
- return false;
11794
- }
12025
+ if (!options || !options.criteria) {
12026
+ return true;
12027
+ }
11795
12028
 
11796
- if (options === undefined || options.constraint === undefined) {
11797
- return true;
11798
- }
11799
- if (options.constraint === '=') {
11800
- return data === options.reference;
11801
- }
11802
- if (options.constraint === 'contains') {
11803
- return data.includes(options.reference);
11804
- }
11805
- if (options.constraint === 'not contain') {
11806
- return !data.includes(options.reference);
11807
- }
11808
- if (options.constraint === 'email') {
11809
- return jSuites.validations.email(data);
11810
- }
11811
- if (options.constraint === 'url') {
11812
- var pattern = new RegExp(/(((https?:\/\/)|(www\.))[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]+)/ig);
11813
- return pattern.test(data) ? true : false;
12029
+ if (!textCriterias[options.criteria]) {
12030
+ return false;
12031
+ }
12032
+
12033
+ return textCriterias[options.criteria](
12034
+ data,
12035
+ options.value,
12036
+ );
11814
12037
  }
11815
- return null;
11816
- }
11817
12038
 
11818
- jSuites.validations.constraints = function() {
11819
- }
12039
+ return component;
12040
+ })();
11820
12041
 
11821
12042
 
11822
12043
 
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "javascript plugins"
20
20
  ],
21
21
  "main": "dist/jsuites.js",
22
- "version": "4.10.3",
22
+ "version": "4.11.0",
23
23
  "bugs": "https://github.com/jsuites/jsuites/issues",
24
24
  "homepage": "https://github.com/jsuites/jsuites",
25
25
  "docs": "https://jsuites.net",