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