Plugin Directory

Changeset 1022794


Ignore:
Timestamp:
11/10/2014 07:54:35 AM (11 years ago)
Author:
rewish
Message:

Version 0.3 Released

Location:
wp-emmet/trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • wp-emmet/trunk/WP/Emmet.php

    r952584 r1022794  
    138138    public function enqueueScripts() {
    139139        $type = $this->editorType();
     140        $deps = array('underscore');
     141
    140142        if ($this->isCodeMirrorMode()) {
    141143            $this->CodeMirror->enqueueAllScripts();
     144            $deps[] = $type;
    142145        }
    143         wp_enqueue_script('wp_wmmet', self::assetURL("js/wp_emmet.js"));
    144         wp_enqueue_script('emmet', self::assetURL("js/{$type}/emmet.js"), array('underscore'), false, true);
     146
     147        wp_enqueue_script('emmet', self::assetURL("js/{$type}/emmet.js"), $deps, false, true);
     148        wp_enqueue_script('wp_wmmet', self::assetURL("js/wp_emmet.js"), array('emmet','editor'));
    145149    }
    146150
  • wp-emmet/trunk/WP/Emmet/CodeMirror.php

    r858784 r1022794  
    3636        $this->_registerThemes();
    3737        $this->registerScript('codemirror');
     38        $this->registerScript('adapter', 'adapter', array('deps' => 'codemirror'));
    3839        $this->_registerModes();
    3940    }
     
    7677     */
    7778    public function enqueueScript($mode = null) {
    78         wp_enqueue_script($mode ? "{$this->domain}-{$mode}" : $this->domain);
     79        $handle = $this->domain;
     80        $deps = array();
     81
     82        if ($mode) {
     83            $deps[] = $this->domain;
     84            $handle.= '-' . $mode;
     85        }
     86
     87        wp_enqueue_script($handle, $deps);
    7988    }
    8089
     
    8493    public function enqueueAllScripts() {
    8594        $this->enqueueScript();
     95        $this->enqueueScript('adapter');
    8696        array_walk($this->modes, array($this, 'enqueueScript'));
    8797    }
  • wp-emmet/trunk/assets/js/wp_emmet.js

    r738398 r1022794  
    1 !function($) {
     1var wp_emmet = (function($) {
     2  'use strict';
     3
    24  var editorID = 'wp-emmet-editor';
    35
     6  /**
     7   * Apply the CodeMirror
     8   *
     9   * @param options
     10   * @returns {*}
     11   */
    412  $.fn.codeMirror = function(options) {
    513    return this.each(function() {
     
    1725  };
    1826
     27  /**
     28   * Get an editor of the CodeMirror
     29   *
     30   * @param editor
     31   * @returns {*}
     32   */
    1933  $.fn.codeMirrorEditor = function(editor) {
    2034    if (editor) {
    21       return $.data(this[0], editorID, editor);
     35      return this.data(editorID, editor);
    2236    }
    23     return $.data(this[0], editorID);
     37    return this.data(editorID);
    2438  };
    2539
    26   window.wp_emmet = {
    27     adaptCodeMirror: function() {
    28       if (typeof wp !== 'undefined' &&
    29         typeof wp.media !== 'undefined' &&
    30         typeof wp.media.editor !== 'undefined') {
    31         this.adaptMediaEditor();
     40  /**
     41   * Apply emmet
     42   *
     43   * @param options
     44   * @param mimeTypes
     45   * @returns {*}
     46   */
     47  $.fn.emmet = function(options, mimeTypes) {
     48    options = options || {};
     49    mimeTypes = mimeTypes || {};
     50
     51    return this.each(function() {
     52      var maxWidth, minHeight,
     53          $textarea = $(this),
     54          file = $textarea.closest('form').find('input[name="file"]').val(),
     55          mode = $textarea.attr('data-cm-mode');
     56
     57      if (!mode) {
     58        mode = mimeTypes[file ? file.split('.').pop() : 'html'];
    3259      }
    3360
    34       if (typeof switchEditors !== 'undefined') {
    35         this.adaptSwitchEditors();
     61      $textarea.codeMirror($.extend({}, options, {mode: mode}));
     62
     63      if (maxWidth = $textarea.attr('data-cm-max-width')) {
     64        $($textarea.codeMirrorEditor().display.wrapper).css({maxWidth: maxWidth});
    3665      }
    3766
    38       if (typeof QTags !== 'undefined') {
    39         this.adaptQTags();
     67      if (minHeight = $textarea.attr('data-cm-min-height')) {
     68        $($textarea.codeMirrorEditor().display.scroller).css({minHeight: minHeight});
    4069      }
     70    });
     71  };
    4172
    42       if (typeof wpLink !== 'undefined') {
    43         this.adaptWPLink();
    44       }
     73  function adjust() {
     74    var editor = $('#content').codeMirrorEditor(),
     75        $top = wp_emmet.$top || $('#ed_toolbar');
    4576
    46       if (typeof fullscreen !== 'undefined') {
    47         this.adaptFullScreen();
    48       }
    49     },
     77    if (editor) {
     78      $(editor.display.wrapper).css('marginTop', $top.innerHeight()|0)
     79    }
     80  }
    5081
    51     adaptMediaEditor: function() {
    52       var originalInsert = wp.media.editor.insert;
     82  var scrollTimerID;
    5383
    54       wp.media.editor.insert = function(h) {
    55         var cursor,
    56             editor = $('#' + wpActiveEditor).codeMirrorEditor();
     84  $(window).on('scroll resize', function() {
     85    adjust();
     86    clearTimeout(scrollTimerID);
     87    scrollTimerID = setTimeout(adjust, 100);
     88  });
    5789
    58         if (!editor) {
    59           return originalInsert.call(this, h);
    60         }
     90  $(document).on('wp-collapse-menu postboxes-columnchange editor-classchange postbox-toggled', adjust);
    6191
    62         editor.doc.replaceSelection(h);
    63         cursor = editor.doc.getCursor();
    64         editor.doc.setCursor(cursor.line, cursor.ch + h.indexOf('>'));
    65         editor.focus();
    66       };
    67     },
    68 
    69     adaptSwitchEditors: function() {
    70       switchEditors.switchto = function(el) {
    71         var params = el.id.split('-'),
    72             $wrap = $('#wp-' + params[0] + '-wrap'),
    73             $textarea = $(tinymce.DOM.get(params[0])),
    74             editor = $textarea.codeMirrorEditor(),
    75             toHTML = params[1] === 'html',
    76             fromHTML = $wrap.hasClass('html-active');
    77 
    78         if ((toHTML && fromHTML) || (!toHTML && !fromHTML)) {
    79           return;
    80         }
    81 
    82         if (!toHTML) {
    83           editor.toTextArea();
    84         }
    85 
    86         this.go(params[0], params[1]);
    87 
    88         if (toHTML) {
    89           editor = CodeMirror.fromTextArea(editor.getTextArea(), editor.options);
    90           editor.disabled = false;
    91           $textarea.codeMirrorEditor(editor);
    92         }
    93       };
    94     },
    95 
    96     adaptQTags: function() {
    97       QTags.TagButton.prototype.callback = function(element, canvas, ed) {
    98         var cursor, html,
    99             editor = $(canvas).codeMirrorEditor(),
    100             text = editor.doc.getSelection(),
    101             startPos = text.indexOf(this.tagStart),
    102             endPos = text.indexOf(this.tagEnd);
    103 
    104         if (startPos !== -1 && endPos !== -1) {
    105           html = text.substring(this.tagStart.length, endPos);
    106         } else {
    107           html = this.tagStart + text + this.tagEnd;
    108         }
    109 
    110         editor.doc.replaceSelection(html);
    111 
    112         if (text) {
    113           cursor = editor.doc.getCursor('end');
    114         } else {
    115           cursor = editor.doc.getCursor('start');
    116           cursor.ch += this.tagStart.length;
    117         }
    118 
    119         editor.doc.setCursor(cursor, cursor);
    120         editor.focus();
    121       };
    122     },
    123 
    124     adaptWPLink: function() {
    125       wpLink.htmlUpdate = function() {
    126         var cursor,
    127             data = this.getAttrs(),
    128             editor = $(this.textarea).codeMirrorEditor(),
    129             tagStart = '<a',
    130             tagEnd = '</a>';
    131 
    132         $.each(data, function(name, value) {
    133           if (value) {
    134             tagStart += ' ' + name + '="' + value + '"';
    135           }
    136         });
    137 
    138         tagStart += '>';
    139 
    140         editor.replaceSelection(tagStart + editor.getSelection() + tagEnd);
    141 
    142         cursor = editor.doc.getCursor('start');
    143         editor.doc.setCursor(cursor.line, cursor.ch + tagStart.length);
    144         editor.focus();
    145 
    146         this.close();
    147       };
    148     },
    149 
    150     adaptFullScreen: function() {
    151       var $fullScreen = $('#wp_mce_fullscreen'),
    152           originalOff = fullscreen.off,
    153           originalSwitchMode = fullscreen.switchmode,
    154           originalSaveContent = fullscreen.savecontent;
    155 
    156       fullscreen.pubsub.subscribe('showing', function() {
    157         var editor = $('#' + wpActiveEditor).codeMirrorEditor();
    158         $fullScreen.codeMirror(editor.options);
    159       });
    160 
    161       fullscreen.off = function() {
    162         var $content = $('#' + fullscreen.settings.editor_id),
    163             editor = $fullScreen.codeMirrorEditor();
    164 
    165         originalOff.call(this);
    166 
    167         if ($content.is(':visible')) {
    168           $content.val(editor.doc.getValue());
    169           $content.codeMirror(editor.options);
    170         }
    171 
    172         if (fullscreen.settings.mode === 'html') {
    173           editor.toTextArea();
    174         }
    175       };
    176 
    177       fullscreen.switchmode = function(to) {
    178         if (fullscreen.settings.mode === to) {
    179           return;
    180         }
    181 
    182         var editor = $fullScreen.codeMirrorEditor(),
    183             mainEditor = $('#' + fullscreen.settings.editor_id).codeMirrorEditor();
    184 
    185         if (to === 'html') {
    186           originalSwitchMode.call(this, to);
    187           $fullScreen.codeMirror(mainEditor.options);
    188         } else {
    189           editor && editor.toTextArea();
    190           originalSwitchMode.call(this, to);
    191         }
    192       };
    193 
    194       fullscreen.savecontent = function() {
    195         if (fullscreen.settings.mode === 'html') {
    196           $fullScreen.codeMirrorEditor().save();
    197         }
    198         originalSaveContent.call(this);
    199       };
    200 
    201       QTags.FullscreenButton.prototype.callback = function(e, c) {
    202         if (!c.id) { return; }
    203         $(c).codeMirrorEditor().toTextArea();
    204         fullscreen.on();
    205       };
    206     }
     92  return {
     93    adjust: adjust
    20794  };
    208 }(jQuery);
     95}(jQuery));
  • wp-emmet/trunk/readme.txt

    r952585 r1022794  
    22Contributors: rewish
    33Tags: emmet, zen-coding, editor, post, plugin, coding
    4 Requires at least: 3.5
    5 Tested up to: 3.9.1
     4Requires at least: 4.0
     5Tested up to: 4.0
    66Stable tag: trunk
    77License: GPLv2 or later
     
    2727
    2828== Changelog ==
     29
     30= 0.3 =
     31* Fixes for WordPress 4.0
     32* Raise the requires version to 4.0
    2933
    3034= 0.2.6 =
  • wp-emmet/trunk/views/apply_for_codemirror.php

    r742780 r1022794  
    44}
    55</style>
     6
    67<script>
    78<?php if ($this->Options->get('override_shortcuts')): ?>
     
    1718jQuery(function($) {
    1819    var options = $.extend(<?php echo $this->Options->toJSON('codemirror'); ?>, {
    19             profile: '<?php echo $this->Options->get('profile'); ?>'
    20         }),
    21         mimeTypes = {
    22             php: 'application/x-httpd-php',
    23             html: 'text/html',
    24             css: 'text/css',
    25             js: 'text/javascript',
    26             json: 'application/json'
    27         };
     20        profile: '<?php echo $this->Options->get('profile'); ?>'
     21    });
     22
     23    var mimeTypes = {
     24        php: 'application/x-httpd-php',
     25        html: 'text/html',
     26        css: 'text/css',
     27        js: 'text/javascript',
     28        json: 'application/json'
     29    };
    2830
    2931    setTimeout(function() {
    30         $('textarea:not(#wp_mce_fullscreen)').each(function() {
    31             var $textarea = $(this),
    32                 file = $textarea.closest('form').find('input[name="file"]').val(),
    33                 mode = $textarea.attr('data-cm-mode'),
    34                 maxWidth = $textarea.attr('data-cm-max-width'),
    35                 minHeight = $textarea.attr('data-cm-min-height');
    36 
    37             $textarea.codeMirror($.extend({}, options, {
    38                 mode: mode || mimeTypes[file ? file.split('.').pop() : 'html']
    39             }));
    40 
    41             if (maxWidth) {
    42                 $($textarea.codeMirrorEditor().display.wrapper).css({maxWidth: maxWidth});
    43             }
    44 
    45             if (minHeight) {
    46                 $($textarea.codeMirrorEditor().display.scroller).css({minHeight: minHeight});
    47             }
    48         });
    49 
    50         wp_emmet.adaptCodeMirror();
    51     }, 0);
     32        $('textarea:not(#content-textarea-clone)').emmet(options, mimeTypes);
     33        wp_emmet.adjust();
     34    }, 1);
    5235});
    5336</script>
  • wp-emmet/trunk/wp-emmet.php

    r952584 r1022794  
    44Plugin URI: https://github.com/rewish/wp-emmet
    55Description: Emmet (ex-Zen Coding) for WordPress.
    6 Version: 0.2.6
     6Version: 0.3
    77Author: rewish
    88Author URI: https://github.com/rewish
Note: See TracChangeset for help on using the changeset viewer.