fragment_highlighter-rails 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6408468fafdf63427c816205dd38a1215f48f4e
4
- data.tar.gz: b461fe69e5f315729de0fcedde65a5a36fd38eb3
3
+ metadata.gz: 9d9a7be38d90a133feec79f9637fbd148af04fae
4
+ data.tar.gz: 0fe0f8c6c1230fb857263c777929c65284833b7c
5
5
  SHA512:
6
- metadata.gz: b75f5574ec1c03e52cb652eee80b8d1e6d5274139d9f18d1dbb5d573945d421e6be293365729c71dcf1b4b19dfef92c12bfaea5a8fea7c861de231dca35ff9a1
7
- data.tar.gz: 74e581c62c117065ad72acdfc4a4d7c34fd2119fa81d0a561b6ea53f202fefd07fb34d9ebd7377379364f8f910ca322b43e71c1f3ac63c7a8a47d247a49c74ca
6
+ metadata.gz: 05569411be52b5fdcd383d7e96410e77fa6fda458bbf61fff77c3c1a70bca23fadec1ca846b1a1f767ee30cb75839f84ae914e699c1581fb63198bf2d3cecf20
7
+ data.tar.gz: 6cf45a9727541c1178ad965749bdc27beab221e71bb639363f9f6e74858aa7916287bac5798f276cc27eb9475fda31ee555bf28a6fcbe817abdaa2a2244aeaff
data/README.md CHANGED
@@ -32,10 +32,13 @@ Or install it yourself as:
32
32
  //= require fragment-highlighter/fragment-highlighter.js
33
33
 
34
34
  $(function() {
35
- let allowedPages = ['/articles/'];
36
- new FragmentHighlighter(allowedPages);
35
+ let options = { allowedPages: ['/articles/'], deniedPages: ['/admin/'] };
36
+ new FragmentHighlighter(options);
37
37
  });
38
+ ## Video Presentation
39
+ [![Watch the video](https://img.youtube.com/vi/sHj-CwYDRhU/0.jpg
40
+ )](https://www.youtube.com/watch?v=sHj-CwYDRhU)
38
41
 
39
42
  ## Contributing
40
43
 
41
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fragment_highlighter-rails.
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/phlowerteam/fragment_highlighter-rails.
@@ -1,5 +1,5 @@
1
1
  module FragmentHighlighter
2
2
  module Rails
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -5,31 +5,38 @@
5
5
  //= require fragment-highlighter/libs/classes/Marker.js
6
6
  //= require fragment-highlighter/libs/classes/Tools.js
7
7
  //= require fragment-highlighter/libs/classes/UserSettings.js
8
+ //= require fragment-highlighter/libs/classes/I18.js
8
9
 
9
10
  class FragmentHighlighter {
10
11
 
11
- constructor(pages) {
12
- FragmentHighlighter.init(pages);
12
+ constructor(options) {
13
+ FragmentHighlighter.init(options);
13
14
  }
14
15
 
15
- static init(allowedPages) {
16
+ static init(options) {
16
17
  $(function(){
17
- if (HView.isSupportedPage(allowedPages)) {
18
+ if (FragmentHighlighter.isEnabled(options)) {
18
19
  HView.renderModeButton();
19
- }
20
20
 
21
- HView.initHighlightWindow();
22
- UserSettings.init();
21
+ HView.initHighlightWindow();
22
+ UserSettings.init();
23
23
 
24
- if (HView.isHModeOn(allowedPages)) {
25
- $(document.body).on('click', '.remove-text', function(e){
26
- Marker.removeMarked(e.target);
27
- });
24
+ if (UserSettings.isHMode()) {
25
+ $(document.body).on('click', '.remove-text', function(e){
26
+ Marker.removeMarked(e.target);
27
+ });
28
28
 
29
- $(document.body).bind('mouseup', function(e){
30
- Marker.extractFragment();
31
- });
29
+ $(document.body).bind('mouseup', function(e){
30
+ Marker.extractFragment();
31
+ });
32
+ }
32
33
  }
33
34
  });
34
35
  }
36
+
37
+ static isEnabled(options) {
38
+ let allowedMatcher = new RegExp("(" + options.allowedPages.join('|') + ")", "g");
39
+ let deniedMatcher = new RegExp("(" + options.deniedPages.join('|') + ")", "g");
40
+ return (allowedMatcher.test(window.location.href) && !deniedMatcher.test(window.location.href));
41
+ }
35
42
  }
@@ -1,14 +1,5 @@
1
1
  class HView {
2
2
 
3
- static isHModeOn(allowedPages) {
4
- return (UserSettings.isHMode() && HView.isSupportedPage(allowedPages));
5
- }
6
-
7
- static isSupportedPage(allowedPages) {
8
- let matcher = new RegExp("(" + allowedPages.join('|') + ")", "g");
9
- return matcher.test(window.location.href)
10
- }
11
-
12
3
  static renderModeButton() {
13
4
  // https://www.w3schools.com/howto/howto_css_sidenav_buttons.asp
14
5
  $('body').prepend(`
@@ -26,7 +17,7 @@ class HView {
26
17
  <div class="modal-content">
27
18
  <div class="modal-header">
28
19
  <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
29
- <h4 class="modal-title" id="myModalLabel">Highlighted Articles</h4>
20
+ <h4 class="modal-title" id="myModalLabel">${I18.tr(I18j.highlighted_fragments)}</h4>
30
21
  </div>
31
22
  <div class="modal-body" id="marked-items-list">
32
23
  ...
@@ -34,12 +25,18 @@ class HView {
34
25
  <div class="modal-footer">
35
26
  <row>
36
27
  <div class="col-md-8">
37
- <div class="checkbox">
38
- <label><input type="checkbox" id="hmode_checkbox" value="" onclick="HWindowCtrls.turnOnHMode()"> TURN ON Highlighting Mode</label>
39
- </div>
28
+ <label class="radio-inline">
29
+ <input id="hmode_off_radio_btn" type="radio" name="optradio" onclick="HWindowCtrls.turnOffHMode()">${I18.tr(I18j.turn_off_hmode)}
30
+ </label>
31
+ <label class="radio-inline">
32
+ <input id="hmode_on_radio_btn" type="radio" name="optradio" onclick="HWindowCtrls.turnOnHMode()">${I18.tr(I18j.turn_on_hmode)}
33
+ </label>
34
+ <label class="radio-inline">
35
+ <input id="hmode_reading_radio_btn" type="radio" name="optradio" onclick="HWindowCtrls.turnOnReadingHMode()">${I18.tr(I18j.turn_on_reading_hmode)}
36
+ </label>
40
37
  </div>
41
38
  <div class="col-md-4">
42
- <button type="button" class="btn btn-primary" onclick='HWindowCtrls.exportJSON()'>Export Settings</button>
39
+ <button type="button" class="btn btn-primary" onclick='HWindowCtrls.exportJSON()'>${I18.tr(I18j.export_settings)}</button>
43
40
  </div>
44
41
  </row>
45
42
  <br>
@@ -52,7 +49,7 @@ class HView {
52
49
  <input type="file" id="fileinput" class="custom-file-input" required>
53
50
  <span class="custom-file-control"></span>
54
51
  </label>
55
- <input type='button' class="btn btn-success" id='btnLoad' value='Import Settings' onclick='HWindowCtrls.importJSON();'>
52
+ <input type='button' class="btn btn-success" id='btnLoad' value='${I18.tr(I18j.import_settings)}' onclick='HWindowCtrls.importJSON();'>
56
53
  </fieldset>
57
54
  </form>
58
55
  </div>
@@ -4,9 +4,18 @@ class HWindowCtrls {
4
4
  $('#marked-items-list').html('');
5
5
  let userSettings = LS.uSettings();
6
6
  for (let key in userSettings.articles_titles) {
7
- $('#marked-items-list').append(`<span><a href='${key}' target='_blank'>${userSettings.articles_titles[key]}</a>&nbsp<a href="#" onclick="HWindowCtrls.deleteFragments('${key}')">[Delete]</a></span><br>`);
7
+ $('#marked-items-list').append(`<span><a href='${key}' target='_blank'>${userSettings.articles_titles[key]}</a>&nbsp<a href="#" onclick="HWindowCtrls.deleteFragments('${key}')">[${I18.tr(I18j.remove)}]</a></span><br>`);
8
8
  };
9
- $('input#hmode_checkbox')[0].checked = userSettings.settings.hmode_is_on;
9
+
10
+ if (userSettings.settings.hmode_is_on) {
11
+ $('input#hmode_on_radio_btn')[0].checked = true;
12
+ } else {
13
+ if (userSettings.settings.hmode_reading_is_on) {
14
+ $('input#hmode_reading_radio_btn')[0].checked = true;
15
+ } else {
16
+ $('input#hmode_off_radio_btn')[0].checked = true;
17
+ }
18
+ }
10
19
  $('#highlightModal').modal();
11
20
  }
12
21
 
@@ -15,7 +24,7 @@ class HWindowCtrls {
15
24
  let dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(userSettings));
16
25
  let dlAnchorElem = document.getElementById('downloadAnchorElem');
17
26
  dlAnchorElem.setAttribute("href", dataStr );
18
- dlAnchorElem.setAttribute("download", "scene.json");
27
+ dlAnchorElem.setAttribute("download", "settings.json");
19
28
  dlAnchorElem.click();
20
29
  }
21
30
 
@@ -23,19 +32,19 @@ class HWindowCtrls {
23
32
  let input, file, fr;
24
33
 
25
34
  if (typeof window.FileReader !== 'function') {
26
- alert("The file API isn't supported on this browser yet.");
35
+ alert(I18.tr(I18j.import.not_supported_api));
27
36
  return;
28
37
  }
29
38
 
30
39
  input = document.getElementById('fileinput');
31
40
  if (!input) {
32
- alert("Um, couldn't find the fileinput element.");
41
+ alert(I18.tr(I18j.import.not_find));
33
42
  }
34
43
  else if (!input.files) {
35
- alert("This browser doesn't seem to support the `files` property of file inputs.");
44
+ alert(I18.tr(I18j.import.not_supported_files));
36
45
  }
37
46
  else if (!input.files[0]) {
38
- alert("Please select a file before clicking 'Load'");
47
+ alert(I18.tr(I18j.import.please_select));
39
48
  }
40
49
  else {
41
50
  file = input.files[0];
@@ -52,7 +61,24 @@ class HWindowCtrls {
52
61
 
53
62
  static turnOnHMode(){
54
63
  let userSettings = LS.uSettings();
55
- userSettings.settings.hmode_is_on = $('input#hmode_checkbox')[0].checked;
64
+ userSettings.settings.hmode_is_on = true;
65
+ userSettings.settings.hmode_reading_is_on = false;
66
+ LS.saveUSettings(userSettings);
67
+ Tools.reloadPage();
68
+ }
69
+
70
+ static turnOffHMode(){
71
+ let userSettings = LS.uSettings();
72
+ userSettings.settings.hmode_is_on = false;
73
+ userSettings.settings.hmode_reading_is_on = false;
74
+ LS.saveUSettings(userSettings);
75
+ Tools.reloadPage();
76
+ }
77
+
78
+ static turnOnReadingHMode(){
79
+ let userSettings = LS.uSettings();
80
+ userSettings.settings.hmode_is_on = false;
81
+ userSettings.settings.hmode_reading_is_on = true;
56
82
  LS.saveUSettings(userSettings);
57
83
  Tools.reloadPage();
58
84
  }
@@ -0,0 +1,75 @@
1
+ const I18j = {
2
+ highlighted_fragments: {
3
+ uk: 'Нотатки',
4
+ ru: 'Нотатки',
5
+ en: 'Notes'
6
+ },
7
+ remove: {
8
+ uk: 'Видалити',
9
+ ru: 'Удалить',
10
+ en: 'Remove'
11
+ },
12
+ turn_off_hmode: {
13
+ uk: 'Відключити',
14
+ ru: 'Отключить',
15
+ en: 'Turn off'
16
+ },
17
+ turn_on_hmode: {
18
+ uk: '"Нотатки"',
19
+ ru: '"Нотатки"',
20
+ en: '"Highlighting"'
21
+ },
22
+ turn_on_reading_hmode: {
23
+ uk: '"Читання"',
24
+ ru: '"Чтение"',
25
+ en: '"Reading" mode'
26
+ },
27
+ import_settings: {
28
+ uk: 'Імпортувати',
29
+ ru: 'Импортировать',
30
+ en: 'Import settings'
31
+ },
32
+ export_settings: {
33
+ uk: 'Експорт',
34
+ ru: 'Экспорт',
35
+ en: 'Export settings'
36
+ },
37
+ import: {
38
+ not_supported_api: {
39
+ uk: "Підтримка файлів поки що не підтримується в цьому браузері.",
40
+ ru: "Поддержка файлов пока что не поддерживается в этом браузере.",
41
+ en: "The file API isn't supported on this browser yet."
42
+ },
43
+ not_find: {
44
+ uk: "Нажаль не знайдено файлового елементу.",
45
+ ru: "К сожалению не найдено файлового элемента.",
46
+ en: "Um, couldn't find the fileinput element."
47
+ },
48
+ not_supported_files: {
49
+ uk: "Цей браузер здається не підтримує елементи.",
50
+ ru: "Этот браузер похоже не поддерживает элементы 'files'.",
51
+ en: "This browser doesn't seem to support the 'files' property of file inputs."
52
+ },
53
+ please_select: {
54
+ uk: "Будь-ласка оберіть файл перед завантаженням.",
55
+ ru: "Пожалуйста выберете файл перед загрузкой.",
56
+ en: "Please select a file before clicking 'Load'."
57
+ }
58
+ }
59
+ }
60
+
61
+ class I18 {
62
+
63
+ static tr(translation) {
64
+ return translation[I18.locale()];
65
+ }
66
+
67
+ static locale() {
68
+ let currentLocale = window.location.href.split('/')[3];
69
+ if (currentLocale == 'uk' || currentLocale == 'ru') {
70
+ return currentLocale;
71
+ } else {
72
+ return 'en';
73
+ }
74
+ }
75
+ }
@@ -17,13 +17,13 @@ class Marker {
17
17
  selection = document.selection.createRange();
18
18
  }
19
19
 
20
- if (selection.toString() !== '') {
20
+ if (selection.toString().length > 2) {
21
21
  Marker.saveFragments(selection.toString());
22
22
  }
23
23
  }
24
24
 
25
25
  static saveFragments(text){
26
- let fragments = text.trim().split("\n\n");
26
+ let fragments = text.trim().split("\n");
27
27
  fragments.forEach( fragment => {
28
28
  if (fragment.length > 0) {
29
29
  UserSettings.saveFragment(fragment);
@@ -25,24 +25,30 @@ class UserSettings {
25
25
  articles: {},
26
26
  articles_titles: {},
27
27
  settings:{
28
- hmode_is_on: true
28
+ hmode_is_on: true,
29
+ hmode_reading_is_on: false
29
30
  }
30
31
  };
31
32
  LS.saveUSettings(userSettings);
32
- } else {
33
- let hModeOn = LS.uSettings().settings.hmode_is_on;
34
- if(hModeOn){
35
- let articleFragments = userSettings.articles[Tools.href()] || [];
36
- articleFragments.forEach(fragment => {
37
- Marker.highlight(fragment.text);
38
- });
39
- }
40
- };
33
+ }
34
+
35
+ if(UserSettings.isHMode() || UserSettings.isHModeReading()){
36
+ let articleFragments = userSettings.articles[Tools.href()] || [];
37
+ articleFragments.forEach(fragment => {
38
+ Marker.highlight(fragment.text);
39
+ });
40
+ }
41
41
  }
42
42
 
43
43
  static isHMode() {
44
44
  let mode;
45
- try { mode = LS.uSettings().settings.hmode_is_on } catch(e) {};
45
+ try { mode = (LS.uSettings().settings.hmode_is_on && !LS.uSettings().settings.hmode_reading_is_on) } catch(e) {};
46
+ return mode;
47
+ }
48
+
49
+ static isHModeReading() {
50
+ let mode;
51
+ try { mode = LS.uSettings().settings.hmode_reading_is_on } catch(e) {};
46
52
  return mode;
47
53
  }
48
54
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fragment_highlighter-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - PhlowerTeam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-09 00:00:00.000000000 Z
11
+ date: 2017-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,6 +86,7 @@ files:
86
86
  - vendor/assets/javascripts/fragment-highlighter/fragment-highlighter.js
87
87
  - vendor/assets/javascripts/fragment-highlighter/libs/classes/HView.js
88
88
  - vendor/assets/javascripts/fragment-highlighter/libs/classes/HWindowCtrls.js
89
+ - vendor/assets/javascripts/fragment-highlighter/libs/classes/I18.js
89
90
  - vendor/assets/javascripts/fragment-highlighter/libs/classes/LS.js
90
91
  - vendor/assets/javascripts/fragment-highlighter/libs/classes/Marker.js
91
92
  - vendor/assets/javascripts/fragment-highlighter/libs/classes/Tools.js
@@ -111,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  version: '0'
112
113
  requirements: []
113
114
  rubyforge_project:
114
- rubygems_version: 2.6.13
115
+ rubygems_version: 2.5.1
115
116
  signing_key:
116
117
  specification_version: 4
117
118
  summary: JavaScript UI library for highlighting text fragments on the page and saving