Plugin Directory

Changeset 1904276


Ignore:
Timestamp:
07/05/2018 04:05:49 AM (8 years ago)
Author:
rahburma
Message:

Display line numbers in syntax highlighted code snippet

Location:
code-editor-and-compiler/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code-editor-and-compiler/trunk/admin/compilebin-admin.php

    r1902882 r1904276  
    77   public function __construct() {
    88      $this->plugin_name = "code-editor-and-compiler";
    9       $this->plugin_version = "1.3.6";
     9      $this->plugin_version = "1.3.7";
    1010      add_action('admin_notices', array($this, 'plugin_activation'));
    1111      add_action('deactivated_plugin', array($this, 'plugin_deactivation'));   
     
    265265      echo $theme_type;
    266266      wp_die();
     267   }
     268   
     269   public function saveLinenumPreferenceInternal() {
     270      $linenum = $_POST['linenum_status'];
     271      delete_option('linenum_status');
     272      delete_transient('linenum_status');
     273      $status = add_option('linenum_status', $linenum, '', 'no');
     274      return $status;
     275   }
     276       
     277   private function saveLinenumPreference() {
     278      $status = saveLinenumPreferenceInternal();
     279      if ($status) {
     280        echo "Line number preference saved successfully.";
     281      } else {
     282        echo "Error setting line number preference. Please try again.";
     283      }
     284      wp_die();
     285   }   
     286   
     287   private function getLinenumPreferenceInternal() {
     288      $linenum_status = null;
     289      if (false === ($linenum_status = get_transient('linenum_status'))) {
     290        $linenum_status = get_option('linenum_status');
     291        set_transient('linenum_status', $linenum_status, YEAR_IN_SECONDS);
     292      }
     293      return $linenum_status;
     294   }
     295   
     296   public function getLinenumPreference() {
     297      $linenum_status = $this->getLinenumPreferenceInternal();
     298      echo $linenum_status;
     299      wp_die();
    267300   }   
    268301   
     
    272305         'editorPref' => $this->getEditorPreferenceInternal(),
    273306         'langPref' => $this->getLangPreferenceInternal(),
    274          'themePref' => $this->getThemePreferenceInternal()
     307         'themePref' => $this->getThemePreferenceInternal(),
     308         'linenumStatus' => $this->getLinenumPreferenceInternal()
    275309      );
    276310      echo json_encode($settingObj);
     
    283317      $statusLangPref = $this->saveLangPreferenceInternal();
    284318      $statusThemePref = $this->saveThemePreferenceInternal();
    285       if (!$statusRunBtn || !$statusEditorPref || !$statusLangPref || !$statusThemePref) {
     319      $statusLinenumPref = $this->saveLinenumPreferenceInternal();
     320      if (!$statusRunBtn || !$statusEditorPref || !$statusLangPref || !$statusThemePref || !$statusLinenumPref) {
    286321         echo "<b>Error saving your preferences. Please try again.</b><br><br>";     
    287322      } else {
     
    294329      $settingObj = array (
    295330         'runBtnStatus' => $this->getRunBtnStatusInternal(),
    296          'themePref' => $this->getThemePreferenceInternal() 
     331         'themePref' => $this->getThemePreferenceInternal(),
     332         'linenumStatus' => $this->getLinenumPreferenceInternal() 
    297333      );
    298334      echo json_encode($settingObj);
  • code-editor-and-compiler/trunk/admin/js/editor-handler.js

    r1902882 r1904276  
    325325                             cdbx_run_btn_status = parseInt(setObj.runBtnStatus);
    326326                          }
     327                          if (setObj.linenumStatus.length > 0) {
     328                             cdbx_linenum_status = parseInt(setObj.linenumStatus);
     329                          }   
    327330                          if (setObj.editorPref.length > 0) {
    328331                             if (setObj.editorPref == CDBX_EDITOR_WEBDESIGN) {
     
    807810               editor_type: $(CDBX_PREF_EDITOR).find('option:selected').val(),
    808811               lang: $(CDBX_PREF_LANG).find('option:selected').val(),
    809                theme: $(CDBX_PREF_THEME).find('option:selected').val()
     812               theme: $(CDBX_PREF_THEME).find('option:selected').val(),
     813               linenum_status: $(CDBX_LINENUM_STATUS).is(":checked") ? 1 : 0   
    810814            };
    811815 
     
    841845                   cdbx_setTheme();
    842846                   cdbx_run_btn_status = cdbx_json.run_btn_status;
     847                   cdbx_linenum_status = cdbx_json.linenum_status;
    843848                   cdbx_updateDOM();
    844849               },
     
    859864                       '<div id="cdbx-global-setting-save-msg" style="color:#000080"></div>' +
    860865                       '<input type="checkbox" id="cdbx-run-btn-status">&nbsp;&nbsp;<span class="cdbx-label-text">Disable code execution</span>&nbsp&nbsp&nbsp&nbsp<span class="cdbx-info-text-1">Syntax highlighter mode only. Run button will not be visible in code snippets.</span><br><br>' +
     866                       '<input type="checkbox" id="cdbx-linenum-status">&nbsp;&nbsp;<span class="cdbx-label-text">Show line numbers</span>&nbsp&nbsp&nbsp&nbsp<span class="cdbx-info-text-1">Display line numbers in syntax highlighted code.</span><br><br>' +
    861867                       '<span class="cdbx-label-text">Preferred Editor</span> &nbsp;&nbsp;<select name="cdbx-pref-editor" id="cdbx-pref-editor" style=""></select>&nbsp&nbsp&nbsp&nbsp<span class="cdbx-info-text-1">Default code editor.</span><br><br>' +
    862868                       '<span class="cdbx-label-text">Preferred Language</span> &nbsp;&nbsp;<select name="cdbx-pref-lang" id="cdbx-pref-lang" style=""></select>&nbsp&nbsp&nbsp&nbsp<span class="cdbx-info-text-1">Default programming language.</span><br><br>' +
     
    890896                // enable the checkbox to hide run button
    891897                $(CDBX_RUN_BTN_STATUS).prop('checked', true); 
     898            }
     899           
     900            if (cdbx_linenum_status) {
     901                // enable the checkbox to hide run button
     902                $(CDBX_LINENUM_STATUS).prop('checked', true); 
    892903            }
    893904           
     
    956967                                if (setObj.runBtnStatus.length > 0) {
    957968                                    cdbx_run_btn_status = parseInt(setObj.runBtnStatus);
     969                                }
     970                                if (setObj.linenumStatus.length > 0) {
     971                                    cdbx_linenum_status = parseInt(setObj.linenumStatus);
    958972                                }
    959973                                if (setObj.editorPref.length > 0) {
  • code-editor-and-compiler/trunk/common/css/editor-style.css

    r1900373 r1904276  
    207207  font-size: 1.1em;   
    208208}
     209
     210pre {   
     211  counter-reset: line;
     212}
     213
     214cdbx-code {
     215  counter-increment: line;   
     216}
     217
     218cdbx-code::before {
     219  content: counter(line);
     220  display: inline-block;
     221  text-align: right;   
     222  min-width: 3.5em;
     223  border-right: 1px solid #ddd;
     224  padding: 0 .5em;
     225  margin-right: .5em;
     226  margin-left: -0.8em;   
     227  color: #888;   
     228  /*background-color: #F8F8FF; */   
     229  -webkit-user-select: none;
     230}
  • code-editor-and-compiler/trunk/common/js/include.js

    r1901884 r1904276  
    4242var CDBX_API_KEY_SAVE_MSG = '#cdbx-api-key-save-msg';
    4343var CDBX_RUN_BTN_STATUS   = '#cdbx-run-btn-status';
     44var CDBX_LINENUM_STATUS   = '#cdbx-linenum-status';
    4445var CDBX_SAVE_GLOBAL_SETTING = '#cdbx-save-global-setting';
    4546var CDBX_GLOBAL_SETTING_SAVE_MSG = '#cdbx-global-setting-save-msg';
     
    163164var cdbx_curEditorIdPref = 0;
    164165var cdbx_run_btn_status = 1;
     166var cdbx_linenum_status = 1;
    165167var cdbx_curThemePrefId = CDBX_THEME_XCODE;
    166168var cdbx_curThemeId = CDBX_THEME_XCODE;
  • code-editor-and-compiler/trunk/compilebin.php

    r1902882 r1904276  
    1010 * Plugin URI:        https://www.compilebin.com
    1111 * Description:       Syntax highlighter and code compiler.
    12  * Version:           1.3.6
     12 * Version:           1.3.7
    1313 * Author:            Compilebin
    1414 * Author URI:        https://www.compilebin.com
  • code-editor-and-compiler/trunk/public/compilebin-public.php

    r1902882 r1904276  
    77   public function __construct() {
    88      $this->plugin_name = "code-editor-and-compiler";
    9       $this->plugin_version = "1.3.6";
     9      $this->plugin_version = "1.3.7";
    1010      add_action('wp_enqueue_scripts', array(&$this, 'enqueueScripts'));
    1111      add_action('wp_enqueue_scripts', array(&$this, 'enqueueStyles'));
  • code-editor-and-compiler/trunk/public/js/editor-handler-public.js

    r1901556 r1904276  
    1919        var cdbx_preProcess = function() {
    2020            var cdbx_preElems = document.getElementsByTagName("PRE");
    21        
    22             for (var i = 0; i < cdbx_preElems.length; i++)
    23             if (cdbx_isCrayonHighlighterPresent(cdbx_preElems[i])) {
    24                 cdbx_preElems[i].classList.add('prettyprint');
    25                 cdbx_preElems[i].setAttribute("style", "padding: 10px; border: 1px solid rgba(231, 231, 230, 1); border-radius: 10px; background-color: #ffffff; font-family: courier, sans-serif; font-size: 13px;");
     21            for (var i = 0; i < cdbx_preElems.length; i++) {
     22                if (cdbx_isCrayonHighlighterPresent(cdbx_preElems[i])) {
     23                    cdbx_preElems[i].classList.add('prettyprint');
     24                    cdbx_preElems[i].setAttribute("style", "padding: 10px; border: 1px solid rgba(231, 231, 230, 1); border-radius: 10px; background-color: #ffffff; font-family: courier, sans-serif; font-size: 13px;");
     25                }
    2626            }
    2727        };
    2828     
    2929        cdbx_preProcess();
     30       
     31        var cdbx_showLineNums = function () {
     32            var cdbx_preElems = document.getElementsByTagName("PRE");
     33            for (var i = 0; i < cdbx_preElems.length; i++) {
     34                var preContent = cdbx_preElems[i].innerHTML;
     35                var codeLine = new Array();
     36                var newContent = '';
     37                codeLine = preContent.split('\n');
     38                for (var j = 0; j < codeLine.length; j++) {
     39                    newContent = newContent + '<cdbx-code>' + codeLine[j] + '</cdbx-code>';
     40                    if (j != codeLine.length) {
     41                        newContent += '\n';
     42                    }
     43                }
     44                cdbx_preElems[i].innerHTML = newContent;
     45            }
     46        };
    3047           
    3148        $.ajax({
     
    5168                     default : break;
    5269                  }
    53                }   
     70               }
     71               if (setObj.linenumStatus.length == 0) {
     72                  // linenum status not found, display line numbers by default
     73                  cdbx_showLineNums();   
     74               } else {
     75                  if (parseInt(setObj.linenumStatus) == 1) {
     76                     cdbx_showLineNums(); 
     77                  }
     78               }
     79                   
    5480            }             
    5581        });
     
    255281            var code = document.getElementById(codeElem).innerHTML;
    256282            $(CDBX_HIDDEN_CONTENT).html(code);
    257             var code = $(CDBX_HIDDEN_CONTENT).text();
     283            code = $(CDBX_HIDDEN_CONTENT).text();
    258284            cdbx_curLangId = elem.dataset.lang;
    259285            cdbx_progName = elem.dataset.filename;
  • code-editor-and-compiler/trunk/readme.txt

    r1902882 r1904276  
    55Requires at least: 3.1
    66Tested up to: 4.9.4
    7 Stable tag: 1.3.6
     7Stable tag: 1.3.7
    88Requires PHP: 5.2.4
    99License: GPLv2 or later
     
    3535
    3636== Changelog ==
     371.3.7
     38Introduced support for displaying line numbers in syntax highlighted code
     39
    37401.3.6
    3841Fixed display issue in firefox
Note: See TracChangeset for help on using the changeset viewer.