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.
To install segnoJs, run
npm install SegnoJS
segno.min.js in your page as follows
segno_default.min.css to the page as follows.
fonts directory and place it at the same directory level as the css file from above.
SegnoJS tracks all DOM elements passed in the selector. For instance, to start tracking, all
p tags, initialize the plugin as follows.
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
||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.|
||1||Value in seconds for how often scroll detection code is called. This has no effect if
||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
||1||Value in seconds for time taken to animate scroll to a bookmark|
||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.|
||'bm'||The query string parameter that is used to share or go to a bookmark.|
The package comes with a default theme. It can be further customized. If using sass, the following variables are available in
|``$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|
||'\e801'||Symbol used for unset bookmark||Any unicode or html|
||segno||Font for the bookmark symbols. The default is downloaded from fontello.com||Any valid font|
||1em||Font size for the symbols||Any valid font size (px, rem, em, pt, etc.)|
||'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
The elements that are bookmarked have
segno-bookmarkable class added for easy styling.
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.
||null||Allows for any custom actions to be taken after the library is initialized|
||null||It is called whenever a bookmark is set. Allows for custom actions such a notification to show that a bookmark has been set.|
||null||It is similar to
||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.|
SegnoJS provides some methods through a global variable
Segno. For Instance you can check if there is a bookmark set using
Full list of methods are below
||none||Returns true if there is a stored bookmark name|
||none||Returns bookmark if there is a stored bookmark.|
||CSS selector for the bookmark||Sets the bookmark|
||none||Unsets all bookmarks|
||none||Goes to the set bookmark|
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
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.
To set up a development environment, clone the repo. Run
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
Copyright (c) 2015, Vox Media, Inc. All rights reserved.
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.