-
Notifications
You must be signed in to change notification settings - Fork 0
/
slot.v1.0.0.js
234 lines (179 loc) · 7.86 KB
/
slot.v1.0.0.js
1
2
3
4
5
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*!
* Slot v1.0.0
* Docs & License: http://dreamidea.in/plugins/slot
* (c) 2015 Dominic George
*/
/*
* Use slot_v1.0.0.css for basic styling.
*/
(function ( $ ) {
var __json_data=[];
$.fn.slot = function( ) {
// This is the easiest way to have default options.
var defaults = {
textColor: "#000",
backColor: "#fff",
fontSize: "1em",
delay: "quite long",
series:[]
};
var options = $.extend({
}, arguments[0] || {});
// defualt extention
// var options = $.extend({
// SlotClick: function() {},serializeClick:function() {}
// }, arguments[0] || {});
var selected =function (data,____THIS){
if(____THIS.attr('select-id')=='0')
{
__json_data.push({"cl":____THIS.attr('data-cl'),"rw":____THIS.attr('data-id'),"data":data});
____THIS.attr('select-id','1');
____THIS.addClass('button-success');
}else{
$.each(__json_data, function (key, data1) {
if(data1.cl==____THIS.attr('data-cl') && data1.rw==____THIS.attr('data-id')){
__json_data.splice(key, 1 );
____THIS.attr('select-id','0');
____THIS.removeClass('button-success');
return false;
}
});
}
var __cr=0;
var __sel_json=[];
$.each(__json_data, function (key2, data2) {
__cr++;
__sel_json.push(data2.data);
});
$('.f-foo').find('label').html(__cr);
return __sel_json;
};
// serialize
var serialize_selected =function (data,____THIS,id){
if(____THIS.attr('select-id')=='0')
{
__json_data.push({id:id,data:data});
____THIS.attr('select-id','1');
____THIS.addClass('button-success');
}else{
$.each(__json_data, function (key, data1) {
if(data1.id==id){
__json_data.splice(key, 1 );
____THIS.attr('select-id','0');
____THIS.removeClass('button-success');
}
});
}
var __cr=0;
var __sel_json=[];
$.each(__json_data, function (key, data1) {
__cr++;
__sel_json.push(data1.data);
});
$('.f-foo').find('label').html(__cr);
return __sel_json;
};
var settings = $.extend( {}, defaults, options );
// Greenify the collection based on the settings variable.
return this.each(function() {
// Plugin code would go here...
var __this= $(this);
$(this).css({
color: settings.color,
backgroundColor: settings.backColor,
fontSize: settings.fontSize
});
__this.addClass('ui-slot');
// click event
$(this).on('click','.ui-slot-r',function(e) {
if(options.serializeClick !== undefined)
{
var ___index=[];
if(options.serializeInput!==undefined)
{
___val=$(options.serializeInput).val();
}else{
___val= prompt("Please enter value");
}
var __count=1;
var ___this=$(this);
for(var i=1;i<=___val;i++)
{
if(___this.attr('d-id')==0){
__count++;
___this=___this.next();
}else if(___this.attr('d-id')===undefined ){ return false; }else{
return false;
}
}
if(parseInt(___val)<=__count){
___this=$(this);
___this.parents('rows-slot').find('a').each(function (){
$.each(__json_data, function (key, data1) {
__json_data.splice(key, 1 );
});
$(this).attr('select-id','0');
$(this).removeClass('button-success');
});
for(var i=1;i<=___val;i++)
{
if(___this.attr('d-id')==0){
var __p= serialize_selected(settings.series[___this.attr('data-cl')].data[___this.attr('data-id')],___this,___this.attr('data-id'));
___index.push({col:___this.attr('data-cl'),rw:___this.attr('data-id')});
___this=___this.next();
}
}
}
return options.serializeClick(___index,__p);
}else{
if (options.SlotClick !== undefined) {
var __p= selected(settings.series[$(this).attr('data-cl')].data[$(this).attr('data-id')],$(this));
var ___index={col:$(this).attr('data-cl'),rw:$(this).attr('data-id')};
return options.SlotClick(___index,settings.series[$(this).attr('data-cl')].data[$(this).attr('data-id')],__p);
//__this.data('index', $(this).index());
}
}
});
var _c='<lf class="lf-cl">';
$.each(settings.series,function (i,val){
if(val.color!== undefined)
color=val.color;
else
color='#28547c';
_c+='<tf-row class="tf-row"><tf class="ui-slot-tf button-secondary" style="background: '+color+';" >'+val.name+'</tf> </tf-row>';
});
_c+='</lf><rows-slot class="rows-slot">';
$.each(settings.series,function (i,val){
_c+='<c class="ui-slot-c"> <cl class="ui-slot-cl">';
if(val.color!== undefined)
color=val.color;
else
color='#28547c';
_c+='<tf-row class="tf-row"><tf class="ui-slot-tf button-secondary " style="background:'+color+';" >'+val.name+'</tf> </tf-row>';
$.each(val.data,function (j,value){
if(value.color!== undefined)
color=value.color;
else
color='#5da1e0';
var __d=0;
if(value.disabled!==undefined){
disabled='pure-button-disabled'; __d=1; color='#5da1e0'; }
else
disabled='';
if(value.selected!==undefined){
sel=1;
disabled='button-success';
color='';
}
else
sel=0;
_c+=' <a class="ui-slot-r button-secondary '+disabled+'" d-id='+__d+' style="background: '+color+';" select-id="'+sel+'" data-cl='+i+' data-id='+j+'>'+value.name+'</a>';
});
_c+=' </cl> </c>';
});
_c+='<hr/> <f-foo class="f-foo"> <a class="ui-slot-r button-secondary pure-button-disabled" style="background: #5da1e0;" > </a> Disabled</f-foo>\n\
<f-foo class="f-foo"> <fa class="ui-slot-r button-secondary button-success" > </fa> Selected (<label id="selected"></label>)</f-foo></rows-slot> ';
$(this).append(_c);
});
};
}( jQuery ));