-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
persianjs jQuery Plugin #18
Open
MBehtemam
wants to merge
4
commits into
usablica:master
Choose a base branch
from
MBehtemam:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
(function( $ ){ | ||
|
||
/** | ||
* Used for Change keyboard layout | ||
* | ||
* @method _switchKey | ||
* @param {String} value | ||
* @return {String} Returns Converted char | ||
*/ | ||
function _switchKey(value) { | ||
if (!value) { | ||
return; | ||
} | ||
var persianChar = [ "ض", "ص", "ث", "ق", "ف", "غ", "ع", "ه", "خ", "ح", "ج", "چ", "ش", "س", "ی", "ب", "ل", "ا", "ت", "ن", "م", "ک", "گ", "ظ", "ط", "ز", "ر", "ذ", "د", "پ", "و","؟" ], | ||
englishChar = [ "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "z", "x", "c", "v", "b", "n", "m", ",","?" ]; | ||
|
||
for (var i = 0, charsLen = persianChar.length; i < charsLen; i++) { | ||
value = value.replace(new RegExp(persianChar[i], "g"), englishChar[i]); | ||
} | ||
return value; | ||
} | ||
|
||
/** | ||
* Used for convert Arabic numbers to Persian | ||
* | ||
* @method _toPersianNumber | ||
* @param {String} value | ||
* @return {String} Returns Converted numbers | ||
*/ | ||
function _toPersianNumber(value) { | ||
if (!value) { | ||
return; | ||
} | ||
var arabicNumbers = ["١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩", "٠"], | ||
persianNumbers = ["۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹", "۰"]; | ||
|
||
for (var i = 0, numbersLen = arabicNumbers.length; i < numbersLen; i++) { | ||
value = value.replace(new RegExp(arabicNumbers[i], "g"), persianNumbers[i]); | ||
} | ||
return value; | ||
} | ||
|
||
/** | ||
* Used for convert English numbers to Persian | ||
* @method _englishNumber | ||
* @param {String} value | ||
* @return {String} Returns Converted numbers | ||
*/ | ||
function _englishNumber(value) { | ||
if (!value) { | ||
return; | ||
} | ||
var englishNumbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"], | ||
persianNumbers = ["۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹", "۰"]; | ||
|
||
for (var i = 0, numbersLen = englishNumbers.length; i < numbersLen; i++) { | ||
value = value.replace(new RegExp(englishNumbers[i], "g"), persianNumbers[i]); | ||
} | ||
return value; | ||
} | ||
|
||
|
||
|
||
var methods = { | ||
englishNumber:function() { | ||
return this.each(function(){ | ||
$value = $(this).val(); | ||
$(this).val(_englishNumber($value)); | ||
}); | ||
|
||
}, | ||
toPersianChar:function(){ | ||
return this.each(function(){ | ||
$value = $(this).val(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You must mention about the state of none input element like <div id="someEnglishNumbers">123</div> elements! :) |
||
$(this).val(_toPersianChar($value)); | ||
}); | ||
}, | ||
toPersianNumber:function(){ | ||
return this.each(function(){ | ||
$value = $(this).val(); | ||
$(this).val(_toPersianNumber($value)); | ||
}); | ||
}, | ||
switchKey:function(){ | ||
return this.each(function(){ | ||
$value = $(this).val(); | ||
$(this).val(_switchKey($value)); | ||
}); | ||
} | ||
|
||
}; | ||
$.fn.persianjs = function( method ) { | ||
|
||
if ( methods[method] ) { | ||
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); | ||
} else if ( typeof method === 'object' || ! method ) { | ||
return methods.init.apply( this, arguments ); | ||
} else { | ||
$.error( 'Method ' + method + ' does not exist on jQuery.tooltip' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. jQuery Tooltip!? |
||
} | ||
|
||
}; | ||
|
||
})( jQuery ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"/> | ||
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | ||
<script src="../jquery.persian.js" type="text/javascript"></script> | ||
<script> | ||
$(function(){ | ||
$("#txtOne,#txtTwo").persianjs("englishNumber"); | ||
$("#txtThree").persianjs("toPersianNumber"); | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<input type="text" value="1234567890" id="txtOne"/> | ||
<input type="text" value="1234567890" id="txtTwo"/> | ||
<input type="text" value="٥" id="txtThree"/> | ||
</body> | ||
</html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
every change in core of persian.js need a method update, it's better to have such a dynamic binding in core method calls.
let see this Gist: https://gist.github.com/salisa/5063522