Go Back   vb.org Archive > vBulletin Modifications > vBulletin 4.x Modifications > vBulletin 4.x Template Modifications
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
"select all" feature for BB Code : CODE/HTML/PHP Details »»
"select all" feature for BB Code : CODE/HTML/PHP
Version: 1.00, by BCP Hung BCP Hung is offline
Developer Last Online: Jan 2019 Show Printable Version Email this Page

Category: BB Code Enhancements - Version: 4.x.x Rating:
Released: 06-09-2011 Last Update: Never Installs: 26
Template Edits
Code Changes Translations  
No support by the author.

About this modification :
This mods template allows you added to the BB Code CODE / HTML / PHP function selects all the content in it with a simple button.
Install :
  1. Insert javascript code into headinclude template
    AdminCP -> Styles & Templates -> Style Manager -> Edit Templates -> headinclude
    Copy and paste following js code to bottom of headinclude template :
    HTML Code:
    <script type="text/javascript">
        function selectAll(a)
        {
            var e  = a.parentNode.parentNode.getElementsByTagName('code')[0];
            if  (window.getSelection)
            {
                var s = window.getSelection();
                if  (s.setBaseAndExtent)
                {
                    s.setBaseAndExtent(e, 0, e, e.innerText.length -  1);
                }
                else
                {
                    var r = document.createRange();
                    r.selectNodeContents(e);
                    s.removeAllRanges();
                    s.addRange(r);
                }
            }
            else if (document.getSelection)
            {
                var s = document.getSelection();
                var r = document.createRange();
                r.selectNodeContents(e);
                s.removeAllRanges();
                s.addRange(r);
            }
            else if  (document.selection)
            {
                var r = document.body.createTextRange();
                r.moveToElementText(e);
                r.select();
            }
        }
    </script>
  2. Insert new code to bbcode template
    ... -> Edit Templates -> BB Code Layout Templates -> bbcode_code
    Find :
    Code:
    {vb:rawphrase code}:
    
    ...and...
    
    {vb:raw code}
    Change :
    Code:
    {vb:rawphrase code}:&nbsp;<input type="button" value="{vb:rawphrase select_code}" onclick="selectAll(this); return false;">
    
    ...and...
    
    <code>{vb:raw code}</code>
  3. Insert new code to bbcode_html template (same bbcode_code)
    ... -> Edit Templates -> BB Code Layout Templates -> bbcode_html
    Find :
    Code:
    {vb:rawphrase html_code}:
    
    ...and...
    
    {vb:raw code}
    Change :
    Code:
    {vb:rawphrase html_code}:&nbsp;<input type="button" value="{vb:rawphrase select_code}" onclick="selectAll(this); return false;">
    
    ...and...
    
    <code>{vb:raw code}</code>
  4. Insert new code to bbcode_php template (same bbcode_code)
    ... -> Edit Templates -> BB Code Layout Templates -> bbcode_php
    Find :
    Code:
    {vb:rawphrase php_code}:
    Change :
    Code:
    {vb:rawphrase php_code}:&nbsp;<input type="button" value="{vb:rawphrase select_code}" onclick="selectAll(this); return false;">
  5. (Optional) Add new phrase : If you don't want to do this step, please look at "Notes" !
    AdminCP -> Languages & Phrases -> Phrase Manager -> [Add New Phrase]
    • Phrase Type : GLOBAL
    • Product : vBulletin
    • Varname : select_code
    • Text : select all
Notes :
If you don't want to create new phrase (step 5), you can search for : {vb:rawphrase select_code} and replace with select all
Next version : add new feature "copy to clipboard".

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.
4 благодарности(ей) от:
bulwinkl, john7911, Muhammad Rahman, ramesh_umk3

Comments
  #12  
Old 07-10-2011, 07:08 AM
nacaruncr nacaruncr is offline
 
Join Date: Nov 2010
Posts: 318
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks men I wait for the upgrade
Reply With Quote
  #13  
Old 11-21-2011, 01:01 PM
f4vn f4vn is offline
 
Join Date: Apr 2007
Posts: 42
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This mod doesn`t work with my site. Error is "Parameter is not an object [Break On This Error] r.selectNodeContents(e); " Can you tell me how to fix it ?

Thank you,
Reply With Quote
  #14  
Old 01-27-2013, 05:36 AM
bigs15 bigs15 is offline
 
Join Date: Oct 2006
Posts: 73
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

is this work with 3.8.7 thankx in advance...
Reply With Quote
  #15  
Old 01-31-2014, 09:25 PM
bulwinkl bulwinkl is offline
 
Join Date: Sep 2005
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Great job, I really appreciated this.

This really should be part of the default Vbulletin.

Worked perfectly in 4.2.2:up:
Reply With Quote
  #16  
Old 02-03-2014, 03:18 PM
ahobilam's Avatar
ahobilam ahobilam is offline
 
Join Date: Aug 2011
Location: Chennai, India
Posts: 128
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am using VB 4.2.2
The code found in my (custom template) bbcode_code and bbcode_html are different
than what you are instructed for find as below:
Code:
<div class="bbcode_container">
	<div class="bbcode_description">{vb:rawphrase html_code}:</div>
	<pre class="bbcode_code"<vb:if condition="$vboptions['codemaxlines']"> style="height:<vb:if condition="$blockheight<=$vboptions['codemaxlines']">{vb:math {vb:math {vb:raw blockheight}+2}}*{vb:stylevar mid_fontSize}}<vb:else />{vb:math {vb:math {vb:raw blockheight}+1}*{vb:stylevar mid_fontSize}}</vb:if>;"</vb:if>>{vb:raw code}</pre>
</div>
Can I replace it, I want to conform before making any changes.

What is the meaning for
....and.....
between the code.
Thanks in advance.
Reply With Quote
  #17  
Old 02-05-2014, 01:14 PM
ramesh_umk3 ramesh_umk3 is offline
 
Join Date: Jul 2010
Location: Earth
Posts: 194
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

it will work as i am running vbulletin 4.2.2

leave ....and.....

replace only starting and ending code which he mentioned

Regards,
Reply With Quote
Благодарность от:
BCP Hung
  #18  
Old 06-06-2016, 06:17 AM
RedHacker RedHacker is offline
 
Join Date: Jan 2009
Posts: 878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks it is work with 4.1.7
Reply With Quote
  #19  
Old 06-15-2016, 09:09 AM
john7911 john7911 is offline
 
Join Date: Feb 2013
Posts: 258
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi,
It does not work on my forum 4.2.3
Can somme one tell me where is the problem?
Thank you



-----------------------------------
It's ok I found the problem I forgot a < in the beginning of the code :erm:
Reply With Quote
  #20  
Old 05-05-2017, 06:19 AM
Raptor Raptor is offline
 
Join Date: Nov 2001
Posts: 499
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This stopped working in Chrome just recently

Works fine in Edge and cellphone browser

Uncaught DOMException: Failed to execute 'setBaseAndExtent' on 'Selection': There is no child at offset 18125.
at selectAll (
Reply With Quote
  #21  
Old 05-07-2017, 12:51 PM
Raptor Raptor is offline
 
Join Date: Nov 2001
Posts: 499
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Update:

Select All works in Chrome Version 57.0.2987.133 (64-bit)

Stopped working after update to Chrome Version 58.0.3029.96 (64-bit)

Problem: the last parameter to the "setBaseAndExtent" shouldn't be the text length, it should be the child node count.

https://developer.mozilla.org/en-US/...tBaseAndExtent

I'm not versed enough in Javascript enough to fix this properly. What does make this work is by removing the following:

PHP Code:
if  (s.setBaseAndExtent)
            {
                
s.setBaseAndExtent(e0ee.innerText.length -  1);
            }
            else
            { 
and the } after the else

So the new Javascript in the headinclude is

PHP Code:
<script type="text/javascript">
    function 
selectAll(a)
    {
        var 
e  a.parentNode.parentNode.getElementsByTagName('code')[0];
        if  (
window.getSelection)
        {
            var 
window.getSelection();
 
                var 
document.createRange();
                
r.selectNodeContents(e);
                
s.removeAllRanges();
                
s.addRange(r);
 
        }
        else if (
document.getSelection)
        {
            var 
document.getSelection();
            var 
document.createRange();
            
r.selectNodeContents(e);
            
s.removeAllRanges();
            
s.addRange(r);
        }
        else if  (
document.selection)
        {
            var 
document.body.createTextRange();
            
r.moveToElementText(e);
            
r.select();
        }
    }
</
script
Hope this helps someone.

If there's anyone who can post the correct java solution without removing any code that would be great.

My vB is 4.2.4 btw
Reply With Quote
Благодарность от:
sub_ubi
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 07:10 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.11524 seconds
  • Memory Usage 2,355KB
  • Queries Executed 26 (?)
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
  • (7)bbcode_code
  • (1)bbcode_html
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (11)post_thanks_box
  • (6)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • 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