Java script Select all code stopped working
5 posters
Page 1 of 1
Java script Select all code stopped working
Java script Select all code stopped working. What can the problem come from?
- 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">
КОПИРАЙ КОДА</span>');
});
Last edited by smurfavr on November 6th 2020, 12:15 pm; edited 1 time in total
Re: Java script Select all code stopped working
if you turn off the falling leaves dose the code work again ?
Re: Java script Select all code stopped working
@Ape I stopped the falling leaves, but the problem still exists.
Re: Java script Select all code stopped working
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.
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.
Re: Java script Select all code stopped working
Excluding the java script, the codes stop and the text copy code and I can't tell if it works.
Re: Java script Select all code stopped working
What he meant is leave only the Select Code Javascript enabled and turning off the rest of the Javascripts.
Forum of the Forums Forumotion Rules | Tips & Tricks | FAQ | Did you forget your password? |
*** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
No support via PM!
Re: Java script Select all code stopped working
Hello @smurfavr,
Change your code to:
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));
TonnyKamper likes this post
Re: Java script Select all code stopped working
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>')});
TonnyKamper likes this post
Re: Java script Select all code stopped working
Problem solved & topic archived.
|
Forum of the Forums Forumotion Rules | Tips & Tricks | FAQ | Did you forget your password? |
*** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
No support via PM!
Similar topics
» Code stopped working
» Code for the lights stopped working.
» Select botton code not working
» Java script help!
» please help me out , Java script problem
» Code for the lights stopped working.
» Select botton code not working
» Java script help!
» please help me out , Java script problem
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum