5 Replies - 733 Views - Last Post: 19 May 2015 - 10:06 AM

#1 TheBumpaster   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 15-May 15

Wrap function does not work

Posted 18 May 2015 - 10:21 PM

var $TextBox = $('#description');
			var $Bold = $('#bold');
			var $Italic = ('#italic');
			var $Underline = ('#underline');
			var $Link = ('#link');
			var $Menu = $('#menu');

function wrapText(startText, endText){
		// Get the text before the selection
                var before = $TextBox.val().substring(0, $TextBox.caret().start);
                
		// Get the text after the selection
                var after = $TextBox.val().substring($TextBox.caret().end, $TextBox.val().length);
                
		// merge text before the selection, a selection wrapped with inserted text and a text after the selection
                $TextBox.val(before + startText + $TextBox.caret().text + endText + after);
                
		// Update the preview
                $("#preview").html($TextBox.val());
}

$Bold.on('click', function() {
                wrapText("<b>", "</b>");
                $Menu.fadeOut("1000");
            });





Why my function wrapText does not work?

Is This A Good Question/Topic? 0
  • +

Replies To: Wrap function does not work

#2 laytonsdad   User is offline

  • Let it rip!
  • member icon

Reputation: 466
  • View blog
  • Posts: 1,992
  • Joined: 30-April 10

Re: Wrap function does not work

Posted 18 May 2015 - 10:34 PM

What does your console tell you?

This post has been edited by laytonsdad: 18 May 2015 - 10:35 PM

Was This Post Helpful? 0
  • +
  • -

#3 TheBumpaster   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 15-May 15

Re: Wrap function does not work

Posted 19 May 2015 - 12:05 AM

Syntax error on jQuery caret plugin, fixed it with a new stable version.
But now it multiplies my text...

This post has been edited by Dormilich: 19 May 2015 - 12:44 AM

Was This Post Helpful? 0
  • +
  • -

#4 laytonsdad   User is offline

  • Let it rip!
  • member icon

Reputation: 466
  • View blog
  • Posts: 1,992
  • Joined: 30-April 10

Re: Wrap function does not work

Posted 19 May 2015 - 01:03 AM

Is the script the same?

Does it duplicate inside the wrap?
Was This Post Helpful? 0
  • +
  • -

#5 TheBumpaster   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 15-May 15

Re: Wrap function does not work

Posted 19 May 2015 - 09:15 AM

View Postlaytonsdad, on 19 May 2015 - 01:03 AM, said:

Is the script the same?

Does it duplicate inside the wrap?

Yes the script is the same, and yes it was duplicating inside, but I was trying to change something and now its not doing anything..., I'll send an attachment here...
https://drive.google...nejQ&authuser=0

TypeError: $(...).caret is not a function

... before = $("#description").val().substring(0, $("#description").caret().start)




I think it's the problem in the plugin...
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6829
  • View blog
  • Posts: 28,311
  • Joined: 12-December 12

Re: Wrap function does not work

Posted 19 May 2015 - 10:06 AM

Quote

TypeError: $(...).caret is not a function

Sounds like you haven't attached the caret plug-in, or maybe attach it after you attempt to use if.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1