2017-08-18 12:16:56 +00:00
'use strict' ;
2017-01-31 05:13:38 +00:00
var form _vars = { } ;
2017-06-10 07:58:15 +00:00
var alertList = [ ] ;
var alertCount = 0 ;
2017-06-12 09:03:14 +00:00
var conn ;
2017-01-31 05:13:38 +00:00
2016-12-02 07:38:54 +00:00
function post _link ( event )
{
event . preventDefault ( ) ;
var form _action = $ ( event . target ) . closest ( 'a' ) . attr ( "href" ) ;
2017-02-16 06:47:55 +00:00
//console.log("Form Action: " + form_action);
2017-03-01 11:36:50 +00:00
$ . ajax ( { url : form _action , type : "POST" , dataType : "json" , data : { js : "1" } } ) ;
2016-12-02 07:38:54 +00:00
}
2017-08-18 12:16:56 +00:00
function bind _to _alerts ( ) {
$ ( ".alertItem.withAvatar a" ) . click ( function ( event ) {
event . stopPropagation ( ) ;
$ . ajax ( { url : "/api/?action=set&module=dismiss-alert" , type : "POST" , dataType : "json" , data : { asid : $ ( this ) . attr ( "data-asid" ) } } ) ;
} ) ;
}
2017-09-10 16:57:22 +00:00
// TODO: Add the ability for users to dismiss alerts
2017-03-03 16:28:49 +00:00
function load _alerts ( menu _alerts )
{
2017-08-15 13:47:56 +00:00
var alertListNode = menu _alerts . getElementsByClassName ( "alertList" ) [ 0 ] ;
var alertCounterNode = menu _alerts . getElementsByClassName ( "alert_counter" ) [ 0 ] ;
2017-08-17 11:13:49 +00:00
alertCounterNode . textContent = "0" ;
2017-03-03 16:28:49 +00:00
$ . ajax ( {
type : 'get' ,
dataType : 'json' ,
2017-08-18 12:16:56 +00:00
url : '/api/?action=get&module=alerts' ,
2017-03-03 16:28:49 +00:00
success : function ( data ) {
if ( "errmsg" in data ) {
2017-08-15 13:47:56 +00:00
alertListNode . innerHTML = "<div class='alertItem'>" + data . errmsg + "</div>" ;
2017-03-03 16:28:49 +00:00
return ;
}
2017-05-29 14:52:37 +00:00
2017-03-03 16:28:49 +00:00
var alist = "" ;
2017-06-05 11:57:27 +00:00
var anyAvatar = false
2017-03-03 16:28:49 +00:00
for ( var i in data . msgs ) {
var msg = data . msgs [ i ] ;
var mmsg = msg . msg ;
2017-05-29 14:52:37 +00:00
2017-03-03 16:28:49 +00:00
if ( "sub" in msg ) {
for ( var i = 0 ; i < msg . sub . length ; i ++ ) {
mmsg = mmsg . replace ( "\{" + i + "\}" , msg . sub [ i ] ) ;
2017-06-05 11:57:27 +00:00
//console.log("Sub #" + i);
//console.log(msg.sub[i]);
2017-03-03 16:28:49 +00:00
}
}
2017-05-29 14:52:37 +00:00
2017-06-10 07:58:15 +00:00
if ( "avatar" in msg ) {
2017-08-18 12:16:56 +00:00
alist += "<div class='alertItem withAvatar' style='background-image:url(\"" + msg . avatar + "\");'><a class='text' data-asid='" + msg . asid + "' href=\"" + msg . path + "\">" + mmsg + "</a></div>" ;
alertList . push ( "<div class='alertItem withAvatar' style='background-image:url(\"" + msg . avatar + "\");'><a class='text' data-asid='" + msg . asid + "' href=\"" + msg . path + "\">" + mmsg + "</a></div>" ) ;
2017-06-05 11:57:27 +00:00
anyAvatar = true
2017-06-10 07:58:15 +00:00
} else {
alist += "<div class='alertItem'><a href=\"" + msg . path + "\" class='text'>" + mmsg + "</a></div>" ;
alertList . push ( "<div class='alertItem'><a href=\"" + msg . path + "\" class='text'>" + mmsg + "</a></div>" ) ;
2017-03-03 16:28:49 +00:00
}
2017-06-05 11:57:27 +00:00
//console.log(msg);
2017-03-03 16:28:49 +00:00
//console.log(mmsg);
}
2017-05-29 14:52:37 +00:00
if ( alist == "" ) alist = "<div class='alertItem'>You don't have any alerts</div>" ;
2017-06-05 11:57:27 +00:00
else {
//menu_alerts.removeClass("hasAvatars");
//if(anyAvatar) menu_alerts.addClass("hasAvatars");
2017-03-03 16:28:49 +00:00
}
2017-08-15 13:47:56 +00:00
alertListNode . innerHTML = alist ;
2017-08-17 11:13:49 +00:00
if ( data . msgCount != 0 && data . msgCount != undefined ) {
2017-08-15 13:47:56 +00:00
alertCounterNode . textContent = data . msgCount ;
menu _alerts . classList . add ( "has_alerts" ) ;
} else {
menu _alerts . classList . remove ( "has_alerts" ) ;
}
2017-06-10 07:58:15 +00:00
alertCount = data . msgCount ;
2017-08-18 12:16:56 +00:00
bind _to _alerts ( ) ;
2017-03-03 16:28:49 +00:00
} ,
error : function ( magic , theStatus , error ) {
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
var errtxt
2017-03-03 16:28:49 +00:00
try {
var data = JSON . parse ( magic . responseText ) ;
2017-06-05 11:57:27 +00:00
if ( "errmsg" in data ) errtxt = data . errmsg ;
2017-05-29 14:52:37 +00:00
else errtxt = "Unable to get the alerts" ;
2017-06-10 07:58:15 +00:00
} catch ( err ) {
errtxt = "Unable to get the alerts" ;
console . log ( magic . responseText ) ;
console . log ( err ) ;
}
2017-08-15 13:47:56 +00:00
alertListNode . innerHTML = "<div class='alertItem'>" + errtxt + "</div>" ;
2017-03-03 16:28:49 +00:00
}
} ) ;
}
2017-08-15 13:47:56 +00:00
function SplitN ( data , ch , n ) {
var out = [ ] ;
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
if ( data . length === 0 ) return out ;
2017-08-15 13:47:56 +00:00
var lastIndex = 0 ;
var j = 0 ;
var lastN = 1 ;
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
for ( let i = 0 ; i < data . length ; i ++ ) {
if ( data [ i ] === ch ) {
2017-08-15 13:47:56 +00:00
out [ j ++ ] = data . substring ( lastIndex , i ) ;
lastIndex = i ;
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
if ( lastN === n ) break ;
2017-08-15 13:47:56 +00:00
lastN ++ ;
2017-05-11 13:04:43 +00:00
}
}
2017-08-15 13:47:56 +00:00
if ( data . length > lastIndex ) out [ out . length - 1 ] += data . substring ( lastIndex ) ;
return out ;
}
2017-05-29 14:52:37 +00:00
2017-08-15 13:47:56 +00:00
$ ( document ) . ready ( function ( ) {
2017-05-11 13:04:43 +00:00
if ( window [ "WebSocket" ] ) {
2017-08-06 15:22:18 +00:00
if ( window . location . protocol == "https:" )
conn = new WebSocket ( "wss://" + document . location . host + "/ws/" ) ;
else conn = new WebSocket ( "ws://" + document . location . host + "/ws/" ) ;
2017-08-15 13:47:56 +00:00
2017-05-11 13:04:43 +00:00
conn . onopen = function ( ) {
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
console . log ( "The WebSockets connection was opened" ) ;
2017-05-29 14:52:37 +00:00
conn . send ( "page " + document . location . pathname + '\r' ) ;
2017-09-10 16:57:22 +00:00
// TODO: Don't ask again, if it's denied. We could have a setting in the UCP which automatically requests this when someone flips desktop notifications on
2017-08-17 11:13:49 +00:00
Notification . requestPermission ( ) ;
2017-05-11 13:04:43 +00:00
}
conn . onclose = function ( ) {
2017-05-29 14:52:37 +00:00
conn = false ;
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
console . log ( "The WebSockets connection was closed" ) ;
2017-05-11 13:04:43 +00:00
}
conn . onmessage = function ( event ) {
2017-06-10 07:58:15 +00:00
//console.log("WS_Message: ",event.data);
if ( event . data [ 0 ] == "{" ) {
try {
var data = JSON . parse ( event . data ) ;
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
} catch ( err ) {
console . log ( err ) ;
}
2017-06-10 07:58:15 +00:00
if ( "msg" in data ) {
var msg = data . msg
2017-08-18 12:16:56 +00:00
if ( "sub" in data )
for ( var i = 0 ; i < data . sub . length ; i ++ )
2017-06-10 07:58:15 +00:00
msg = msg . replace ( "\{" + i + "\}" , data . sub [ i ] ) ;
2017-08-18 12:16:56 +00:00
if ( "avatar" in data ) alertList . push ( "<div class='alertItem withAvatar' style='background-image:url(\"" + data . avatar + "\");'><a class='text' data-asid='" + data . asid + "' href=\"" + data . path + "\">" + msg + "</a></div>" ) ;
2017-06-10 07:58:15 +00:00
else alertList . push ( "<div class='alertItem'><a href=\"" + data . path + "\" class='text'>" + msg + "</a></div>" ) ;
if ( alertList . length > 8 ) alertList . shift ( ) ;
//console.log("post alertList",alertList);
alertCount ++ ;
var alist = ""
2017-08-18 12:16:56 +00:00
for ( var i = 0 ; i < alertList . length ; i ++ ) alist += alertList [ i ] ;
2017-06-10 07:58:15 +00:00
//console.log(alist);
2017-09-10 16:57:22 +00:00
// TODO: Add support for other alert feeds like PM Alerts
2017-08-18 12:16:56 +00:00
var general _alerts = document . getElementById ( "general_alerts" ) ;
var alertListNode = general _alerts . getElementsByClassName ( "alertList" ) [ 0 ] ;
var alertCounterNode = general _alerts . getElementsByClassName ( "alert_counter" ) [ 0 ] ;
alertListNode . innerHTML = alist ;
alertCounterNode . textContent = alertCount ;
2017-08-17 11:13:49 +00:00
2017-09-10 16:57:22 +00:00
// TODO: Add some sort of notification queue to avoid flooding the end-user with notices?
// TODO: Use the site name instead of "Something Happened"
2017-08-17 11:13:49 +00:00
if ( Notification . permission === "granted" ) {
var n = new Notification ( "Something Happened" , {
body : msg ,
icon : data . avatar ,
} ) ;
setTimeout ( n . close . bind ( n ) , 8000 ) ;
}
2017-08-18 12:16:56 +00:00
bind _to _alerts ( ) ;
2017-06-10 07:58:15 +00:00
}
}
2017-05-29 14:52:37 +00:00
var messages = event . data . split ( '\r' ) ;
2017-05-11 13:04:43 +00:00
for ( var i = 0 ; i < messages . length ; i ++ ) {
2017-05-29 14:52:37 +00:00
//console.log("Message:");
//console.log(messages[i]);
2017-05-11 13:04:43 +00:00
if ( messages [ i ] . startsWith ( "set " ) ) {
2017-05-29 14:52:37 +00:00
//msgblocks = messages[i].split(' ',3);
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
let msgblocks = SplitN ( messages [ i ] , " " , 3 ) ;
2017-06-05 11:57:27 +00:00
if ( msgblocks . length < 3 ) continue ;
2017-05-29 14:52:37 +00:00
document . querySelector ( msgblocks [ 1 ] ) . innerHTML = msgblocks [ 2 ] ;
2017-05-11 13:04:43 +00:00
} else if ( messages [ i ] . startsWith ( "set-class " ) ) {
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
let msgblocks = SplitN ( messages [ i ] , " " , 3 ) ;
2017-06-05 11:57:27 +00:00
if ( msgblocks . length < 3 ) continue ;
2017-05-29 14:52:37 +00:00
document . querySelector ( msgblocks [ 1 ] ) . className = msgblocks [ 2 ] ;
2017-05-11 13:04:43 +00:00
}
}
}
}
2017-06-05 11:57:27 +00:00
else conn = false ;
2017-05-29 14:52:37 +00:00
2016-12-02 07:38:54 +00:00
$ ( ".open_edit" ) . click ( function ( event ) {
2017-08-18 15:56:36 +00:00
//console.log("clicked on .open_edit");
2016-12-02 07:38:54 +00:00
event . preventDefault ( ) ;
$ ( ".hide_on_edit" ) . hide ( ) ;
$ ( ".show_on_edit" ) . show ( ) ;
} ) ;
2017-05-29 14:52:37 +00:00
2017-01-31 05:13:38 +00:00
$ ( ".topic_item .submit_edit" ) . click ( function ( event ) {
2016-12-02 07:38:54 +00:00
event . preventDefault ( ) ;
2017-08-20 09:39:02 +00:00
//console.log("clicked on .topic_item .submit_edit");
2016-12-02 07:38:54 +00:00
$ ( ".topic_name" ) . html ( $ ( ".topic_name_input" ) . val ( ) ) ;
$ ( ".topic_content" ) . html ( $ ( ".topic_content_input" ) . val ( ) ) ;
$ ( ".topic_status_e:not(.open_edit)" ) . html ( $ ( ".topic_status_input" ) . val ( ) ) ;
2017-05-29 14:52:37 +00:00
2016-12-02 07:38:54 +00:00
$ ( ".hide_on_edit" ) . show ( ) ;
$ ( ".show_on_edit" ) . hide ( ) ;
2017-05-29 14:52:37 +00:00
2016-12-02 07:38:54 +00:00
var topic _name _input = $ ( '.topic_name_input' ) . val ( ) ;
var topic _status _input = $ ( '.topic_status_input' ) . val ( ) ;
var topic _content _input = $ ( '.topic_content_input' ) . val ( ) ;
2017-08-18 15:56:36 +00:00
var form _action = this . form . getAttribute ( "action" ) ;
2017-02-16 06:47:55 +00:00
//console.log("New Topic Name: " + topic_name_input);
//console.log("New Topic Status: " + topic_status_input);
2017-08-18 15:56:36 +00:00
//console.log("New Topic Content: " + topic_content_input);
2017-02-16 06:47:55 +00:00
//console.log("Form Action: " + form_action);
2016-12-02 07:38:54 +00:00
$ . ajax ( {
url : form _action ,
2017-05-29 14:52:37 +00:00
type : "POST" ,
dataType : "json" ,
2016-12-02 07:38:54 +00:00
data : {
topic _name : topic _name _input ,
topic _status : topic _status _input ,
topic _content : topic _content _input ,
topic _js : 1
2017-05-29 14:52:37 +00:00
}
2016-12-02 07:38:54 +00:00
} ) ;
} ) ;
2017-05-29 14:52:37 +00:00
2016-12-02 07:38:54 +00:00
$ ( ".delete_item" ) . click ( function ( event )
{
post _link ( event ) ;
var block = $ ( this ) . closest ( '.deletable_block' ) ;
block . remove ( ) ;
} ) ;
2017-05-29 14:52:37 +00:00
2016-12-02 07:38:54 +00:00
$ ( ".edit_item" ) . click ( function ( event )
{
event . preventDefault ( ) ;
var block _parent = $ ( this ) . closest ( '.editable_parent' ) ;
var block = block _parent . find ( '.editable_block' ) . eq ( 0 ) ;
2016-12-03 04:50:35 +00:00
block . html ( "<textarea style='width: 99%;' name='edit_item'>" + block . html ( ) + "</textarea><br /><a href='" + $ ( this ) . closest ( 'a' ) . attr ( "href" ) + "'><button class='submit_edit' type='submit'>Update</button></a>" ) ;
2017-05-29 14:52:37 +00:00
2016-12-02 07:38:54 +00:00
$ ( ".submit_edit" ) . click ( function ( event )
{
event . preventDefault ( ) ;
var block _parent = $ ( this ) . closest ( '.editable_parent' ) ;
var block = block _parent . find ( '.editable_block' ) . eq ( 0 ) ;
var newContent = block . find ( 'textarea' ) . eq ( 0 ) . val ( ) ;
block . html ( newContent ) ;
2017-05-29 14:52:37 +00:00
2016-12-02 07:38:54 +00:00
var form _action = $ ( this ) . closest ( 'a' ) . attr ( "href" ) ;
2017-02-16 06:47:55 +00:00
//console.log("Form Action: " + form_action);
2017-09-03 04:50:31 +00:00
$ . ajax ( { url : form _action , type : "POST" , dataType : "json" , data : { isJs : "1" , edit _item : newContent }
2016-12-02 07:38:54 +00:00
} ) ;
} ) ;
} ) ;
2017-05-29 14:52:37 +00:00
2016-12-06 10:26:48 +00:00
$ ( ".edit_field" ) . click ( function ( event )
{
event . preventDefault ( ) ;
var block _parent = $ ( this ) . closest ( '.editable_parent' ) ;
var block = block _parent . find ( '.editable_block' ) . eq ( 0 ) ;
block . html ( "<input name='edit_field' value='" + block . text ( ) + "' type='text'/><a href='" + $ ( this ) . closest ( 'a' ) . attr ( "href" ) + "'><button class='submit_edit' type='submit'>Update</button></a>" ) ;
2017-05-29 14:52:37 +00:00
2016-12-06 10:26:48 +00:00
$ ( ".submit_edit" ) . click ( function ( event )
{
event . preventDefault ( ) ;
var block _parent = $ ( this ) . closest ( '.editable_parent' ) ;
var block = block _parent . find ( '.editable_block' ) . eq ( 0 ) ;
var newContent = block . find ( 'input' ) . eq ( 0 ) . val ( ) ;
block . html ( newContent ) ;
2017-05-29 14:52:37 +00:00
2016-12-06 10:26:48 +00:00
var form _action = $ ( this ) . closest ( 'a' ) . attr ( "href" ) ;
2017-02-16 06:47:55 +00:00
//console.log("Form Action: " + form_action);
2016-12-06 10:26:48 +00:00
$ . ajax ( {
url : form _action + "?session=" + session ,
type : "POST" ,
dataType : "json" ,
2017-09-03 04:50:31 +00:00
data : { isJs : "1" , edit _item : newContent }
2016-12-06 10:26:48 +00:00
} ) ;
} ) ;
} ) ;
2017-05-29 14:52:37 +00:00
2017-01-31 05:13:38 +00:00
$ ( ".edit_fields" ) . click ( function ( event )
{
event . preventDefault ( ) ;
2017-08-27 09:33:45 +00:00
if ( $ ( this ) . find ( "input" ) . length !== 0 ) return ;
2017-05-29 14:52:37 +00:00
//console.log("clicked .edit_fields");
2017-01-31 05:13:38 +00:00
var block _parent = $ ( this ) . closest ( '.editable_parent' ) ;
2017-05-29 14:52:37 +00:00
//console.log(block_parent);
2017-01-31 05:13:38 +00:00
block _parent . find ( '.hide_on_edit' ) . hide ( ) ;
2017-06-06 08:47:33 +00:00
block _parent . find ( '.show_on_edit' ) . show ( ) ;
2017-01-31 05:13:38 +00:00
block _parent . find ( '.editable_block' ) . show ( ) ;
block _parent . find ( '.editable_block' ) . each ( function ( ) {
2017-02-16 06:47:55 +00:00
var field _name = this . getAttribute ( "data-field" ) ;
var field _type = this . getAttribute ( "data-type" ) ;
2017-05-29 14:52:37 +00:00
if ( field _type == "list" )
{
2017-02-16 06:47:55 +00:00
var field _value = this . getAttribute ( "data-value" ) ;
2017-01-31 05:13:38 +00:00
if ( field _name in form _vars ) var it = form _vars [ field _name ] ;
else var it = [ 'No' , 'Yes' ] ;
var itLen = it . length ;
var out = "" ;
2017-05-29 14:52:37 +00:00
//console.log("Field Name '" + field_name + "'")
//console.log("Field Type",field_type)
//console.log("Field Value '" + field_value + "'")
2017-06-05 11:57:27 +00:00
for ( var i = 0 ; i < itLen ; i ++ ) {
2017-09-25 00:48:35 +00:00
var sel = "" ;
2017-05-29 14:52:37 +00:00
if ( field _value == i || field _value == it [ i ] ) {
sel = "selected " ;
this . classList . remove ( field _name + '_' + it [ i ] ) ;
this . innerHTML = "" ;
2017-09-25 00:48:35 +00:00
}
2017-01-31 05:13:38 +00:00
out += "<option " + sel + "value='" + i + "'>" + it [ i ] + "</option>" ;
}
2017-06-05 11:57:27 +00:00
this . innerHTML = "<select data-field='" + field _name + "' name='" + field _name + "'>" + out + "</select>" ;
2017-01-31 05:13:38 +00:00
}
2017-06-05 11:57:27 +00:00
else if ( field _type == "hidden" ) { }
else this . innerHTML = "<input name='" + field _name + "' value='" + this . textContent + "' type='text'/>" ;
2017-01-31 05:13:38 +00:00
} ) ;
2017-05-29 14:52:37 +00:00
// Remove any handlers already attached to the submitter
$ ( ".submit_edit" ) . unbind ( "click" ) ;
2017-01-31 05:13:38 +00:00
$ ( ".submit_edit" ) . click ( function ( event )
{
event . preventDefault ( ) ;
2017-05-29 14:52:37 +00:00
//console.log("running .submit_edit event");
2017-09-03 04:50:31 +00:00
var out _data = { isJs : "1" }
2017-01-31 05:13:38 +00:00
var block _parent = $ ( this ) . closest ( '.editable_parent' ) ;
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
block _parent . find ( '.editable_block' ) . each ( function ( ) {
2017-02-16 06:47:55 +00:00
var field _name = this . getAttribute ( "data-field" ) ;
var field _type = this . getAttribute ( "data-type" ) ;
2017-06-05 11:57:27 +00:00
if ( field _type == "list" ) {
2017-05-29 14:52:37 +00:00
var newContent = $ ( this ) . find ( 'select :selected' ) . text ( ) ;
this . classList . add ( field _name + '_' + newContent ) ;
this . innerHTML = "" ;
2017-06-05 11:57:27 +00:00
} else if ( field _type == "hidden" ) {
var newContent = $ ( this ) . val ( ) ;
2017-05-29 14:52:37 +00:00
} else {
var newContent = $ ( this ) . find ( 'input' ) . eq ( 0 ) . val ( ) ;
this . innerHTML = newContent ;
}
this . setAttribute ( "data-value" , newContent ) ;
out _data [ field _name ] = newContent ;
2017-01-31 05:13:38 +00:00
} ) ;
2017-05-29 14:52:37 +00:00
2017-01-31 05:13:38 +00:00
var form _action = $ ( this ) . closest ( 'a' ) . attr ( "href" ) ;
2017-02-16 06:47:55 +00:00
//console.log("Form Action: " + form_action);
//console.log(out_data);
2017-01-31 05:13:38 +00:00
$ . ajax ( { url : form _action + "?session=" + session , type : "POST" , dataType : "json" , data : out _data } ) ;
block _parent . find ( '.hide_on_edit' ) . show ( ) ;
block _parent . find ( '.show_on_edit' ) . hide ( ) ;
} ) ;
} ) ;
2017-05-29 14:52:37 +00:00
2017-08-18 12:16:56 +00:00
// This one's for Tempra Conflux
2017-09-10 16:57:22 +00:00
// TODO: We might want to use pure JS here
2017-02-16 06:47:55 +00:00
$ ( ".ip_item" ) . each ( function ( ) {
var ip = this . textContent ;
2017-01-17 07:55:46 +00:00
if ( ip . length > 10 ) {
2017-02-16 06:47:55 +00:00
this . innerHTML = "Show IP" ;
this . onclick = function ( event ) {
2017-01-17 07:55:46 +00:00
event . preventDefault ( ) ;
2017-02-16 06:47:55 +00:00
this . textContent = ip ;
} ;
2017-01-17 07:55:46 +00:00
}
} ) ;
2017-05-29 14:52:37 +00:00
2017-03-05 07:53:41 +00:00
$ ( this ) . click ( function ( ) {
2017-03-03 16:28:49 +00:00
$ ( ".selectedAlert" ) . removeClass ( "selectedAlert" ) ;
2017-06-05 11:57:27 +00:00
$ ( "#back" ) . removeClass ( "alertActive" ) ;
} ) ;
$ ( ".alert_bell" ) . click ( function ( ) {
var menu _alerts = $ ( this ) . parent ( ) ;
if ( menu _alerts . hasClass ( "selectedAlert" ) ) {
event . stopPropagation ( ) ;
menu _alerts . removeClass ( "selectedAlert" ) ;
$ ( "#back" ) . removeClass ( "alertActive" ) ;
}
2017-03-03 16:28:49 +00:00
} ) ;
2017-05-29 14:52:37 +00:00
2017-08-15 13:47:56 +00:00
var alert _menu _list = document . getElementsByClassName ( "menu_alerts" ) ;
for ( var i = 0 ; i < alert _menu _list . length ; i ++ ) {
load _alerts ( alert _menu _list [ i ] ) ;
}
2017-05-29 14:52:37 +00:00
2017-03-01 11:36:50 +00:00
$ ( ".menu_alerts" ) . click ( function ( event ) {
2017-03-03 16:28:49 +00:00
event . stopPropagation ( ) ;
2017-03-01 11:36:50 +00:00
if ( $ ( this ) . hasClass ( "selectedAlert" ) ) return ;
2017-08-15 13:47:56 +00:00
if ( ! conn ) load _alerts ( this ) ;
2017-06-05 11:57:27 +00:00
this . className += " selectedAlert" ;
document . getElementById ( "back" ) . className += " alertActive"
2017-03-01 11:36:50 +00:00
} ) ;
2017-05-29 14:52:37 +00:00
2017-06-16 10:41:30 +00:00
$ ( "input,textarea,select,option" ) . keyup ( function ( event ) {
event . stopPropagation ( ) ;
} )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
$ ( ".create_topic_link" ) . click ( function ( event ) {
event . preventDefault ( ) ;
$ ( ".topic_create_form" ) . show ( ) ;
} ) ;
$ ( ".topic_create_form .close_form" ) . click ( function ( ) {
event . preventDefault ( ) ;
$ ( ".topic_create_form" ) . hide ( ) ;
} ) ;
function uploadFileHandler ( ) {
var fileList = this . files ;
// Truncate the number of files to 5
let files = [ ] ;
for ( var i = 0 ; i < fileList . length && i < 5 ; i ++ )
files [ i ] = fileList [ i ] ;
// Iterate over the files
for ( let i = 0 ; i < files . length ; i ++ ) {
console . log ( "files[" + i + "]" , files [ i ] ) ;
let reader = new FileReader ( ) ;
reader . onload = function ( e ) {
var fileDock = document . getElementById ( "upload_file_dock" ) ;
var fileItem = document . createElement ( "label" ) ;
console . log ( "fileItem" , fileItem ) ;
if ( ! files [ i ] [ "name" ] . indexOf ( '.' > - 1 ) ) {
// TODO: Surely, there's a prettier and more elegant way of doing this?
alert ( "This file doesn't have an extension" ) ;
return ;
}
var ext = files [ i ] [ "name" ] . split ( '.' ) . pop ( ) ;
fileItem . innerText = "." + ext ;
fileItem . className = "formbutton uploadItem" ;
fileItem . style . backgroundImage = "url(" + e . target . result + ")" ;
fileDock . appendChild ( fileItem ) ;
let reader = new FileReader ( ) ;
reader . onload = function ( e ) {
crypto . subtle . digest ( 'SHA-256' , e . target . result ) . then ( function ( hash ) {
const hashArray = Array . from ( new Uint8Array ( hash ) )
return hashArray . map ( b => ( '00' + b . toString ( 16 ) ) . slice ( - 2 ) ) . join ( '' )
} ) . then ( function ( hash ) {
console . log ( "hash" , hash ) ;
let content = document . getElementById ( "topic_content" )
console . log ( "content.value" , content . value ) ;
if ( content . value == "" ) content . value = content . value + "//" + siteURL + "/attachs/" + hash + "." + ext ;
else content . value = content . value + "\r\n//" + siteURL + "/attachs/" + hash + "." + ext ;
console . log ( "content.value" , content . value ) ;
} ) ;
}
reader . readAsArrayBuffer ( files [ i ] ) ;
}
reader . readAsDataURL ( files [ i ] ) ;
}
}
var uploadFiles = document . getElementById ( "quick_topic_upload_files" ) ;
if ( uploadFiles != null ) {
uploadFiles . addEventListener ( "change" , uploadFileHandler , false ) ;
}
2017-09-10 16:57:22 +00:00
$ ( "#themeSelectorSelect" ) . change ( function ( ) {
console . log ( "Changing the theme to " + this . options [ this . selectedIndex ] . getAttribute ( "val" ) ) ;
$ . ajax ( {
url : this . form . getAttribute ( "action" ) + "?session=" + session ,
type : "POST" ,
dataType : "json" ,
data : { "newTheme" : this . options [ this . selectedIndex ] . getAttribute ( "val" ) , isJs : "1" } ,
success : function ( data , status , xhr ) {
console . log ( "Theme successfully switched" ) ;
console . log ( "data" , data ) ;
console . log ( "status" , status ) ;
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
console . log ( "xhr" , xhr ) ;
2017-09-10 16:57:22 +00:00
window . location . reload ( ) ;
} ,
// TODO: Use a standard error handler for the AJAX calls in here which throws up the response (if JSON) in a .notice? Might be difficult to trace errors in the console, if we reuse the same function every-time
error : function ( xhr , status , errstr ) {
console . log ( "The AJAX request failed" ) ;
console . log ( "xhr" , xhr ) ;
console . log ( "status" , status ) ;
console . log ( "errstr" , errstr ) ;
if ( status == "parsererror" ) {
console . log ( "The server didn't respond with a valid JSON response" ) ;
}
}
} ) ;
} ) ;
2017-06-16 10:41:30 +00:00
this . onkeyup = function ( event ) {
2017-02-16 06:47:55 +00:00
if ( event . which == 37 ) this . querySelectorAll ( "#prevFloat a" ) [ 0 ] . click ( ) ;
if ( event . which == 39 ) this . querySelectorAll ( "#nextFloat a" ) [ 0 ] . click ( ) ;
} ;
2017-05-29 14:52:37 +00:00
} ) ;