The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Select Content Button

View previous topic View next topic Go down

Select Content Button

Post by Base on July 18th 2011, 5:46 pm

Select Content Button


Hello Forumotion members,


In this tutorial, you will discover how to put a 'Select Content' button for every code box as seen on this forum. This tutorial is compatible for all forum versions.

An example of the 'Select Content' button as seen on this forum:

Clicking it will automatically select the contents of the code box:

Step 1:
Navigate to...
Administration Panel → Modules Tab → Javascript codes management → Create a new javascript

Step 2:
Call it whatever you like and set its placement to all pages.

Step 3:
Once you have done that, you will need to add the following code into 'Javascript Code' field :

Code:
    function selectCode(e) {
        var doc = document
            , text = $(e).closest("dl").find(".cont_code,code").get(0)
            , range, selection
        ;
        if (doc.body.createTextRange) {
            range = document.body.createTextRange();
            range.moveToElementText(text);
            range.select();
        } else if (window.getSelection) {
            selection = window.getSelection();        
            range = document.createRange();
            range.selectNodeContents(text);
            selection.removeAllRanges();
            selection.addRange(range);
        }
    };
    $(function(){$("dl.codebox:not(.spoiler,.hidecode)  > dd.code, dl.codebox:not(.spoiler,.hidecode)  > dd > code").closest("dl").find('dt').append('<span onClick="selectCode(this)" class="selectCode">Select Content</span>')});

Step 4 :
Go to  Administration Panel > Display > Colors > CSS stylesheet

Add the following to your stylesheet to style the select content button and submit :
Code:
.selectCode { float:right; text-transform: uppercase; cursor:pointer; }
div.cont_code { clear: right; }


If you have done all the steps correctly then you should have a fully functioning 'Select Content' button appearing for every code box. Wink

avatar
Base
Forumaster

Male Posts : 10386
Reputation : 1693
Language : English and French
Location : United Kingdom, England

http://forumotionhub.net

Back to top Go down

Re: Select Content Button

Post by SLGray on April 25th 2017, 8:48 pm

The JavaScript has been updated since an issue with Chrome and Firefox.  You need to update your JavaScript if you are using it.


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.

avatar
SLGray
Administrator
Administrator

Male Posts : 40515
Reputation : 2733
Language : English
Location : United States

https://fmthemes.forumotion.com/

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum