CKEditor4 Tips

How to use CKEditor 4

Basic usage:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Edit Template</title>
<script src="//cdn.ckeditor.com/4.21.0/full/ckeditor.js"></script>
</head>
<body>
    <form action="template-save.php" method="post">
        <input type="text" name="title" value="<?php echo $title; ?>">
        <input type="hidden" name="id" value="<?php echo $id; ?>">
        <textarea id="myeditor" name="myeditor" cols="80" rows="10">
        <?php
          echo htmlspecialchars($content); // htmlspecialchars is needed to preserve code snippets
        ?>
        </textarea>
        <script>
          CKEDITOR.config.allowedContent = true;
          CKEDITOR.config.autoParagraph = false;
          CKEDITOR.replace('myeditor',{width: "100%", height: "400px"});
        </script>
      <input type="submit" class="button"/>
    </form>
</body>
</html>

Tutorial for config parameters: https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html

CKEditor by default adds paragraph tags <p></p> around a line of text after the user presses the Enter key. autoParagraph = false configuration changes this behavior to add a line break <br/> instead.

HREFLANG

<html>
<head>
  <link rel="alternate" hreflang="x-default" href="https://test.com/pages/contact/">
  <link rel="alternate" hreflang="en" href="https://test.com/pages/contact/"> 
  <link rel="alternate" hreflang="ja" href="https://test.com/pages/contact-ja/">
  <link rel="alternate" hreflang="ko" href="https://test.com/pages/contact-ko/">
</head>
<body>
...
</body>
</html>

Detect Browser Version

<script>
function get_browser(){
    var N=navigator.appName, ua=navigator.userAgent, tem;
    var M=ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
    if(M && (tem= ua.match(/version\/([\.\d]+)/i))!= null) M[2]= tem[1];
    M=M? [M[1], M[2]]: [N, navigator.appVersion, '-?'];
    return M[0];
    }
function get_browser_version(){
    var N=navigator.appName, ua=navigator.userAgent, tem;
    var M=ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
    if(M && (tem= ua.match(/version\/([\.\d]+)/i))!= null) M[2]= tem[1];
    M=M? [M[1], M[2]]: [N, navigator.appVersion, "-?"];
    return M[1];
    }
  document.write(get_browser()+'<br>'+get_browser_version());
</script>

MSIE
7.0

Continue reading “Detect Browser Version”

Straight Quotes and Curly Quotes

DescriptionHTML
Straight single quote
Straight double quote 
Opening single quote&lsquo;
Closing single quote&rsquo;
Opening double quote&ldquo;
Closing double quote&rdquo;

<q>Hello</q> renders as “Hello”. Parent element (like html) must have a lang attribute (like lang=”en”) so the q tag knows what kind of curly quotes to use.