@contentpilot/page-tools 1.1.2 → 2.1.0
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/LICENSE +21 -0
- package/README.md +61 -9
- package/index.esm.js +6 -0
- package/index.js +143 -94
- package/package.json +31 -4
- package/.github/workflows/npm-publish.yml +0 -26
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 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,23 +1,75 @@
|
|
|
1
1
|
# Content Pilot Page Tools
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@contentpilot/page-tools)
|
|
4
|
+
|
|
3
5
|
Set of page tools for users to print, email, share, etc.
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Install the package:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @contentpilot/page-tools --save-dev
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Import the module:
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
import { PageTools, init } from "@contentpilot/page-tools";
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or include `./node_modules/@contentpilot/page-tools/index.js` as a plain
|
|
22
|
+
script.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
Without jQuery, it auto-initializes on `.page-tools` on `DOMContentLoaded`.
|
|
27
|
+
With jQuery, nothing runs until you call `.cpPageTools()`.
|
|
6
28
|
|
|
7
|
-
|
|
29
|
+
**Initialize:**
|
|
8
30
|
|
|
9
|
-
|
|
31
|
+
```javascript
|
|
32
|
+
import { init } from "@contentpilot/page-tools";
|
|
10
33
|
|
|
11
|
-
|
|
34
|
+
init(".page-tools", {
|
|
35
|
+
print: ".tool-print",
|
|
36
|
+
email: ".tool-email",
|
|
37
|
+
bookmark: ".tool-bookmark",
|
|
38
|
+
});
|
|
39
|
+
```
|
|
12
40
|
|
|
13
|
-
|
|
41
|
+
**jQuery Compatibility:**
|
|
14
42
|
|
|
15
|
-
|
|
43
|
+
```javascript
|
|
44
|
+
$(".page-tools").cpPageTools();
|
|
16
45
|
|
|
17
|
-
|
|
46
|
+
// With options
|
|
47
|
+
$(".page-tools").cpPageTools({
|
|
48
|
+
print: ".my-print-btn",
|
|
49
|
+
email: ".my-email-btn",
|
|
50
|
+
bookmark: ".my-bookmark-btn",
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The 1.x options are unchanged. Sites using the jQuery plugin need no code
|
|
55
|
+
changes.
|
|
56
|
+
|
|
57
|
+
### Options
|
|
58
|
+
|
|
59
|
+
Selectors are scoped to the container element.
|
|
60
|
+
|
|
61
|
+
- `print` - Print button selector (default `.tool-print`)
|
|
62
|
+
- `email` - Email button selector (default `.tool-email`)
|
|
63
|
+
- `bookmark` - Bookmark button selector (default `.tool-bookmark`)
|
|
64
|
+
|
|
65
|
+
## Publish to NPM
|
|
18
66
|
|
|
19
67
|
To update this repository on NPM using the GitHub action,
|
|
20
68
|
|
|
21
69
|
1. Bump the version number in `package.json`
|
|
22
|
-
2.
|
|
23
|
-
3.
|
|
70
|
+
2. Open a PR titled `Release x.x.x`
|
|
71
|
+
3. Squash and merge it once approved
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT
|
package/index.esm.js
ADDED
package/index.js
CHANGED
|
@@ -1,99 +1,148 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Page Tools
|
|
3
3
|
* Set of page tools for users to print, email, share, etc.
|
|
4
|
-
*
|
|
5
|
-
* @version 1.1.1
|
|
6
4
|
*
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
10
|
-
* @copyright Copyright © 2018 Content Pilot
|
|
11
|
-
* @license GPL-2.0+
|
|
5
|
+
* @author Content Pilot
|
|
6
|
+
* @copyright Copyright (c) 2019 Content Pilot
|
|
7
|
+
* @license MIT
|
|
12
8
|
*/
|
|
13
|
-
(function ( $ ) {
|
|
14
9
|
|
|
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
|
-
|
|
10
|
+
// Plain script, no leaked globals; bundlers get index.esm.js.
|
|
11
|
+
(() => {
|
|
12
|
+
class PageTools {
|
|
13
|
+
constructor(element, options = {}) {
|
|
14
|
+
if (element.dataset.cpPageToolsInit) return;
|
|
15
|
+
element.dataset.cpPageToolsInit = "true";
|
|
16
|
+
|
|
17
|
+
this.element = element;
|
|
18
|
+
this.settings = {
|
|
19
|
+
print: ".tool-print",
|
|
20
|
+
email: ".tool-email",
|
|
21
|
+
bookmark: ".tool-bookmark",
|
|
22
|
+
...options,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
this.init();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Trigger page print via browser
|
|
30
|
+
*
|
|
31
|
+
* @since 1.0.0
|
|
32
|
+
*/
|
|
33
|
+
setupPrint() {
|
|
34
|
+
const printButtons = this.element.querySelectorAll(this.settings.print);
|
|
35
|
+
printButtons.forEach((button) => {
|
|
36
|
+
button.addEventListener("click", (e) => {
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
e.stopPropagation();
|
|
39
|
+
window.print();
|
|
40
|
+
return false;
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Trigger email send with the page URL inside the content area
|
|
47
|
+
*
|
|
48
|
+
* @since 1.0.0
|
|
49
|
+
*/
|
|
50
|
+
setupEmail() {
|
|
51
|
+
const emailButtons = this.element.querySelectorAll(this.settings.email);
|
|
52
|
+
emailButtons.forEach((button) => {
|
|
53
|
+
button.addEventListener("click", (e) => {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
window.location.href = `mailto:?body=${window.location.href}`;
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Trigger bookmark action
|
|
62
|
+
*
|
|
63
|
+
* @since 1.1.0
|
|
64
|
+
*/
|
|
65
|
+
setupBookmark() {
|
|
66
|
+
const bookmarkButtons = this.element.querySelectorAll(
|
|
67
|
+
this.settings.bookmark
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
bookmarkButtons.forEach((button) => {
|
|
71
|
+
button.addEventListener("click", (e) => {
|
|
72
|
+
if (window.sidebar && window.sidebar.addPanel) {
|
|
73
|
+
// Firefox <23
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
e.stopPropagation();
|
|
76
|
+
window.sidebar.addPanel(document.title, window.location.href, "");
|
|
77
|
+
return false;
|
|
78
|
+
} else if (window.external && "AddFavorite" in window.external) {
|
|
79
|
+
// Internet Explorer
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
e.stopPropagation();
|
|
82
|
+
window.external.AddFavorite(location.href, document.title);
|
|
83
|
+
return false;
|
|
84
|
+
} else if (
|
|
85
|
+
(window.opera && window.print) ||
|
|
86
|
+
(window.sidebar && !(window.sidebar instanceof Node))
|
|
87
|
+
) {
|
|
88
|
+
// Opera <15 and Firefox >23
|
|
89
|
+
/**
|
|
90
|
+
* For Firefox <23 and Opera <15, no need for JS to add to bookmarks
|
|
91
|
+
* The only thing needed is a `title` and a `rel="sidebar"`
|
|
92
|
+
* To ensure that the bookmarked URL doesn't have a complementary `#` from our trigger's href
|
|
93
|
+
* we force the current URL
|
|
94
|
+
*/
|
|
95
|
+
button.setAttribute("rel", "sidebar");
|
|
96
|
+
button.setAttribute("title", document.title);
|
|
97
|
+
button.setAttribute("href", window.location.href);
|
|
98
|
+
return true;
|
|
99
|
+
} else {
|
|
100
|
+
// 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
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
e.stopPropagation();
|
|
103
|
+
const isMac =
|
|
104
|
+
navigator.userAgent.toLowerCase().indexOf("mac") !== -1;
|
|
105
|
+
alert(
|
|
106
|
+
`Add this page to your bookmarks by pressing ${
|
|
107
|
+
isMac ? "Command/Cmd" : "CTRL"
|
|
108
|
+
} + D on your keyboard.`
|
|
109
|
+
);
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
init() {
|
|
117
|
+
this.setupPrint();
|
|
118
|
+
this.setupEmail();
|
|
119
|
+
this.setupBookmark();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// jQuery plugin wrapper for backwards compatibility.
|
|
124
|
+
if (typeof jQuery !== "undefined") {
|
|
125
|
+
jQuery.fn.cpPageTools = function (options) {
|
|
126
|
+
return this.each(function () {
|
|
127
|
+
new PageTools(this, options);
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function init(selector = ".page-tools", options = {}) {
|
|
133
|
+
const pageToolsElements = document.querySelectorAll(selector);
|
|
134
|
+
pageToolsElements.forEach((element) => {
|
|
135
|
+
new PageTools(element, options);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
140
|
+
// Only auto-init if jQuery plugin wasn't used.
|
|
141
|
+
if (typeof jQuery === "undefined") {
|
|
142
|
+
init();
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Exposed for index.esm.js.
|
|
147
|
+
window.CpPageTools = { PageTools, init };
|
|
148
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,21 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentpilot/page-tools",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Set of page tools for users to print, email, share, etc.",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"module": "index.esm.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./index.esm.js",
|
|
10
|
+
"default": "./index.js"
|
|
11
|
+
},
|
|
12
|
+
"./index.js": "./index.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"index.js",
|
|
16
|
+
"index.esm.js"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"lint": "eslint index.js index.esm.js",
|
|
21
|
+
"lint:fix": "eslint index.js index.esm.js --fix",
|
|
22
|
+
"format": "prettier --write .",
|
|
23
|
+
"format:check": "prettier --check ."
|
|
24
|
+
},
|
|
6
25
|
"publishConfig": {
|
|
7
26
|
"access": "public"
|
|
8
27
|
},
|
|
9
28
|
"repository": {
|
|
10
29
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/
|
|
30
|
+
"url": "https://github.com/content-pilot/page-tools.git"
|
|
12
31
|
},
|
|
13
32
|
"keywords": [
|
|
14
33
|
"WordPress",
|
|
15
34
|
"tools",
|
|
16
35
|
"Content",
|
|
17
|
-
"Pilot"
|
|
36
|
+
"Pilot",
|
|
37
|
+
"Content Pilot",
|
|
38
|
+
"page"
|
|
18
39
|
],
|
|
19
40
|
"author": "Content Pilot",
|
|
20
|
-
"license": "MIT"
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@eslint/js": "^10.0.1",
|
|
44
|
+
"eslint": "^10.8.0",
|
|
45
|
+
"eslint-config-prettier": "^10.1.8",
|
|
46
|
+
"prettier": "^3.9.6"
|
|
47
|
+
}
|
|
21
48
|
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
name: npm-publish
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
branches:
|
|
5
|
-
- master
|
|
6
|
-
jobs:
|
|
7
|
-
npm-publish:
|
|
8
|
-
name: npm-publish
|
|
9
|
-
runs-on: ubuntu-latest
|
|
10
|
-
steps:
|
|
11
|
-
- name: Checkout repository
|
|
12
|
-
uses: actions/checkout@master
|
|
13
|
-
- name: Set up Node.js
|
|
14
|
-
uses: actions/setup-node@v1
|
|
15
|
-
with:
|
|
16
|
-
node-version: '10.x'
|
|
17
|
-
registry-url: 'https://registry.npmjs.org'
|
|
18
|
-
- name: Publish if version has been updated
|
|
19
|
-
uses: pascalgn/npm-publish-action@1.3.3
|
|
20
|
-
with: # All of theses inputs are optional
|
|
21
|
-
tag_name: "%s"
|
|
22
|
-
commit_pattern: "^Release (\\S+)"
|
|
23
|
-
workspace: "."
|
|
24
|
-
env: # More info about the environment variables in the README
|
|
25
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this as is, it's automatically generated
|
|
26
|
-
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} # You need to set this in your repo settings
|