Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-21-2010, 10:29 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Adding code selection button to postbit?

Hi all, i am trying to add a button to the postbit template where a user can highlight all the code in a code textbox with one click, i am trying to use this:
HTML Code:
 <input type="button" value="Highlight Text" onClick="javascript:this.form.text_area.focus();this.form.text_area.select();">
which came from this
HTML Code:
<form name="select_all">

<textarea name="text_area" rows="10" cols="80">
MY TEXT TO HIGHLIGHT</textarea>

<br />
<input type="button" value="Highlight Text" onClick="javascript:this.form.text_area.focus();this.form.text_area.select();">

</form>
How would i change the <input line to focus the code box?
Reply With Quote
  #2  
Old 02-21-2010, 11:14 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That's a hard one without knowing exactly what's going on. You need to be able to find the JS object, so you either need to understand the DOM structure that results from your HTML or else give the thing you want to find a unique name or id. In the example you gave, the object is found because it's a member of the same form with a specific name.

Are you adding one button that selects the first code area, or a button attached to each code area?
Reply With Quote
  #3  
Old 02-21-2010, 11:18 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Good question!, i didn't think about multiple code boxes, it would have to be per code area.
Reply With Quote
  #4  
Old 02-21-2010, 11:25 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well that would make it easier to modify the JS but probably harder to add the buttons. I'd work out all the HTML you want, then figure out the JS to get to the object. I use the Google Chrome browser's "Inspect Element" (right click) function to look at the structure.
Reply With Quote
  #5  
Old 02-21-2010, 11:30 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

kh99, i'm not with you?, i assumed that the example i gave would be all i needed, i found it on the net, In IE my users can Ctrl+ left click to the left of a code box which will select all the code but this doesn't work in FF due to the security restrictions the browser has in place to prevent access to the clipboard, so i thought it would be cool if all users just saw a button to highlight the text in the code box. (the example i i gave works cross browser)
Reply With Quote
  #6  
Old 02-21-2010, 11:38 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

heh heh..well as you know, I'm probably the one who doesn't follow. I guess I was saying, if you want to add a button for each code area, how are you going to do that? Or I guess you're asking? I don't know, that's harder than adding one button in the post. I guess you could modify the bbcode definition to include a button.

The other thing I was saying, to modify the JS you posted you'd have to first know what HTML you are working with (which means working out the previous question).

Sorry, I'm not actually a JS expert, maybe I should let someone else take on this one.
Reply With Quote
  #7  
Old 02-21-2010, 11:45 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Lol, yes i am asking, the bbcode definition, is that in my server files, if it is i would have a hack at adding the <input there. looking at the source code for a particular post that has a code box i see that my code is held between <pre tags like this
HTML Code:
<!-- message -->
		<div id="post_message_649524">
			
<br /><br />
			<!-- google_ad_section_start -->Try this, it's ThisWorkbook event code:<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px"><acronym title="Visual Basic for Applications">VBA</acronym> CODE:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 800px;
		height: 178px;
		text-align: left;
		overflow: auto"><font color="blue">Option Explicit</font> 
<font color="blue">Private</font> <font color="blue">Sub</font> Workbook_Deactivate() 
    UserForm1.Hide 
<font color="blue">End Sub</font> 
 
<font color="blue">Private</font> <font color="blue">Sub</font> Workbook_WindowActivate(<font color="blue">ByVal</font> Wn <font color="blue">As</font> Window) 
    UserForm1.Show vbModeless 
    Range("A1").Select 
    AppActivate Application.Caption 
<font color="blue">End Sub</font> </pre>
</div>
Reply With Quote
  #8  
Old 02-21-2010, 01:49 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well when I mentioned changing the bbcode I was thinking of that editor in the ACP, but I forgot that you can't change the built in ones that way. Maybe someone else knows how to do that?
Reply With Quote
  #9  
Old 02-21-2010, 07:15 PM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi i found that the code is parsed by the bbcode template bbcode_code, so i wrapped the <pre tags with FORM, it adds the button underneath every code area but does not highlight it when clicked?
HTML Code:
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">$vbphrase[code]:</div>
	<form><pre name="codearea" class="alt2" dir="ltr" style="
		margin: 0px;
		padding: $stylevar[cellpadding]px;
		border: 1px inset;
		width: $stylevar[codeblockwidth];
		height: {$blockheight}px;
		text-align: left;
		overflow: auto">$code</pre><input type="button" value="Highlight Code" onClick="javascript:this.form.codearea.focus();this.form.codearea.select();">
</form>
</div> 
Any ideas?
Reply With Quote
  #10  
Old 02-21-2010, 09:00 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think it doesn't work because the "select()" function is only a member of the object if it's an <input type="text"> or <textarea>. I did a little searching and I wasn't able to figure out how to select other text, but I did find this page: http://dynamic-tools.net/toolbox/copyToClipboard/ which shows how to copy to the clipboard by pressing a button.

So you can either try that, or else try making it a textarea.
Reply With Quote
Reply


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. The time now is 08:38 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04603 seconds
  • Memory Usage 2,263KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_html
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete