Sha256: 6b04c3d96f17f1c2297acf840d67fe9fd942ed6c377a207a021af843f05d43c3

Contents?: true

Size: 1.24 KB

Versions: 6

Compression:

Stored size: 1.24 KB

Contents

"use strict";
/* global global: false */
var console = require("console");
var $ = require("jquery");
var inlineDocument = require("juice/lib/inline")({}).inlineDocument;

var inlinerPlugin = function(vm) {
  vm.inline = function(doc) {
    // tinymce may have added style attributes to elements that will also have global styles to be inlined
    $('[style]:not([replacedstyle])', doc).each(function(index, el) {
      var $el = $(el);
      $el.attr('replacedstyle', $el.attr('style'));
    });

    var style = [];
    $('style[data-inline="true"]', doc).each(function(index, element) {
      var content = $(element).html();
      content = content.replace(/<!-- ko ((?!--).)*? -->/g, ''); // this replaces the above with a more formal (but slower) solution
      content = content.replace(/<!-- \/ko -->/g, '');
      style.push(content);
      $(element).removeAttr('data-inline');
    });
    var styleText = style.join("\n");
    var $context = function(selector, context) {
      if (typeof context == 'undefined') context = doc;
      return $(selector, context);
    };
    $context.root = function() {
      return $(':root', doc);
    };
    inlineDocument($context, styleText, { styleAttributeName: 'replacedstyle' });
  };
};

module.exports = inlinerPlugin;

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mosaico-2.0.0 vendor/assets/mosaico-0.16.0/mosaico/src/js/ext/inliner.js
mosaico-1.1.1 vendor/assets/mosaico-0.16.0/mosaico/src/js/ext/inliner.js
mosaico-1.1.0 vendor/assets/mosaico-0.16.0/mosaico/src/js/ext/inliner.js
mosaico-1.0.2 vendor/assets/mosaico-0.16.0/mosaico/src/js/ext/inliner.js
mosaico-1.0.1 vendor/assets/mosaico-0.16.0/mosaico/src/js/ext/inliner.js
mosaico-1.0.0 vendor/assets/mosaico-0.16.0/mosaico/src/js/ext/inliner.js