PageSourceSearch

https://thefiddleback.com/js/jquery.dropj.0.0.4.js

js thefiddleback.com collected 2026-09-27 00:47:48 UTC 4,555 bytes, 148 lines download raw bytes

1/*
2  jQuery.dropJ plugin
3  Version 0.0.4 - 20081010
4  @requires jQuery v1.2.3, recommends v1.2.6
5
6  Project page: http://code.google.com/p/jquery-dropj/
7  Copyright (c) 2008 Ashley Pond V
8  Licensed under the Artistic 2.0 - http://www.perlfoundation.org/artistic_license_2_0
9*/
10
11(function($) {
12// http://unicode.org/versions/Unicode4.1.0/
13//        CJK unified -> 4E00-9FFF
14// Korean _syllables_ -> AC00-D7A3
15//     Latin extended -> 00C0-02B8
16var CJKrx = /^\s*([^\uAC00-\uD7A3\u4E00-\u9FFF]?[\u00C0-\u02B8\uAC00-\uD7A3\u4E00-\u9FFF])(.*)/im;
17var ExtRx = /^\s*([^a-z\u00C0-\u02B8]?[a-z\u00C0-\u02B8])(.*)/im;
18var ASCIIrx = /^\s*(\W?[a-z])(.*)/im;
19var UnifiedRx = /^\s*([^a-z\u00C0-\u02B8\uAC00-\uD7A3\u4E00-\u9FFF]?[a-z\u00C0-\u02B8\uAC00-\uD7A3\u4E00-\u9FFF])(.*)/im;
20
21var Mode = {
22  "ascii":ASCIIrx
23 ,"cjk":CJKrx
24 ,"extended":ExtRx
25 ,"unified":UnifiedRx
26};
27
28var dCSS = {
29  padding:0
30  ,display:"block"
31  ,textAlign:"right"
32  ,float:"left"          // Other text should flow around it.
33  ,fontStyle:"normal"    // Italics would be bad here.
34  ,overflow:"visible"    // Bottom margin can clip.
35  ,textDecoration:"none" // When drop cap is a link. ! important breaks IE
36  ,marginRight:"5px"
37};
38
39$.fn.dropJ = function(arg) {
40    var opts = $.extend({}, $.fn.dropJ.defaults, arg);
41    return this.each(function() {
42      $this = $(this);
43      var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
44      if ( _addDropCap($this.get(0),$this.get(0),o) && o.clear )
45      {
46          $this.css({clear:"left"});
47      }
48    });
49};
50
51$.fn.dropJ.defaults = {
52    "css":dCSS
53   ,"clear":true
54   ,"keepCase":true
55   ,"regex":Mode.ascii
56   ,"element":"span"
57   ,"factor":3
58   ,"toggleFamily":false
59   ,"class":"dropJ"
60};
61
62function _addDropCap(c,n,o) {
63   var rx = Mode[o.mode] || Mode.ascii;
64   if ( ( n.nodeType == 3 ) && n.nodeValue.match(rx) )
65   {
66      var val = n.nodeValue;
67      val = val.replace(/\n+/g, " "); // stupid Rx is missing s flag.
68      var capRemainder = val.match(rx);
69
70      // this shuffle step courtesy of uneven Rx handling across browsers
71      var capText = capRemainder ?
72            capRemainder[ capRemainder.length - 2 ] : '';
73      var remainderText = capRemainder ?
74            capRemainder[ capRemainder.length - 1 ] : '';
75
76      if ( ! o.keepCase ) capText = capText.toUpperCase();
77      var cap = document.createTextNode(capText);
78      var remainder = document.createTextNode(remainderText);
79      var dropCap = document.createElement(o["element"]);
80      dropCap.appendChild(cap);
81      n.parentNode.replaceChild(remainder,n);
82      remainder.parentNode.insertBefore(dropCap,remainder);
83      $(dropCap).css(o["css"]);
84      $(dropCap).addClass(o["class"]);
85      _setSpecialCSS(c,dropCap,o)
86      return dropCap;
87   }
88   else if ( n.nodeType == 3 )
89   {
90      $(n).parent().css({float:"left",display:"inline"});
91   }
92   for ( var i = 0; i < n.childNodes.length; i++ )
93   {
94      var dc = _addDropCap(c,n.childNodes[i],o);
95      if ( dc ) return dc;
96   }
97};
98
99function _setSpecialCSS(c,dc,o){
100  var h = $(dc).css("lineHeight");
101  if ( o.factor == true )
102  {
103  // should have an immediate fail case, yes? width v height test
104     if ( o.hang )
105     {
106        var fs = ( $(c).height() ) + "px";
107        var lh = ( $(c).height() * .9 ) + "px";
108        $(dc).css({fontSize:fs,lineHeight:lh});
109        _update_hang(dc); // do a mini-recurse here too...? everwhere?
110     }
111     else
112     {
113       var i = 6;
114       while ( i-- ) {
115         if ( $(dc).height() >= $(c).height() ) break;
116         if ( $(dc).width() > ( .4 * $(c).width() ) ) break;
117         var fs = ( $(c).height() * 1.2 ) + "px";
118         var lh = ( $(c).height() * 1 ) + "px";
119         $(dc).css({fontSize:fs,lineHeight:lh});
120       }
121       var mb = ( -1 * $(dc).height() / 9 ) + "px";
122       $(dc).css({marginBottom:mb});
123     }
124  }
125  else if ( h.substr(h.length - 2, 2) == "px" ) // pixel mode
126  {
127     var px = h.substring(0,h.length - 2);
128     var mt = ( -1 * Math.round( px / 10 ) ) + "px";
129     var mb = ( -1 * Math.round( px / 5 ) ) + "px";
130     $(dc).css({marginTop:mt,marginBottom:mb});
131     var fs = ( o.factor * 1.05 * px ) + "px";
132     var lh = ( o.factor * px * 0.98 ) + "px";
133     $(dc).css({fontSize:fs,lineHeight:lh});
134  }
135  else // em mode
136  {
137     var fs = ( o.factor * 1.05 ) + "em";
138     $(dc).css({fontSize:fs});
139     $(dc).css({margin:"-.1ex 0 -.25ex 0",lineHeight:"95%"});
140  }
141  if ( o.hang ) _update_hang(dc);
142}
143function _update_hang(dc){
144   var m = ( -1 * $(dc).width() ) + "px";
145   $(dc).css({marginLeft:m,marginRight:m});
146}
147
148})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.