SegnoJS
SegnoJs is a simple bookmarking jQuery plugin library that lets you keep track of the user's progress on a page. The library allows the user to pick up from where they left off when they return to the page.
This is a beta version of the software.
Dependencies
jQuery
Installation
To install segnoJs, run
npm install SegnoJS
Include segno.min.js
in your page as follows
The javascript adds invisible bookmarks. To make them visible and styled, add segno_default.min.css
to the page as follows.
Copy fonts
directory and place it at the same directory level as the css file from above.
Getting started
SegnoJS tracks all DOM elements passed in the selector. For instance, to start tracking, all p
tags, initialize the plugin as follows.
;
Customization
SegnoJS takes the following parameters that allow you to customize how it works.
For instance, you can change the color of the bookmark by passing in color
option as follows during initialization.
;
Below is the full list of available options
Property | Default Value | Purpose |
---|---|---|
setOnScroll |
true | Boolean flag that determines if bookmarks are set automatically when user scrolls to a valid DOM element. If this is set to false bookmarks can be set manually by clicking on the bookmark symbol. |
scrollDebounceSec |
1 | Value in seconds for how often scroll detection code is called. This has no effect if setOnScroll is false. |
autoScroll |
true | Boolean flag that determines if on load the page should automatically scroll to a bookmark if it is set. If set to false, you can still scroll to a bookmark using gotoBookmark method. |
scrollAnimationSec |
1 | Value in seconds for time taken to animate scroll to a bookmark |
scrollOffset |
0 | Number of pixels to offset when scrolling to a bookmark. This is useful if there is a fixed header or navbar. This can be a fixed number or a statement that is evaluated once or a function that is evaluated each time bookmark calculations are run. |
qsp |
'bm' | The query string parameter that is used to share or go to a bookmark. |
Styling
The package comes with a default theme. It can be further customized. If using sass, the following variables are available in css\segno_vars.scss
variable | default | purpose | options |
---|---|---|---|
``$bookmark-color` | #666 | Color of the bookmark symbol | Any valid sass color |
``$bookmark-set-symbol` | '\e800' | Symbol used for set bookmark | Any unicode or html |
$bookmark-unset-symbol |
'\e801' | Symbol used for unset bookmark | Any unicode or html |
$bookmark-font-family |
segno | Font for the bookmark symbols. The default is downloaded from fontello.com | Any valid font |
$bookmark-font-size |
1em | Font size for the symbols | Any valid font size (px, rem, em, pt, etc.) |
$bookmark-positioning |
'inline' | Positioning for the bookmark symbol. The default option places the bookmark inline at the end of the element it is tracking. To place it in the margin, use 'margin'. | 'inline' or 'margin' |
For more custom styling, the bookmark can be styled using .segno-bookmark
for positioning and .segno-bookmark:before
css selectors.
Active bookmarks have segno-active
class in addition to segno-bookmark
class.
The elements that are bookmarked have segno-bookmarkable
class added for easy styling.
Callbacks
In addition to the properties mentioned above, SegnoJS also lets you specify callback function that will be executed when certain events happen. For instance, to call a function whenever a bookmark is set, add the following to init code.
;
The following are the available callbacks.
Callback | Default Value | Purpose |
---|---|---|
afterInit |
null | Allows for any custom actions to be taken after the library is initialized |
onBookmarkSet |
null | It is called whenever a bookmark is set. Allows for custom actions such a notification to show that a bookmark has been set. |
onBookmarkUnset |
null | It is similar to onBookmarkSet . It is called whenever a bookmark is unset. |
onHasBookmarkAtInit |
null | This is called if there is a bookmark already set when the page loads and no bookmark has been provided as a query string parameter. |
Methods
SegnoJS provides some methods through a global variable Segno
. For Instance you can check if there is a bookmark set using
Segno;
Full list of methods are below
Function | Parameters | Purpose |
---|---|---|
hasBookmark |
none | Returns true if there is a stored bookmark name |
getBookmark |
none | Returns bookmark if there is a stored bookmark. |
setBookmark(bookmark) |
CSS selector for the bookmark | Sets the bookmark |
unsetBookmark() |
none | Unsets all bookmarks |
gotoBookmark() |
none | Goes to the set bookmark |
Other features
SegnoJS supports sharing bookmarks via query string parameter. If the url contains a parameter bm
, the page disregards existing bookmarks and scroll the one specified in the URL.
This parameter can be changed at initialization by passing qsp
parameter.
How does it work?
Segno stores the user's progress in a story in browser's local storage. If local storage is not available, it falls back to using cookies.
Development
To set up a development environment, clone the repo. Run npm install
.
Install httpserver
globally using, npm install -g httpserver
.
Build and run the project, using npm start
from thr command line. This will start the test page on http://localhost:8080
Contributing to the project
This is an active project and we encourage contributions. Please review our guidelines and code of conduct before contributing.
Here are a few ways in which you can contribute
- Add features or fixes
- Report issues
- Improve our documentation
License
Copyright (c) 2015, Vox Media, Inc. All rights reserved.
BSD license
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.