From e9d06b1ea823707383195d7a49f53e4657c6dc73 Mon Sep 17 00:00:00 2001
From: zhouminming01
Date: Sun, 11 Aug 2013 11:10:14 +0800
Subject: [PATCH 1/2] update
---
assets/index.css | 3 +
bin/jquery.emphasis.js | 121 ++++++++++++++++++++++++++++++-------
bin/jquery.emphasis.min.js | 4 +-
demo.html | 102 +------------------------------
src/emphasis.js | 25 ++++++--
src/markInfo.js | 4 +-
src/util.js | 76 +++++++++++++++++++----
src/variable.js | 16 ++++-
8 files changed, 204 insertions(+), 147 deletions(-)
diff --git a/assets/index.css b/assets/index.css
index 8d33165..cb49bd4 100644
--- a/assets/index.css
+++ b/assets/index.css
@@ -206,6 +206,9 @@ dl {
-o-writing-mode: vertical-rl;
writing-mode: vertical-rl;
}
+#example11 em {
+ letter-spacing: 5px;
+}
.lang-zh {
font-family:"ff-tisa-web-pro-1","ff-tisa-web-pro-2",
diff --git a/bin/jquery.emphasis.js b/bin/jquery.emphasis.js
index 5f6367e..579c7c0 100644
--- a/bin/jquery.emphasis.js
+++ b/bin/jquery.emphasis.js
@@ -8,10 +8,24 @@ var classInlineBlockHash = 'inline-block' + hash;
var classInlineHash = 'inline' + hash;
var classScaleHash = 'scale' + hash;
var classOverMarkHash = 'over' + hash;
+var classRightMarkHash = 'right' + hash;
+var classLeftMarkHash = 'left' + hash;
var classUnderMarkHash = 'under' + hash;
var positionClassMap = {
'over': classOverMarkHash,
- 'under': classUnderMarkHash
+ 'under': classUnderMarkHash,
+ 'right': classRightMarkHash,
+ 'left': classLeftMarkHash
+};
+var positionToOriginMap = {
+ 'over': ':top left;',
+ 'under': ':bottom left;',
+ 'right': ':top right;',
+ 'left': ':top left;'
+};
+var isVerticalPosition = {
+ 'right': 1,
+ 'left': 1
};
var uniqueId = 0;
@@ -58,7 +72,8 @@ var skipHtmlTagName = {
/*global hash:false, uniqueId:false, classInlineBlockHash:false,
-classInlineHash:false, classOverMarkHash:false, classScaleHash:false */
+classInlineHash:false, classOverMarkHash:false, classScaleHash:false,
+classRightMarkHash:false, classLeftMarkHash:false*/
var styleSheet;
// cache for presudo-class css rule
@@ -181,6 +196,7 @@ var Util = {
*/
supportEmphasis: function supportEmphasis() {
// TODO
+ return false;
if (typeof supportEmphasis.result !== 'undefined') {
return supportEmphasis.result;
}
@@ -255,11 +271,6 @@ var Util = {
'text-decoration:inherit;' +
'line-height:inherit;'
);
- // .inline-block.over
- this.addCSSRule('.' + classInlineBlockHash + '.' + classOverMarkHash,
- 'padding:0.5em 0 0 0;'
- );
-
// .inline
this.addCSSRule('.' + classInlineHash,
'position:relative;' +
@@ -305,30 +316,85 @@ var Util = {
styleForBeforeClass
);
+
// .inline.scale:before
this.addCSSRule(
'.' + classInlineHash + '.' + classScaleHash + ':before',
'bottom: -0.5em;' +
'width: 200%;'
);
+ // .inline-block.scale:before
+ this.addCSSRule(
+ '.' + classInlineBlockHash + '.' + classScaleHash + ':before',
+ 'width: 200%;'
+ );
+
+ // over
+ // .inline-block.over
+ this.addCSSRule('.' + classInlineBlockHash + '.' + classOverMarkHash,
+ 'padding:0.5em 0 0 0;'
+ );
// .inline.over:before
this.addCSSRule(
'.' + classInlineHash + '.' + classOverMarkHash + ':before',
'top: -0.5em;' +
'bottom: auto;'
);
-
- // .inline-block.scale:before
- this.addCSSRule(
- '.' + classInlineBlockHash + '.' + classScaleHash + ':before',
- 'width: 200%;'
- );
// .inline-block.over:before
this.addCSSRule(
'.' + classInlineBlockHash + '.' + classOverMarkHash + ':before',
'top: 0;' +
'bottom: auto;'
);
+
+
+ // right
+ // .inline-block.right
+ this.addCSSRule('.' + classInlineBlockHash + '.' + classRightMarkHash,
+ 'padding:0 0.5em 0 0;'
+ );
+ // .right:before
+ this.addCSSRule(
+ '.' + classRightMarkHash + ':before',
+ 'vertical-align:middle;' +
+ 'height: 100%;' +
+ 'line-height: 100%;' +
+ 'width: 1em;' +
+ 'top: 0;' +
+ 'background: red;' +
+ 'bottom: auto;'
+ );
+ // .inline.right:before
+ this.addCSSRule(
+ '.' + classInlineHash + '.' + classRightMarkHash + ':before',
+ 'right: -0.5em;'
+ );
+ // .inline-block.right:before
+ this.addCSSRule(
+ '.' + classInlineBlockHash + '.' + classRightMarkHash + ':before',
+ 'right: 0;'
+ );
+ // .right.scale:before
+ this.addCSSRule(
+ '.' + classRightMarkHash + '.' + classScaleHash + ':before',
+ 'height: 200%;' +
+ 'line-height: 200%;' +
+ 'width: 1em;'
+ );
+ /*
+ // .inline.scale.right:before
+ this.addCSSRule(
+ '.' + classInlineHash + '.' + classScaleHash +
+ '.' + classRightMarkHash + ':before',
+ 'line-height: 2em;'
+ );
+ // .inline-block.scale.right:before
+ this.addCSSRule(
+ '.' + classInlineBlockHash + '.' + classScaleHash +
+ '.' + classRightMarkHash + ':before',
+ 'line-height: 2em;'
+ );
+ */
},
/**
@@ -380,9 +446,6 @@ var Util = {
}
};
-var rString = /['"]([^'"]+)['"]/;
-var rMark = /(dot|circle|double-circle|triangle|sesame)/;
-var rPosition = /(under|over|left|right)/;
var rString = /['"]([^'"]+)['"]/;
var rMark = /(dot|circle|double-circle|triangle|sesame)/;
var rPosition = /(under|over|left|right)/;
@@ -472,6 +535,7 @@ MarkInfo.prototype.parse = function(styleAndColor, position) {
setResult = this.set('mark', r[1]);
} else {
// >> color like 'red'
+ // TODO validate color param
setResult = this.set('color', $.trim(value));
}
@@ -538,6 +602,7 @@ MarkInfo.prototype.autoComplete = function() {
/*global classInlineBlockHash:false, classInlineHash:false,
classOverMarkHash:false, classScaleHash:false,
skipHtmlTagName:false, Util:false, positionClassMap:false,
+positionToOriginMap:false, isVerticalPosition:false,
ignoreCharacter:false, MarkInfo:false, markMap:false */
/**
@@ -715,6 +780,8 @@ Emphasis.prototype.fakeEmphasis = function($el, markInfo, level) {
}
};
+
+
/**
* text node to html with mark
*
@@ -735,6 +802,11 @@ Emphasis.prototype.textToHtml = function($node, $parent, markInfo) {
useInlineBlock = true;
}
+ var isVertical = isVerticalPosition[markInfo.position];
+ if (isVertical) {
+ console.log(markInfo);
+ }
+
// calculate mark style
var useScale = Util.supportScale();
var markStyle;
@@ -742,16 +814,20 @@ Emphasis.prototype.textToHtml = function($node, $parent, markInfo) {
// support `transform: scale(0.5);`
markStyle = useScale[0] + ':scale(0.5);' +
useScale[1] +
- (markInfo.position === 'over' ? ':top left;' : ':bottom left;');
+ positionToOriginMap[markInfo.position];
} else {
- markStyle = 'font-size:' + markFontSize + 'px;' +
- 'height:' + markFontSize + 'px;' +
- 'line-height:' + markFontSize + 'px;';
+ if (isVertical) {
+ markStyle = 'font-size:' + markFontSize + 'px;';
+ } else {
+ markStyle = 'font-size:' + markFontSize + 'px;' +
+ 'height:' + markFontSize + 'px;' +
+ 'line-height:' + markFontSize + 'px;';
+ }
}
// add css rules for mark `font-size or scale` relative style
var uniqueFontClass = Util.addBeforeCSSRule(
'mark',
- useScale ? markInfo.position : markFontSize,
+ markInfo.position + markFontSize,
markStyle
);
@@ -785,7 +861,8 @@ Emphasis.prototype.textToHtml = function($node, $parent, markInfo) {
var marginRightStyle = '';
if (letterSpacing !== 'normal' &&
letterSpacing !== 0) {
- marginRightStyle = 'margin-right:' + letterSpacing + ';';
+ marginRightStyle = (isVertical ? 'margin-bottom:' : 'margin-right:') +
+ letterSpacing + ';';
}
// generate html
diff --git a/bin/jquery.emphasis.min.js b/bin/jquery.emphasis.min.js
index 0266874..30f3fbb 100644
--- a/bin/jquery.emphasis.min.js
+++ b/bin/jquery.emphasis.min.js
@@ -1,6 +1,6 @@
/*!
jquery.emphasis.js
0.1.1
- 10-08-2013
+ 11-08-2013
*/
-!function(a){function b(a,b,c){this.markInfo=a,this.$el=b,this.styleNames=c,this.setEmphasis()}var c,d="9a91ab9b8e64d2cf7fce0616b66efbaf",e="inline-block"+d,f="inline"+d,g="scale"+d,h="over"+d,i="under"+d,j={over:h,under:i},k=0,l={dot:["•","◦"],circle:["●","○"],"double-circle":["◉","◎"],triangle:["▲","△"],sesame:["﹅","﹆"]},m={" ":1," ":1,"፡":1,"တ0":1,"တ1":1,"္F":1,"႑F":1,"་":1,"༌":1,"":1," ":1," ":1," ":1,"\0":1," ":1,"\n":1,"\r":1,"
":1},n={style:1,script:1,textarea:1,input:1},o={"char":{},color:{},mark:{}},p={addCSSRule:function(b,d){if(!c){var e=document.createElement("style");e.type="text/css",a("head").eq(0).prepend(e),c=document.styleSheets[0]}c.insertRule?c.insertRule(b+"{"+d+"}",c.cssRules.length):c.addRule(b,d,-1)},addBeforeCSSRule:function(a,b,c){var e=o[a];if(e[b])return e[b];var f=a+k++ +d;return this.addCSSRule("."+f+":before",c),e[b]=f,f},testStyle:function(a,b){for(var c=["webkit","moz","o","ms"],d=0,e=c.length;e>d;d++)if(""===a.style[c[d]+b])return c[d]+b;var f=b.charAt(0).toLowerCase()+b.slice(1);return"undefined"!=typeof a.style[f]?f:!1},jsNameToCssName:function(a){return a.replace(/[A-Z]/g,function(a){return"-"+a.toLowerCase()}).replace(/^(webkit|moz|o|ms)\-/,"-$1-")},supportScale:function u(){if("undefined"!=typeof u.result)return u.result;var a,b=document.createElement("div"),c=this.testStyle(b,"Transform"),d=this.testStyle(b,"TransformOrigin");return c&&d?(c=this.jsNameToCssName(c),d=this.jsNameToCssName(d),a=[c,d]):a=null,u.result=a,a},supportEmphasis:function v(){if("undefined"!=typeof v.result)return v.result;var a,b=document.createElement("div"),c=this.testStyle(b,"TextEmphasis"),d=this.testStyle(b,"TextEmphasisPosition");return a=c&&d?[c,d]:null,v.result=a,a},supportWritingMode:function w(){if("undefined"!=typeof w.result)return w.result;var a,b=document.createElement("div"),c=this.testStyle(b,"WritingMode");return c?(c=this.jsNameToCssName(c),a=c):a=null,w.result=a,a},initCSSRule:function x(){if(!x.inited){x.inited=!0,this.addCSSRule("."+e,"position:relative;display:inline-block;_zoom:1;float:none;border:none;margin:0;padding:0 0 0.5em 0;vertical-align: baseline;color:inherit;font-size:inherit;font-family:inherit;letter-spacing: normal;text-decoration:inherit;line-height:inherit;"),this.addCSSRule("."+e+"."+h,"padding:0.5em 0 0 0;"),this.addCSSRule("."+f,"position:relative;float:none;border:none;margin:0;padding:0;vertical-align: baseline;color:inherit;font-size:inherit;font-family:inherit;letter-spacing: normal;text-decoration:inherit;line-height:inherit;");var a="position:absolute;bottom: 0;left: 0;height: 1em;line-height: 1em;text-align: center;width: 100%;float:none;border:none;margin:0;padding:0;vertical-align: baseline;color:inherit;font-size: inherit;font-family:inherit;text-decoration: none;";this.addCSSRule("."+f+":before",a+"bottom: -1em;"),this.addCSSRule("."+e+":before",a),this.addCSSRule("."+f+"."+g+":before","bottom: -0.5em;width: 200%;"),this.addCSSRule("."+f+"."+h+":before","top: -0.5em;bottom: auto;"),this.addCSSRule("."+e+"."+g+":before","width: 200%;"),this.addCSSRule("."+e+"."+h+":before","top: 0;bottom: auto;")}},getLineHeight:function(a,b){var c=a.css("line-height");return"normal"===c?this.getNormalLineHeight(b):c.match(/px/)?parseInt(c,10):b*c},getNormalLineHeight:function y(b){if("undefined"!=typeof y.result)return y.result;var c=a('Some words.
');c.css("font-size",b+"px"),c.appendTo("body");var d=c.height();return c.remove(),y.result=d,d}},q=/['"]([^'"]+)['"]/,r=/(dot|circle|double-circle|triangle|sesame)/,s=/(under|over|left|right)/,q=/['"]([^'"]+)['"]/,r=/(dot|circle|double-circle|triangle|sesame)/,s=/(under|over|left|right)/,t=function(a,b){this.parse(a,b)};t.prototype.set=function(a,b){return"undefined"!=typeof this[a]?!1:(this[a]=b,!0)},t.prototype.parse=function(b,c){var d;if(c){if(!(d=c.match(s)))return this.error=!0,void 0;this.position=d[1]}if(!b)return this.error=!0,void 0;b=b.split(" ");for(var e,f,g=0,h=b.length;h>g;g++){if(e=b[g],d=e.match(q)){var i=d[1];if(i.length>1&&(i=i.charAt(0)),f=this.set("mark",i),this.isStringMark=!0,f)return}else{if(-1!==e.indexOf("none"))return this.isNone=!0,void 0;f=-1!==e.indexOf("filled")?this.set("filled",!0):-1!==e.indexOf("open")?this.set("filled",!1):(d=e.match(r))?this.set("mark",d[1]):this.set("color",a.trim(e))}if(!f)return this.error=!0,void 0}"undefined"==typeof this.mark&&"undefined"==typeof this.filled&&(this.error=!0)},t.prototype.autoComplete=function(){if(!this.isNone){var a=navigator.language||navigator.browserLanguage;a=a.slice(0,2);var b="ja"===a;null==this.position&&(this.position=b?"over":"under");var c="undefined"!=typeof this.filled,d="undefined"!=typeof this.mark;c&&d||d&&this.isStringMark||(d?this.filled=!0:c&&(this.mark="circle"))}},b.prototype.removeEmphasis=function(){this.styleNames?this.$el.css(this.styleNames[0],"none"):this.removeEmphasizedTag(this.$el)},b.prototype.setEmphasis=function(){this.markInfo.isNone?this.removeEmphasis():(this.markInfo.autoComplete(),this.styleNames?this.setEmphasisByCSS():this.setEmphasisByFallback())},b.prototype.setEmphasisByCSS=function(){var a={};a[this.styleNames[0]]=this.markInfo.isStringMark?'"'+this.markInfo.mark+'"':""+(this.markInfo.filled?"filled":"open")+" "+this.markInfo.mark+" "+(this.markInfo.color||""),a[this.styleNames[1]]=this.markInfo.position,this.$el.css(a)},b.prototype.setEmphasisByFallback=function(){p.initCSSRule(),this.markInfo.character=l[this.markInfo.mark]?l[this.markInfo.mark][this.markInfo.filled?0:1]:this.markInfo.mark.charAt(0),this.fakeEmphasis(this.$el,this.markInfo)},b.prototype.removeEmphasizedTag=function(b,c){if(this.isEmphasizedTag(b[0]))return b.replaceWith(b.text()),void 0;for(var d,e=b.children(),f=0,g=e.length;g>f;f++)d=a(e[f]),this.isEmphasizedTag(d[0])?d.replaceWith(d.text()):c||this.removeEmphasizedTag(d)},b.prototype.hasEmphasizedTag=function(a){for(var b,c=a.children(),d=0,e=c.length;e>d;d++)if(b=c[d],this.isEmphasizedTag(b))return!0;return!1},b.prototype.isEmphasizedTag=function(a){var b=a.className;return-1!==b.indexOf(e)||-1!==b.indexOf(f)},b.prototype.fakeEmphasis=function(b,c,d){d=d||1,1===d&&this.removeEmphasizedTag(b,!0);for(var e,f=b.contents(),g=0,h=f.length;h>g;g++)if(e=f[g],3===e.nodeType)this.textToHtml(a(e),b,c);else if(1===e.nodeType){var i=this.isEmphasizedTag(e),j=e.nodeName.toLowerCase();n[j]||i||this.fakeEmphasis(a(e),c,d+1)}},b.prototype.textToHtml=function(a,b,c){var d=parseInt(b.css("font-size"),10),h=p.getLineHeight(b,d),i=d/2,k=!1;i>(h-d)/2&&(k=!0);var l,n=p.supportScale();l=n?n[0]+":scale(0.5);"+n[1]+("over"===c.position?":top left;":":bottom left;"):"font-size:"+i+"px;"+"height:"+i+"px;"+"line-height:"+i+"px;";var o=p.addBeforeCSSRule("mark",n?c.position:i,l),q="";c.color&&(q=p.addBeforeCSSRule("color",c.color,"color:"+c.color+" !important;"));var r=k?e:f,s=p.addBeforeCSSRule("char",c.character,"content:'"+c.character+"';"),t=j[c.position],u=b.css("letter-spacing"),v="";"normal"!==u&&0!==u&&(v="margin-right:"+u+";");for(var w,x='',y="",z=a.text(),A=[],B=0,C=z.length;C>B;B++)w=z.charAt(B),m[w]?A.push(w):(A.push(x),A.push(w),A.push(y));a.replaceWith(A.join(""))},a.fn.emphasis=function(c,d){var e=new t(c,d);if(!e.error)return this.each(function(c,d){var f=a(d),g=p.supportEmphasis();new b(e,f,g)}),this}}(jQuery);
\ No newline at end of file
+!function(a){function b(a,b,c){this.markInfo=a,this.$el=b,this.styleNames=c,this.setEmphasis()}var c,d="9a91ab9b8e64d2cf7fce0616b66efbaf",e="inline-block"+d,f="inline"+d,g="scale"+d,h="over"+d,i="right"+d,j="left"+d,k="under"+d,l={over:h,under:k,right:i,left:j},m={over:":top left;",under:":bottom left;",right:":top right;",left:":top left;"},n={right:1,left:1},o=0,p={dot:["•","◦"],circle:["●","○"],"double-circle":["◉","◎"],triangle:["▲","△"],sesame:["﹅","﹆"]},q={" ":1," ":1,"፡":1,"တ0":1,"တ1":1,"္F":1,"႑F":1,"་":1,"༌":1,"":1," ":1," ":1," ":1,"\0":1," ":1,"\n":1,"\r":1,"
":1},r={style:1,script:1,textarea:1,input:1},s={"char":{},color:{},mark:{}},t={addCSSRule:function(b,d){if(!c){var e=document.createElement("style");e.type="text/css",a("head").eq(0).prepend(e),c=document.styleSheets[0]}c.insertRule?c.insertRule(b+"{"+d+"}",c.cssRules.length):c.addRule(b,d,-1)},addBeforeCSSRule:function(a,b,c){var e=s[a];if(e[b])return e[b];var f=a+o++ +d;return this.addCSSRule("."+f+":before",c),e[b]=f,f},testStyle:function(a,b){for(var c=["webkit","moz","o","ms"],d=0,e=c.length;e>d;d++)if(""===a.style[c[d]+b])return c[d]+b;var f=b.charAt(0).toLowerCase()+b.slice(1);return"undefined"!=typeof a.style[f]?f:!1},jsNameToCssName:function(a){return a.replace(/[A-Z]/g,function(a){return"-"+a.toLowerCase()}).replace(/^(webkit|moz|o|ms)\-/,"-$1-")},supportScale:function y(){if("undefined"!=typeof y.result)return y.result;var a,b=document.createElement("div"),c=this.testStyle(b,"Transform"),d=this.testStyle(b,"TransformOrigin");return c&&d?(c=this.jsNameToCssName(c),d=this.jsNameToCssName(d),a=[c,d]):a=null,y.result=a,a},supportEmphasis:function z(){return!1},supportWritingMode:function A(){if("undefined"!=typeof A.result)return A.result;var a,b=document.createElement("div"),c=this.testStyle(b,"WritingMode");return c?(c=this.jsNameToCssName(c),a=c):a=null,A.result=a,a},initCSSRule:function B(){if(!B.inited){B.inited=!0,this.addCSSRule("."+e,"position:relative;display:inline-block;_zoom:1;float:none;border:none;margin:0;padding:0 0 0.5em 0;vertical-align: baseline;color:inherit;font-size:inherit;font-family:inherit;letter-spacing: normal;text-decoration:inherit;line-height:inherit;"),this.addCSSRule("."+f,"position:relative;float:none;border:none;margin:0;padding:0;vertical-align: baseline;color:inherit;font-size:inherit;font-family:inherit;letter-spacing: normal;text-decoration:inherit;line-height:inherit;");var a="position:absolute;bottom: 0;left: 0;height: 1em;line-height: 1em;text-align: center;width: 100%;float:none;border:none;margin:0;padding:0;vertical-align: baseline;color:inherit;font-size: inherit;font-family:inherit;text-decoration: none;";this.addCSSRule("."+f+":before",a+"bottom: -1em;"),this.addCSSRule("."+e+":before",a),this.addCSSRule("."+f+"."+g+":before","bottom: -0.5em;width: 200%;"),this.addCSSRule("."+e+"."+g+":before","width: 200%;"),this.addCSSRule("."+e+"."+h,"padding:0.5em 0 0 0;"),this.addCSSRule("."+f+"."+h+":before","top: -0.5em;bottom: auto;"),this.addCSSRule("."+e+"."+h+":before","top: 0;bottom: auto;"),this.addCSSRule("."+e+"."+i,"padding:0 0.5em 0 0;"),this.addCSSRule("."+i+":before","vertical-align:middle;height: 100%;line-height: 100%;width: 1em;top: 0;background: red;bottom: auto;"),this.addCSSRule("."+f+"."+i+":before","right: -0.5em;"),this.addCSSRule("."+e+"."+i+":before","right: 0;"),this.addCSSRule("."+i+"."+g+":before","height: 200%;line-height: 200%;width: 1em;")}},getLineHeight:function(a,b){var c=a.css("line-height");return"normal"===c?this.getNormalLineHeight(b):c.match(/px/)?parseInt(c,10):b*c},getNormalLineHeight:function C(b){if("undefined"!=typeof C.result)return C.result;var c=a('Some words.
');c.css("font-size",b+"px"),c.appendTo("body");var d=c.height();return c.remove(),C.result=d,d}},u=/['"]([^'"]+)['"]/,v=/(dot|circle|double-circle|triangle|sesame)/,w=/(under|over|left|right)/,x=function(a,b){this.parse(a,b)};x.prototype.set=function(a,b){return"undefined"!=typeof this[a]?!1:(this[a]=b,!0)},x.prototype.parse=function(b,c){var d;if(c){if(!(d=c.match(w)))return this.error=!0,void 0;this.position=d[1]}if(!b)return this.error=!0,void 0;b=b.split(" ");for(var e,f,g=0,h=b.length;h>g;g++){if(e=b[g],d=e.match(u)){var i=d[1];if(i.length>1&&(i=i.charAt(0)),f=this.set("mark",i),this.isStringMark=!0,f)return}else{if(-1!==e.indexOf("none"))return this.isNone=!0,void 0;f=-1!==e.indexOf("filled")?this.set("filled",!0):-1!==e.indexOf("open")?this.set("filled",!1):(d=e.match(v))?this.set("mark",d[1]):this.set("color",a.trim(e))}if(!f)return this.error=!0,void 0}"undefined"==typeof this.mark&&"undefined"==typeof this.filled&&(this.error=!0)},x.prototype.autoComplete=function(){if(!this.isNone){var a=navigator.language||navigator.browserLanguage;a=a.slice(0,2);var b="ja"===a;null==this.position&&(this.position=b?"over":"under");var c="undefined"!=typeof this.filled,d="undefined"!=typeof this.mark;c&&d||d&&this.isStringMark||(d?this.filled=!0:c&&(this.mark="circle"))}},b.prototype.removeEmphasis=function(){this.styleNames?this.$el.css(this.styleNames[0],"none"):this.removeEmphasizedTag(this.$el)},b.prototype.setEmphasis=function(){this.markInfo.isNone?this.removeEmphasis():(this.markInfo.autoComplete(),this.styleNames?this.setEmphasisByCSS():this.setEmphasisByFallback())},b.prototype.setEmphasisByCSS=function(){var a={};a[this.styleNames[0]]=this.markInfo.isStringMark?'"'+this.markInfo.mark+'"':""+(this.markInfo.filled?"filled":"open")+" "+this.markInfo.mark+" "+(this.markInfo.color||""),a[this.styleNames[1]]=this.markInfo.position,this.$el.css(a)},b.prototype.setEmphasisByFallback=function(){t.initCSSRule(),this.markInfo.character=p[this.markInfo.mark]?p[this.markInfo.mark][this.markInfo.filled?0:1]:this.markInfo.mark.charAt(0),this.fakeEmphasis(this.$el,this.markInfo)},b.prototype.removeEmphasizedTag=function(b,c){if(this.isEmphasizedTag(b[0]))return b.replaceWith(b.text()),void 0;for(var d,e=b.children(),f=0,g=e.length;g>f;f++)d=a(e[f]),this.isEmphasizedTag(d[0])?d.replaceWith(d.text()):c||this.removeEmphasizedTag(d)},b.prototype.hasEmphasizedTag=function(a){for(var b,c=a.children(),d=0,e=c.length;e>d;d++)if(b=c[d],this.isEmphasizedTag(b))return!0;return!1},b.prototype.isEmphasizedTag=function(a){var b=a.className;return-1!==b.indexOf(e)||-1!==b.indexOf(f)},b.prototype.fakeEmphasis=function(b,c,d){d=d||1,1===d&&this.removeEmphasizedTag(b,!0);for(var e,f=b.contents(),g=0,h=f.length;h>g;g++)if(e=f[g],3===e.nodeType)this.textToHtml(a(e),b,c);else if(1===e.nodeType){var i=this.isEmphasizedTag(e),j=e.nodeName.toLowerCase();r[j]||i||this.fakeEmphasis(a(e),c,d+1)}},b.prototype.textToHtml=function(a,b,c){var d=parseInt(b.css("font-size"),10),h=t.getLineHeight(b,d),i=d/2,j=!1;i>(h-d)/2&&(j=!0);var k=n[c.position];k&&console.log(c);var o,p=t.supportScale();o=p?p[0]+":scale(0.5);"+p[1]+m[c.position]:k?"font-size:"+i+"px;":"font-size:"+i+"px;"+"height:"+i+"px;"+"line-height:"+i+"px;";var r=t.addBeforeCSSRule("mark",c.position+i,o),s="";c.color&&(s=t.addBeforeCSSRule("color",c.color,"color:"+c.color+" !important;"));var u=j?e:f,v=t.addBeforeCSSRule("char",c.character,"content:'"+c.character+"';"),w=l[c.position],x=b.css("letter-spacing"),y="";"normal"!==x&&0!==x&&(y=(k?"margin-bottom:":"margin-right:")+x+";");for(var z,A='',B="",C=a.text(),D=[],E=0,F=C.length;F>E;E++)z=C.charAt(E),q[z]?D.push(z):(D.push(A),D.push(z),D.push(B));a.replaceWith(D.join(""))},a.fn.emphasis=function(c,d){var e=new x(c,d);if(!e.error)return this.each(function(c,d){var f=a(d),g=t.supportEmphasis();new b(e,f,g)}),this}}(jQuery);
\ No newline at end of file
diff --git a/demo.html b/demo.html
index 475271f..03472df 100644
--- a/demo.html
+++ b/demo.html
@@ -12,115 +12,15 @@
jQuery.emphasis.js Demo
-
When you're down, and the world seems dark and empty,
Your forever friend lifts you up in spirits and makes that dark and empty world suddenly seem bright and full.
Your forever friend gets you through the hard times, the sad times, and the confused times. If you turn and walk away, Your forever friend follows, If you lose you way,
Your forever friend guides you and cheers you on.
-
$('#example1 em').css('color', 'red');
-$('#example1 em:eq(0)').emphasis('filled');
-$('#example1 em:eq(1)').emphasis('dot #069');
-$('#example1 em:eq(2)').emphasis('open sesame', 'over');
-
-
-
Different language
-
-
過去(かこ)から逃(に)げるのは許(ゆる)してやる。だけどな、せめて今と明日からは、逃げんじゃねぇよ。原谅你逃避过去,但是,至少不要逃避现在和明天啊。---《无头骑士异闻录》
-
やさしい言葉(ことば)は、たとえ簡単(かんたん)な言葉でも、ずっとずっ と心(こころ)にこだまする。温柔的言语,就算是简单一句话,也会一直一直在心中回响。
-
$('#example2 em:eq(0), #example2 em:eq(2)')
- .emphasis('open sesame', 'over');
-$('#example2 em:eq(1), #example2 em:eq(3)')
- .emphasis('filled dot', 'under');
-
-
-
Special case
-
-
letter-spacing
-
-
Freeeeeeeeeeeeeeeeeeeeedom!
-
$('#example3 span').emphasis('filled');
-
-
-
color
-
-
Every cloud has a silver lining!
-
$('#example4 em').css('color', '#069').emphasis('filled orange');
-
-
-
block element
-
-
- It was the best of times,
- It was the worst of times,
- It was the age of wisdom,
- It was the age of foolishness,
- It was the epoch of belief,
- It was the epoch of incredulity,
- It was the season of Light,
- It was the season of Darkness,
- It was the spring of hope,
- It was the winter of despair.
-
-
$('#example5 em').emphasis('filled dot orange');
-$('#example5 p').emphasis('filled dot');
-
-
-
emphasis('none')
-
-
There is not an emphasis.
-
-
$('#example6 p').emphasis('dot')
- .emphasis('none');
-
-
Different font-size
-
-
Browser like chrome, firefox, opera, safari can setup the minimal font-size. It will effect this plugin if the browser not support CSS3 transform.
-
-
$('#example7 em:eq(0)').css('font-size', '24px')
- .emphasis('dot');
-$('#example7 em:eq(1)').css('font-size', '12px')
- .emphasis('dot');
-
-
-
Special character
-
-
Lift up your head princess, if not, the crown falls.
-
-
$('#example8 em').css('font-family', 'monospace')
- .css('font-style', 'normal')
- .css('font-size', '24px')
- .emphasis('"♥"');
-
-
-
Special line-height
-
-
- line-height: normal;
- - Behind every successful man there's a lot u unsuccessful years.
- line-height: 200%;
- - I think success has no rules, but you can learn a lot from failure.
- - with inline image
- - There are no secrets to success.
It is the result of preparation, hard work, and learning from failure.
-
-
$('#example9 em').emphasis('circle');
-
-
-
Priority test
-
-
- East Asian documents traditionally use small symbols next to each glyph to emphasize a run of text.
-
-
$('#example10 em:eq(0)').emphasis('open sesame orange');
-$('#example10 p').emphasis('circle');
-$('#example10 em:eq(1)').emphasis('open sesame #069');
-
-
diff --git a/src/emphasis.js b/src/emphasis.js
index 7a7cc91..ffcc540 100644
--- a/src/emphasis.js
+++ b/src/emphasis.js
@@ -1,6 +1,7 @@
/*global classInlineBlockHash:false, classInlineHash:false,
classOverMarkHash:false, classScaleHash:false,
skipHtmlTagName:false, Util:false, positionClassMap:false,
+positionToOriginMap:false, isVerticalPosition:false,
ignoreCharacter:false, MarkInfo:false, markMap:false */
/**
@@ -178,6 +179,8 @@ Emphasis.prototype.fakeEmphasis = function($el, markInfo, level) {
}
};
+
+
/**
* text node to html with mark
*
@@ -198,6 +201,11 @@ Emphasis.prototype.textToHtml = function($node, $parent, markInfo) {
useInlineBlock = true;
}
+ var isVertical = isVerticalPosition[markInfo.position];
+ if (isVertical) {
+ console.log(markInfo);
+ }
+
// calculate mark style
var useScale = Util.supportScale();
var markStyle;
@@ -205,16 +213,20 @@ Emphasis.prototype.textToHtml = function($node, $parent, markInfo) {
// support `transform: scale(0.5);`
markStyle = useScale[0] + ':scale(0.5);' +
useScale[1] +
- (markInfo.position === 'over' ? ':top left;' : ':bottom left;');
+ positionToOriginMap[markInfo.position];
} else {
- markStyle = 'font-size:' + markFontSize + 'px;' +
- 'height:' + markFontSize + 'px;' +
- 'line-height:' + markFontSize + 'px;';
+ if (isVertical) {
+ markStyle = 'font-size:' + markFontSize + 'px;';
+ } else {
+ markStyle = 'font-size:' + markFontSize + 'px;' +
+ 'height:' + markFontSize + 'px;' +
+ 'line-height:' + markFontSize + 'px;';
+ }
}
// add css rules for mark `font-size or scale` relative style
var uniqueFontClass = Util.addBeforeCSSRule(
'mark',
- useScale ? markInfo.position : markFontSize,
+ markInfo.position + markFontSize,
markStyle
);
@@ -248,7 +260,8 @@ Emphasis.prototype.textToHtml = function($node, $parent, markInfo) {
var marginRightStyle = '';
if (letterSpacing !== 'normal' &&
letterSpacing !== 0) {
- marginRightStyle = 'margin-right:' + letterSpacing + ';';
+ marginRightStyle = (isVertical ? 'margin-bottom:' : 'margin-right:') +
+ letterSpacing + ';';
}
// generate html
diff --git a/src/markInfo.js b/src/markInfo.js
index f9b1cc8..b130831 100644
--- a/src/markInfo.js
+++ b/src/markInfo.js
@@ -1,9 +1,6 @@
var rString = /['"]([^'"]+)['"]/;
var rMark = /(dot|circle|double-circle|triangle|sesame)/;
var rPosition = /(under|over|left|right)/;
-var rString = /['"]([^'"]+)['"]/;
-var rMark = /(dot|circle|double-circle|triangle|sesame)/;
-var rPosition = /(under|over|left|right)/;
/**
* MarkInfo
*
@@ -90,6 +87,7 @@ MarkInfo.prototype.parse = function(styleAndColor, position) {
setResult = this.set('mark', r[1]);
} else {
// >> color like 'red'
+ // TODO validate color param
setResult = this.set('color', $.trim(value));
}
diff --git a/src/util.js b/src/util.js
index b022135..f3b2715 100644
--- a/src/util.js
+++ b/src/util.js
@@ -1,5 +1,6 @@
/*global hash:false, uniqueId:false, classInlineBlockHash:false,
-classInlineHash:false, classOverMarkHash:false, classScaleHash:false */
+classInlineHash:false, classOverMarkHash:false, classScaleHash:false,
+classRightMarkHash:false, classLeftMarkHash:false*/
var styleSheet;
// cache for presudo-class css rule
@@ -122,6 +123,7 @@ var Util = {
*/
supportEmphasis: function supportEmphasis() {
// TODO
+ return false;
if (typeof supportEmphasis.result !== 'undefined') {
return supportEmphasis.result;
}
@@ -196,11 +198,6 @@ var Util = {
'text-decoration:inherit;' +
'line-height:inherit;'
);
- // .inline-block.over
- this.addCSSRule('.' + classInlineBlockHash + '.' + classOverMarkHash,
- 'padding:0.5em 0 0 0;'
- );
-
// .inline
this.addCSSRule('.' + classInlineHash,
'position:relative;' +
@@ -246,30 +243,85 @@ var Util = {
styleForBeforeClass
);
+
// .inline.scale:before
this.addCSSRule(
'.' + classInlineHash + '.' + classScaleHash + ':before',
'bottom: -0.5em;' +
'width: 200%;'
);
+ // .inline-block.scale:before
+ this.addCSSRule(
+ '.' + classInlineBlockHash + '.' + classScaleHash + ':before',
+ 'width: 200%;'
+ );
+
+ // over
+ // .inline-block.over
+ this.addCSSRule('.' + classInlineBlockHash + '.' + classOverMarkHash,
+ 'padding:0.5em 0 0 0;'
+ );
// .inline.over:before
this.addCSSRule(
'.' + classInlineHash + '.' + classOverMarkHash + ':before',
'top: -0.5em;' +
'bottom: auto;'
);
-
- // .inline-block.scale:before
- this.addCSSRule(
- '.' + classInlineBlockHash + '.' + classScaleHash + ':before',
- 'width: 200%;'
- );
// .inline-block.over:before
this.addCSSRule(
'.' + classInlineBlockHash + '.' + classOverMarkHash + ':before',
'top: 0;' +
'bottom: auto;'
);
+
+
+ // right
+ // .inline-block.right
+ this.addCSSRule('.' + classInlineBlockHash + '.' + classRightMarkHash,
+ 'padding:0 0.5em 0 0;'
+ );
+ // .right:before
+ this.addCSSRule(
+ '.' + classRightMarkHash + ':before',
+ 'vertical-align:middle;' +
+ 'height: 100%;' +
+ 'line-height: 100%;' +
+ 'width: 1em;' +
+ 'top: 0;' +
+ 'background: red;' +
+ 'bottom: auto;'
+ );
+ // .inline.right:before
+ this.addCSSRule(
+ '.' + classInlineHash + '.' + classRightMarkHash + ':before',
+ 'right: -0.5em;'
+ );
+ // .inline-block.right:before
+ this.addCSSRule(
+ '.' + classInlineBlockHash + '.' + classRightMarkHash + ':before',
+ 'right: 0;'
+ );
+ // .right.scale:before
+ this.addCSSRule(
+ '.' + classRightMarkHash + '.' + classScaleHash + ':before',
+ 'height: 200%;' +
+ 'line-height: 200%;' +
+ 'width: 1em;'
+ );
+ /*
+ // .inline.scale.right:before
+ this.addCSSRule(
+ '.' + classInlineHash + '.' + classScaleHash +
+ '.' + classRightMarkHash + ':before',
+ 'line-height: 2em;'
+ );
+ // .inline-block.scale.right:before
+ this.addCSSRule(
+ '.' + classInlineBlockHash + '.' + classScaleHash +
+ '.' + classRightMarkHash + ':before',
+ 'line-height: 2em;'
+ );
+ */
},
/**
diff --git a/src/variable.js b/src/variable.js
index 5da1314..f996e1d 100644
--- a/src/variable.js
+++ b/src/variable.js
@@ -5,10 +5,24 @@ var classInlineBlockHash = 'inline-block' + hash;
var classInlineHash = 'inline' + hash;
var classScaleHash = 'scale' + hash;
var classOverMarkHash = 'over' + hash;
+var classRightMarkHash = 'right' + hash;
+var classLeftMarkHash = 'left' + hash;
var classUnderMarkHash = 'under' + hash;
var positionClassMap = {
'over': classOverMarkHash,
- 'under': classUnderMarkHash
+ 'under': classUnderMarkHash,
+ 'right': classRightMarkHash,
+ 'left': classLeftMarkHash
+};
+var positionToOriginMap = {
+ 'over': ':top left;',
+ 'under': ':bottom left;',
+ 'right': ':top right;',
+ 'left': ':top left;'
+};
+var isVerticalPosition = {
+ 'right': 1,
+ 'left': 1
};
var uniqueId = 0;
From 00c28b20e59a1e3547bad38a554368c2d8d1eaa9 Mon Sep 17 00:00:00 2001
From: zmmbreeze
Date: Mon, 12 Aug 2013 21:31:33 +0800
Subject: [PATCH 2/2] update
---
assets/index.css | 3 ++-
bin/jquery.emphasis.js | 29 +++++++----------------------
bin/jquery.emphasis.min.js | 4 ++--
src/emphasis.js | 7 ++++++-
src/util.js | 22 +---------------------
5 files changed, 18 insertions(+), 47 deletions(-)
diff --git a/assets/index.css b/assets/index.css
index cb49bd4..e3f2198 100644
--- a/assets/index.css
+++ b/assets/index.css
@@ -207,7 +207,8 @@ dl {
writing-mode: vertical-rl;
}
#example11 em {
- letter-spacing: 5px;
+ font-style: normal;
+ line-height: 2;
}
.lang-zh {
diff --git a/bin/jquery.emphasis.js b/bin/jquery.emphasis.js
index 579c7c0..d9e9a4a 100644
--- a/bin/jquery.emphasis.js
+++ b/bin/jquery.emphasis.js
@@ -356,6 +356,7 @@ var Util = {
// .right:before
this.addCSSRule(
'.' + classRightMarkHash + ':before',
+ 'left:auto;' +
'vertical-align:middle;' +
'height: 100%;' +
'line-height: 100%;' +
@@ -374,27 +375,6 @@ var Util = {
'.' + classInlineBlockHash + '.' + classRightMarkHash + ':before',
'right: 0;'
);
- // .right.scale:before
- this.addCSSRule(
- '.' + classRightMarkHash + '.' + classScaleHash + ':before',
- 'height: 200%;' +
- 'line-height: 200%;' +
- 'width: 1em;'
- );
- /*
- // .inline.scale.right:before
- this.addCSSRule(
- '.' + classInlineHash + '.' + classScaleHash +
- '.' + classRightMarkHash + ':before',
- 'line-height: 2em;'
- );
- // .inline-block.scale.right:before
- this.addCSSRule(
- '.' + classInlineBlockHash + '.' + classScaleHash +
- '.' + classRightMarkHash + ':before',
- 'line-height: 2em;'
- );
- */
},
/**
@@ -802,13 +782,18 @@ Emphasis.prototype.textToHtml = function($node, $parent, markInfo) {
useInlineBlock = true;
}
+ // writing-mode is vertical
var isVertical = isVerticalPosition[markInfo.position];
if (isVertical) {
console.log(markInfo);
}
// calculate mark style
- var useScale = Util.supportScale();
+
+ // chrome has a bug when using vertical writing-mode and transform:scale
+ // http://jsbin.com/upiyot/1/
+ var useScale = !isVertical && Util.supportScale();
+
var markStyle;
if (useScale) {
// support `transform: scale(0.5);`
diff --git a/bin/jquery.emphasis.min.js b/bin/jquery.emphasis.min.js
index 30f3fbb..918da18 100644
--- a/bin/jquery.emphasis.min.js
+++ b/bin/jquery.emphasis.min.js
@@ -1,6 +1,6 @@
/*!
jquery.emphasis.js
0.1.1
- 11-08-2013
+ 12-08-2013
*/
-!function(a){function b(a,b,c){this.markInfo=a,this.$el=b,this.styleNames=c,this.setEmphasis()}var c,d="9a91ab9b8e64d2cf7fce0616b66efbaf",e="inline-block"+d,f="inline"+d,g="scale"+d,h="over"+d,i="right"+d,j="left"+d,k="under"+d,l={over:h,under:k,right:i,left:j},m={over:":top left;",under:":bottom left;",right:":top right;",left:":top left;"},n={right:1,left:1},o=0,p={dot:["•","◦"],circle:["●","○"],"double-circle":["◉","◎"],triangle:["▲","△"],sesame:["﹅","﹆"]},q={" ":1," ":1,"፡":1,"တ0":1,"တ1":1,"္F":1,"႑F":1,"་":1,"༌":1,"":1," ":1," ":1," ":1,"\0":1," ":1,"\n":1,"\r":1,"
":1},r={style:1,script:1,textarea:1,input:1},s={"char":{},color:{},mark:{}},t={addCSSRule:function(b,d){if(!c){var e=document.createElement("style");e.type="text/css",a("head").eq(0).prepend(e),c=document.styleSheets[0]}c.insertRule?c.insertRule(b+"{"+d+"}",c.cssRules.length):c.addRule(b,d,-1)},addBeforeCSSRule:function(a,b,c){var e=s[a];if(e[b])return e[b];var f=a+o++ +d;return this.addCSSRule("."+f+":before",c),e[b]=f,f},testStyle:function(a,b){for(var c=["webkit","moz","o","ms"],d=0,e=c.length;e>d;d++)if(""===a.style[c[d]+b])return c[d]+b;var f=b.charAt(0).toLowerCase()+b.slice(1);return"undefined"!=typeof a.style[f]?f:!1},jsNameToCssName:function(a){return a.replace(/[A-Z]/g,function(a){return"-"+a.toLowerCase()}).replace(/^(webkit|moz|o|ms)\-/,"-$1-")},supportScale:function y(){if("undefined"!=typeof y.result)return y.result;var a,b=document.createElement("div"),c=this.testStyle(b,"Transform"),d=this.testStyle(b,"TransformOrigin");return c&&d?(c=this.jsNameToCssName(c),d=this.jsNameToCssName(d),a=[c,d]):a=null,y.result=a,a},supportEmphasis:function z(){return!1},supportWritingMode:function A(){if("undefined"!=typeof A.result)return A.result;var a,b=document.createElement("div"),c=this.testStyle(b,"WritingMode");return c?(c=this.jsNameToCssName(c),a=c):a=null,A.result=a,a},initCSSRule:function B(){if(!B.inited){B.inited=!0,this.addCSSRule("."+e,"position:relative;display:inline-block;_zoom:1;float:none;border:none;margin:0;padding:0 0 0.5em 0;vertical-align: baseline;color:inherit;font-size:inherit;font-family:inherit;letter-spacing: normal;text-decoration:inherit;line-height:inherit;"),this.addCSSRule("."+f,"position:relative;float:none;border:none;margin:0;padding:0;vertical-align: baseline;color:inherit;font-size:inherit;font-family:inherit;letter-spacing: normal;text-decoration:inherit;line-height:inherit;");var a="position:absolute;bottom: 0;left: 0;height: 1em;line-height: 1em;text-align: center;width: 100%;float:none;border:none;margin:0;padding:0;vertical-align: baseline;color:inherit;font-size: inherit;font-family:inherit;text-decoration: none;";this.addCSSRule("."+f+":before",a+"bottom: -1em;"),this.addCSSRule("."+e+":before",a),this.addCSSRule("."+f+"."+g+":before","bottom: -0.5em;width: 200%;"),this.addCSSRule("."+e+"."+g+":before","width: 200%;"),this.addCSSRule("."+e+"."+h,"padding:0.5em 0 0 0;"),this.addCSSRule("."+f+"."+h+":before","top: -0.5em;bottom: auto;"),this.addCSSRule("."+e+"."+h+":before","top: 0;bottom: auto;"),this.addCSSRule("."+e+"."+i,"padding:0 0.5em 0 0;"),this.addCSSRule("."+i+":before","vertical-align:middle;height: 100%;line-height: 100%;width: 1em;top: 0;background: red;bottom: auto;"),this.addCSSRule("."+f+"."+i+":before","right: -0.5em;"),this.addCSSRule("."+e+"."+i+":before","right: 0;"),this.addCSSRule("."+i+"."+g+":before","height: 200%;line-height: 200%;width: 1em;")}},getLineHeight:function(a,b){var c=a.css("line-height");return"normal"===c?this.getNormalLineHeight(b):c.match(/px/)?parseInt(c,10):b*c},getNormalLineHeight:function C(b){if("undefined"!=typeof C.result)return C.result;var c=a('Some words.
');c.css("font-size",b+"px"),c.appendTo("body");var d=c.height();return c.remove(),C.result=d,d}},u=/['"]([^'"]+)['"]/,v=/(dot|circle|double-circle|triangle|sesame)/,w=/(under|over|left|right)/,x=function(a,b){this.parse(a,b)};x.prototype.set=function(a,b){return"undefined"!=typeof this[a]?!1:(this[a]=b,!0)},x.prototype.parse=function(b,c){var d;if(c){if(!(d=c.match(w)))return this.error=!0,void 0;this.position=d[1]}if(!b)return this.error=!0,void 0;b=b.split(" ");for(var e,f,g=0,h=b.length;h>g;g++){if(e=b[g],d=e.match(u)){var i=d[1];if(i.length>1&&(i=i.charAt(0)),f=this.set("mark",i),this.isStringMark=!0,f)return}else{if(-1!==e.indexOf("none"))return this.isNone=!0,void 0;f=-1!==e.indexOf("filled")?this.set("filled",!0):-1!==e.indexOf("open")?this.set("filled",!1):(d=e.match(v))?this.set("mark",d[1]):this.set("color",a.trim(e))}if(!f)return this.error=!0,void 0}"undefined"==typeof this.mark&&"undefined"==typeof this.filled&&(this.error=!0)},x.prototype.autoComplete=function(){if(!this.isNone){var a=navigator.language||navigator.browserLanguage;a=a.slice(0,2);var b="ja"===a;null==this.position&&(this.position=b?"over":"under");var c="undefined"!=typeof this.filled,d="undefined"!=typeof this.mark;c&&d||d&&this.isStringMark||(d?this.filled=!0:c&&(this.mark="circle"))}},b.prototype.removeEmphasis=function(){this.styleNames?this.$el.css(this.styleNames[0],"none"):this.removeEmphasizedTag(this.$el)},b.prototype.setEmphasis=function(){this.markInfo.isNone?this.removeEmphasis():(this.markInfo.autoComplete(),this.styleNames?this.setEmphasisByCSS():this.setEmphasisByFallback())},b.prototype.setEmphasisByCSS=function(){var a={};a[this.styleNames[0]]=this.markInfo.isStringMark?'"'+this.markInfo.mark+'"':""+(this.markInfo.filled?"filled":"open")+" "+this.markInfo.mark+" "+(this.markInfo.color||""),a[this.styleNames[1]]=this.markInfo.position,this.$el.css(a)},b.prototype.setEmphasisByFallback=function(){t.initCSSRule(),this.markInfo.character=p[this.markInfo.mark]?p[this.markInfo.mark][this.markInfo.filled?0:1]:this.markInfo.mark.charAt(0),this.fakeEmphasis(this.$el,this.markInfo)},b.prototype.removeEmphasizedTag=function(b,c){if(this.isEmphasizedTag(b[0]))return b.replaceWith(b.text()),void 0;for(var d,e=b.children(),f=0,g=e.length;g>f;f++)d=a(e[f]),this.isEmphasizedTag(d[0])?d.replaceWith(d.text()):c||this.removeEmphasizedTag(d)},b.prototype.hasEmphasizedTag=function(a){for(var b,c=a.children(),d=0,e=c.length;e>d;d++)if(b=c[d],this.isEmphasizedTag(b))return!0;return!1},b.prototype.isEmphasizedTag=function(a){var b=a.className;return-1!==b.indexOf(e)||-1!==b.indexOf(f)},b.prototype.fakeEmphasis=function(b,c,d){d=d||1,1===d&&this.removeEmphasizedTag(b,!0);for(var e,f=b.contents(),g=0,h=f.length;h>g;g++)if(e=f[g],3===e.nodeType)this.textToHtml(a(e),b,c);else if(1===e.nodeType){var i=this.isEmphasizedTag(e),j=e.nodeName.toLowerCase();r[j]||i||this.fakeEmphasis(a(e),c,d+1)}},b.prototype.textToHtml=function(a,b,c){var d=parseInt(b.css("font-size"),10),h=t.getLineHeight(b,d),i=d/2,j=!1;i>(h-d)/2&&(j=!0);var k=n[c.position];k&&console.log(c);var o,p=t.supportScale();o=p?p[0]+":scale(0.5);"+p[1]+m[c.position]:k?"font-size:"+i+"px;":"font-size:"+i+"px;"+"height:"+i+"px;"+"line-height:"+i+"px;";var r=t.addBeforeCSSRule("mark",c.position+i,o),s="";c.color&&(s=t.addBeforeCSSRule("color",c.color,"color:"+c.color+" !important;"));var u=j?e:f,v=t.addBeforeCSSRule("char",c.character,"content:'"+c.character+"';"),w=l[c.position],x=b.css("letter-spacing"),y="";"normal"!==x&&0!==x&&(y=(k?"margin-bottom:":"margin-right:")+x+";");for(var z,A='',B="",C=a.text(),D=[],E=0,F=C.length;F>E;E++)z=C.charAt(E),q[z]?D.push(z):(D.push(A),D.push(z),D.push(B));a.replaceWith(D.join(""))},a.fn.emphasis=function(c,d){var e=new x(c,d);if(!e.error)return this.each(function(c,d){var f=a(d),g=t.supportEmphasis();new b(e,f,g)}),this}}(jQuery);
\ No newline at end of file
+!function(a){function b(a,b,c){this.markInfo=a,this.$el=b,this.styleNames=c,this.setEmphasis()}var c,d="9a91ab9b8e64d2cf7fce0616b66efbaf",e="inline-block"+d,f="inline"+d,g="scale"+d,h="over"+d,i="right"+d,j="left"+d,k="under"+d,l={over:h,under:k,right:i,left:j},m={over:":top left;",under:":bottom left;",right:":top right;",left:":top left;"},n={right:1,left:1},o=0,p={dot:["•","◦"],circle:["●","○"],"double-circle":["◉","◎"],triangle:["▲","△"],sesame:["﹅","﹆"]},q={" ":1," ":1,"፡":1,"တ0":1,"တ1":1,"္F":1,"႑F":1,"་":1,"༌":1,"":1," ":1," ":1," ":1,"\0":1," ":1,"\n":1,"\r":1,"
":1},r={style:1,script:1,textarea:1,input:1},s={"char":{},color:{},mark:{}},t={addCSSRule:function(b,d){if(!c){var e=document.createElement("style");e.type="text/css",a("head").eq(0).prepend(e),c=document.styleSheets[0]}c.insertRule?c.insertRule(b+"{"+d+"}",c.cssRules.length):c.addRule(b,d,-1)},addBeforeCSSRule:function(a,b,c){var e=s[a];if(e[b])return e[b];var f=a+o++ +d;return this.addCSSRule("."+f+":before",c),e[b]=f,f},testStyle:function(a,b){for(var c=["webkit","moz","o","ms"],d=0,e=c.length;e>d;d++)if(""===a.style[c[d]+b])return c[d]+b;var f=b.charAt(0).toLowerCase()+b.slice(1);return"undefined"!=typeof a.style[f]?f:!1},jsNameToCssName:function(a){return a.replace(/[A-Z]/g,function(a){return"-"+a.toLowerCase()}).replace(/^(webkit|moz|o|ms)\-/,"-$1-")},supportScale:function y(){if("undefined"!=typeof y.result)return y.result;var a,b=document.createElement("div"),c=this.testStyle(b,"Transform"),d=this.testStyle(b,"TransformOrigin");return c&&d?(c=this.jsNameToCssName(c),d=this.jsNameToCssName(d),a=[c,d]):a=null,y.result=a,a},supportEmphasis:function z(){return!1},supportWritingMode:function A(){if("undefined"!=typeof A.result)return A.result;var a,b=document.createElement("div"),c=this.testStyle(b,"WritingMode");return c?(c=this.jsNameToCssName(c),a=c):a=null,A.result=a,a},initCSSRule:function B(){if(!B.inited){B.inited=!0,this.addCSSRule("."+e,"position:relative;display:inline-block;_zoom:1;float:none;border:none;margin:0;padding:0 0 0.5em 0;vertical-align: baseline;color:inherit;font-size:inherit;font-family:inherit;letter-spacing: normal;text-decoration:inherit;line-height:inherit;"),this.addCSSRule("."+f,"position:relative;float:none;border:none;margin:0;padding:0;vertical-align: baseline;color:inherit;font-size:inherit;font-family:inherit;letter-spacing: normal;text-decoration:inherit;line-height:inherit;");var a="position:absolute;bottom: 0;left: 0;height: 1em;line-height: 1em;text-align: center;width: 100%;float:none;border:none;margin:0;padding:0;vertical-align: baseline;color:inherit;font-size: inherit;font-family:inherit;text-decoration: none;";this.addCSSRule("."+f+":before",a+"bottom: -1em;"),this.addCSSRule("."+e+":before",a),this.addCSSRule("."+f+"."+g+":before","bottom: -0.5em;width: 200%;"),this.addCSSRule("."+e+"."+g+":before","width: 200%;"),this.addCSSRule("."+e+"."+h,"padding:0.5em 0 0 0;"),this.addCSSRule("."+f+"."+h+":before","top: -0.5em;bottom: auto;"),this.addCSSRule("."+e+"."+h+":before","top: 0;bottom: auto;"),this.addCSSRule("."+e+"."+i,"padding:0 0.5em 0 0;"),this.addCSSRule("."+i+":before","left:auto;vertical-align:middle;height: 100%;line-height: 100%;width: 1em;top: 0;background: red;bottom: auto;"),this.addCSSRule("."+f+"."+i+":before","right: -0.5em;"),this.addCSSRule("."+e+"."+i+":before","right: 0;")}},getLineHeight:function(a,b){var c=a.css("line-height");return"normal"===c?this.getNormalLineHeight(b):c.match(/px/)?parseInt(c,10):b*c},getNormalLineHeight:function C(b){if("undefined"!=typeof C.result)return C.result;var c=a('Some words.
');c.css("font-size",b+"px"),c.appendTo("body");var d=c.height();return c.remove(),C.result=d,d}},u=/['"]([^'"]+)['"]/,v=/(dot|circle|double-circle|triangle|sesame)/,w=/(under|over|left|right)/,x=function(a,b){this.parse(a,b)};x.prototype.set=function(a,b){return"undefined"!=typeof this[a]?!1:(this[a]=b,!0)},x.prototype.parse=function(b,c){var d;if(c){if(!(d=c.match(w)))return this.error=!0,void 0;this.position=d[1]}if(!b)return this.error=!0,void 0;b=b.split(" ");for(var e,f,g=0,h=b.length;h>g;g++){if(e=b[g],d=e.match(u)){var i=d[1];if(i.length>1&&(i=i.charAt(0)),f=this.set("mark",i),this.isStringMark=!0,f)return}else{if(-1!==e.indexOf("none"))return this.isNone=!0,void 0;f=-1!==e.indexOf("filled")?this.set("filled",!0):-1!==e.indexOf("open")?this.set("filled",!1):(d=e.match(v))?this.set("mark",d[1]):this.set("color",a.trim(e))}if(!f)return this.error=!0,void 0}"undefined"==typeof this.mark&&"undefined"==typeof this.filled&&(this.error=!0)},x.prototype.autoComplete=function(){if(!this.isNone){var a=navigator.language||navigator.browserLanguage;a=a.slice(0,2);var b="ja"===a;null==this.position&&(this.position=b?"over":"under");var c="undefined"!=typeof this.filled,d="undefined"!=typeof this.mark;c&&d||d&&this.isStringMark||(d?this.filled=!0:c&&(this.mark="circle"))}},b.prototype.removeEmphasis=function(){this.styleNames?this.$el.css(this.styleNames[0],"none"):this.removeEmphasizedTag(this.$el)},b.prototype.setEmphasis=function(){this.markInfo.isNone?this.removeEmphasis():(this.markInfo.autoComplete(),this.styleNames?this.setEmphasisByCSS():this.setEmphasisByFallback())},b.prototype.setEmphasisByCSS=function(){var a={};a[this.styleNames[0]]=this.markInfo.isStringMark?'"'+this.markInfo.mark+'"':""+(this.markInfo.filled?"filled":"open")+" "+this.markInfo.mark+" "+(this.markInfo.color||""),a[this.styleNames[1]]=this.markInfo.position,this.$el.css(a)},b.prototype.setEmphasisByFallback=function(){t.initCSSRule(),this.markInfo.character=p[this.markInfo.mark]?p[this.markInfo.mark][this.markInfo.filled?0:1]:this.markInfo.mark.charAt(0),this.fakeEmphasis(this.$el,this.markInfo)},b.prototype.removeEmphasizedTag=function(b,c){if(this.isEmphasizedTag(b[0]))return b.replaceWith(b.text()),void 0;for(var d,e=b.children(),f=0,g=e.length;g>f;f++)d=a(e[f]),this.isEmphasizedTag(d[0])?d.replaceWith(d.text()):c||this.removeEmphasizedTag(d)},b.prototype.hasEmphasizedTag=function(a){for(var b,c=a.children(),d=0,e=c.length;e>d;d++)if(b=c[d],this.isEmphasizedTag(b))return!0;return!1},b.prototype.isEmphasizedTag=function(a){var b=a.className;return-1!==b.indexOf(e)||-1!==b.indexOf(f)},b.prototype.fakeEmphasis=function(b,c,d){d=d||1,1===d&&this.removeEmphasizedTag(b,!0);for(var e,f=b.contents(),g=0,h=f.length;h>g;g++)if(e=f[g],3===e.nodeType)this.textToHtml(a(e),b,c);else if(1===e.nodeType){var i=this.isEmphasizedTag(e),j=e.nodeName.toLowerCase();r[j]||i||this.fakeEmphasis(a(e),c,d+1)}},b.prototype.textToHtml=function(a,b,c){var d=parseInt(b.css("font-size"),10),h=t.getLineHeight(b,d),i=d/2,j=!1;i>(h-d)/2&&(j=!0);var k=n[c.position];k&&console.log(c);var o,p=!k&&t.supportScale();o=p?p[0]+":scale(0.5);"+p[1]+m[c.position]:k?"font-size:"+i+"px;":"font-size:"+i+"px;"+"height:"+i+"px;"+"line-height:"+i+"px;";var r=t.addBeforeCSSRule("mark",c.position+i,o),s="";c.color&&(s=t.addBeforeCSSRule("color",c.color,"color:"+c.color+" !important;"));var u=j?e:f,v=t.addBeforeCSSRule("char",c.character,"content:'"+c.character+"';"),w=l[c.position],x=b.css("letter-spacing"),y="";"normal"!==x&&0!==x&&(y=(k?"margin-bottom:":"margin-right:")+x+";");for(var z,A='',B="",C=a.text(),D=[],E=0,F=C.length;F>E;E++)z=C.charAt(E),q[z]?D.push(z):(D.push(A),D.push(z),D.push(B));a.replaceWith(D.join(""))},a.fn.emphasis=function(c,d){var e=new x(c,d);if(!e.error)return this.each(function(c,d){var f=a(d),g=t.supportEmphasis();new b(e,f,g)}),this}}(jQuery);
\ No newline at end of file
diff --git a/src/emphasis.js b/src/emphasis.js
index ffcc540..7520319 100644
--- a/src/emphasis.js
+++ b/src/emphasis.js
@@ -201,13 +201,18 @@ Emphasis.prototype.textToHtml = function($node, $parent, markInfo) {
useInlineBlock = true;
}
+ // writing-mode is vertical
var isVertical = isVerticalPosition[markInfo.position];
if (isVertical) {
console.log(markInfo);
}
// calculate mark style
- var useScale = Util.supportScale();
+
+ // chrome has a bug when using vertical writing-mode and transform:scale
+ // http://jsbin.com/upiyot/1/
+ var useScale = !isVertical && Util.supportScale();
+
var markStyle;
if (useScale) {
// support `transform: scale(0.5);`
diff --git a/src/util.js b/src/util.js
index f3b2715..3ca48c1 100644
--- a/src/util.js
+++ b/src/util.js
@@ -283,6 +283,7 @@ var Util = {
// .right:before
this.addCSSRule(
'.' + classRightMarkHash + ':before',
+ 'left:auto;' +
'vertical-align:middle;' +
'height: 100%;' +
'line-height: 100%;' +
@@ -301,27 +302,6 @@ var Util = {
'.' + classInlineBlockHash + '.' + classRightMarkHash + ':before',
'right: 0;'
);
- // .right.scale:before
- this.addCSSRule(
- '.' + classRightMarkHash + '.' + classScaleHash + ':before',
- 'height: 200%;' +
- 'line-height: 200%;' +
- 'width: 1em;'
- );
- /*
- // .inline.scale.right:before
- this.addCSSRule(
- '.' + classInlineHash + '.' + classScaleHash +
- '.' + classRightMarkHash + ':before',
- 'line-height: 2em;'
- );
- // .inline-block.scale.right:before
- this.addCSSRule(
- '.' + classInlineBlockHash + '.' + classScaleHash +
- '.' + classRightMarkHash + ':before',
- 'line-height: 2em;'
- );
- */
},
/**