1. systemnikass.ya.ru

    05.03.2009

    0 ↑
    0 ↓
    Странно, вот код, не рассвечивается...
    /**
    * Debug_Console_JS: JavaScript debugger console.
    * @author Aleksandr Michalicyn (http://systemnik.net.ru)
    * @author (design) Dmitry Koteroff (http://dklab.ru) MEGA THANKS!!! :)
    * @author (design addons) Furax MEGA THANKS!!! :)
    * @license #see readme.txt
    * @version 1.1.1
    * @date 2009 March 4 Wed 15:00
    */

    /**
    * Bind method for Function objects
    * @param context
    * @return {FUNCTION}
    */
    if (!Function.prototype.bind)
    {
    Function.prototype.bind = function(context)
    {
    var function_obj = this;
    return function()
    {
    function_obj.apply(context, arguments);
    }
    }
    }

    /**
    * Creation a copy of a anonymous class "Debug_Console"
    */
    var debug_console = new function()
    {
    /**
    * Private methods && properties
    */

    /**
    * This property specify context of debug_console object
    * @access private
    */
    var self = this;

    /**
    * Link to console block (div) for messages and groups blocks
    * @access private
    */
    var console_block = null;

    /**
    * Link to root console block (div) for menu div and console block
    * @access private
    */
    var console_root_block = null;

    /**
    * Link to menu block (div) for menu
    * @access private
    */
    var menu_block = null;

    /**
    * Console messages groups
    * @access private
    */
    var groups = {};

    /**
    * This method set event in object.
    * @access private
    */
    var set_event = function(event_type, event_interpriter, object)
    {
    if (event_type == 'load' || event_type == 'keydown')
    {
    object = object.document.documentElement;
    }

    if (object.addEventListener)
    {
    object.addEventListener(event_type, event_interpriter, false);
    } else {
    object.attachEvent('on' + event_type, event_interpriter);
    }
    }

    /**
    * This method unset event in object.
    * @access private
    */
    var unset_event = function(event_type, event_interpriter, object)
    {
    if (event_type == 'load' || event_type == 'keydown')
    {
    object = object.document.documentElement;
    }

    if (object.removeEventListener)
    {
    object.removeEventListener(event_type, event_interpriter, false);
    } else {
    object.detachEvent('on' + event_type, event_interpriter);
    }
    }

    /**
    * Method open/close colsole.
    * @access public
    */
    var toggle = function(event_obj)
    {
    console_root_block.style.display = (console_root_block.style.display === "none") ? 'block' : 'none';
    }

    /**
    * This property will specify the console is enabled.
    * @access private
    */
    var enabled = true;

    /**
    * Function create html code of console and insert to document.
    * @access private
    */
    var create = function()
    {
    console_root_block = document.createElement('div');
    console_root_block.className = 'console_root_block_class';
    console_root_block.style.maxWidth = (screen.width-11) + 'px';
    console_root_block.style.display = 'none';

    console_block = document.createElement('div');
    console_block.className = 'console_block_class';
    console_root_block.appendChild(console_block);

    var key = document.createElement('a');
    key.href = '#';
    key.className = 'console_key_class';
    key.appendChild(document.createTextNode('Menu'));
    console_block.appendChild(key);
    set_event('click', toggle_menu, key);

    menu_block = document.createElement('div');
    menu_block.className = 'menu_block_class';
    menu_block.style.display = 'none';
    console_root_block.appendChild(menu_block);

    var eval_block = document.createElement('div');
    eval_block.className = 'eval_block';

    self.eval_textarea = document.createElement('textarea');
    self.eval_textarea.className = 'console_textarea_class';
    eval_block.appendChild(self.eval_textarea);

    var br = document.createElement('br');
    eval_block.appendChild(br);

    var eval_key = document.createElement('a');
    eval_key.id = 'eval_key';
    eval_key.href = '#';
    eval_key.className = 'console_key_class';
    eval_key.appendChild(document.createTextNode('Eval'));
    set_event('click', self.eval_code, eval_key);

    eval_block.appendChild(eval_key);
    menu_block.appendChild(eval_block);

    var body = document.body;
    if (body.firstChild)
    {
    body.insertBefore(console_root_block, body.firstChild);
    } else {
    body.appendChild(console_root_block);
    }
    }

    /**
    * Method toggle menu of console
    * @access private
    */
    var toggle_menu = function()
    {
    menu_block.style.display = (menu_block.style.display === "none") ? 'block' : 'none';
    }

    /**
    * Method preinterprite the event.
    * @access private
    */
    var pre_toggle = function(event_obj)
    {
    if (event_obj.keyCode == 192 && event_obj.ctrlKey == true)
    {
    toggle();
    }
    }

    /**
    * Method put variable to console.
    * @access private
    */
    var put = function(msg_array, group_array)
    {
    var msg_text = msg_array[0];
    var msg_title = (msg_array[1]) ? msg_array[1] : null;
    var msg_color = (msg_array[2]) ? msg_array[2] : null;
    var msg_text_node = document.createTextNode(msg_array[0]);
    var msg_block = document.createElement('div');
    msg_block.appendChild(msg_text_node);
    var current_console_block = console_block;
    if (group_array)
    {
    var group_name = group_array[0][0];
    current_console_block = groups[group_name];
    if (!current_console_block)
    {
    var group_title_title = (group_array[0][1]) ? group_array[0][1] : null;
    var group_title_color = (group_array[0][2]) ? group_array[0][2] : null;
    var group_color = (group_array[1]) ? group_array[1] : null;
    var group_block = document.createElement('div');
    group_block.className = "group_block";
    var group_head_block = document.createElement('div');
    if (group_title_color)
    {
    group_head_block.style.color = group_title_color;
    }

    if (group_title_title)
    {
    group_head_block.title = group_title_title;
    }
    var group_head_block_text_node = document.createTextNode(group_name + ':');
    group_head_block.appendChild(group_head_block_text_node);
    group_head_block.className = "group_head_block";
    group_block.appendChild(group_head_block);
    current_console_block = groups[group_name] = document.createElement('div');
    current_console_block.className = "console_block";
    if (group_color)
    {
    current_console_block.style.color = group_color;
    }

    group_block.appendChild(current_console_block);
    console_block.appendChild(group_block);
    }
    }

    if (msg_title)
    {
    msg_block.title = msg_title;
    try { span.style.cursor = "pointer"; } catch (e) {}
    }

    if (msg_color)
    {
    msg_block.style.color = msg_color;
    }
    current_console_block.appendChild(msg_block);
    }

    /**
    * Method call method "put" with arguments of Error information
    * @access private
    */
    var put_error = function(message, url, line)
    {
    var error_message = "Message: " + message + "; URL: " + url;
    self.put([
    [error_message, "~ at " + line + " line"]
    ], [
    [
    "Errors",
    "JavaScript Errors",
    "red"
    ],
    "red"
    ]);
    }

    /**
    * Public methods && properties
    */

    /**
    * Textarea for code to eval
    * @access public
    */
    self.eval_textarea = null;

    /**
    * Method call private method "put" of console.
    * @access public
    * @arguments
    * 1, 2, 3, 4, e.t.c. {ARRAY} (three elements; message; title; color) or any
    * last argument -- {ARRAY} (three elements; group name; title; color)
    */
    self.put = function(msgs_array, group_array)
    {
    group_array = (group_array) ? group_array : null;
    for (var i = 0; i < msgs_array.length; i++)
    {
    // Call private method put!!! Not this! ;)
    put(msgs_array, group_array);
    }
    }

    /**
    * Method disable console.
    * @see #unset_event
    * @access public
    */
    self.disable = function()
    {
    if (enabled)
    {
    unset_event('keydown', pre_toggle, window);
    enabled = false;
    if (self.onDisableToggle)
    {
    toggle();
    }
    }
    }

    /**
    * Method enable console.
    * @see #set_event
    * @access public
    */
    self.enable = function()
    {
    if (!enabled)
    {
    set_event('keydown', pre_toggle, window);
    enabled = true;
    if (self.onEnableToggle)
    {
    toggle();
    }
    }
    }

    /**
    * This property specify toggle console on disable method call
    * @access public
    */
    self.onDisableToggle = true;

    /**
    * This property specify toggle console on enable method call
    * @access public
    */
    self.onEnableToggle = true;

    /**
    * Initialization.
    */
    this.init = function()
    {
    create();
    set_event('keydown', pre_toggle, window);
    set_event('error', put_error, window);
    }
    }

    /**
    * Function eval code entered to eval textarea
    * @access public
    */
    debug_console.eval_code = function()
    {
    eval(debug_console.eval_textarea.value);
    }.bind(window);

    debug_console.init();
  2. Иван Сагалаев

    05.03.2009

    0 ↑
    0 ↓

    Видите, половина кода курсивом? Вот там, где он начинается, в коде присутствует <i>, и она-то и ломает расцветку. Все угловые скобки в HTML, в том числе и внутри <pre> надо экранировать (&lt;i&gt;).

  3. systemnikass.ya.ru

    07.03.2009

    0 ↑
    0 ↓
    Вот, посмотрите: http://systemnik.net.ru/testirovanie-podsvetki-t174.html
    (Это измененный стиль Visual Studio (добавил только вывод текущего класса элемента))
    как вдите, он пишет что пхп...
  4. Иван Сагалаев

    07.03.2009

    0 ↑
    0 ↓

    как вдите, он пишет что пхп...

    Вижу. Вроде бы, мы уже разобрались, что эвристика работает не всегда. Вы хотите меня про каждый случай спрашивать "почему"? С какой целью?

  5. systemnikass.ya.ru

    08.03.2009

    0 ↑
    0 ↓
    Чтож... Ну просто этот код слабо похож на пхп... Ну к примеру баксов нет. ;) Я поимаю, я бы там баксов понаделал... (что допустимо я явасркипте), да и вообще...
    там "." а не "->", что тоже свойственно яваскрипту, но не пхп...
  6. Иван Сагалаев

    08.03.2009

    0 ↑
    0 ↓

    Программа, она не человек, у ней нет искусственного интеллекта. Попробуйте взять код highlight.js и выразить там вот это все: "баксов нет", "точки вместо стрелок". Я думаю, довольно быстро станет очевидно, сколько сил, времени и строк кода будет занимать та степень интеллектуальности, которую вы ожидаете от этого кода.

    Кстати, этот конкретный код переполнен phpdoc'ами. И скорее всего, именно от этого посчитался сильно похожим на PHP.

Внимание! Это довольно старый топик, посты в него не попадут в новые, и их никто не увидит. Пишите пост, если хотите просто дополнить топик, а чтобы задать новый вопрос — начните новый.