jsuites 4.10.4 → 4.11.1

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