2 // Configure ZeroClipboard
3 var zeroClipBoard = require('zeroclipboard');
5 swfPath: '/ZeroClipboard.swf'
8 window.setupPageShow = module.exports = function (pageId) {
11 var $pointer = $('#pointer').detach();
12 var $pointerInner = $pointer.children('div.pointer').first();
13 var isSelection = false;
15 // Select all contents on input click
16 $pointer.on('click', 'input', function(e) {
21 // Set up copy-to-clipboard
22 new zeroClipBoard($pointer.find('button').first()[0]);
24 // Hide pointer when clicking away
25 $(document.body).find('*').on('click focus', function (e) {
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;
36 // Show pointer and set link
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);
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 + '%');
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)');
65 $('.page-content').find(':contains("' + text + '")').smoothScrollTo();
69 // Check the hash on load
70 if (window.location.hash) {
71 var text = window.location.hash.replace(/\%20/g, ' ').substr(1);
75 // Get current tree's width
76 var bookTreeWidth = $(".book-tree").width();
78 var headerHeight = $("#header").height() + $(".faded-small").height();
79 $(window).scroll(function () {
80 if($(window).scrollTop() > headerHeight){
82 $(".book-tree").width(bookTreeWidth);
83 $(".book-tree").css("position", "fixed");
84 $(".book-tree").css("top", 0);
86 // Lock it back in place
87 $(".book-tree").css("position", "relative");