Calgarypuck Forums - The Unofficial Calgary Flames Fan Community
Old 01-24-2018, 09:04 PM   #1
photon
The new goggles also do nothing.
 
photon's Avatar
 
Join Date: Oct 2001
Location: Calgary
Exp:
Default Any Javascript gurus?

I added some Javascript from twitter that converts some HTML code into a full tweet.

https://twitter.com/user/status/952218108948811776

The only problem I don't like is using the quick reply or editing the post, it doesn't work since the javascript code is triggered with a window.onload.

But I'm not a javascript expert, is there any way I could change it so that it would also be triggered if someone uses the quick reply box to post a new post or edit an existing post?

Not that it matters much, just kind of weird that the embedded tweet doesn't show up in a first post.
__________________
Uncertainty is an uncomfortable position.
But certainty is an absurd one.
photon is offline   Reply With Quote
Old 01-25-2018, 10:15 AM   #2
psyang
Powerplay Quarterback
 
Join Date: Jan 2010
Exp:
Default

Quote:
Originally Posted by photon View Post
I added some Javascript from twitter that converts some HTML code into a full tweet.

https://twitter.com/user/status/952218108948811776

The only problem I don't like is using the quick reply or editing the post, it doesn't work since the javascript code is triggered with a window.onload.

But I'm not a javascript expert, is there any way I could change it so that it would also be triggered if someone uses the quick reply box to post a new post or edit an existing post?

Not that it matters much, just kind of weird that the embedded tweet doesn't show up in a first post.
It should be possible. I'm guessing "quick reply" makes an ajax call to the server to submit the new post, then dynamically updates the page when it gets the call's response. There is no page refresh, so no windows.onload event is triggered.

So, depending on what vBulletin allows, the simplest thing to do is trigger the twitter javascript on the callback from the post submission ajax call.
psyang is offline   Reply With Quote
The Following User Says Thank You to psyang For This Useful Post:
Old 01-25-2018, 10:25 AM   #3
CaptainCrunch
Norm!
 
CaptainCrunch's Avatar
 
Join Date: Jun 2002
Exp:
Default

10 Rem *This is not the answer you are looking for Joshua*
20 Print "Do you want to play a game"
30 Input answer$
40) If answer$ = "Y" goto 100 rem*answer Y sends program to launch nuclear missiles library*
30 cls
40 Goto 20
__________________
My name is Ozymandias, King of Kings;

Look on my Works, ye Mighty, and despair!
CaptainCrunch is offline   Reply With Quote
The Following User Says Thank You to CaptainCrunch For This Useful Post:
Old 01-25-2018, 10:50 AM   #4
psyang
Powerplay Quarterback
 
Join Date: Jan 2010
Exp:
Default

Quote:
Originally Posted by CaptainCrunch View Post
10 Rem *This is not the answer you are looking for Joshua*
20 Print "Do you want to play a game"
30 Input answer$
40) If answer$ = "Y" goto 100 rem*answer Y sends program to launch nuclear missiles library*
30 cls
40 Goto 20
I was with you until you used CLS instead of HOME to clear the screen. You must have been a Commodore guy, not an Apple guy. And I was starting to like you

This sent me down memory lane a little - the computer in Wargames was an IMSAI microcomputer that ran CP/M. Looking for what the clear screen command would have been for that computer, I found that there are a few different BASIC interpreters available for CP/M. At the end of the the link is a brief description of the Super Star Trek game. I remember finding the listing for this game somewhere, and reading through it. It was one of the games that sparked my love for programming - the text-based map display blew me away.
psyang is offline   Reply With Quote
Old 01-25-2018, 10:56 AM   #5
psyang
Powerplay Quarterback
 
Join Date: Jan 2010
Exp:
Default

Quote:
Originally Posted by psyang View Post
I was with you until you used CLS instead of HOME to clear the screen. You must have been a Commodore guy, not an Apple guy. And I was starting to like you

This sent me down memory lane a little - the computer in Wargames was an IMSAI microcomputer that ran CP/M. Looking for what the clear screen command would have been for that computer, I found that there are a few different BASIC interpreters available for CP/M. At the end of the the link is a brief description of the Super Star Trek game. I remember finding the listing for this game somewhere, and reading through it. It was one of the games that sparked my love for programming - the text-based map display blew me away.
Oh man, sorry for going way off topic, but I had a hazy recollection of where I saw the Star Trek code listing. I had this old yellow book that just had listings of BASIC computer games. For some reason, I thought the author was related to the Amdahl computer. So I did a google search, and found it!

Basic Computer Games by David Ahl (not related to Amdahl). Looking at the table of contents picture, I see Super Star Trek in there. I typed in many of the games from the book into my Apple IIe, and it taught me that there were different "dialects" of BASIC, so not all listings would work without modification. Super Star Trek I remember was really long - I think the font size was half the size of the other listings, and it still took pages to list, so I never tried typing it in, but I read through it, and learned a lot.
psyang is offline   Reply With Quote
Old 01-25-2018, 11:17 AM   #6
photon
The new goggles also do nothing.
 
photon's Avatar
 
Join Date: Oct 2001
Location: Calgary
Exp:
Default

Quote:
Originally Posted by psyang View Post
It should be possible. I'm guessing "quick reply" makes an ajax call to the server to submit the new post, then dynamically updates the page when it gets the call's response. There is no page refresh, so no windows.onload event is triggered.

So, depending on what vBulletin allows, the simplest thing to do is trigger the twitter javascript on the callback from the post submission ajax call.
Yeah, that's the part where I start to get out of my depth

I'll have to poke around and try and see where I can shoehorn it in.
__________________
Uncertainty is an uncomfortable position.
But certainty is an absurd one.
photon is offline   Reply With Quote
Old 01-25-2018, 11:27 AM   #7
CaptainCrunch
Norm!
 
CaptainCrunch's Avatar
 
Join Date: Jun 2002
Exp:
Default

Quote:
Originally Posted by psyang View Post
I was with you until you used CLS instead of HOME to clear the screen. You must have been a Commodore guy, not an Apple guy. And I was starting to like you

This sent me down memory lane a little - the computer in Wargames was an IMSAI microcomputer that ran CP/M. Looking for what the clear screen command would have been for that computer, I found that there are a few different BASIC interpreters available for CP/M. At the end of the the link is a brief description of the Super Star Trek game. I remember finding the listing for this game somewhere, and reading through it. It was one of the games that sparked my love for programming - the text-based map display blew me away.
I was a Commodore guy, I started with the 64, and then moved to the 128 and learned CP/M to go with basic. Then moved onto the Amiga. When I got the Amiga, I found a C compiler and learned C, it was amazing what you could do graphically and sound wise on an Amiga with C. I also found a Pascal and a Prolog compiler for the Amiga. Prolog was such a pain in the butt, but if you figured out decision tree's and decision logic, you could make some very cool apps.
__________________
My name is Ozymandias, King of Kings;

Look on my Works, ye Mighty, and despair!
CaptainCrunch is offline   Reply With Quote
Old 01-25-2018, 11:33 AM   #8
psyang
Powerplay Quarterback
 
Join Date: Jan 2010
Exp:
Default

Quote:
Originally Posted by photon View Post
Yeah, that's the part where I start to get out of my depth

I'll have to poke around and try and see where I can shoehorn it in.
Typically, the ajax call will have two callback functions - one that gets called on success, and one on failure. Hopefully it's easy to find each, and easy to modify the code for the success callback.

The one thing that can trip people up in javascript is understanding context - the "this" object will point to different contexts depending on when/where it is used. So variables/functions you expect to be available in one place may not be available elsewhere because the context has changed. But context is a first class citizen, and can be passed around too, which is cool, but can also be confusing.

Anyways, good luck!
psyang is offline   Reply With Quote
The Following User Says Thank You to psyang For This Useful Post:
Old 01-25-2018, 11:44 AM   #9
psyang
Powerplay Quarterback
 
Join Date: Jan 2010
Exp:
Default

Quote:
Originally Posted by CaptainCrunch View Post
I was a Commodore guy, I started with the 64, and then moved to the 128 and learned CP/M to go with basic. Then moved onto the Amiga. When I got the Amiga, I found a C compiler and learned C, it was amazing what you could do graphically and sound wise on an Amiga with C. I also found a Pascal and a Prolog compiler for the Amiga. Prolog was such a pain in the butt, but if you figured out decision tree's and decision logic, you could make some very cool apps.
Started on an Apple II in grade 6, then got an Apple IIe at home. There was a big Apple/Commodore rift in junior high as our computer lab had about a half dozen of each. Apple's floppy drive was infinitely faster than Commodore's, but I was jealous of Commodore's sprite support. So easy to animate graphics on a Commodore, as opposed to drawing/erasing/drawing everything on an Apple. Double buffering made the animation smooth, but was still a pain.

Then, strangely, I didn't touch a computer all through high school, and didn't even think about going into Comp Sci in university. Fortunately, first year I had to take a couple CS courses as part of my degree, and by third year, I had switched majors into CS and never looked back.

It was in University where I first encountered an Amiga - my roommate had one. I just remember playing a game on it where the winning move involved decapitating your opponent. My roommate said the game was banned in Germany or something like that. It was an incredible gaming computer.

Never learned Prolog - just read about it. I think the theory was you shouldn't have to know how a computer figures out something, you should just be able to ask it questions, and have it respond. Looks like modern AI is realizing this dream.

Ok, enough reminiscing - I have to get some work done
psyang is offline   Reply With Quote
Old 01-25-2018, 11:52 AM   #10
kermitology
It's not easy being green!
 
kermitology's Avatar
 
Join Date: Oct 2001
Location: In the tubes to Vancouver Island
Exp:
Default

Can you post what you're working with? It's easier to help when we see some samples.
__________________
Who is in charge of this product and why haven't they been fired yet?
kermitology is offline   Reply With Quote
Old 01-25-2018, 12:34 PM   #11
kermitology
It's not easy being green!
 
kermitology's Avatar
 
Join Date: Oct 2001
Location: In the tubes to Vancouver Island
Exp:
Default

Looking at the response of a quick reply, what happens is that it submits the content of the form from the message box to the server, which responds with a postbit template that the existing page appends to the post list. It also includes legacy posts (posts that occurred between the user's initial thread load and the quick reply). So you might try to add some kind of event handler to that action.
__________________
Who is in charge of this product and why haven't they been fired yet?
kermitology is offline   Reply With Quote
Old 01-25-2018, 01:07 PM   #12
psyang
Powerplay Quarterback
 
Join Date: Jan 2010
Exp:
Default

Ok, it looks like you want to add your twitter javascript in the qr_do_ajax_post function inside of vbulletin_quick_reply.js

The file is minimized, but you can try adding the function right after the string

Quote:
fetch_object("qr_submit").blur()
You should add a semi-colon after blur(), so it looks like:

Quote:
fetch_object("qr_submit").blur();myTwitterJavascri ptFunction();
Modifying vbulletin code directly is not good since the next update of vbulletin will wipe your change. One possibility is to add an onBlur event handler to the "Post Quick Reply" button (its id is "qr_submit"). The only issue here is if a user tabs so that the "Post Quick Reply" button is active, then tabs off of it, that will trigger the blur event, which will then run the javascript. Maybe not a big deal. Is it a problem if the javascript function is run more than once on a page?

Note, this will take care of the case when user submits a tweet via Post Quick Reply.

There will be another location for the javascript if the user edits a post. One second...

Last edited by psyang; 01-25-2018 at 01:21 PM. Reason: formatting
psyang is offline   Reply With Quote
Old 01-25-2018, 01:18 PM   #13
psyang
Powerplay Quarterback
 
Join Date: Jan 2010
Exp:
Default

I think if you add the javascript right after these lines in vbulletin_quick_edit.js

Quote:
vB_QuickEditor.restore(C.responseXML.getElementsBy TagName("postbit")[0].firstChild.nodeValue, "tableobj");
PostBit_Init(fetch_object("post" + vB_QuickEditor.postid), vB_QuickEditor.postid)
it should trigger after the user saves an edit. The problem is these lines appear twice in that file, so ignore the one which is preceded immediately by

Quote:
document.body.style.cursor = "auto";
as those lines occur after the user cancels an edit.

Note, you need to add a semicolon after ".postid)" above, just as for my previous post. Don't know why the semicolons are missing. So it should read:

Quote:
vB_QuickEditor.restore(C.responseXML.getElementsBy TagName("postbit")[0].firstChild.nodeValue, "tableobj");
PostBit_Init(fetch_object("post" + vB_QuickEditor.postid), vB_QuickEditor.postid);myTwitterJavascriptFunction ();

I hope you have a test area where you can test this, as I'd hate to be responsible for taking down the site with ill-advised suggestions

Last edited by psyang; 01-25-2018 at 01:20 PM.
psyang is offline   Reply With Quote
Old 01-25-2018, 01:26 PM   #14
photon
The new goggles also do nothing.
 
photon's Avatar
 
Join Date: Oct 2001
Location: Calgary
Exp:
Default

I had a test area, but I haven't updated it in a while, I should do that. I can also fork the template and use the fork so it only impacts me.

As far as I know running the twitter function more than once shouldn't be a problem, all it does is look for all the div tags with the id='tweet' and replaces those divs with the full tweet HTML for the tweet. So running it again would either catch any new div tags, or do nothing if there are none.

Thanks I'll take a look at what you've got here!
__________________
Uncertainty is an uncomfortable position.
But certainty is an absurd one.
photon is offline   Reply With Quote
Old 01-25-2018, 02:00 PM   #15
psyang
Powerplay Quarterback
 
Join Date: Jan 2010
Exp:
Default

If running the javascript function more than once is not an issue, you might look at just modifying the PostBit_Init function found in vbulletin_global.js. This seems to be called during the ajax responses (as well as at other times). That way, there is only one place to make a change, instead of multiple places. It will probably take care of other cases we aren't thinking of where ajax might be used as well.

Add the twitter function after the function "child_img_alt_2_title(C)" but before "function vBulletin_init()". It should look like:

Before:
Quote:
child_img_alt_2_title(C)}function vBulletin_init()
After:
Quote:
child_img_alt_2_title(C);myTwitterFunction();}func tion vBulletin_init()
psyang is offline   Reply With Quote
Old 01-26-2018, 07:51 PM   #16
photon
The new goggles also do nothing.
 
photon's Avatar
 
Join Date: Oct 2001
Location: Calgary
Exp:
Default

As a separate thread to this, I was thinking that someone must have already come up with a solution for this kind of thing.

My first choice would be a tweet-to-image generator, as this would be the easiest to display and would work across devices, no Javascript required.

There are a few sites like that out there, but they don't look for mass consumption. I didn't find any open source projects either, maybe that's something to look into doing.

I did however find https://iframely.com which supports a huge number of sites to embed things, taking the URL and giving back the necessary HTML. And you can run your own hosted version too.

I might play around with this instead, if I can get it working then I don't have to worry about any Javascript stuff, and I'd get embeds for pretty much any site I could imagine at the same time.
__________________
Uncertainty is an uncomfortable position.
But certainty is an absurd one.
photon is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 04:10 AM.

Calgary Flames
2023-24




Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright Calgarypuck 2021