semantic-ui-sass 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +5 -0
- data/app/assets/fonts/semantic-ui/basic.icons.eot +0 -0
- data/app/assets/fonts/semantic-ui/basic.icons.svg +450 -0
- data/app/assets/fonts/semantic-ui/basic.icons.ttf +0 -0
- data/app/assets/fonts/semantic-ui/basic.icons.woff +0 -0
- data/app/assets/fonts/semantic-ui/icons.eot +0 -0
- data/app/assets/fonts/semantic-ui/icons.otf +0 -0
- data/app/assets/fonts/semantic-ui/icons.svg +399 -0
- data/app/assets/fonts/semantic-ui/icons.ttf +0 -0
- data/app/assets/fonts/semantic-ui/icons.woff +0 -0
- data/app/assets/images/semantic-ui/loader-large-inverted.gif +0 -0
- data/app/assets/images/semantic-ui/loader-large.gif +0 -0
- data/app/assets/images/semantic-ui/loader-medium-inverted.gif +0 -0
- data/app/assets/images/semantic-ui/loader-medium.gif +0 -0
- data/app/assets/images/semantic-ui/loader-mini-inverted.gif +0 -0
- data/app/assets/images/semantic-ui/loader-mini.gif +0 -0
- data/app/assets/images/semantic-ui/loader-small-inverted.gif +0 -0
- data/app/assets/images/semantic-ui/loader-small.gif +0 -0
- data/app/assets/javascripts/semantic-ui.js +20 -0
- data/app/assets/javascripts/semantic-ui/accordion.js +419 -0
- data/app/assets/javascripts/semantic-ui/behavior/api.js +638 -0
- data/app/assets/javascripts/semantic-ui/behavior/colorize.js +270 -0
- data/app/assets/javascripts/semantic-ui/behavior/form.js +702 -0
- data/app/assets/javascripts/semantic-ui/behavior/state.js +725 -0
- data/app/assets/javascripts/semantic-ui/chatroom.js +769 -0
- data/app/assets/javascripts/semantic-ui/checkbox.js +344 -0
- data/app/assets/javascripts/semantic-ui/dimmer.js +564 -0
- data/app/assets/javascripts/semantic-ui/dropdown.js +724 -0
- data/app/assets/javascripts/semantic-ui/modal.js +553 -0
- data/app/assets/javascripts/semantic-ui/nag.js +545 -0
- data/app/assets/javascripts/semantic-ui/popup.js +727 -0
- data/app/assets/javascripts/semantic-ui/rating.js +403 -0
- data/app/assets/javascripts/semantic-ui/search.js +772 -0
- data/app/assets/javascripts/semantic-ui/shape.js +778 -0
- data/app/assets/javascripts/semantic-ui/sidebar.js +490 -0
- data/app/assets/javascripts/semantic-ui/tab.js +689 -0
- data/app/assets/javascripts/semantic-ui/transition.js +654 -0
- data/app/assets/javascripts/semantic-ui/video.js +457 -0
- data/app/assets/stylesheets/semantic-ui.scss +4 -0
- data/app/assets/stylesheets/semantic-ui/collections/_all.scss +6 -0
- data/app/assets/stylesheets/semantic-ui/collections/_breadcrumb.scss +77 -0
- data/app/assets/stylesheets/semantic-ui/collections/_form.scss +569 -0
- data/app/assets/stylesheets/semantic-ui/collections/_grid.scss +643 -0
- data/app/assets/stylesheets/semantic-ui/collections/_menu.scss +1767 -0
- data/app/assets/stylesheets/semantic-ui/collections/_message.scss +347 -0
- data/app/assets/stylesheets/semantic-ui/collections/_table.scss +524 -0
- data/app/assets/stylesheets/semantic-ui/elements/_all.scss +12 -0
- data/app/assets/stylesheets/semantic-ui/elements/_basic.icon.scss +479 -0
- data/app/assets/stylesheets/semantic-ui/elements/_button.scss +1187 -0
- data/app/assets/stylesheets/semantic-ui/elements/_divider.scss +199 -0
- data/app/assets/stylesheets/semantic-ui/elements/_header.scss +342 -0
- data/app/assets/stylesheets/semantic-ui/elements/_icon.scss +772 -0
- data/app/assets/stylesheets/semantic-ui/elements/_image.scss +181 -0
- data/app/assets/stylesheets/semantic-ui/elements/_input.scss +338 -0
- data/app/assets/stylesheets/semantic-ui/elements/_label.scss +827 -0
- data/app/assets/stylesheets/semantic-ui/elements/_loader.scss +185 -0
- data/app/assets/stylesheets/semantic-ui/elements/_progress.scss +352 -0
- data/app/assets/stylesheets/semantic-ui/elements/_segment.scss +464 -0
- data/app/assets/stylesheets/semantic-ui/elements/_step.scss +293 -0
- data/app/assets/stylesheets/semantic-ui/modules/_accordion.scss +199 -0
- data/app/assets/stylesheets/semantic-ui/modules/_all.scss +16 -0
- data/app/assets/stylesheets/semantic-ui/modules/_chatroom.scss +281 -0
- data/app/assets/stylesheets/semantic-ui/modules/_checkbox.scss +481 -0
- data/app/assets/stylesheets/semantic-ui/modules/_dimmer.scss +236 -0
- data/app/assets/stylesheets/semantic-ui/modules/_dropdown.scss +548 -0
- data/app/assets/stylesheets/semantic-ui/modules/_modal.scss +217 -0
- data/app/assets/stylesheets/semantic-ui/modules/_nag.scss +173 -0
- data/app/assets/stylesheets/semantic-ui/modules/_popup.scss +255 -0
- data/app/assets/stylesheets/semantic-ui/modules/_rating.scss +179 -0
- data/app/assets/stylesheets/semantic-ui/modules/_reveal.scss +365 -0
- data/app/assets/stylesheets/semantic-ui/modules/_search.scss +273 -0
- data/app/assets/stylesheets/semantic-ui/modules/_shape.scss +113 -0
- data/app/assets/stylesheets/semantic-ui/modules/_sidebar.scss +150 -0
- data/app/assets/stylesheets/semantic-ui/modules/_tab.scss +63 -0
- data/app/assets/stylesheets/semantic-ui/modules/_transition.scss +1096 -0
- data/app/assets/stylesheets/semantic-ui/modules/_video.scss +98 -0
- data/app/assets/stylesheets/semantic-ui/views/_all.scss +5 -0
- data/app/assets/stylesheets/semantic-ui/views/_comment.scss +221 -0
- data/app/assets/stylesheets/semantic-ui/views/_feed.scss +152 -0
- data/app/assets/stylesheets/semantic-ui/views/_item.scss +651 -0
- data/app/assets/stylesheets/semantic-ui/views/_list.scss +555 -0
- data/app/assets/stylesheets/semantic-ui/views/_statistic.scss +27 -0
- data/lib/semantic/ui/sass.rb +10 -0
- data/lib/semantic/ui/sass/engine.rb +13 -0
- data/lib/semantic/ui/sass/version.rb +8 -0
- data/semantic-ui-sass.gemspec +24 -0
- data/tasks/converter.rb +237 -0
- metadata +177 -0
@@ -0,0 +1,769 @@
|
|
1
|
+
/*
|
2
|
+
* # Semantic - Chatroom
|
3
|
+
* http://github.com/jlukic/semantic-ui/
|
4
|
+
*
|
5
|
+
*
|
6
|
+
* Copyright 2013 Contributors
|
7
|
+
* Released under the MIT license
|
8
|
+
* http://opensource.org/licenses/MIT
|
9
|
+
*
|
10
|
+
*/
|
11
|
+
|
12
|
+
;(function ($, window, document, undefined) {
|
13
|
+
|
14
|
+
$.fn.chatroom = function(parameters) {
|
15
|
+
var
|
16
|
+
settings = $.extend(true, {}, $.fn.chatroom.settings, parameters),
|
17
|
+
|
18
|
+
className = settings.className,
|
19
|
+
namespace = settings.namespace,
|
20
|
+
selector = settings.selector,
|
21
|
+
error = settings.error,
|
22
|
+
|
23
|
+
// hoist arguments
|
24
|
+
moduleArguments = arguments || false
|
25
|
+
;
|
26
|
+
$(this)
|
27
|
+
.each(function() {
|
28
|
+
var
|
29
|
+
$module = $(this),
|
30
|
+
|
31
|
+
$expandButton = $module.find(selector.expandButton),
|
32
|
+
$userListButton = $module.find(selector.userListButton),
|
33
|
+
|
34
|
+
$userList = $module.find(selector.userList),
|
35
|
+
$room = $module.find(selector.room),
|
36
|
+
$userCount = $module.find(selector.userCount),
|
37
|
+
|
38
|
+
$log = $module.find(selector.log),
|
39
|
+
$message = $module.find(selector.message),
|
40
|
+
|
41
|
+
$messageInput = $module.find(selector.messageInput),
|
42
|
+
$messageButton = $module.find(selector.messageButton),
|
43
|
+
|
44
|
+
instance = $module.data('module'),
|
45
|
+
|
46
|
+
html = '',
|
47
|
+
users = {},
|
48
|
+
|
49
|
+
channel,
|
50
|
+
loggedInUser,
|
51
|
+
|
52
|
+
message,
|
53
|
+
count,
|
54
|
+
|
55
|
+
height,
|
56
|
+
|
57
|
+
pusher,
|
58
|
+
module
|
59
|
+
;
|
60
|
+
|
61
|
+
module = {
|
62
|
+
|
63
|
+
width: {
|
64
|
+
log : $log.width(),
|
65
|
+
userList : $userList.outerWidth()
|
66
|
+
},
|
67
|
+
|
68
|
+
initialize: function() {
|
69
|
+
|
70
|
+
// check error conditions
|
71
|
+
if(Pusher === undefined) {
|
72
|
+
module.error(error.pusher);
|
73
|
+
}
|
74
|
+
if(settings.key === undefined || settings.channelName === undefined) {
|
75
|
+
module.error(error.key);
|
76
|
+
return false;
|
77
|
+
}
|
78
|
+
else if( !(settings.endpoint.message || settings.endpoint.authentication) ) {
|
79
|
+
module.error(error.endpoint);
|
80
|
+
return false;
|
81
|
+
}
|
82
|
+
|
83
|
+
// define pusher
|
84
|
+
pusher = new Pusher(settings.key);
|
85
|
+
Pusher.channel_auth_endpoint = settings.endpoint.authentication;
|
86
|
+
|
87
|
+
channel = pusher.subscribe(settings.channelName);
|
88
|
+
|
89
|
+
channel.bind('pusher:subscription_succeeded', module.user.list.create);
|
90
|
+
channel.bind('pusher:subscription_error', module.error);
|
91
|
+
channel.bind('pusher:member_added', module.user.joined);
|
92
|
+
channel.bind('pusher:member_removed', module.user.left);
|
93
|
+
channel.bind('update_messages', module.message.receive);
|
94
|
+
|
95
|
+
$.each(settings.customEvents, function(label, value) {
|
96
|
+
channel.bind(label, value);
|
97
|
+
});
|
98
|
+
|
99
|
+
// bind module events
|
100
|
+
$userListButton
|
101
|
+
.on('click.' + namespace, module.event.toggleUserList)
|
102
|
+
;
|
103
|
+
$expandButton
|
104
|
+
.on('click.' + namespace, module.event.toggleExpand)
|
105
|
+
;
|
106
|
+
$messageInput
|
107
|
+
.on('keydown.' + namespace, module.event.input.keydown)
|
108
|
+
.on('keyup.' + namespace, module.event.input.keyup)
|
109
|
+
;
|
110
|
+
$messageButton
|
111
|
+
.on('mouseenter.' + namespace, module.event.hover)
|
112
|
+
.on('mouseleave.' + namespace, module.event.hover)
|
113
|
+
.on('click.' + namespace, module.event.submit)
|
114
|
+
;
|
115
|
+
// scroll to bottom of chat log
|
116
|
+
$log
|
117
|
+
.animate({
|
118
|
+
scrollTop: $log.prop('scrollHeight')
|
119
|
+
}, 400)
|
120
|
+
;
|
121
|
+
$module
|
122
|
+
.data('module', module)
|
123
|
+
.addClass(className.loading)
|
124
|
+
;
|
125
|
+
|
126
|
+
},
|
127
|
+
|
128
|
+
// refresh module
|
129
|
+
refresh: function() {
|
130
|
+
// reset width calculations
|
131
|
+
$userListButton
|
132
|
+
.removeClass(className.active)
|
133
|
+
;
|
134
|
+
module.width = {
|
135
|
+
log : $log.width(),
|
136
|
+
userList : $userList.outerWidth()
|
137
|
+
};
|
138
|
+
if( $userListButton.hasClass(className.active) ) {
|
139
|
+
module.user.list.hide();
|
140
|
+
}
|
141
|
+
$module.data('module', module);
|
142
|
+
},
|
143
|
+
|
144
|
+
user: {
|
145
|
+
|
146
|
+
updateCount: function() {
|
147
|
+
if(settings.userCount) {
|
148
|
+
users = $module.data('users');
|
149
|
+
count = 0;
|
150
|
+
$.each(users, function() {
|
151
|
+
count++;
|
152
|
+
});
|
153
|
+
$userCount
|
154
|
+
.html( settings.templates.userCount(count) )
|
155
|
+
;
|
156
|
+
}
|
157
|
+
},
|
158
|
+
|
159
|
+
// add user to user list
|
160
|
+
joined: function(member) {
|
161
|
+
users = $module.data('users');
|
162
|
+
if(member.id != 'anonymous' && users[ member.id ] === undefined ) {
|
163
|
+
users[ member.id ] = member.info;
|
164
|
+
if(settings.randomColor && member.info.color === undefined) {
|
165
|
+
member.info.color = settings.templates.color(member.id);
|
166
|
+
}
|
167
|
+
html = settings.templates.userList(member.info);
|
168
|
+
if(member.info.isAdmin) {
|
169
|
+
$(html)
|
170
|
+
.prependTo($userList)
|
171
|
+
;
|
172
|
+
}
|
173
|
+
else {
|
174
|
+
$(html)
|
175
|
+
.appendTo($userList)
|
176
|
+
;
|
177
|
+
}
|
178
|
+
if(settings.partingMessages) {
|
179
|
+
$log
|
180
|
+
.append( settings.templates.joined(member.info) )
|
181
|
+
;
|
182
|
+
module.message.scroll.test();
|
183
|
+
}
|
184
|
+
module.user.updateCount();
|
185
|
+
}
|
186
|
+
},
|
187
|
+
|
188
|
+
// remove user from user list
|
189
|
+
left: function(member) {
|
190
|
+
users = $module.data('users');
|
191
|
+
if(member !== undefined && member.id !== 'anonymous') {
|
192
|
+
delete users[ member.id ];
|
193
|
+
$module
|
194
|
+
.data('users', users)
|
195
|
+
;
|
196
|
+
$userList
|
197
|
+
.find('[data-id='+ member.id + ']')
|
198
|
+
.remove()
|
199
|
+
;
|
200
|
+
if(settings.partingMessages) {
|
201
|
+
$log
|
202
|
+
.append( settings.templates.left(member.info) )
|
203
|
+
;
|
204
|
+
module.message.scroll.test();
|
205
|
+
}
|
206
|
+
module.user.updateCount();
|
207
|
+
}
|
208
|
+
},
|
209
|
+
|
210
|
+
list: {
|
211
|
+
|
212
|
+
// receives list of members and generates user list
|
213
|
+
create: function(members) {
|
214
|
+
users = {};
|
215
|
+
members.each(function(member) {
|
216
|
+
if(member.id !== 'anonymous' && member.id !== 'undefined') {
|
217
|
+
if(settings.randomColor && member.info.color === undefined) {
|
218
|
+
member.info.color = settings.templates.color(member.id);
|
219
|
+
}
|
220
|
+
// sort list with admin first
|
221
|
+
html = (member.info.isAdmin)
|
222
|
+
? settings.templates.userList(member.info) + html
|
223
|
+
: html + settings.templates.userList(member.info)
|
224
|
+
;
|
225
|
+
users[ member.id ] = member.info;
|
226
|
+
}
|
227
|
+
});
|
228
|
+
$module
|
229
|
+
.data('users', users)
|
230
|
+
.data('user', users[members.me.id] )
|
231
|
+
.removeClass(className.loading)
|
232
|
+
;
|
233
|
+
$userList
|
234
|
+
.html(html)
|
235
|
+
;
|
236
|
+
module.user.updateCount();
|
237
|
+
$.proxy(settings.onJoin, $userList.children())();
|
238
|
+
},
|
239
|
+
|
240
|
+
// shows user list
|
241
|
+
show: function() {
|
242
|
+
$log
|
243
|
+
.animate({
|
244
|
+
width: (module.width.log - module.width.userList)
|
245
|
+
}, {
|
246
|
+
duration : settings.speed,
|
247
|
+
easing : settings.easing,
|
248
|
+
complete : module.message.scroll.move
|
249
|
+
})
|
250
|
+
;
|
251
|
+
},
|
252
|
+
|
253
|
+
// hides user list
|
254
|
+
hide: function() {
|
255
|
+
$log
|
256
|
+
.stop()
|
257
|
+
.animate({
|
258
|
+
width: (module.width.log)
|
259
|
+
}, {
|
260
|
+
duration : settings.speed,
|
261
|
+
easing : settings.easing,
|
262
|
+
complete : module.message.scroll.move
|
263
|
+
})
|
264
|
+
;
|
265
|
+
}
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
},
|
270
|
+
|
271
|
+
message: {
|
272
|
+
|
273
|
+
// handles scrolling of chat log
|
274
|
+
scroll: {
|
275
|
+
test: function() {
|
276
|
+
height = $log.prop('scrollHeight') - $log.height();
|
277
|
+
if( Math.abs($log.scrollTop() - height) < settings.scrollArea) {
|
278
|
+
module.message.scroll.move();
|
279
|
+
}
|
280
|
+
},
|
281
|
+
|
282
|
+
move: function() {
|
283
|
+
height = $log.prop('scrollHeight') - $log.height();
|
284
|
+
$log
|
285
|
+
.scrollTop(height)
|
286
|
+
;
|
287
|
+
}
|
288
|
+
},
|
289
|
+
|
290
|
+
// sends chat message
|
291
|
+
send: function(message) {
|
292
|
+
if( !module.utils.emptyString(message) ) {
|
293
|
+
$.api({
|
294
|
+
url : settings.endpoint.message,
|
295
|
+
method : 'POST',
|
296
|
+
data : {
|
297
|
+
'message': {
|
298
|
+
content : message,
|
299
|
+
timestamp : new Date().getTime()
|
300
|
+
}
|
301
|
+
}
|
302
|
+
});
|
303
|
+
}
|
304
|
+
},
|
305
|
+
|
306
|
+
// receives chat response and processes
|
307
|
+
receive: function(response) {
|
308
|
+
message = response.data;
|
309
|
+
users = $module.data('users');
|
310
|
+
loggedInUser = $module.data('user');
|
311
|
+
if(users[ message.userID] !== undefined) {
|
312
|
+
// logged in user's messages already pushed instantly
|
313
|
+
if(loggedInUser === undefined || loggedInUser.id != message.userID) {
|
314
|
+
message.user = users[ message.userID ];
|
315
|
+
module.message.display(message);
|
316
|
+
}
|
317
|
+
}
|
318
|
+
},
|
319
|
+
|
320
|
+
// displays message in chat log
|
321
|
+
display: function(message) {
|
322
|
+
$log
|
323
|
+
.append( settings.templates.message(message) )
|
324
|
+
;
|
325
|
+
module.message.scroll.test();
|
326
|
+
$.proxy(settings.onMessage, $log.children().last() )();
|
327
|
+
}
|
328
|
+
|
329
|
+
},
|
330
|
+
|
331
|
+
expand: function() {
|
332
|
+
$module
|
333
|
+
.addClass(className.expand)
|
334
|
+
;
|
335
|
+
$.proxy(settings.onExpand, $module )();
|
336
|
+
module.refresh();
|
337
|
+
},
|
338
|
+
|
339
|
+
contract: function() {
|
340
|
+
$module
|
341
|
+
.removeClass(className.expand)
|
342
|
+
;
|
343
|
+
$.proxy(settings.onContract, $module )();
|
344
|
+
module.refresh();
|
345
|
+
},
|
346
|
+
|
347
|
+
event: {
|
348
|
+
|
349
|
+
input: {
|
350
|
+
|
351
|
+
keydown: function(event) {
|
352
|
+
if(event.which == 13) {
|
353
|
+
$messageButton
|
354
|
+
.addClass(className.down)
|
355
|
+
;
|
356
|
+
}
|
357
|
+
},
|
358
|
+
|
359
|
+
keyup: function(event) {
|
360
|
+
if(event.which == 13) {
|
361
|
+
$messageButton
|
362
|
+
.removeClass(className.down)
|
363
|
+
;
|
364
|
+
module.event.submit();
|
365
|
+
}
|
366
|
+
}
|
367
|
+
|
368
|
+
},
|
369
|
+
|
370
|
+
// handles message form submit
|
371
|
+
submit: function() {
|
372
|
+
var
|
373
|
+
message = $messageInput.val(),
|
374
|
+
loggedInUser = $module.data('user')
|
375
|
+
;
|
376
|
+
if(loggedInUser !== undefined && !module.utils.emptyString(message)) {
|
377
|
+
module.message.send(message);
|
378
|
+
// display immediately
|
379
|
+
module.message.display({
|
380
|
+
user: loggedInUser,
|
381
|
+
text: message
|
382
|
+
});
|
383
|
+
module.message.scroll.move();
|
384
|
+
$messageInput
|
385
|
+
.val('')
|
386
|
+
;
|
387
|
+
|
388
|
+
}
|
389
|
+
},
|
390
|
+
|
391
|
+
// handles button click on expand button
|
392
|
+
toggleExpand: function() {
|
393
|
+
if( !$module.hasClass(className.expand) ) {
|
394
|
+
$expandButton
|
395
|
+
.addClass(className.active)
|
396
|
+
;
|
397
|
+
module.expand();
|
398
|
+
}
|
399
|
+
else {
|
400
|
+
$expandButton
|
401
|
+
.removeClass(className.active)
|
402
|
+
;
|
403
|
+
module.contract();
|
404
|
+
}
|
405
|
+
},
|
406
|
+
|
407
|
+
// handles button click on user list button
|
408
|
+
toggleUserList: function() {
|
409
|
+
if( !$log.is(':animated') ) {
|
410
|
+
if( !$userListButton.hasClass(className.active) ) {
|
411
|
+
$userListButton
|
412
|
+
.addClass(className.active)
|
413
|
+
;
|
414
|
+
module.user.list.show();
|
415
|
+
}
|
416
|
+
else {
|
417
|
+
$userListButton
|
418
|
+
.removeClass('active')
|
419
|
+
;
|
420
|
+
module.user.list.hide();
|
421
|
+
}
|
422
|
+
}
|
423
|
+
|
424
|
+
}
|
425
|
+
},
|
426
|
+
|
427
|
+
utils: {
|
428
|
+
|
429
|
+
emptyString: function(string) {
|
430
|
+
if(typeof string == 'string') {
|
431
|
+
return (string.search(/\S/) == -1);
|
432
|
+
}
|
433
|
+
return false;
|
434
|
+
}
|
435
|
+
|
436
|
+
},
|
437
|
+
|
438
|
+
|
439
|
+
|
440
|
+
setting: function(name, value) {
|
441
|
+
if(value !== undefined) {
|
442
|
+
if( $.isPlainObject(name) ) {
|
443
|
+
$.extend(true, settings, name);
|
444
|
+
}
|
445
|
+
else {
|
446
|
+
settings[name] = value;
|
447
|
+
}
|
448
|
+
}
|
449
|
+
else {
|
450
|
+
return settings[name];
|
451
|
+
}
|
452
|
+
},
|
453
|
+
internal: function(name, value) {
|
454
|
+
if(value !== undefined) {
|
455
|
+
if( $.isPlainObject(name) ) {
|
456
|
+
$.extend(true, module, name);
|
457
|
+
}
|
458
|
+
else {
|
459
|
+
module[name] = value;
|
460
|
+
}
|
461
|
+
}
|
462
|
+
else {
|
463
|
+
return module[name];
|
464
|
+
}
|
465
|
+
},
|
466
|
+
debug: function() {
|
467
|
+
if(settings.debug) {
|
468
|
+
if(settings.performance) {
|
469
|
+
module.performance.log(arguments);
|
470
|
+
}
|
471
|
+
else {
|
472
|
+
module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
|
473
|
+
module.debug.apply(console, arguments);
|
474
|
+
}
|
475
|
+
}
|
476
|
+
},
|
477
|
+
verbose: function() {
|
478
|
+
if(settings.verbose && settings.debug) {
|
479
|
+
if(settings.performance) {
|
480
|
+
module.performance.log(arguments);
|
481
|
+
}
|
482
|
+
else {
|
483
|
+
module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
|
484
|
+
module.verbose.apply(console, arguments);
|
485
|
+
}
|
486
|
+
}
|
487
|
+
},
|
488
|
+
error: function() {
|
489
|
+
module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
|
490
|
+
module.error.apply(console, arguments);
|
491
|
+
},
|
492
|
+
performance: {
|
493
|
+
log: function(message) {
|
494
|
+
var
|
495
|
+
currentTime,
|
496
|
+
executionTime,
|
497
|
+
previousTime
|
498
|
+
;
|
499
|
+
if(settings.performance) {
|
500
|
+
currentTime = new Date().getTime();
|
501
|
+
previousTime = time || currentTime;
|
502
|
+
executionTime = currentTime - previousTime;
|
503
|
+
time = currentTime;
|
504
|
+
performance.push({
|
505
|
+
'Element' : element,
|
506
|
+
'Name' : message[0],
|
507
|
+
'Arguments' : [].slice.call(message, 1) || '',
|
508
|
+
'Execution Time' : executionTime
|
509
|
+
});
|
510
|
+
}
|
511
|
+
clearTimeout(module.performance.timer);
|
512
|
+
module.performance.timer = setTimeout(module.performance.display, 100);
|
513
|
+
},
|
514
|
+
display: function() {
|
515
|
+
var
|
516
|
+
title = settings.name + ':',
|
517
|
+
totalTime = 0
|
518
|
+
;
|
519
|
+
time = false;
|
520
|
+
clearTimeout(module.performance.timer);
|
521
|
+
$.each(performance, function(index, data) {
|
522
|
+
totalTime += data['Execution Time'];
|
523
|
+
});
|
524
|
+
title += ' ' + totalTime + 'ms';
|
525
|
+
if(moduleSelector) {
|
526
|
+
title += ' \'' + moduleSelector + '\'';
|
527
|
+
}
|
528
|
+
title += ' ' + '(' + $allDropdowns.size() + ')';
|
529
|
+
if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
|
530
|
+
console.groupCollapsed(title);
|
531
|
+
if(console.table) {
|
532
|
+
console.table(performance);
|
533
|
+
}
|
534
|
+
else {
|
535
|
+
$.each(performance, function(index, data) {
|
536
|
+
console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
|
537
|
+
});
|
538
|
+
}
|
539
|
+
console.groupEnd();
|
540
|
+
}
|
541
|
+
performance = [];
|
542
|
+
}
|
543
|
+
},
|
544
|
+
invoke: function(query, passedArguments, context) {
|
545
|
+
var
|
546
|
+
maxDepth,
|
547
|
+
found
|
548
|
+
;
|
549
|
+
passedArguments = passedArguments || queryArguments;
|
550
|
+
context = element || context;
|
551
|
+
if(typeof query == 'string' && instance !== undefined) {
|
552
|
+
query = query.split(/[\. ]/);
|
553
|
+
maxDepth = query.length - 1;
|
554
|
+
$.each(query, function(depth, value) {
|
555
|
+
if( $.isPlainObject( instance[value] ) && (depth != maxDepth) ) {
|
556
|
+
instance = instance[value];
|
557
|
+
}
|
558
|
+
else if( instance[value] !== undefined ) {
|
559
|
+
found = instance[value];
|
560
|
+
}
|
561
|
+
else {
|
562
|
+
module.error(error.method);
|
563
|
+
}
|
564
|
+
});
|
565
|
+
}
|
566
|
+
if ( $.isFunction( found ) ) {
|
567
|
+
return found.apply(context, passedArguments);
|
568
|
+
}
|
569
|
+
return found || false;
|
570
|
+
}
|
571
|
+
};
|
572
|
+
|
573
|
+
if(methodInvoked) {
|
574
|
+
if(instance === undefined) {
|
575
|
+
module.initialize();
|
576
|
+
}
|
577
|
+
module.invoke(query);
|
578
|
+
}
|
579
|
+
else {
|
580
|
+
if(instance !== undefined) {
|
581
|
+
module.destroy();
|
582
|
+
}
|
583
|
+
module.initialize();
|
584
|
+
}
|
585
|
+
})
|
586
|
+
;
|
587
|
+
|
588
|
+
return (invokedResponse)
|
589
|
+
? invokedResponse
|
590
|
+
: this
|
591
|
+
;
|
592
|
+
};
|
593
|
+
|
594
|
+
$.fn.chatroom.settings = {
|
595
|
+
|
596
|
+
name : 'Chat',
|
597
|
+
debug : false,
|
598
|
+
namespace : 'chat',
|
599
|
+
|
600
|
+
channel : 'present-chat',
|
601
|
+
|
602
|
+
onJoin : function(){},
|
603
|
+
onMessage : function(){},
|
604
|
+
onExpand : function(){},
|
605
|
+
onContract : function(){},
|
606
|
+
|
607
|
+
customEvents : {},
|
608
|
+
|
609
|
+
partingMessages : false,
|
610
|
+
userCount : true,
|
611
|
+
randomColor : true,
|
612
|
+
|
613
|
+
speed : 300,
|
614
|
+
easing : 'easeOutQuint',
|
615
|
+
|
616
|
+
// pixels from bottom of chat log that should trigger auto scroll to bottom
|
617
|
+
scrollArea : 9999,
|
618
|
+
|
619
|
+
endpoint : {
|
620
|
+
message : false,
|
621
|
+
authentication : false
|
622
|
+
},
|
623
|
+
|
624
|
+
error: {
|
625
|
+
method : 'The method you called is not defined',
|
626
|
+
endpoint : 'Please define a message and authentication endpoint.',
|
627
|
+
key : 'You must specify a pusher key and channel.',
|
628
|
+
pusher : 'You must include the Pusher library.'
|
629
|
+
},
|
630
|
+
|
631
|
+
className : {
|
632
|
+
expand : 'expand',
|
633
|
+
active : 'active',
|
634
|
+
hover : 'hover',
|
635
|
+
down : 'down',
|
636
|
+
loading : 'loading'
|
637
|
+
},
|
638
|
+
|
639
|
+
selector : {
|
640
|
+
userCount : '.actions .message',
|
641
|
+
userListButton : '.actions .list.button',
|
642
|
+
expandButton : '.actions .expand.button',
|
643
|
+
room : '.room',
|
644
|
+
userList : '.room .list',
|
645
|
+
log : '.room .log',
|
646
|
+
message : '.room .log .message',
|
647
|
+
author : '.room log .message .author',
|
648
|
+
messageInput : '.talk input',
|
649
|
+
messageButton : '.talk .send.button'
|
650
|
+
},
|
651
|
+
|
652
|
+
templates: {
|
653
|
+
|
654
|
+
userCount: function(number) {
|
655
|
+
return number + ' users in chat';
|
656
|
+
},
|
657
|
+
|
658
|
+
color: function(userID) {
|
659
|
+
var
|
660
|
+
colors = [
|
661
|
+
'#000000',
|
662
|
+
'#333333',
|
663
|
+
'#666666',
|
664
|
+
'#999999',
|
665
|
+
'#CC9999',
|
666
|
+
'#CC6666',
|
667
|
+
'#CC3333',
|
668
|
+
'#993333',
|
669
|
+
'#663333',
|
670
|
+
'#CC6633',
|
671
|
+
'#CC9966',
|
672
|
+
'#CC9933',
|
673
|
+
'#999966',
|
674
|
+
'#CCCC66',
|
675
|
+
'#99CC66',
|
676
|
+
'#669933',
|
677
|
+
'#669966',
|
678
|
+
'#33A3CC',
|
679
|
+
'#336633',
|
680
|
+
'#33CCCC',
|
681
|
+
'#339999',
|
682
|
+
'#336666',
|
683
|
+
'#336699',
|
684
|
+
'#6666CC',
|
685
|
+
'#9966CC',
|
686
|
+
'#333399',
|
687
|
+
'#663366',
|
688
|
+
'#996699',
|
689
|
+
'#993366',
|
690
|
+
'#CC6699'
|
691
|
+
]
|
692
|
+
;
|
693
|
+
return colors[ Math.floor( Math.random() * colors.length) ];
|
694
|
+
},
|
695
|
+
|
696
|
+
message: function(message) {
|
697
|
+
var
|
698
|
+
html = ''
|
699
|
+
;
|
700
|
+
if(message.user.isAdmin) {
|
701
|
+
message.user.color = '#55356A';
|
702
|
+
html += '<div class="admin message">';
|
703
|
+
html += '<span class="quirky ui flag team"></span>';
|
704
|
+
}
|
705
|
+
/*
|
706
|
+
else if(message.user.isPro) {
|
707
|
+
html += '<div class="indent message">';
|
708
|
+
html += '<span class="quirky ui flag pro"></span>';
|
709
|
+
}
|
710
|
+
*/
|
711
|
+
else {
|
712
|
+
html += '<div class="message">';
|
713
|
+
}
|
714
|
+
html += '<p>';
|
715
|
+
if(message.user.color !== undefined) {
|
716
|
+
html += '<span class="author" style="color: ' + message.user.color + ';">' + message.user.name + '</span>: ';
|
717
|
+
}
|
718
|
+
else {
|
719
|
+
html += '<span class="author">' + message.user.name + '</span>: ';
|
720
|
+
}
|
721
|
+
html += ''
|
722
|
+
+ message.text
|
723
|
+
+ ' </p>'
|
724
|
+
+ '</div>'
|
725
|
+
;
|
726
|
+
return html;
|
727
|
+
},
|
728
|
+
|
729
|
+
joined: function(member) {
|
730
|
+
return (typeof member.name !== undefined)
|
731
|
+
? '<div class="status">' + member.name + ' has joined the chat.</div>'
|
732
|
+
: false
|
733
|
+
;
|
734
|
+
},
|
735
|
+
left: function(member) {
|
736
|
+
return (typeof member.name !== undefined)
|
737
|
+
? '<div class="status">' + member.name + ' has left the chat.</div>'
|
738
|
+
: false
|
739
|
+
;
|
740
|
+
},
|
741
|
+
|
742
|
+
userList: function(member) {
|
743
|
+
var
|
744
|
+
html = ''
|
745
|
+
;
|
746
|
+
if(member.isAdmin) {
|
747
|
+
member.color = '#55356A';
|
748
|
+
}
|
749
|
+
html += ''
|
750
|
+
+ '<div class="user" data-id="' + member.id + '">'
|
751
|
+
+ ' <div class="image">'
|
752
|
+
+ ' <img src="' + member.avatarURL + '">'
|
753
|
+
+ ' </div>'
|
754
|
+
;
|
755
|
+
if(member.color !== undefined) {
|
756
|
+
html += ' <p><a href="/users/' + member.id + '" target="_blank" style="color: ' + member.color + ';">' + member.name + '</a></p>';
|
757
|
+
}
|
758
|
+
else {
|
759
|
+
html += ' <p><a href="/users/' + member.id + '" target="_blank">' + member.name + '</a></p>';
|
760
|
+
}
|
761
|
+
html += '</div>';
|
762
|
+
return html;
|
763
|
+
}
|
764
|
+
|
765
|
+
}
|
766
|
+
|
767
|
+
};
|
768
|
+
|
769
|
+
})( jQuery, window , document );
|