Skip to content

Commit

Permalink
Added NPM support , CommonJS support and made it more Jquery validate…
Browse files Browse the repository at this point in the history
… friendly (ivirabyan#77)

* added package json

* forgot else

* Added VS solution

* Update README.md

* copy all data attributes to the hidden field.

* copy data attr

* add data elements

* fixed coffee weird function generation

* Copy all data tags from the actual input to the hidden element so that jquery validations can work.

* Removed the Visual studio dependency files from the pull request.
  • Loading branch information
pratikvasani authored and ivirabyan committed May 4, 2017
1 parent 4b47a67 commit 2bc6d9c
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
.DS_Store
/node_modules
/.vs
/bower_components
/packages/Microsoft.Net.Compilers.1.3.2
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

Changes
===============
This is a modification on top of the existing plugin by ivirabyan/jquery-mentions , I have added support for npm and CommonJS

jquery-mentions
===============
Adds mentioning support to your text fields.
Expand Down
2 changes: 1 addition & 1 deletion example.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<body>
<p>Try to type "@a"</p>
<p>Textarea example:</p>
<textarea class="mentions" name="text">@[alex](user:1) is my best friend! I love to play @[angry birds](game:5)</textarea>
<textarea class="mentions" data-val-required="true" name="text">@[alex](user:1) is my best friend! I love to play @[angry birds](game:5)</textarea>

<p>Input example:</p>
<input class="mentions" name="text" value="@[alex](user:1) is my best friend! I love to play @[angry birds](game:5)" />
Expand Down
14 changes: 13 additions & 1 deletion jquery.mentions.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
namespace = "mentionsInput"

if typeof module == "object" && typeof module.exports == "object"
# looks like a CommonJS environment , use the require syntax to get the dependencies
$ = require "jquery";
require "jquery-ui/ui/widgets/autocomplete"
else
$ = window.jQuery;

Selection =
get: (input) ->
Expand Down Expand Up @@ -237,8 +243,14 @@ class MentionsInput extends MentionsBase
@_updateValue()

_createHidden: ->
hidden = $('<input>', {type: 'hidden', name: @input.attr('name')})
hidden = $('<input>', {type: 'hidden', name: @input.attr('name')});

$.each(@input.data(), (name, value) -> hidden.attr("data-" + name.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-').toLowerCase(), JSON.stringify(value))

);
@input.removeData();
hidden.appendTo(@container)

@input.removeAttr('name')
return hidden

Expand Down
15 changes: 13 additions & 2 deletions jquery.mentions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "jquery-mentions",
"version": "1.0.1",
"description": "Added npm support and CommonJS support",
"main": "jquery.mentions.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pratikvasani/jquery-mentions.git"
},
"keywords": [
"jquery-plugin"
],
"author": "Pratik",
"license": "ISC",
"bugs": {
"url": "https://github.com/pratikvasani/jquery-mentions/issues"
},
"homepage": "https://github.com/pratikvasani/jquery-mentions#readme",
"devDependencies": {
"coffee-script": "^1.12.5"
},
"dependencies": {
"jquery": "~1.9.1",
"jquery-ui": "~1.10.3"
}
}

0 comments on commit 2bc6d9c

Please sign in to comment.