ui_bibz 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +49 -49
  3. data/app/assets/javascripts/input-connected.coffee +2 -1
  4. data/app/assets/javascripts/ui_bibz.coffee +9 -2
  5. data/app/assets/stylesheets/fix-bootstrap-4.sass +4 -0
  6. data/app/assets/stylesheets/fix_addon.sass +6 -6
  7. data/app/assets/stylesheets/notifications.sass +7 -0
  8. data/app/assets/stylesheets/ui_bibz.sass +4 -1
  9. data/lib/ui_bibz.rb +1 -0
  10. data/lib/ui_bibz/helpers/ui/core/icons_helper.rb +9 -0
  11. data/lib/ui_bibz/infos.rb +2 -2
  12. data/lib/ui_bibz/rails/engine.rb +5 -1
  13. data/lib/ui_bibz/ui/core/forms/dropdowns/components/dropdown_header.rb +1 -1
  14. data/lib/ui_bibz/ui/core/forms/textareas/markdown_editor_field.rb +1 -1
  15. data/lib/ui_bibz/ui/core/icons/glyph.rb +1 -1
  16. data/lib/ui_bibz/ui/core/notifications/components/bar.rb +11 -2
  17. data/lib/ui_bibz/ui/extensions/core/component/glyph_extension.rb +4 -12
  18. data/lib/ui_bibz/utils/glyph_changer.rb +54 -0
  19. data/vendor/assets/fonts/fa-brands-400.eot +0 -0
  20. data/vendor/assets/fonts/fa-brands-400.svg +1154 -0
  21. data/vendor/assets/fonts/fa-brands-400.ttf +0 -0
  22. data/vendor/assets/fonts/fa-brands-400.woff +0 -0
  23. data/vendor/assets/fonts/fa-brands-400.woff2 +0 -0
  24. data/vendor/assets/fonts/fa-regular-400.eot +0 -0
  25. data/vendor/assets/fonts/fa-regular-400.svg +467 -0
  26. data/vendor/assets/fonts/fa-regular-400.ttf +0 -0
  27. data/vendor/assets/fonts/fa-regular-400.woff +0 -0
  28. data/vendor/assets/fonts/fa-regular-400.woff2 +0 -0
  29. data/vendor/assets/fonts/fa-solid-900.eot +0 -0
  30. data/vendor/assets/fonts/fa-solid-900.svg +2444 -0
  31. data/vendor/assets/fonts/fa-solid-900.ttf +0 -0
  32. data/vendor/assets/fonts/fa-solid-900.woff +0 -0
  33. data/vendor/assets/fonts/fa-solid-900.woff2 +0 -0
  34. data/vendor/assets/javascripts/all.js +3685 -0
  35. data/vendor/assets/javascripts/bootstrap-markdown.js +159 -56
  36. data/vendor/assets/stylesheets/all.min.css +5 -0
  37. data/vendor/assets/stylesheets/svg-with-js.css +5 -0
  38. metadata +21 -4
  39. data/vendor/assets/javascripts/fontawesome-all.min.js +0 -5
  40. data/vendor/assets/stylesheets/fa-svg-with-js.css +0 -345
@@ -18,13 +18,13 @@
18
18
  * ========================================================== */
19
19
  (function(factory) {
20
20
  if (typeof define === "function" && define.amd) {
21
- //RequireJS
21
+ // RequireJS
22
22
  define(["jquery"], factory);
23
23
  } else if (typeof exports === 'object') {
24
- //Backbone.js
24
+ // Backbone.js
25
25
  factory(require('jquery'));
26
26
  } else {
27
- //Jquery plugin
27
+ // jQuery plugin
28
28
  factory(jQuery);
29
29
  }
30
30
  }(function($) {
@@ -113,7 +113,7 @@
113
113
  var button = buttons[z],
114
114
  buttonContainer, buttonIconContainer,
115
115
  buttonHandler = ns + '-' + button.name,
116
- buttonIcon = this.__getIcon(button.icon),
116
+ buttonIcon = this.__getIcon(button),
117
117
  btnText = button.btnText ? button.btnText : '',
118
118
  btnClass = button.btnClass ? button.btnClass : 'btn',
119
119
  tabIndex = button.tabIndex ? button.tabIndex : '-1',
@@ -149,7 +149,7 @@
149
149
  callback.push(button.callback);
150
150
  }
151
151
 
152
- // Attach the button group into container dom
152
+ // Attach the button group into container DOM
153
153
  container.append(btnGroupContainer);
154
154
  }
155
155
  }
@@ -167,6 +167,10 @@
167
167
  this.$textarea.css('resize', this.$options.resize);
168
168
  }
169
169
 
170
+ // Re-attach markdown data
171
+ this.$textarea.data('markdown', this);
172
+ },
173
+ __setEventListeners: function() {
170
174
  this.$textarea.on({
171
175
  'focus': $.proxy(this.focus, this),
172
176
  'keyup': $.proxy(this.keyup, this),
@@ -181,9 +185,6 @@
181
185
  if (this.eventSupported('keypress')) {
182
186
  this.$textarea.on('keypress', $.proxy(this.keypress, this));
183
187
  }
184
-
185
- // Re-attach markdown data
186
- this.$textarea.data('markdown', this);
187
188
  },
188
189
  __handle: function(e) {
189
190
  var target = $(e.currentTarget),
@@ -222,7 +223,14 @@
222
223
  return string;
223
224
  },
224
225
  __getIcon: function(src) {
225
- return typeof src == 'object' ? src[this.$options.iconlibrary] : src;
226
+ if(typeof src == 'object'){
227
+ var customIcon = this.$options.customIcons[src.name];
228
+ console.log(customIcon)
229
+ console.log(this.$options)
230
+ return typeof customIcon == 'undefined' ? src.icon[this.$options.iconlibrary] : customIcon;
231
+ } else {
232
+ return src;
233
+ }
226
234
  },
227
235
  setFullscreen: function(mode) {
228
236
  var $editor = this.$editor,
@@ -276,12 +284,12 @@
276
284
  // iterate the additional button groups
277
285
  $.each(options.additionalButtons[0], function(idx, buttonGroup) {
278
286
 
279
- // see if the group name of the addional group matches an existing group
287
+ // see if the group name of the additional group matches an existing group
280
288
  var matchingGroups = $.grep(allBtnGroups, function(allButtonGroup, allIdx) {
281
289
  return allButtonGroup.name === buttonGroup.name;
282
290
  });
283
291
 
284
- // if it matches add the addional buttons to that group, if not just add it to the all buttons group
292
+ // if it matches add the additional buttons to that group, if not just add it to the all buttons group
285
293
  if (matchingGroups.length > 0) {
286
294
  matchingGroups[0].data = matchingGroups[0].data.concat(buttonGroup.data);
287
295
  } else {
@@ -346,7 +354,7 @@
346
354
  editable.attrValues.push(this.nodeValue);
347
355
  });
348
356
 
349
- // Set editor to blocked the original container
357
+ // Set editor to block the original container
350
358
  container.replaceWith(editor);
351
359
  }
352
360
 
@@ -413,6 +421,7 @@
413
421
  this.$oldContent = this.getContent();
414
422
 
415
423
  this.__setListener();
424
+ this.__setEventListeners();
416
425
 
417
426
  // Set editor attributes, data short-hand API and listener
418
427
  this.$editor.attr('id', (new Date()).getTime());
@@ -471,26 +480,51 @@
471
480
  // enable dropZone if available and configured
472
481
  if (options.dropZoneOptions) {
473
482
  if (this.$editor.dropzone) {
474
- options.dropZoneOptions.init = function() {
475
- var caretPos = 0;
476
- this.on('drop', function(e) {
477
- caretPos = textarea.prop('selectionStart');
478
- });
479
- this.on('success', function(file, path) {
480
- var text = textarea.val();
481
- textarea.val(text.substring(0, caretPos) + '\n![description](' + path + ')\n' + text.substring(caretPos));
482
- });
483
- this.on('error', function(file, error, xhr) {
484
- console.log('Error:', error);
485
- });
486
- };
487
- this.$textarea.addClass('dropzone');
483
+ if(!options.dropZoneOptions.init) {
484
+ options.dropZoneOptions.init = function() {
485
+ var caretPos = 0;
486
+ this.on('drop', function(e) {
487
+ caretPos = textarea.prop('selectionStart');
488
+ });
489
+ this.on('success', function(file, path) {
490
+ var text = textarea.val();
491
+ textarea.val(text.substring(0, caretPos) + '\n![description](' + path + ')\n' + text.substring(caretPos));
492
+ });
493
+ this.on('error', function(file, error, xhr) {
494
+ console.log('Error:', error);
495
+ });
496
+ };
497
+ }
498
+ this.$editor.addClass('dropzone');
488
499
  this.$editor.dropzone(options.dropZoneOptions);
489
500
  } else {
490
501
  console.log('dropZoneOptions was configured, but DropZone was not detected.');
491
502
  }
492
503
  }
493
504
 
505
+ // enable data-uris via drag and drop
506
+ if (options.enableDropDataUri === true) {
507
+ this.$editor.on('drop', function(e) {
508
+ var caretPos = textarea.prop('selectionStart');
509
+ e.stopPropagation();
510
+ e.preventDefault();
511
+ $.each(e.originalEvent.dataTransfer.files, function(index, file){
512
+ var fileReader = new FileReader();
513
+ fileReader.onload = (function(file) {
514
+ var type = file.type.split('/')[0];
515
+ return function(e) {
516
+ var text = textarea.val();
517
+ if (type === 'image')
518
+ textarea.val(text.substring(0, caretPos) + '\n<img src="'+ e.target.result +'" />\n' + text.substring(caretPos) );
519
+ else
520
+ textarea.val(text.substring(0, caretPos) + '\n<a href="'+ e.target.result +'">Download ' + file.name + '</a>\n' + text.substring(caretPos) );
521
+ };
522
+ })(file);
523
+ fileReader.readAsDataURL(file);
524
+ });
525
+ });
526
+ }
527
+
494
528
  // Trigger the onShow hook
495
529
  options.onShow(this);
496
530
 
@@ -526,19 +560,19 @@
526
560
  callbackContent;
527
561
 
528
562
  if (this.$isPreview === true) {
529
- // Avoid sequenced element creation on missused scenario
563
+ // Avoid sequenced element creation on misused scenario
530
564
  // @see https://github.com/toopay/bootstrap-markdown/issues/170
531
565
  return this;
532
566
  }
533
567
 
534
- // Give flag that tell the editor enter preview mode
568
+ // Give flag that tells the editor to enter preview mode
535
569
  this.$isPreview = true;
536
570
  // Disable all buttons
537
571
  this.disableButtons('all').enableButtons('cmdPreview');
538
572
 
539
573
  // Try to get the content from callback
540
- callbackContent = options.onPreview(this);
541
- // Set the content based from the callback content if string otherwise parse value from textarea
574
+ callbackContent = options.onPreview(this, replacementContainer);
575
+ // Set the content based on the callback content if string, otherwise parse value from textarea
542
576
  content = typeof callbackContent == 'string' ? callbackContent : this.parseContent();
543
577
 
544
578
  // Build preview element
@@ -554,8 +588,9 @@
554
588
 
555
589
  // Set the preview element dimensions
556
590
  replacementContainer.css({
557
- width: container.outerWidth() + 'px',
558
- height: container.outerHeight() + 'px'
591
+ "width": container.outerWidth() + 'px',
592
+ "min-height": container.outerHeight() + 'px',
593
+ "height": "auto"
559
594
  });
560
595
 
561
596
  if (this.$options.resize) {
@@ -576,7 +611,7 @@
576
611
  return this;
577
612
  },
578
613
  hidePreview: function() {
579
- // Give flag that tell the editor quit preview mode
614
+ // Give flag that tells the editor to quit preview mode
580
615
  this.$isPreview = false;
581
616
 
582
617
  // Obtain the preview container
@@ -590,6 +625,9 @@
590
625
  // Disable configured disabled buttons
591
626
  this.disableButtons(this.$options.disabledButtons);
592
627
 
628
+ // Perform any callbacks
629
+ this.$options.onPreviewEnd(this);
630
+
593
631
  // Back to the editor
594
632
  this.$textarea.show();
595
633
  this.__setListener();
@@ -807,12 +845,12 @@
807
845
 
808
846
  blocked = true;
809
847
  } else {
810
- // The next tab memory contains nothing...
848
+ // The next tab's memory contains nothing...
811
849
  // check the cursor position to determine tab action
812
850
  var cursor = this.getSelection();
813
851
 
814
852
  if (cursor.start == cursor.end && cursor.end == this.getContent().length) {
815
- // The cursor already reach the end of the content
853
+ // The cursor has reached the end of the content
816
854
  blocked = false;
817
855
  } else {
818
856
  // Put the cursor to the end
@@ -826,7 +864,29 @@
826
864
 
827
865
  case 13: // enter
828
866
  blocked = false;
867
+ var chars = this.getContent().split('');
868
+ var enterIndex = this.getSelection().start;
869
+ var priorNewlineIndex = -1; // initial line break at before index 0
870
+
871
+ // traverse backwards through chars to check if last line break was num/bullet item
872
+ for (var i = enterIndex - 2; i >= 0; i--) {
873
+ if (chars[i] === '\n') {
874
+ priorNewlineIndex = i;
875
+ break;
876
+ }
877
+ }
878
+
879
+ var charFollowingLastLineBreak = chars[priorNewlineIndex + 1];
880
+ if (charFollowingLastLineBreak === '-') {
881
+ this.addBullet(enterIndex);
882
+ } else if ($.isNumeric(charFollowingLastLineBreak)) {
883
+ var numBullet = this.getBulletNumber(priorNewlineIndex + 1);
884
+ if (numBullet) {
885
+ this.addNumberedBullet(enterIndex, numBullet);
886
+ }
887
+ }
829
888
  break;
889
+
830
890
  case 27: // escape
831
891
  if (this.$isFullscreen) this.setFullscreen(false);
832
892
  blocked = false;
@@ -843,6 +903,26 @@
843
903
 
844
904
  this.$options.onChange(this);
845
905
  },
906
+ insertContent: function(index, content) {
907
+ var firstHalf = this.getContent().slice(0, index);
908
+ var secondHalf = this.getContent().slice(index + 1);
909
+ this.setContent(firstHalf.concat(content).concat(secondHalf));
910
+ },
911
+ addBullet: function(index) {
912
+ this.insertContent(index, '- \n');
913
+ this.setSelection(index + 2, index + 2); // Put the cursor after the bullet
914
+ },
915
+ addNumberedBullet: function(index, num) {
916
+ var numBullet = (num + 1) + '. \n';
917
+ this.insertContent(index, numBullet);
918
+
919
+ var prefixLength = num.toString().length + 2;
920
+ this.setSelection(index + prefixLength, index + prefixLength); // Put the cursor after the number
921
+ },
922
+ getBulletNumber: function(startIndex) {
923
+ var bulletNum = this.getContent().slice(startIndex).split('.')[0];
924
+ return $.isNumeric(bulletNum) ? parseInt(bulletNum) : null;
925
+ },
846
926
  change: function(e) {
847
927
  this.$options.onChange(this);
848
928
  return this;
@@ -948,6 +1028,7 @@
948
1028
  initialstate: 'editor',
949
1029
  parser: null,
950
1030
  dropZoneOptions: null,
1031
+ enableDropDataUri: false,
951
1032
 
952
1033
  /* Buttons Properties */
953
1034
  buttons: [
@@ -959,8 +1040,9 @@
959
1040
  title: 'Bold',
960
1041
  icon: {
961
1042
  glyph: 'glyphicon glyphicon-bold',
962
- fa: 'fas fa-bold',
1043
+ fa: 'fa fa-bold',
963
1044
  'fa-3': 'icon-bold',
1045
+ 'fa-5': 'fas fa-bold',
964
1046
  octicons: 'octicon octicon-bold'
965
1047
  },
966
1048
  callback: function(e) {
@@ -995,8 +1077,9 @@
995
1077
  hotkey: 'Ctrl+I',
996
1078
  icon: {
997
1079
  glyph: 'glyphicon glyphicon-italic',
998
- fa: 'fas fa-italic',
1080
+ fa: 'fa fa-italic',
999
1081
  'fa-3': 'icon-italic',
1082
+ 'fa-5': 'fas fa-italic',
1000
1083
  octicons: 'octicon octicon-italic'
1001
1084
  },
1002
1085
  callback: function(e) {
@@ -1031,8 +1114,9 @@
1031
1114
  hotkey: 'Ctrl+H',
1032
1115
  icon: {
1033
1116
  glyph: 'glyphicon glyphicon-header',
1034
- fa: 'fas fa-header',
1117
+ fa: 'fa fa-header',
1035
1118
  'fa-3': 'icon-font',
1119
+ 'fa-5': 'fas fa-heading',
1036
1120
  octicons: 'octicon octicon-text-size'
1037
1121
  },
1038
1122
  callback: function(e) {
@@ -1075,8 +1159,9 @@
1075
1159
  hotkey: 'Ctrl+L',
1076
1160
  icon: {
1077
1161
  glyph: 'glyphicon glyphicon-link',
1078
- fa: 'fas fa-link',
1162
+ fa: 'fa fa-link',
1079
1163
  'fa-3': 'icon-link',
1164
+ 'fa-5': 'fas fa-link',
1080
1165
  octicons: 'octicon octicon-link'
1081
1166
  },
1082
1167
  callback: function(e) {
@@ -1112,8 +1197,9 @@
1112
1197
  hotkey: 'Ctrl+G',
1113
1198
  icon: {
1114
1199
  glyph: 'glyphicon glyphicon-picture',
1115
- fa: 'fas fa-picture-o',
1200
+ fa: 'fa fa-picture-o',
1116
1201
  'fa-3': 'icon-picture',
1202
+ 'fa-5': 'far fa-image',
1117
1203
  octicons: 'octicon octicon-file-media'
1118
1204
  },
1119
1205
  callback: function(e) {
@@ -1155,8 +1241,9 @@
1155
1241
  title: 'Unordered List',
1156
1242
  icon: {
1157
1243
  glyph: 'glyphicon glyphicon-list',
1158
- fa: 'fas fa-list',
1244
+ fa: 'fa fa-list',
1159
1245
  'fa-3': 'icon-list-ul',
1246
+ 'fa-5': 'fas fa-list-ul',
1160
1247
  octicons: 'octicon octicon-list-unordered'
1161
1248
  },
1162
1249
  callback: function(e) {
@@ -1206,8 +1293,9 @@
1206
1293
  title: 'Ordered List',
1207
1294
  icon: {
1208
1295
  glyph: 'glyphicon glyphicon-th-list',
1209
- fa: 'fas fa-list-ol',
1296
+ fa: 'fa fa-list-ol',
1210
1297
  'fa-3': 'icon-list-ol',
1298
+ 'fa-5': 'fas fa-list-ol',
1211
1299
  octicons: 'octicon octicon-list-ordered'
1212
1300
  },
1213
1301
  callback: function(e) {
@@ -1232,13 +1320,15 @@
1232
1320
  // Set the cursor
1233
1321
  cursor = selected.start + 3;
1234
1322
  } else {
1323
+ var i = 1;
1235
1324
  var list = [];
1236
1325
 
1237
1326
  list = selected.text.split('\n');
1238
1327
  chunk = list[0];
1239
1328
 
1240
1329
  $.each(list, function(k, v) {
1241
- list[k] = '1. ' + v;
1330
+ list[k] = i + '. ' + v;
1331
+ i++;
1242
1332
  });
1243
1333
 
1244
1334
  e.replaceSelection('\n\n' + list.join('\n'));
@@ -1256,9 +1346,10 @@
1256
1346
  hotkey: 'Ctrl+K',
1257
1347
  title: 'Code',
1258
1348
  icon: {
1259
- glyph: 'glyphicon glyphicon-asterisk',
1260
- fa: 'fas fa-code',
1349
+ glyph: 'glyphicon glyphicon-console',
1350
+ fa: 'fa fa-code',
1261
1351
  'fa-3': 'icon-code',
1352
+ 'fa-5': 'fas fa-code',
1262
1353
  octicons: 'octicon octicon-code'
1263
1354
  },
1264
1355
  callback: function(e) {
@@ -1301,8 +1392,9 @@
1301
1392
  title: 'Quote',
1302
1393
  icon: {
1303
1394
  glyph: 'glyphicon glyphicon-comment',
1304
- fa: 'fas fa-quote-left',
1395
+ fa: 'fa fa-quote-left',
1305
1396
  'fa-3': 'icon-quote-left',
1397
+ 'fa-5': 'fas fa-quote-left',
1306
1398
  octicons: 'octicon octicon-quote'
1307
1399
  },
1308
1400
  callback: function(e) {
@@ -1359,8 +1451,9 @@
1359
1451
  btnClass: 'btn btn-primary btn-sm',
1360
1452
  icon: {
1361
1453
  glyph: 'glyphicon glyphicon-search',
1362
- fa: 'fas fa-search',
1454
+ fa: 'fa fa-search',
1363
1455
  'fa-3': 'icon-search',
1456
+ 'fa-5': 'fas fa-search',
1364
1457
  octicons: 'octicon octicon-search'
1365
1458
  },
1366
1459
  callback: function(e) {
@@ -1369,7 +1462,7 @@
1369
1462
  content;
1370
1463
 
1371
1464
  if (isPreview === false) {
1372
- // Give flag that tell the editor enter preview mode
1465
+ // Give flag that tells the editor to enter preview mode
1373
1466
  e.showPreview();
1374
1467
  } else {
1375
1468
  e.hidePreview();
@@ -1378,6 +1471,7 @@
1378
1471
  }]
1379
1472
  }]
1380
1473
  ],
1474
+ customIcons: {},
1381
1475
  additionalButtons: [], // Place to hook more buttons by code
1382
1476
  reorderButtonGroups: [],
1383
1477
  hiddenButtons: [], // Default hidden buttons
@@ -1387,16 +1481,24 @@
1387
1481
  enable: true,
1388
1482
  icons: {
1389
1483
  fullscreenOn: {
1390
- fa: 'fas fa-expand',
1391
- glyph: 'glyphicon glyphicon-fullscreen',
1392
- 'fa-3': 'icon-resize-full',
1393
- octicons: 'octicon octicon-link-external'
1484
+ name: "fullscreenOn",
1485
+ icon: {
1486
+ fa: 'fa fa-expand',
1487
+ glyph: 'glyphicon glyphicon-fullscreen',
1488
+ 'fa-3': 'icon-resize-full',
1489
+ 'fa-5': 'fas fa-expand-arrows-alt',
1490
+ octicons: 'octicon octicon-link-external'
1491
+ }
1394
1492
  },
1395
1493
  fullscreenOff: {
1396
- fa: 'fas fa-compress',
1397
- glyph: 'glyphicon glyphicon-fullscreen',
1398
- 'fa-3': 'icon-resize-small',
1399
- octicons: 'octicon octicon-browser'
1494
+ name: "fullscreenOff",
1495
+ icon: {
1496
+ fa: 'fa fa-compress',
1497
+ glyph: 'glyphicon glyphicon-fullscreen',
1498
+ 'fa-3': 'icon-resize-small',
1499
+ 'fa-5': 'fas fa-compress',
1500
+ octicons: 'octicon octicon-browser'
1501
+ }
1400
1502
  }
1401
1503
  }
1402
1504
  },
@@ -1404,6 +1506,7 @@
1404
1506
  /* Events hook */
1405
1507
  onShow: function(e) {},
1406
1508
  onPreview: function(e) {},
1509
+ onPreviewEnd: function(e) {},
1407
1510
  onSave: function(e) {},
1408
1511
  onBlur: function(e) {},
1409
1512
  onFocus: function(e) {},