@contentpilot/page-tools 1.1.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ name: npm-publish
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ jobs:
7
+ npm-publish:
8
+ name: npm-publish
9
+ runs-on: ubuntu-latest
10
+ if: contains(github.event.head_commit.message, 'Release')
11
+ steps:
12
+ - name: Checkout repository
13
+ uses: actions/checkout@v4
14
+ - name: Setup Node.js
15
+ uses: actions/setup-node@v4
16
+ with:
17
+ node-version: "20.x"
18
+ - name: Publish to NPM
19
+ uses: JS-DevTools/npm-publish@v3
20
+ with:
21
+ package: "./package.json"
22
+ access: public
23
+ tag: latest
24
+ token: ${{ secrets.NPM_AUTH_TOKEN }}
25
+ - name: Create Git tag
26
+ run: |
27
+ VERSION=$(node -p "require('./package.json').version")
28
+ git tag "$VERSION"
29
+ git push origin "$VERSION"
package/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "semi": true,
3
+ "singleQuote": false,
4
+ "tabWidth": 2,
5
+ "trailingComma": "es5",
6
+ "printWidth": 80
7
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Content Pilot
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,26 +1,51 @@
1
- # Content Pilot Page Tools
2
-
3
- Set of page tools for users to print, email, share, etc.
4
-
5
- # Install as devDependency
6
-
7
- `npm install @contentpilot/page-tools --save-dev`
8
-
9
- # Require JS file in task runner
10
-
11
- `./node_modules/@contentpilot/page-tools/index.js`
12
-
13
- # Bind to content area
14
-
15
- `$('.page-tools').cpPageTools();`
16
-
17
- # Change Log
18
-
19
- = 1.1.1 =
20
- * Fix typo preventing the bookmark action from triggering.
21
-
22
- = 1.1.0 =
23
- * Add ability to bookmark page
24
-
25
- = 1.0.0 =
26
- * Initial commit with renamed package
1
+ # Content Pilot Page Tools
2
+
3
+ Set of page tools for users to print, email, share, etc.
4
+
5
+ ### Installation
6
+
7
+ `npm install @contentpilot/page-tools --save-dev`
8
+
9
+ ### Require JS file in task runner
10
+
11
+ `./node_modules/@contentpilot/page-tools/index.js`
12
+
13
+ ### Usage
14
+
15
+ #### With jQuery (legacy)
16
+
17
+ ```javascript
18
+ $(".page-tools").cpPageTools();
19
+
20
+ // With options
21
+ $(".page-tools").cpPageTools({
22
+ print: ".my-print-btn",
23
+ email: ".my-email-btn",
24
+ bookmark: ".my-bookmark-btn",
25
+ });
26
+ ```
27
+
28
+ #### Without jQuery (ES6)
29
+
30
+ Include `index.js` in your site's build/task-runner pipeline — it's a plain
31
+ browser script, not a module to `import`/`require`.
32
+
33
+ ```javascript
34
+ // Auto-initializes on elements with class "page-tools".
35
+
36
+ // Or manually:
37
+ const element = document.querySelector(".custom-page-tools");
38
+ new PageTools(element, {
39
+ print: ".custom-print-btn",
40
+ email: ".custom-email-btn",
41
+ bookmark: ".custom-bookmark-btn",
42
+ });
43
+ ```
44
+
45
+ ### Publish to NPM
46
+
47
+ To update this repository on NPM using the GitHub action,
48
+
49
+ 1. Bump the version number in `package.json`
50
+ 2. Commit with message pattern of `Release x.x.x`
51
+ 3. Push to `main` branch to `origin`
@@ -0,0 +1,28 @@
1
+ import js from "@eslint/js";
2
+ import prettier from "eslint-config-prettier";
3
+
4
+ export default [
5
+ js.configs.recommended,
6
+ prettier,
7
+ {
8
+ languageOptions: {
9
+ ecmaVersion: "latest",
10
+ sourceType: "module",
11
+ globals: {
12
+ window: "readonly",
13
+ document: "readonly",
14
+ navigator: "readonly",
15
+ alert: "readonly",
16
+ location: "readonly",
17
+ Node: "readonly",
18
+ jQuery: "readonly",
19
+ },
20
+ },
21
+ rules: {
22
+ "no-unused-vars": "warn",
23
+ "no-console": "warn",
24
+ "prefer-const": "error",
25
+ "no-var": "error",
26
+ },
27
+ },
28
+ ];
package/index.js CHANGED
@@ -1,99 +1,133 @@
1
- /**
2
- *
3
- * Set of page tools for users to print, email, share, etc.
4
- *
5
- * @version 1.1.1
6
- *
7
- * @package Page Tools
8
- * @author Content Pilot, Dallas, Texas
9
- * @link https://www.contentpilot.com
10
- * @copyright Copyright © 2018 Content Pilot
11
- * @license GPL-2.0+
12
- */
13
- (function ( $ ) {
14
-
15
- $.fn.cpPageTools = function( options ) {
16
-
17
- var settings = $.extend({
18
- print: '.tool-print',
19
- email: '.tool-email',
20
- bookmark: '.tool-bookmark',
21
- }, options );
22
-
23
- /**
24
- * Trigger page print via browser
25
- *
26
- * @return {false}
27
- * @since 1.0.0
28
- */
29
- function print() {
30
- $( settings.print ).click(function() {
31
- window.print();
32
- return false;
33
- });
34
- }
35
-
36
- /**
37
- * Trigger email send with the page URL inside the content area
38
- *
39
- * @return {void}
40
- * @since 1.0.0
41
- */
42
- function email() {
43
- $( settings.email ).click(function(e) {
44
- e.preventDefault();
45
- window.location.href = "mailto:?body=" + window.location.href;
46
- });
47
- }
48
-
49
- /**
50
- * Trigger bookmark action
51
- *
52
- * @return {false}
53
- * @since 1.1.0
54
- */
55
- function bookmark() {
56
-
57
- var triggerBookmark = $( settings.bookmark );
58
-
59
- triggerBookmark.click(function() {
60
-
61
- if (window.sidebar && window.sidebar.addPanel) { // Firefox <23
62
-
63
- window.sidebar.addPanel(document.title,window.location.href,'');
64
-
65
- } else if(window.external && ('AddFavorite' in window.external)) { // Internet Explorer
66
-
67
- window.external.AddFavorite(location.href,document.title);
68
-
69
- } else if(window.opera && window.print || window.sidebar && ! (window.sidebar instanceof Node)) { // Opera <15 and Firefox >23
70
- /**
71
- * For Firefox <23 and Opera <15, no need for JS to add to bookmarks
72
- * The only thing needed is a `title` and a `rel="sidebar"`
73
- * To ensure that the bookmarked URL doesn't have a complementary `#` from our trigger's href
74
- * we force the current URL
75
- */
76
- triggerBookmark.attr('rel', 'sidebar').attr('title', document.title).attr('href', window.location.href);
77
- return true;
78
-
79
- } else { // For the other browsers (mainly WebKit) we use a simple alert to inform users that they can add to bookmarks with ctrl+D/cmd+D
80
-
81
- alert('Add this page to your bookmarks by pressing ' + (navigator.userAgent.toLowerCase().indexOf('mac') != - 1 ? 'Command/Cmd' : 'CTRL') + ' + D on your keyboard.');
82
-
83
- }
84
-
85
- // If you have something in the `href` of your trigger.
86
- return false;
87
-
88
- });
89
-
90
- }
91
-
92
- // Init
93
- print();
94
- email();
95
- bookmark();
96
-
97
- };
98
-
99
- }( jQuery ));
1
+ /**
2
+ * Page Tools - Pure JavaScript implementation
3
+ * Set of page tools for users to print, email, share, etc.
4
+ *
5
+ * @version 2.0.0
6
+ * @package Page Tools
7
+ * @author Content Pilot, Dallas, Texas
8
+ * @link https://www.contentpilot.com
9
+ * @copyright Copyright © 2018 Content Pilot
10
+ * @license GPL-2.0+
11
+ */
12
+
13
+ class PageTools {
14
+ constructor(element, options = {}) {
15
+ this.element = element;
16
+ this.settings = {
17
+ print: ".tool-print",
18
+ email: ".tool-email",
19
+ bookmark: ".tool-bookmark",
20
+ ...options,
21
+ };
22
+
23
+ this.init();
24
+ }
25
+
26
+ /**
27
+ * Trigger page print via browser
28
+ *
29
+ * @since 1.0.0
30
+ */
31
+ setupPrint() {
32
+ const printButtons = this.element.querySelectorAll(this.settings.print);
33
+ printButtons.forEach((button) => {
34
+ button.addEventListener("click", (e) => {
35
+ e.preventDefault();
36
+ window.print();
37
+ return false;
38
+ });
39
+ });
40
+ }
41
+
42
+ /**
43
+ * Trigger email send with the page URL inside the content area
44
+ *
45
+ * @since 1.0.0
46
+ */
47
+ setupEmail() {
48
+ const emailButtons = this.element.querySelectorAll(this.settings.email);
49
+ emailButtons.forEach((button) => {
50
+ button.addEventListener("click", (e) => {
51
+ e.preventDefault();
52
+ window.location.href = `mailto:?body=${window.location.href}`;
53
+ });
54
+ });
55
+ }
56
+
57
+ /**
58
+ * Trigger bookmark action
59
+ *
60
+ * @since 1.1.0
61
+ */
62
+ setupBookmark() {
63
+ const bookmarkButtons = this.element.querySelectorAll(
64
+ this.settings.bookmark
65
+ );
66
+
67
+ bookmarkButtons.forEach((button) => {
68
+ button.addEventListener("click", (e) => {
69
+ if (window.sidebar && window.sidebar.addPanel) {
70
+ // Firefox <23
71
+ e.preventDefault();
72
+ window.sidebar.addPanel(document.title, window.location.href, "");
73
+ return false;
74
+ } else if (window.external && "AddFavorite" in window.external) {
75
+ // Internet Explorer
76
+ e.preventDefault();
77
+ window.external.AddFavorite(location.href, document.title);
78
+ return false;
79
+ } else if (
80
+ (window.opera && window.print) ||
81
+ (window.sidebar && !(window.sidebar instanceof Node))
82
+ ) {
83
+ // Opera <15 and Firefox >23
84
+ /**
85
+ * For Firefox <23 and Opera <15, no need for JS to add to bookmarks
86
+ * The only thing needed is a `title` and a `rel="sidebar"`
87
+ * To ensure that the bookmarked URL doesn't have a complementary `#` from our trigger's href
88
+ * we force the current URL
89
+ */
90
+ button.setAttribute("rel", "sidebar");
91
+ button.setAttribute("title", document.title);
92
+ button.setAttribute("href", window.location.href);
93
+ return true;
94
+ } else {
95
+ // For the other browsers (mainly WebKit) we use a simple alert to inform users that they can add to bookmarks with ctrl+D/cmd+D
96
+ e.preventDefault();
97
+ const isMac = navigator.userAgent.toLowerCase().indexOf("mac") !== -1;
98
+ alert(
99
+ `Add this page to your bookmarks by pressing ${
100
+ isMac ? "Command/Cmd" : "CTRL"
101
+ } + D on your keyboard.`
102
+ );
103
+ return false;
104
+ }
105
+ });
106
+ });
107
+ }
108
+
109
+ init() {
110
+ this.setupPrint();
111
+ this.setupEmail();
112
+ this.setupBookmark();
113
+ }
114
+ }
115
+
116
+ // jQuery plugin wrapper for backwards compatibility.
117
+ if (typeof jQuery !== "undefined") {
118
+ jQuery.fn.cpPageTools = function (options) {
119
+ return this.each(function () {
120
+ new PageTools(this, options);
121
+ });
122
+ };
123
+ }
124
+
125
+ document.addEventListener("DOMContentLoaded", () => {
126
+ // Only auto-init if jQuery plugin wasn't used.
127
+ if (typeof jQuery === "undefined") {
128
+ const pageToolsElements = document.querySelectorAll(".page-tools");
129
+ pageToolsElements.forEach((element) => {
130
+ new PageTools(element);
131
+ });
132
+ }
133
+ });
package/package.json CHANGED
@@ -1,25 +1,36 @@
1
1
  {
2
2
  "name": "@contentpilot/page-tools",
3
- "version": "1.1.1",
3
+ "version": "2.0.2",
4
4
  "description": "Set of page tools for users to print, email, share, etc.",
5
5
  "main": "index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "lint": "eslint index.js",
9
+ "lint:fix": "eslint index.js --fix",
10
+ "format": "prettier --write .",
11
+ "format:check": "prettier --check ."
12
+ },
6
13
  "publishConfig": {
7
14
  "access": "public"
8
15
  },
9
- "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
11
- },
12
16
  "repository": {
13
17
  "type": "git",
14
- "url": "git+https://bitbucket.org/contentpilot/page-tools.git"
18
+ "url": "https://github.com/content-pilot/page-tools.git"
15
19
  },
16
20
  "keywords": [
17
21
  "WordPress",
18
22
  "tools",
19
23
  "Content",
20
- "Pilot"
24
+ "Pilot",
25
+ "Content Pilot",
26
+ "page"
21
27
  ],
22
- "author": "Clayton Collie, Content Pilot",
28
+ "author": "Content Pilot",
23
29
  "license": "MIT",
24
- "homepage": "https://bitbucket.org/contentpilot/page-tools#readme"
30
+ "devDependencies": {
31
+ "@eslint/js": "^10.0.1",
32
+ "eslint": "^10.8.0",
33
+ "eslint-config-prettier": "^10.1.8",
34
+ "prettier": "^3.9.6"
35
+ }
25
36
  }