Giter Club home page Giter Club logo

Comments (6)

SteelBRS avatar SteelBRS commented on August 25, 2024

+1

from jquery-mentions-input.

SteelBRS avatar SteelBRS commented on August 25, 2024

This is actually an extremely important feature - in order to use the plugin as an editor you need to be able to set the marked up initial text

from jquery-mentions-input.

LaundroMat avatar LaundroMat commented on August 25, 2024

Hi,

I'm not much of a JavaScript coder, but I stumbled on this while looking for something similar. I've hacked this together:

        update: function() {
            var messageText = getInputBoxValue();
            // Strip codes
            // add each mention to mentionsCollection
            // And update

            var mentionText = utils.htmlEncode(getInputBoxValue());
            var re = /@\[(.*?)\]\((.*?):(.*?)\)+/g; // Searches through @[value](type:id)

            var match;
            var newMentionText = mentionText;
            while ((match = re.exec(mentionText)) != null) {    // Find all matches in a string
                console.log(match);
                newMentionText = newMentionText.replace(match[0],match[1]);
                mentionsCollection.push({   // Btw: match[0] is the complete match
                    'id': match[3],
                    'type': match[2],
                    'value': match[1]
                });
            }
            elmInputBox.val(newMentionText);
            updateValues();
        },

Put it somewhere in the public methods of the javascript file. In your own code, you should call $('#name_of_your_textarea').mentionsInput("update");

Mind you that:

  • This only works with the standard templates for the mentions data (i.e. @[value](type:id)). If you have defined a seperate template, you should rework the regex. My JS knowledge is too limited to be able to translate the template to a regex
  • I've cobbled this together in about half an hour; don't shoot me if it doesn't work :/

(Both reasons are why I didn't fork and did a pull request: the above is far from tested and isn't ready for production due to the hardcoded template translation).

from jquery-mentions-input.

SteelBRS avatar SteelBRS commented on August 25, 2024

Thanks mr. LaundroMat :-)

Also I had to write a different version of getInputBoxValue() - couldn't get jQuery textarea.val() to work:

function getInputBoxValue() {
  return $.trim(elmInputBox.val());
}

function getInputBoxValueRaw() {
  var childNodes = domInput.childNodes;
  if (childNodes.length > 0)
    return $.trim(childNodes[0].nodeValue);
  else
    return "";
}

from jquery-mentions-input.

SteelBRS avatar SteelBRS commented on August 25, 2024

Doesn't work in IE, this was what I meant:

function getInputBoxValueRaw() {
  return $.trim(domInput.defaultValue);
}

(Works in IE9, FF14 & CHR21)

from jquery-mentions-input.

lysender avatar lysender commented on August 25, 2024

This is already possible with "defaultValue" parameter (although ( still have issues with it).

from jquery-mentions-input.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.