@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.
- package/.github/workflows/npm-publish.yml +29 -0
- package/.prettierrc +7 -0
- package/LICENSE +21 -0
- package/README.md +51 -26
- package/eslint.config.js +28 -0
- package/index.js +133 -99
- package/package.json +19 -8
|
@@ -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
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
|
-
|
|
6
|
-
|
|
7
|
-
`npm install @contentpilot/page-tools --save-dev`
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
`./node_modules/@contentpilot/page-tools/index.js`
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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`
|
package/eslint.config.js
ADDED
|
@@ -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
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
10
|
-
* @
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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": "
|
|
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": "
|
|
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": "
|
|
28
|
+
"author": "Content Pilot",
|
|
23
29
|
"license": "MIT",
|
|
24
|
-
"
|
|
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
|
}
|