Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
libre
marka
Commits
ce8e64e4
Commit
ce8e64e4
authored
Jan 27, 2016
by
Smari McCarthy
Browse files
Start matching symbols
parent
37af0df8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
14 deletions
+47
-14
css/marka.css
css/marka.css
+1
-1
js/marka.js
js/marka.js
+46
-13
No files found.
css/marka.css
View file @
ce8e64e4
...
...
@@ -56,4 +56,4 @@
}
.marka
>
.marka-results
>
.marka-result
{
padding
:
0.1em
;
}
\ No newline at end of file
}
js/marka.js
View file @
ce8e64e4
...
...
@@ -2,13 +2,11 @@ cached_exchange_rates = {}
function
Marka
(
target
)
{
this
.
setCurrency
(
"
eur
"
);
this
.
getValueInSetCurrency
(
200
,
"
usd
"
,
function
(
value
){
console
.
log
(
"
Exchanged to:
"
+
value
);
});
if
(
!
target
)
{
this
.
target
=
$
(
'
body
'
).
get
();
}
else
{
...
...
@@ -21,7 +19,8 @@ function Marka(target) {
Marka
.
prototype
.
match
=
function
()
{
// docs: https://github.com/padolsey/findAndReplaceDOMText
var
currencySymbols
=
"
[€$¢¥₹₨]
"
;
this
.
currencySymbols
=
"
[€$¢¥₹₨]
"
;
var
currencySymbols
=
this
.
currencySymbols
;
var
currencyWords
=
"
(
"
+
currencySymbols
+
"
|kr|[Dd]ollars|[Cc]ents on the dollar|[Cc]ents|[Ee]uros|[Pp]ounds|[Rr]upees|[Zz]loty)
"
;
var
numbers
=
"
[
\\
d,.]+
"
;
var
optSpace
=
"
[
\\
s]*
"
;
...
...
@@ -35,7 +34,6 @@ Marka.prototype.match = function() {
var
format3
=
numbers
+
optSpace
+
magnitudes
+
optSpace
+
currencyWords
;
var
regex
=
new
RegExp
(
"
(
"
+
format1
+
"
|
"
+
format2
+
"
|
"
+
format3
+
"
)
"
,
"
g
"
)
findAndReplaceDOMText
(
this
.
target
,
{
find
:
regex
,
wrap
:
this
.
wrapNode
()
...
...
@@ -46,20 +44,55 @@ Marka.prototype.doConversions = function() {
var
self
=
this
;
$
(
"
.marka
"
).
each
(
function
(
index
,
value
)
{
var
text
=
$
(
value
).
text
();
self
.
splitSymbols
(
text
);
var
res
=
self
.
splitSymbols
(
text
);
if
(
!
res
)
{
$
(
value
).
replaceWith
(
text
)
}
});
}
Marka
.
prototype
.
splitSymbols
=
function
(
text
)
{
var
numbers
=
/
[\d
,.
]
+/
;
var
number
=
text
.
match
(
numbers
)[
0
];
try
{
var
number
=
text
.
match
(
numbers
)[
0
];
}
catch
(
e
)
{
return
false
;
}
var
residual
=
text
.
replace
(
numbers
,
""
);
var
symbol
=
this
.
findSymbol
(
residual
);
return
{
number
:
number
,
symbol
:
symbol
}
;
var
result
=
this
.
findSymbol
(
residual
);
return
true
;
}
Marka
.
prototype
.
findSymbol
=
function
(
text
)
{
var
result
=
{
certain
:
false
,
symbol
:
null
}
text
=
$
.
trim
(
text
);
console
.
log
(
"
>
"
+
text
+
"
<
"
);
if
(
text
.
match
(
/
[
A-Z
]{3}
/
))
{
for
(
code
in
currency_info
)
{
if
(
code
==
text
)
{
console
.
log
(
"
FOUND SYMBOL:
"
+
code
);
}
}
}
else
if
(
text
.
match
(
/
[
$€¥
]
/
))
{
for
(
code
in
currency_info
)
{
if
(
currency_info
[
code
].
symbol
==
text
)
{
console
.
log
(
"
FOUND SYMBOL:
"
+
code
);
}
}
}
return
text
;
/*
"ILS": {
"symbol": "₪",
"name": "Israeli New Sheqel",
"symbol_native": "₪",
"decimal_digits": 2,
"rounding": 0,
"code": "ILS",
"name_plural": "Israeli new sheqels"
},
*/
}
Marka
.
prototype
.
wrapNode
=
function
()
{
...
...
@@ -75,7 +108,7 @@ Marka.prototype.getValueInCurrency = function(value, from_currency, to_currency,
if
(
!
to_currency
){
callback
(
value
);
}
this
.
retreiveExchangeRates
(
from_currency
,
to_currency
,
function
(
rate
){
var
converted_amount
=
value
*
rate
;
callback
(
converted_amount
);
...
...
@@ -83,7 +116,7 @@ Marka.prototype.getValueInCurrency = function(value, from_currency, to_currency,
}
Marka
.
prototype
.
getCurrentCurrency
=
function
(){
var
currency
=
this
.
getCookie
(
"
currency
"
);
var
currency
=
this
.
getCookie
(
"
currency
"
);
return
currency
;
}
...
...
@@ -3459,4 +3492,4 @@ var currency_info = {
"
code
"
:
"
ZMK
"
,
"
name_plural
"
:
"
Zambian kwachas
"
}
}
\ No newline at end of file
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment