Dan Brown

Updated pointer to be able to show includes

Also fixed pointer copying on flash-blocked browsers
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
16 "laravel-elixir": "^6.0.0-11", 16 "laravel-elixir": "^6.0.0-11",
17 "laravel-elixir-browserify-official": "^0.1.3", 17 "laravel-elixir-browserify-official": "^0.1.3",
18 "marked": "^0.3.5", 18 "marked": "^0.3.5",
19 - "moment": "^2.12.0", 19 + "moment": "^2.12.0"
20 - "zeroclipboard": "^2.2.0" 20 + },
21 + "dependencies": {
22 + "clipboard": "^1.5.16"
21 } 23 }
22 } 24 }
......
No preview for this file type
1 "use strict"; 1 "use strict";
2 // Configure ZeroClipboard 2 // Configure ZeroClipboard
3 -import ZeroClipBoard from "zeroclipboard"; 3 +import Clipboard from "clipboard";
4 4
5 export default window.setupPageShow = function (pageId) { 5 export default window.setupPageShow = function (pageId) {
6 6
7 // Set up pointer 7 // Set up pointer
8 let $pointer = $('#pointer').detach(); 8 let $pointer = $('#pointer').detach();
9 + let pointerShowing = false;
9 let $pointerInner = $pointer.children('div.pointer').first(); 10 let $pointerInner = $pointer.children('div.pointer').first();
10 let isSelection = false; 11 let isSelection = false;
12 + let pointerModeLink = true;
13 + let pointerSectionId = '';
11 14
12 // Select all contents on input click 15 // Select all contents on input click
13 $pointer.on('click', 'input', function (e) { 16 $pointer.on('click', 'input', function (e) {
...@@ -15,19 +18,34 @@ export default window.setupPageShow = function (pageId) { ...@@ -15,19 +18,34 @@ export default window.setupPageShow = function (pageId) {
15 e.stopPropagation(); 18 e.stopPropagation();
16 }); 19 });
17 20
18 - // Set up copy-to-clipboard 21 + // Pointer mode toggle
19 - ZeroClipBoard.config({ 22 + $pointer.on('click', 'span.icon', event => {
20 - swfPath: window.baseUrl('/ZeroClipboard.swf') 23 + let $icon = $(event.currentTarget);
24 + pointerModeLink = !pointerModeLink;
25 + $icon.html(pointerModeLink ? '<i class="zmdi zmdi-link"></i>' : '<i class="zmdi zmdi-square-down"></i>');
26 + updatePointerContent();
21 }); 27 });
22 - new ZeroClipBoard($pointer.find('button').first()[0]); 28 +
29 + // Set up clipboard
30 + let clipboard = new Clipboard('#pointer button');
23 31
24 // Hide pointer when clicking away 32 // Hide pointer when clicking away
25 - $(document.body).find('*').on('click focus', function (e) { 33 + $(document.body).find('*').on('click focus', event => {
26 - if (!isSelection) { 34 + if (!pointerShowing || isSelection) return;
35 + let target = $(event.target);
36 + if (target.is('.zmdi') || $(event.target).closest('#pointer').length === 1) return;
37 +
27 $pointer.detach(); 38 $pointer.detach();
28 - } 39 + pointerShowing = false;
29 }); 40 });
30 41
42 + function updatePointerContent() {
43 + let inputText = pointerModeLink ? window.baseUrl(`/link/${pageId}#${pointerSectionId}`) : `{{@${pageId}#${pointerSectionId}}}`;
44 + if (pointerModeLink && inputText.indexOf('http') !== 0) inputText = window.location.protocol + "//" + window.location.host + inputText;
45 +
46 + $pointer.find('input').val(inputText);
47 + }
48 +
31 // Show pointer when selecting a single block of tagged content 49 // Show pointer when selecting a single block of tagged content
32 $('.page-content [id^="bkmrk"]').on('mouseup keyup', function (e) { 50 $('.page-content [id^="bkmrk"]').on('mouseup keyup', function (e) {
33 e.stopPropagation(); 51 e.stopPropagation();
...@@ -36,12 +54,12 @@ export default window.setupPageShow = function (pageId) { ...@@ -36,12 +54,12 @@ export default window.setupPageShow = function (pageId) {
36 54
37 // Show pointer and set link 55 // Show pointer and set link
38 let $elem = $(this); 56 let $elem = $(this);
39 - let link = window.baseUrl('/link/' + pageId + '#' + $elem.attr('id')); 57 + pointerSectionId = $elem.attr('id');
40 - if (link.indexOf('http') !== 0) link = window.location.protocol + "//" + window.location.host + link; 58 + updatePointerContent();
41 - $pointer.find('input').val(link); 59 +
42 - $pointer.find('button').first().attr('data-clipboard-text', link);
43 $elem.before($pointer); 60 $elem.before($pointer);
44 $pointer.show(); 61 $pointer.show();
62 + pointerShowing = true;
45 63
46 // Set pointer to sit near mouse-up position 64 // Set pointer to sit near mouse-up position
47 let pointerLeftOffset = (e.pageX - $elem.offset().left - ($pointerInner.width() / 2)); 65 let pointerLeftOffset = (e.pageX - $elem.offset().left - ($pointerInner.width() / 2));
......
...@@ -109,4 +109,3 @@ $button-border-radius: 2px; ...@@ -109,4 +109,3 @@ $button-border-radius: 2px;
109 box-shadow: none; 109 box-shadow: none;
110 } 110 }
111 } 111 }
...\ No newline at end of file ...\ No newline at end of file
112 -
......
...@@ -138,6 +138,10 @@ ...@@ -138,6 +138,10 @@
138 font-size: 18px; 138 font-size: 18px;
139 padding-top: 4px; 139 padding-top: 4px;
140 } 140 }
141 + span.icon {
142 + cursor: pointer;
143 + user-select: none;
144 + }
141 .button { 145 .button {
142 line-height: 1; 146 line-height: 1;
143 margin: 0 0 0 -4px; 147 margin: 0 0 0 -4px;
......
...@@ -53,9 +53,9 @@ ...@@ -53,9 +53,9 @@
53 53
54 <div class="pointer-container" id="pointer"> 54 <div class="pointer-container" id="pointer">
55 <div class="pointer anim"> 55 <div class="pointer anim">
56 - <i class="zmdi zmdi-link"></i> 56 + <span class="icon text-primary"><i class="zmdi zmdi-link"></i></span>
57 - <input readonly="readonly" type="text" placeholder="url"> 57 + <input readonly="readonly" type="text" id="pointer-url" placeholder="url">
58 - <button class="button icon" title="{{ trans('entities.pages_copy_link') }}" data-clipboard-text=""><i class="zmdi zmdi-copy"></i></button> 58 + <button class="button icon" data-clipboard-target="#pointer-url" type="button" title="{{ trans('entities.pages_copy_link') }}"><i class="zmdi zmdi-copy"></i></button>
59 </div> 59 </div>
60 </div> 60 </div>
61 61
......