Welcome Guest [Log In] [Register]
This board has been archived and is no longer accepting new questions. If you have a support question for your ZetaBoard, please visit us at the new support board. Registration is free and easy.


Visit the NEW ZetaBoards Support forum!

Username:   Password:
Add Reply
Functions; To help sprouting coders
Topic Started: Feb 12 2008, 02:17 PM (2,688 Views)
Viral
Member Avatar
i'm stanley nao
[ *  *  *  *  * ]
Safari 3.0: 100%
Firefox 2.0: 100%
Opera: 100%
IE 7.0: 100%


Basically, I made this yesterday. It's a compilation of different functions to help coders out and hopefully 'giver birth' to some newer ones.

If you have this script installed on your ZB forum, you can call any of the below functions:

Code:
 

setSkin("skin to set") // This function will check the theme the viewer is using. If it is not the one you specify, it will change it to the one you specify.

selectedSkin() // This will return the skin you are using. So if you do: alert(selectedSkin()); it will display a pop-up box with the skin you are using.

messageBox("link","text to show","closing text") // My favourite. You know the message box you get when you have a PM? This is it, but you can specify where to go if you click it, the text it will have and the closing text.

username(); // Returns the viewer's Username. alert(username()); will display a pop-up with your username.

random(a,b); // Nice fun function. Will generate a random number between a and b. alert(random(12,25)); displays a pop-up with a random number between 12 and 25.

browser(); // alert(browser()[0]); displays a pop-up with the browser you are using. alert(browser()[1]) displays a popup with the browser version you are using.

date(order); // Hard to understand. alert(date("d","m",y")); pop-up displaying the date in dd-mm-yyyy form. You can change the order of the "d","y","m".

submenu("text","link"); // submenu("Google","http://google.com"); will add the text Google to your submenu. It will have the link http://google.com.

removeFromSubmenu("text"); // removeFromSubmenu("Search"); completely removes the Search link from your submenu.

page(); // alert(page()); display a pop-up showing the title of the page you are on.

inbox(); // alert(inbox()); displays how many messages you have.





There aren't that many at the moment, but if I can have some suggestions on what to add, that would be great. For now, this goes in the Javascript box, as high as possible.


Code: HTML
 
<script src="http://moregfx.com/Open%20Source/functions.js">
// Made by Viral of http://www.zetaresources.com
</script>


Edited by Viral, Mar 19 2008, 06:47 PM.
Offline Profile Quote Post Goto Top
 
Arrogant
Member Avatar
Vote Choco and Nicola!
[ *  *  * ]
err... Viral, i'm not sure if you're aware of this... but your scripting doesn't exactly flow.. >.>

i mean, it's all in bug chunks, small chunks, chunky.. chunks.. :s
i'm not one for using jQuery, and i think i've voiced my opinion on that quite a bit... but man, for the love of God...

please.... Please... PLEASE... consider learning how to make your script flow.. -_-
Edited by Arrogant, Feb 12 2008, 02:26 PM.
Offline Profile Quote Post Goto Top
 
Viral
Member Avatar
i'm stanley nao
[ *  *  *  *  * ]
beta, I see your point. I was just reading GS's blog, and have already started changing stuff into jQuery.

Don't worry, everything that is jQuery possible is being edited now.
Offline Profile Quote Post Goto Top
 
Arrogant
Member Avatar
Vote Choco and Nicola!
[ *  *  * ]
no, it's not that. sometimes, things aren't worth scripting in jQuery. you just have to know how and when to use it, is all.

for example - your inbox thing: you don't need jQuery for that, and i've edited it out of my post.
you just need to tie everything up into a nice little function.

Code:
 
if(username() == "Guest") return false; else return document.getElementById("menu_pm").getElementsByTagName("small")[0].innerHTML;



to be honest, you're good at JavaScript, and you're improving quite a bit. you just need to learn how to make things minimal and efficient. d:
Edited by Arrogant, Feb 12 2008, 02:33 PM.
Offline Profile Quote Post Goto Top
 
Viral
Member Avatar
i'm stanley nao
[ *  *  *  *  * ]
But, it's easier for jQuery in a place like that, as the coding is shorter.

Obviously, not everything should be used in jQuery but stuff like that should.
Offline Profile Quote Post Goto Top
 
Arrogant
Member Avatar
Vote Choco and Nicola!
[ *  *  * ]
true, because it's already loaded up and whatnot - but the browser still has to parse the arguments and return a function based on what was entered into them.

i'm not quite sure on how long it takes to do all of that, but i've found that it's much faster to just code normally, without jQuery dependence (especially when doing small-scale things... :s). i haven't checked the actually timing on it all, but when i code normally, it seems to just happen alot faster compared to when i rely on jQuery.

ahh... invasion of the typos! D:!

x.x
Edited by Arrogant, Feb 12 2008, 02:46 PM.
Offline Profile Quote Post Goto Top
 
Interrobang
Member Avatar
Yeah, I went there.
[ * ]
The timing on a jQuery #id selector is almost parity with getElementById().
The timing on a proper "element.class" selector is almost parity with any JS you use, not counting the fact that you have to write a class selector function.

The speed difference, unless you're doing something like manipulating a 1000-row table (at that point, I agree that you should use plain JS), is so minimal that I heartily agree with Viral that increased readability and reduced development time >>>> the 10 ms you save in a script. No one is going to notice.

jQuery is shorter to write and easier to read, making it more maintainable. I'm sure that you can find much better ways to optimize scripts than rewriting everything with longhand selectors.

And I'd still like to see your version of something like this without jQuery: :P
Code:
 
$("#item li, #otheritem li").click(function(){
$(this).css('color', '#c00');
});
jQuery is a good tool. Don't discourage people from using it. No one here is going to be writing enterprise-level stuff on which milliseconds hinge.
Offline Profile Quote Post Goto Top
 
Arrogant
Member Avatar
Vote Choco and Nicola!
[ *  *  * ]
again, "you just have to know how and when to use it, is all." :p

of course using plain JavaScript to do something like what you presented would be less practical.

however, most people don't know how to use jQuery, nor would they ever be bothered to learn it.
so, as far as it having increased readability, you're dead wrong. :)
Edited by Arrogant, Feb 12 2008, 08:23 PM.
Offline Profile Quote Post Goto Top
 
Viral
Member Avatar
i'm stanley nao
[ *  *  *  *  * ]
But isn't that just saying (for example), "Don't use PHP because some people won't understand it, or be able to read it"?
Offline Profile Quote Post Goto Top
 
choco
SPORE
[ *  *  * ]
That's a bad example, as PHP code isn't commonly viewed while running, unless you're putting it out for the world to see. Also, PHP is a programming language; jQuery isn't. :P
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
Go to Next Page
« Previous Topic · User Created Codes · Next Topic »
Add Reply