The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Java script Select all code stopped working

5 posters

Go down

Solved Java script Select all code stopped working

Post by smurfavr Tue Nov 03, 2020 8:27 pm

Java script Select all code stopped working. What can the problem come from?
Java script Select all code stopped working OTHiVzR

Code:
function selectCode(a){a=$(a).closest("dl").find(".cont_code,code")[0];if(window.getSelection){var c=window.getSelection();if(c.setBaseAndExtent)c.setBaseAndExtent(a,0,a,a.innerText.length-1);else{window.opera&&a.innerHTML.substring(a.innerHTML.length-4)=="<BR>"&&(a.innerHTML+=" ");var b=document.createRange();b.selectNodeContents(a);c.removeAllRanges();c.addRange(b)}}else document.getSelection?(c=document.getSelection(),b=document.createRange(),b.selectNodeContents(a),
        c.removeAllRanges(),c.addRange(b)):document.selection&&(b=document.body.createTextRange(),b.moveToElementText(a),b.select())}
       
      $(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">
КОПИРАЙ&nbsp;&nbsp;КОДА</span>');
        });


Last edited by smurfavr on Fri Nov 06, 2020 11:15 am; edited 1 time in total
smurfavr
smurfavr
Active Poster

Male Posts : 1883
Reputation : 22
Language : Bulgarian

http://smurfa.bulgarianforum.net/

Back to top Go down

Solved Re: Java script Select all code stopped working

Post by Ape Tue Nov 03, 2020 8:44 pm

if you turn off the falling leaves dose the code work again ?


Java script Select all code stopped working Left1212Java script Select all code stopped working Center11Java script Select all code stopped working Right112
Java script Select all code stopped working Ape_b110
Java script Select all code stopped working Ape1010
Ape
Ape
Administrator
Administrator

Male Posts : 19039
Reputation : 1988
Language : fluent in dork / mumbojumbo & English haha

http://chatworld.forumotion.co.uk/

Back to top Go down

Solved Re: Java script Select all code stopped working

Post by smurfavr Wed Nov 04, 2020 8:14 pm

@Ape I stopped the falling leaves, but the problem still exists.
smurfavr
smurfavr
Active Poster

Male Posts : 1883
Reputation : 22
Language : Bulgarian

http://smurfa.bulgarianforum.net/

Back to top Go down

Solved Re: Java script Select all code stopped working

Post by Ape Wed Nov 04, 2020 10:16 pm

Thank you for you reply @smurfavr I have ran some tests and everything looks to be ok our end

Can you please turn off your JavaScripts and then see if the problem is still there ?

I am asking this as it looks like it is only your forum that has the problem after I done tests on 6 other sites and on this support forum and can't reproduce the problem.


Java script Select all code stopped working Left1212Java script Select all code stopped working Center11Java script Select all code stopped working Right112
Java script Select all code stopped working Ape_b110
Java script Select all code stopped working Ape1010
Ape
Ape
Administrator
Administrator

Male Posts : 19039
Reputation : 1988
Language : fluent in dork / mumbojumbo & English haha

http://chatworld.forumotion.co.uk/

Back to top Go down

Solved Re: Java script Select all code stopped working

Post by smurfavr Thu Nov 05, 2020 11:18 am

Excluding the java script, the codes stop and the text copy code and I can't tell if it works.
smurfavr
smurfavr
Active Poster

Male Posts : 1883
Reputation : 22
Language : Bulgarian

http://smurfa.bulgarianforum.net/

Back to top Go down

Solved Re: Java script Select all code stopped working

Post by TheCrow Thu Nov 05, 2020 12:15 pm

What he meant is leave only the Select Code Javascript enabled and turning off the rest of the Javascripts.
TheCrow
TheCrow
Manager
Manager

Male Posts : 6882
Reputation : 794
Language : Greek, English

https://forumote.forumotion.com

Back to top Go down

Solved Re: Java script Select all code stopped working

Post by tikky Thu Nov 05, 2020 8:29 pm

Hello @smurfavr,

Change your code to:
Code:
/* global Clipboard, jQuery*/
(function($) {
 
    $(function() {
 
        $('.post .code').each(function() {
 
            var $copy = $('<a>', {
                'class': 'fa-code-copy-button',
                'title': 'Copiar',
                'role': 'button',
                'text': 'КОПИРАЙ КОДА'
            }).css('float', 'right');
 
            $copy.prependTo($(this).parents('.codebox').not('.spoiler').find('dt'));
        });
 
        $.getScript('https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.7.1/clipboard.min.js', function() {
            new Clipboard('.fa-code-copy-button', {
                target: function(trigger) {
                    return $(trigger).parents('.codebox').find('.cont_code').get(0);
                }
            });
        });
 
    });
}(jQuery));
Your current code has an error and it's old :/ AND it probably stopped working due to a browser update
tikky
tikky
Forumember

Posts : 890
Reputation : 157
Language : 🇵🇹

https://www.forumotion.com/create-forum/modernbb

TonnyKamper likes this post

Back to top Go down

Solved Re: Java script Select all code stopped working

Post by jucarese Fri Nov 06, 2020 9:59 am

This also works and does not depend on any external address, which can fail.

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 all</span>')});
jucarese
jucarese
Hyperactive

Male Posts : 2414
Reputation : 112
Language : spanish
Location : SSF Admin

http://asistencia.foroactivo.com/u23082

TonnyKamper likes this post

Back to top Go down

Solved Re: Java script Select all code stopped working

Post by smurfavr Fri Nov 06, 2020 11:16 am

@pedxz, @jucarese, Thank you both codes work.
smurfavr
smurfavr
Active Poster

Male Posts : 1883
Reputation : 22
Language : Bulgarian

http://smurfa.bulgarianforum.net/

Back to top Go down

Solved Re: Java script Select all code stopped working

Post by TheCrow Fri Nov 06, 2020 12:21 pm

Problem solved & topic archived.
Please read our forum rules: ESF General Rules
TheCrow
TheCrow
Manager
Manager

Male Posts : 6882
Reputation : 794
Language : Greek, English

https://forumote.forumotion.com

Back to top Go down

Back to top

- Similar topics

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