edlopez

hanzi wrapper

Apr 13th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.88 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5.     <!-- CSS -->
  6.     <link type="text/css" href="css/ui-lightness/jquery-ui-1.8.18.custom.css" rel="stylesheet" />
  7.     <!-- jQuery -->
  8.     <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
  9.     <script type="text/javascript" src="js/jquery-ui-1.8.18.custom.min.js"></script>
  10.     <script type="text/javascript" src="jquery.ba-replacetext.min.js"></script>
  11.     <!-- mes scripts -->
  12.     <script id="allScripts">
  13.     $(document).ready(function() { // Execute when the DOM is fully loaded.
  14.         // add a shortcut method/function
  15.         (function( $ ) {
  16.             // @search: a string used to as search and replace
  17.             // @tag: tag to create wrapping element
  18.             $.fn.wrapHanzi = function(search, tag) {
  19.                 return this.each(function() {
  20.                     regex = new RegExp(search, 'g'); // create a regex on the fly, See: http://is.gd/BfR9gR
  21.                     wrap = '<'+tag+'>'+search+'</'+tag+'>';
  22.  
  23.                     $(this).replaceText( regex, wrap);
  24.                 });
  25.             };
  26.         })( jQuery );
  27.  
  28.         $("#text").wrapHanzi('水', 'easy');
  29.         $("span").wrapHanzi('韓', 'unknow');
  30.         $("span").wrapHanzi('國', 'partial');
  31.         $("span").wrapHanzi('有', 'easy');
  32.     });
  33.     </script>
  34.     <style>
  35.         easy { color: #729fcf; }
  36.         unknow { color: #cc0000; }
  37.         partial { color: #f57900; }
  38.     </style>
  39. </head>
  40. <body>
  41.     <div class="wiki-article">TEST TEXT:
  42.         <span id="text">他是<i></i>韓國人。他的韓國,是否那裡火山又有火,又有冰冰的了。</span>
  43.         <span id="text">他是<i></i>韓國人。他的韓國,是否那裡火山又有火,又有冰冰的了。</span>
  44.     </div>
  45. </body>
  46. </html>
Advertisement
Add Comment
Please, Sign In to add comment