To use Mark.js on your webpage, you must link to the library's stylesheet
and script file in your HTML as follows:
<link rel="stylesheet" type="text/css" href="mark-styles.css">
<script type="text/javascript" src="js/mark.js">
Then, in your HTML's respective JS file, instantiate a default Mark.js pop-up.
const markInstance = new Mark();
This pop-up is fixed to the top-left of the viewport by default. Now, we can use the Mark.js API (which is fully-defined below) to
edit the pop-up's state. Here is a code snippet of basic changes we can make to our Mark instances.
markInstance.setParentElement("elementID");
markInstance.setRight("0");
markInstance.applyAbsolutePositioning();
markInstance.setHighlighterColours("#FFFF00", "lime", "cyan", "#FF7777");
markInstance.setPopUpBackgroundColour("#222222");
markInstance.setPopUpBorderColour("#gray");
markInstance.setPopUpTextColour("#CCCCCC");
markInstance.setOffButtonColour("#FF6666");
markInstance.setOnButtonColour("#AAFFAA");
markInstance.setSwitchTextColour("#222222");
markInstance.setNoteInputColour("white");
markInstance.setNoteLayerNumber(2);
markInstance.addNote({
left: 400,
top: 120,
}, "Hey user!", "#elementID2");
markInstance.setNoteLayerNumber(1);
- selector: an HTML selector
Instantiates a default Mark.js pop-up. If selector is provided,
the pop-up is positioned absolutely at the top-left of the corresponding HTML element. Otherwise,
the pop-up is fixed to the top-left of the viewport.
Hides the Mark.js pop-up associated with the Mark.js object the method is called on.
Show the Mark.js pop-up associated with the Mark.js object the method is called on.
- value: a number of pixels (of type Number).
If the Mark.js pop-up is positioned absolutely, set the y-coordinate of the top of the Mark.js pop-up to the y-coordinate of the top edge of its "reference element" plus
value. Otherwise, the Mark.js pop-up has fixed positioning; set
its top property to value.
- value: a number of pixels (of type Number).
If the Mark.js pop-up is positioned absolutely, set the y-coordinate of the bottom of the Mark.js pop-up to the y-coordinate of the bottom edge of its "reference element" minus
value px. Otherwise, the Mark.js pop-up has fixed positioning; set
its bottom property to value px.
- value: a number of pixels (of type Number).
If the Mark.js pop-up is positioned absolutely, set the x-coordinate of the left of the Mark.js pop-up to the x-coordinate of the left edge of its "reference element" plus
value px. Otherwise, the Mark.js pop-up has fixed positioning; set
its left property to value px.
- value: a number of pixels (of type Number).
If the Mark.js pop-up is positioned absolutely, set the x-coordinate of the right of the Mark.js pop-up to the x-coordinate of the right edge of its "reference element" plus
value px. Otherwise, the Mark.js pop-up has fixed positioning; set
its right property to value px.
Fix the position of the Mark.js pop-up. The pop-up is given one of top/bottom properties
according to the following rules.
-
If setTop/setBottom has not been called on this Mark instance, give the pop-up
a top property of 0.
-
Otherwise, if setTop was called on the Mark instance more recently than setBottom was called, give the pop-up
a top property equal to the input of the argument used in the last call to setTop.
-
Otherwise, setBottom was called on the Mark instance more recently than setTop was called; give the pop-up
a bottom property equal to the input of the argument used in the last call to setBottom.
The pop-up is given one of left/right properties according to the same idea with setLeft/setRight.
Position the Mark.js pop-up absolutely relative to the last reference element set. The last reference element is determined
according to the following rules.
-
If setParent has been called on this Mark instance, the pop-up's reference element is the
one defined by the selector argument to the last call to setParent.
-
Otherwise, setParent has not been called on this Mark instance. The pop-up's reference element
is the one defined by the selector argument given to the constructor. If there was no selector
argument given to the constructor, the popup's reference element is the document's body.
The pop-up is given one of top/bottom properties according to the following rules.
-
If setTop/setBottom has not been called on this Mark instance, give the pop-up
a top property of 0.
-
Otherwise, if setTop was called on the Mark instance more recently than setBottom was called, give the pop-up
a top property equal to the input of the argument used in the last call to setTop.
-
Otherwise, setBottom was called on the Mark instance more recently than setTop was called; give the pop-up
a bottom property equal to the input of the argument used in the last call to setBottom.
The pop-up is given one of left/right properties according to the same idea with setLeft/setRight.
Set the parent element used when the Mark instance's pop-up is positioned absolutely.
-
position: an object containing a top property OR a bottom property (not both), and containing
a left propery OR a right property (not both).
- text: text to place in the note.
- referenceSelector: the selector of an HTML element that we want
to use as a reference when attatching this note.
Paste a new note, with the message text, on the Note Layer that this Mark instance is currently set to (this can be set by both the developer
using setNoteLayerNumber, and the user via the Mark instance's pop-up).
- layerNumber: an integer from 1 to 3, inclusive.
Set this Mark instance's note layer to Note Layer <layerNumber>.
After this method is run, the only notes written with this Mark instance visible to the user are those written when
this Mark instance was on Note Layer <layerNumber>.
- i: an integer from 0 to 3, inclusive.
Set the active highlighter colour (the one the user can currently highlight with) to be the (i + 1)-th
that is displayed on this Mark instance' pop-up (viewing from left to right).
- colour0: a CSS colour value (as a string).
- colour1: a CSS colour value (as a string).
- colour2: a CSS colour value (as a string).
- colour3: a CSS colour value (as a string).
Set the colours provided to the user to be the ones provided. Display
them in the same order that they are provided as arguments (left to right).
- colour: a CSS colour value (string).
Set the pop-up's background colour to the one specified by the colour string.
- colour: a CSS colour value (string).
Set the pop-up's text colour to the one specified by the colour string.
- colour: a CSS colour value (string).
Set the pop-up's text colour to the one specified by the colour string.
- colour: a CSS colour value (string).
Set the pop-up's border colours to the one specified by the colour string.
- colour: a CSS colour value (string).
Set the pop-up's on button colours to the one specified by the colour string.
- colour: a CSS colour value (string).
Set the pop-up's off button colours to the one specified by the colour string.
- colour: a CSS colour value (string).
Set the pop-up's note input text colour to the one specified by the colour string.
- colour: a CSS colour value (string).
Set the pop-up's button text colours to the one specified by the colour string.
This method does not apply to the pop-up's on/off switches.
Apply the default dark theme to this Mark instance's pop-up.
Apply the default light theme to this Mark instance's pop-up.
Maximize the view of this Mark instance's pop-up.
Minimize the view of this Mark instance's pop-up.
Take away the minimize/maximize button from this Mark instance's pop-up.
Give this Mark instance's pop-up a minimize/maximize button.