Created
March 26, 2013 06:14
-
-
Save hmiorroi/5243491 to your computer and use it in GitHub Desktop.
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
(function($) { | |
$.fn.noYkKern = function(){ | |
var _fs = 20; | |
var _s = $('<span>').css({'font-size':_fs}).html(')。'); | |
var _b = $('<div>').css({'height':'0', 'overflow':'hidden'}).append(_s); | |
$(this).append(_b); | |
var _w = _s.width(); | |
_b.remove() | |
return (_w >= _fs*2) | |
} | |
$.fn.ykKern = function(options) { | |
var defs = { | |
mk : "{[「『(⦅〈《〔〘【〖", | |
ak : "}]」』)⦆〉》〕〙】〗", | |
kt : "、,。.", | |
class : "ykk" | |
} | |
defs.regexep = '[' + defs.ak + defs.kt + ']{1,}' + '[' + defs.mk + defs.kt + ']{1,}' + '|' + | |
'[' + defs.ak + defs.kt + ']{1,}' + '[' + defs.ak + defs.kt + ']{1,}' + '|' + | |
'[' + defs.mk + ']{2,}' | |
var options = $.extend(defs, options); | |
var reg = new RegExp('('+defs.regexep+')', 'g') | |
return this.each(function(i){ | |
var _t = $(this).html(); | |
$.each(_t.match(reg), function(i){ | |
var l = this.length; | |
var k = '<span class="' + defs.class + '">'+ this.substring(0, l-1) +'</span>' + this.charAt(l-1); | |
_t = _t.replace(this, k); | |
}) | |
$(this).html(_t) | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment