Dan Brown

Updated page pointer to sit near mouse location and extracted page js into browserify bundle

1 -// Configure ZeroClipboard 1 +
2 -window.ZeroClipboard = require('zeroclipboard');
3 -window.ZeroClipboard.config({
4 - swfPath: '/ZeroClipboard.swf'
5 -});
6 2
7 // AngularJS - Create application and load components 3 // AngularJS - Create application and load components
8 var angular = require('angular'); 4 var angular = require('angular');
...@@ -60,3 +56,6 @@ if (elemExists('#html-editor')) { ...@@ -60,3 +56,6 @@ if (elemExists('#html-editor')) {
60 var tinyMceOptions = require('./pages/page-form'); 56 var tinyMceOptions = require('./pages/page-form');
61 tinymce.init(tinyMceOptions); 57 tinymce.init(tinyMceOptions);
62 } 58 }
59 +
60 +// Page specific items
61 +require('./pages/page-show');
...\ No newline at end of file ...\ No newline at end of file
......
1 +"use strict";
2 +// Configure ZeroClipboard
3 +var zeroClipBoard = require('zeroclipboard');
4 +zeroClipBoard.config({
5 + swfPath: '/ZeroClipboard.swf'
6 +});
7 +
8 +window.setupPageShow = module.exports = function (pageId) {
9 +
10 + // Set up pointer
11 + var $pointer = $('#pointer').detach();
12 + var $pointerInner = $pointer.children('div.pointer').first();
13 + var isSelection = false;
14 +
15 + // Select all contents on input click
16 + $pointer.on('click', 'input', function(e) {
17 + $(this).select();
18 + e.stopPropagation();
19 + });
20 +
21 + // Set up copy-to-clipboard
22 + new zeroClipBoard($pointer.find('button').first()[0]);
23 +
24 + // Hide pointer when clicking away
25 + $(document.body).find('*').on('click focus', function (e) {
26 + if (!isSelection) {
27 + $pointer.detach();
28 + }
29 + });
30 +
31 + // Show pointer when selecting a single block of tagged content
32 + $('.page-content [id^="bkmrk"]').on('mouseup keyup', function (e) {
33 + var selection = window.getSelection();
34 + if (selection.toString().length === 0) return;
35 +
36 + // Show pointer and set link
37 + var $elem = $(this);
38 + var link = window.location.protocol + "//" + window.location.host + '/link/' + pageId + '#' + $elem.attr('id');
39 + $pointer.find('input').val(link);
40 + $pointer.find('button').first().attr('data-clipboard-text', link);
41 + $elem.before($pointer);
42 + $pointer.show();
43 +
44 + // Set pointer to sit near mouse-up position
45 + var pointerLeftOffset = (e.pageX - $elem.offset().left - ($pointerInner.width() / 2));
46 + if (pointerLeftOffset < 0) pointerLeftOffset = 0;
47 + var pointerLeftOffsetPercent = (pointerLeftOffset / $elem.width()) * 100;
48 + $pointerInner.css('left', pointerLeftOffsetPercent + '%');
49 +
50 + e.stopPropagation();
51 +
52 + isSelection = true;
53 + setTimeout(() => {
54 + isSelection = false;
55 + }, 100);
56 + });
57 +
58 + // Go to, and highlight if necessary, the specified text.
59 + function goToText(text) {
60 + var idElem = $('.page-content #' + text).first();
61 + if (idElem.length !== 0) {
62 + idElem.smoothScrollTo();
63 + idElem.css('background-color', 'rgba(244, 249, 54, 0.25)');
64 + } else {
65 + $('.page-content').find(':contains("' + text + '")').smoothScrollTo();
66 + }
67 + }
68 +
69 + // Check the hash on load
70 + if (window.location.hash) {
71 + var text = window.location.hash.replace(/\%20/g, ' ').substr(1);
72 + goToText(text);
73 + }
74 +
75 +};
...\ No newline at end of file ...\ No newline at end of file
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
57 .pointer-container { 57 .pointer-container {
58 position: relative; 58 position: relative;
59 display: none; 59 display: none;
60 - left: 2%; 60 + left: 0;
61 } 61 }
62 .pointer { 62 .pointer {
63 border: 1px solid #CCC; 63 border: 1px solid #CCC;
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
68 position: absolute; 68 position: absolute;
69 top: -60px; 69 top: -60px;
70 background-color:#FFF; 70 background-color:#FFF;
71 + width: 272px;
71 &:before { 72 &:before {
72 position: absolute; 73 position: absolute;
73 left: 50%; 74 left: 50%;
......
...@@ -80,5 +80,6 @@ ...@@ -80,5 +80,6 @@
80 80
81 @yield('bottom') 81 @yield('bottom')
82 <script src="{{ versioned_asset('js/common.js') }}"></script> 82 <script src="{{ versioned_asset('js/common.js') }}"></script>
83 +@yield('scripts')
83 </body> 84 </body>
84 </html> 85 </html>
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
33 </div> 33 </div>
34 34
35 35
36 - <div class="container"> 36 + <div class="container" id="page-show">
37 <div class="row"> 37 <div class="row">
38 <div class="col-md-9 print-full-width"> 38 <div class="col-md-9 print-full-width">
39 <div class="page-content anim fadeIn"> 39 <div class="page-content anim fadeIn">
...@@ -66,62 +66,11 @@ ...@@ -66,62 +66,11 @@
66 </div> 66 </div>
67 </div> 67 </div>
68 68
69 + @include('partials/highlight')
70 +@stop
69 71
70 - 72 +@section('scripts')
71 -
72 -
73 <script> 73 <script>
74 - $(document).ready(function() { 74 + setupPageShow({{$page->id}});
75 -
76 -
77 - // Set up pointer
78 - var $pointer = $('#pointer').detach();
79 - var pageId = {{$page->id}};
80 - var isSelection = false;
81 -
82 - $pointer.find('input').click(function(e){$(this).select();e.stopPropagation();});
83 - new ZeroClipboard( $pointer.find('button').first()[0] );
84 -
85 - $(document.body).find('*').on('click focus', function(e) {
86 - if(!isSelection) {
87 - $pointer.detach();
88 - }
89 - });
90 -
91 - $('.page-content [id^="bkmrk"]').on('mouseup keyup', function(e) {
92 - var selection = window.getSelection();
93 - if(selection.toString().length === 0) return;
94 - // Show pointer and set link
95 - var $elem = $(this);
96 - var link = window.location.protocol + "//" + window.location.host + '/link/' + pageId + '#' + $elem.attr('id');
97 - $pointer.find('input').val(link);
98 - $pointer.find('button').first().attr('data-clipboard-text', link);
99 - $elem.before($pointer);
100 - $pointer.show();
101 - e.stopPropagation();
102 -
103 - isSelection = true;
104 - setTimeout(function() {
105 - isSelection = false;
106 - }, 100);
107 - });
108 -
109 - function goToText(text) {
110 - var idElem = $('.page-content').find('#' + text).first();
111 - if(idElem.length !== 0) {
112 - idElem.smoothScrollTo();
113 - } else {
114 - $('.page-content').find(':contains("'+text+'")').smoothScrollTo();
115 - }
116 - }
117 -
118 - if(window.location.hash) {
119 - var text = window.location.hash.replace(/\%20/g, ' ').substr(1);
120 - goToText(text);
121 - }
122 -
123 - });
124 </script> 75 </script>
125 -
126 - @include('partials/highlight')
127 @stop 76 @stop
......