summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--static/js/pichat.js123
1 files changed, 77 insertions, 46 deletions
diff --git a/static/js/pichat.js b/static/js/pichat.js
index 5259be5..5163a2d 100644
--- a/static/js/pichat.js
+++ b/static/js/pichat.js
@@ -231,8 +231,16 @@ Youtube = {
function getUriType(uri){
if (PicRegex.test(uri.file.toLowerCase()))
return "image";
-
- if (parseDomain(uri.host) == "youtube.com" && ('v' in uri.queryKey || uri.anchor.indexOf('v') != -1))
+
+ var domain = parseDomain(uri.host)
+
+ if (domain == "gstatic" && uri.path == "/images" && 'q' in uri.queryKey)
+ return "image";
+
+ // actual image url = uri.queryKey['q'].split(":").slice(2).join(":") but often the original image is broken...
+
+
+ if (domain == "youtube" && ('v' in uri.queryKey || uri.anchor.indexOf('v') != -1))
return "youtube";
if (uri.path.substr(-4) == ".mid" || uri.path.substr(-5) == ".midi")
@@ -423,50 +431,61 @@ function invalidImageDomain(content) {
}
}
+function clearMessages(){
+ track('UI', 'ClearScreen');
+ $('.dump').remove();
+}
+
function submitMessage() {
- var content = $.trim($('#msgInput').val());
+ var content = $.trim($('#msgInput').val());
+
+ if (content == "/clear") {
+ clearMessages()
+ $('#msgInput').val('');
+ return;
+ }
- var invalidDomain = invalidImageDomain(content);
- if (invalidDomain) {
- $('#msgInput').blur(); // Remove focus to prevent FF alert loop
- alert("Sorry, cannot accept images from " + invalidDomain + ". Maybe host the image elsewhere?");
- return;
- }
+ var invalidDomain = invalidImageDomain(content);
+ if (invalidDomain) {
+ $('#msgInput').blur(); // Remove focus to prevent FF alert loop
+ alert("Sorry, cannot accept images from " + invalidDomain + ". Maybe host the image elsewhere?");
+ return;
+ }
- $('#msgInput').val('');
- if (content == '') { return; }
- if (content.length > 2468) {
- alert("POST TOO LONG DUDE!");
- return;
- } // this shouldn't just be client side :V
- PendingMessages[content] = true;
+ $('#msgInput').val('');
+ if (content == '') { return; }
+ if (content.length > 2468) {
+ alert("POST TOO LONG DUDE!");
+ return;
+ } // this shouldn't just be client side :V
+ PendingMessages[content] = true;
- var msg = { 'nick': Nick, 'content': content };
- var div = addNewMessage(msg, true);
+ var msg = { 'nick': Nick, 'content': content };
+ var div = addNewMessage(msg, true);
- var onSuccess = function(json) {
- if (typeof pageTracker !== 'undefined') {
- pageTracker._trackEvent('Message', 'Submit',
- typeof Room !== 'undefined' ? Room : 'UnknownRoom');
- }
- div.attr('id', 'message-' + json)
- .removeClass('loading').addClass('loaded');
- };
- var onError = function(resp, textStatus, errorThrown) {
- div.remove();
- handleMsgError(resp);
- };
+ var onSuccess = function(json) {
+ if (typeof pageTracker !== 'undefined') {
+ pageTracker._trackEvent('Message', 'Submit',
+ typeof Room !== 'undefined' ? Room : 'UnknownRoom');
+ }
+ div.attr('id', 'message-' + json)
+ .removeClass('loading').addClass('loaded');
+ };
+ var onError = function(resp, textStatus, errorThrown) {
+ div.remove();
+ handleMsgError(resp);
+ };
- $.ajax({
- type: 'POST',
- timeout: 15000,
- url: '/msg',
- data: { 'room': Room, 'content': content },
- cache: false,
- dataType: 'json',
- success: onSuccess,
- error: onError
- });
+ $.ajax({
+ type: 'POST',
+ timeout: 15000,
+ url: '/msg',
+ data: { 'room': Room, 'content': content },
+ cache: false,
+ dataType: 'json',
+ success: onSuccess,
+ error: onError
+ });
}
function ifEnter(fn) {
@@ -1205,11 +1224,13 @@ var Search = {
'closed': true,
'initFullpage': function(){
+ Search.type = "fullpage"
Search.init()
Search.initSpaceFill = Search.initSpaceFillFullpage
},
'initInpage': function(){
+ Search.type = "inpage"
Search.init()
Search.initSpaceFill = Search.initSpaceFillInpage
},
@@ -1253,7 +1274,7 @@ var Search = {
"height": $(document).height(),
"type": "columns",
"spacing": "justify",
- "minMargin": 16,
+ "minMargin": 8,
"columnWidth": 120
})
},
@@ -1293,10 +1314,17 @@ var Search = {
var width = img.width
var height = img.height
- if (width > SpaceFill.config.columnWidth) {
- scaleFactor = SpaceFill.config.columnWidth / width
- width = SpaceFill.config.columnWidth
+ var maxWidth = SpaceFill.config.columnWidth
+ var maxHeight = Math.floor(SpaceFill.config.columnWidth * 1.2)
+
+ if (width > maxWidth) {
+ scaleFactor = maxWidth / width
+ width = maxWidth
height = Math.floor(height * scaleFactor)
+ } else if (height > maxHeight) {
+ scaleFactor = maxHeight / height
+ height = maxHeight
+ width = Math.floor(width * scaleFactor)
}
img.adjWidth = width
img.adjHeight = height
@@ -1571,8 +1599,11 @@ parseUri.options = {
};
// end parseUri
+// this doesn't properly deal with eg, .gov.uk .co.ck etc
function parseDomain(host){
- return host.toLowerCase().replace(/^www\./, "")
+ var chunks = host.split(".")
+ if (chunks.length == 1) return chunks[0]
+ else return chunks[chunks.length - 2]
}
var Away = {
@@ -1849,4 +1880,4 @@ var SHA1 = {
return (msw << 16) | (lsw & 0xFFFF);
},
"bit_rol": function(num, cnt) { return (num << cnt) | (num >>> (32 - cnt)) }
-} \ No newline at end of file
+}