Choose from our various pricing plans. There is a package for everyone!


Code numbering

View previous topic View next topic Go down

Locked Code numbering

Post by tommycoo on Sat Jun 08, 2013 1:01 am

hello matti ?
i want to ask you how you can make, code tag with number line beside it ?
avatar
tommycoo
Member
Member

Age : 21
Posts : 60
Join date : 2012-08-20
Forum Version : PunBB
Reputation : 1

View user profile

Back to top Go down

Locked Re: Code numbering

Post by Irate on Sat Jun 08, 2013 10:47 am

There are certainly quite some options and if you want a code editor with syntax highlighting for many various programming languages, there are premade codes on google. I will however write something like that for you when I am on my PC.
avatar
Irate
Member
Member

Age : 21
Posts : 91
Join date : 2013-05-01
Forum Version : PhpBB2
Reputation : 2

View user profile http://duelacademy.net

Back to top Go down

Locked Re: Code numbering

Post by tommycoo on Sat Jun 08, 2013 2:20 pm

oke then i'll wait for that, but can you give me just a simple code maybe ?
because i don't want make my forum heavy load because of that Wink

thanks before
avatar
tommycoo
Member
Member

Age : 21
Posts : 60
Join date : 2012-08-20
Forum Version : PunBB
Reputation : 1

View user profile

Back to top Go down

Locked Re: Code numbering

Post by Irate on Sat Jun 08, 2013 7:30 pm

This code should work for phpBB 2.

Code:
setTimeout(function(){ // set a timeout function

var codes = document.getElementsByClassName("cont_code"); // get our code tags

for(var i = 0; i < codes.length; i++) { // loop through them

var cstring = { text: "" }; // set an object with an empty string as only property

cstring.text += codes[i].innerHTML.toString(); // get all the content from the code into the string

var lines = cstring.text.split("\n"); // split on new lines and convert to array

var curline = i + 1; // current line

for(var j = 0; j < lines.length; j++) { // loop through lines

codes[i].innerHTML = "";

codes[i].innerHTML += "" + curline + " | " + lines[j] + "\n"; // extract the strings from the array again

}

cstring.text = ""; // reset the text for each iteration

}

},0 // run the code as soon as possible
);

I haven't tested it yet but it should work.


Last edited by Irate on Sun Jun 09, 2013 8:13 pm; edited 1 time in total
avatar
Irate
Member
Member

Age : 21
Posts : 91
Join date : 2013-05-01
Forum Version : PhpBB2
Reputation : 2

View user profile http://duelacademy.net

Back to top Go down

Locked Re: Code numbering

Post by tommycoo on Sun Jun 09, 2013 11:30 am

my forum is punbb irate Razz lol!
avatar
tommycoo
Member
Member

Age : 21
Posts : 60
Join date : 2012-08-20
Forum Version : PunBB
Reputation : 1

View user profile

Back to top Go down

Locked Re: Code numbering

Post by Irate on Sun Jun 09, 2013 2:00 pm

I didn't see that in your profile description so I guessed.

I'll give you more information once I got on my PC.

Edit: I updated the code. Wink
avatar
Irate
Member
Member

Age : 21
Posts : 91
Join date : 2013-05-01
Forum Version : PhpBB2
Reputation : 2

View user profile http://duelacademy.net

Back to top Go down

Locked Re: Code numbering

Post by tommycoo on Mon Jun 10, 2013 1:19 am

i've used the code, and there is nothing change ?
avatar
tommycoo
Member
Member

Age : 21
Posts : 60
Join date : 2012-08-20
Forum Version : PunBB
Reputation : 1

View user profile

Back to top Go down

Locked Re: Code numbering

Post by Irate on Mon Jun 10, 2013 6:55 pm

Try replacing setTimeout(function(){ ... },0); with jQuery(document).ready(function(){ ... });
avatar
Irate
Member
Member

Age : 21
Posts : 91
Join date : 2013-05-01
Forum Version : PhpBB2
Reputation : 2

View user profile http://duelacademy.net

Back to top Go down

Locked Re: Code numbering

Post by tommycoo on Tue Jun 11, 2013 12:30 am

yes there is a change but with two code tag there is number 1 and 2 like this


i want some thing like this forum tag code line and different color
avatar
tommycoo
Member
Member

Age : 21
Posts : 60
Join date : 2012-08-20
Forum Version : PunBB
Reputation : 1

View user profile

Back to top Go down

Locked Re: Code numbering

Post by Irate on Tue Jun 11, 2013 8:46 am

Okay, I will see what I can do for you, I'm currently on, well, not vacation, but on a trip with my class so I have no access to a computer right now.
avatar
Irate
Member
Member

Age : 21
Posts : 91
Join date : 2013-05-01
Forum Version : PhpBB2
Reputation : 2

View user profile http://duelacademy.net

Back to top Go down

Locked Re: Code numbering

Post by tommycoo on Tue Jun 11, 2013 12:27 pm

hem okay then irate, i'll wait for this code but, can you give me asap Smile
avatar
tommycoo
Member
Member

Age : 21
Posts : 60
Join date : 2012-08-20
Forum Version : PunBB
Reputation : 1

View user profile

Back to top Go down

Locked Re: Code numbering

Post by tommycoo on Sat Jun 15, 2013 4:12 am

up
avatar
tommycoo
Member
Member

Age : 21
Posts : 60
Join date : 2012-08-20
Forum Version : PunBB
Reputation : 1

View user profile

Back to top Go down

Locked Re: Code numbering

Post by Irate on Sat Jun 15, 2013 8:26 am

Just sitting in the bus on my way home Wink
I'll edit this post with the code when I have it.
avatar
Irate
Member
Member

Age : 21
Posts : 91
Join date : 2013-05-01
Forum Version : PhpBB2
Reputation : 2

View user profile http://duelacademy.net

Back to top Go down

Locked Re: Code numbering

Post by tommycoo on Sun Jun 16, 2013 3:17 am

Okay, i can't wait Wink
avatar
tommycoo
Member
Member

Age : 21
Posts : 60
Join date : 2012-08-20
Forum Version : PunBB
Reputation : 1

View user profile

Back to top Go down

Locked Re: Code numbering

Post by Irate on Sun Jun 16, 2013 1:16 pm

Well, I found an easy solution but discarded it because it only works if there is only one code in the the entire document, so I wrote out something more explicit.

Code:
jQuery(document).ready(function(){

var code = document.getElementsByTagName("code");

for(var n = 0; n < code.length; n++) {

var str = code[n].innerHTML.split("<br>");

code[n].innerHTML = "";

for(var i = 0; i < str.length; i++) {

var curline = i + 1;

code[n].innerHTML += "" + curline + " | " + str[i];

}

}

});

Try that.
avatar
Irate
Member
Member

Age : 21
Posts : 91
Join date : 2013-05-01
Forum Version : PhpBB2
Reputation : 2

View user profile http://duelacademy.net

Back to top Go down

Locked Re: Code numbering

Post by tommycoo on Mon Jun 17, 2013 3:06 am

Nope doesn't work Sad
i really want that code panda like tthis forum :/
avatar
tommycoo
Member
Member

Age : 21
Posts : 60
Join date : 2012-08-20
Forum Version : PunBB
Reputation : 1

View user profile

Back to top Go down

Locked Re: Code numbering

Post by Irate on Mon Jun 17, 2013 6:49 am

Well, ask Matti if you can use the code he is currently using.
I will have another look at my code. I need to test it -_-
avatar
Irate
Member
Member

Age : 21
Posts : 91
Join date : 2013-05-01
Forum Version : PhpBB2
Reputation : 2

View user profile http://duelacademy.net

Back to top Go down

Locked Re: Code numbering

Post by Axtrix on Mon Jun 17, 2013 9:16 am

Code:
jQuery(document).ready(function(){

var codebox = document.getElementsByTagName("code");

for(var n = 0; n < codebox.length; n++) {

  var str = codebox[n].innerHTML.split("<br>");
 
  codebox[n].innerHTML = "";

for(var i = 0; i < str.length; i++) {
 
  var curline = i + 1;
 
  codebox[n].innerHTML += "" + curline + " | " + str[i] + "<br>";

}

}

});

That worked for me...
avatar
Axtrix
Member
Member

Age : 20
Posts : 4
Join date : 2012-08-26
Reputation : 0

View user profile

Back to top Go down

Locked Re: Code numbering

Post by Th1nK on Fri Dec 19, 2014 1:47 pm

User inactive and topic locked
avatar
Th1nK
Administrator
Administrator

Posts : 468
Join date : 2012-04-06
Reputation : 43

View user profile http://www.csshelp.net

Back to top Go down

Locked Re: Code numbering

Post by Sponsored content


Sponsored content


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