@osimatic/helpers-js 1.1.57 → 1.1.59

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.
package/flash_message.js CHANGED
@@ -1,15 +1,15 @@
1
1
  class FlashMessage {
2
- static displaySuccess(message, reload, modal=null) {
3
- this.display('success', message, reload, modal);
2
+ static displaySuccess(message, reload=false, modal=null, onMessageHidden=null) {
3
+ this.display('success', message, reload, modal, onMessageHidden);
4
4
  }
5
- static displayWarning(message, modal=null) {
6
- this.display('warning', message, false, modal);
5
+ static displayWarning(message, modal=null, onMessageHidden=null) {
6
+ this.display('warning', message, false, modal, onMessageHidden);
7
7
  }
8
- static displayError(message, modal=null) {
9
- this.display('danger', message, false, modal);
8
+ static displayError(message, modal=null, onMessageHidden=null) {
9
+ this.display('danger', message, false, modal, onMessageHidden);
10
10
  }
11
11
 
12
- static display(type, message, reload, modal=null) {
12
+ static display(type, message, reload=false, modal=null, onMessageHidden=null) {
13
13
  if (null !== modal) {
14
14
  modal.modal('hide');
15
15
  }
@@ -22,6 +22,9 @@ class FlashMessage {
22
22
 
23
23
  setTimeout(function () {
24
24
  $('div.snackbar').remove();
25
+ if (typeof onMessageHidden == 'function') {
26
+ onMessageHidden();
27
+ }
25
28
  }, 6000);
26
29
 
27
30
  if (true === reload) {
package/location.js CHANGED
@@ -7,11 +7,11 @@ class Country {
7
7
  return '<span><img src="'+Country.getFlagPath(countryCode)+'" alt="" title="'+Country.getCountryName(countryCode)+'" class="flag" /></span>'
8
8
  }
9
9
 
10
- static fillCountrySelect(select, defaultValue) {
10
+ static fillCountrySelect(select, defaultValue=null) {
11
11
  if (select.children().length === 0) {
12
12
  Object.entries(Country.getCountries()).forEach(([countryCode, countryName]) => select.append('<option value="' + countryCode + '">' + countryName + '</option>'));
13
13
  }
14
- if (typeof defaultValue != 'undefined') {
14
+ if (null != defaultValue) {
15
15
  select.val(defaultValue);
16
16
  }
17
17
  if (typeof select.selectpicker != 'undefined') {
@@ -309,11 +309,7 @@ class PostalAddress {
309
309
  });
310
310
  }
311
311
 
312
- static format(addressData, separator) {
313
- if (typeof separator == 'undefined') {
314
- separator = '<br/>';
315
- }
316
-
312
+ static format(addressData, separator='<br/>') {
317
313
  function empty(value) {
318
314
  return typeof value == 'undefined' || value == null || value === '';
319
315
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.1.57",
3
+ "version": "1.1.59",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -0,0 +1,36 @@
1
+ class SortableList {
2
+ static init(sortableList, clientYOffset=0) {
3
+ const items = sortableList.find('[draggable="true"]');
4
+ items.get().forEach(item => {
5
+ $(item).on('dragstart', () => {
6
+ // Adding dragging class to an item after a delay
7
+ setTimeout(() => $(item).addClass('dragging'), 0);
8
+
9
+ });
10
+
11
+ // Removing dragging class from the item on the dragend event
12
+ $(item).on('dragend', () => $(item).removeClass('dragging'));
13
+ });
14
+
15
+ const initSortableList = (e) => {
16
+ e.preventDefault();
17
+
18
+ const draggingItem = sortableList.find('.dragging');
19
+
20
+ // Getting all items except currently dragging and making an array of them
21
+ const siblings = [...sortableList.find('[draggable="true"]:not(.dragging)').get()];
22
+
23
+ // Finding the sibling after which the dragging item should be placed
24
+ let nextSibling = siblings.find(sibling => {
25
+ //console.log(e.clientY, sibling.offsetTop + sibling.offsetHeight / 2, sibling.offsetTop, sibling.offsetHeight, sibling);
26
+ return e.clientY+clientYOffset <= sibling.offsetTop + sibling.offsetHeight / 2;
27
+ });
28
+
29
+ // Inserting the dragging item before the found sibling
30
+ sortableList.get()[0].insertBefore(draggingItem.get()[0], nextSibling);
31
+ };
32
+
33
+ sortableList.on('dragover', initSortableList);
34
+ sortableList.on('dragenter', e => e.preventDefault());
35
+ }
36
+ }