Commit d520f755 authored by Joris Handstanger's avatar Joris Handstanger Committed by Robin De Herdt
Browse files

Resolve #3262294 "Provide live css"

parent f8dd9c1d
Loading
Loading
Loading
Loading
+8 −3
Changes for README.md: 8 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -4,8 +4,10 @@ Simple live css is a D8 rewrite of https://www.drupal.org/project/live_css,
but with basic features only.

CSS can be added within the page, with live preview. The changes can then
be saved to a CSS file that will be added to every non-admin page. Its
primary usage purpose is (temporarily) overriding existing css.
be saved to a CSS file that will be added to every page.
It is also possible to enable a separate editor for pages using the admin theme.

The primary usage purpose for this module is (temporarily) overriding existing css.

## Installation

@@ -45,4 +47,7 @@ Install using composer: `composer require drupal/simple_live_css`

## Configuration

Enable the 'Edit live CSS' permission.
Enable the 'Edit live CSS' permission for access to the regular live CSS editor.

If desired, it is also possible to enable live CSS on admin pages by enabling the "Enable admin live CSS" setting on `/admin/config/user-interface/simple-live-css`.
This also requires the 'Edit admin live CSS' permission.
+7 −0
Changes for config/schema/simple_live_css.schema.yml: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
simple_live_css.settings:
  type: config_object
  label: 'Simple live CSS settings'
  mapping:
    enable_admin_live_css:
      label: 'Enable admin live CSS'
      type: boolean
+13 −4
Changes for js/components/liveCssEditor.js: 13 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -12,12 +12,21 @@
   *
   * @constructor
   */
  let LiveCssEditor = function () {
  let LiveCssEditor = function (isAdmin) {
    this.body = $('body');
    this.html = $('html');

    this.isAdminEditor = isAdmin;
    this.link = $("link[href*='" + drupalSettings.simple_live_css.css_file_path + "']");
    this.button = $("<button class='js--live-css-button live-css-button'>" + Drupal.t('LIVE CSS') + "</button>");

    if (this.isAdminEditor) {
      this.title = Drupal.t('ADMIN LIVE CSS');
    }
    else {
      this.title = Drupal.t('LIVE CSS');
    }

    this.button = $("<button class='js--live-css-button live-css-button'>" + this.title + "</button>");

    this.ajaxSaveIsTriggered = false;
    this.liveCssService = new LiveCssService();
@@ -174,7 +183,7 @@
  LiveCssEditor.prototype.initEventListeners = function () {
    let that = this;
    $(this.button).click(function () {
      $.when(that.liveCssService.getCss()).done(function (code) {
      $.when(that.liveCssService.getCss(that.isAdminEditor)).done(function (code) {
        that.initEditor(code);
        that.disableCssFile();
      });
@@ -202,7 +211,7 @@
      });

      let code = that.getEditorValue();
      $.when(that.liveCssService.save(code)).done(function () {
      $.when(that.liveCssService.save(code, that.isAdminEditor)).done(function () {
        $('.js--live-css-editor-container').unblock();
        that.setEditorStatusMessage('All changes saved');
        that.setAjaxSaveIsTriggered(true);
+10 −4
Changes for js/services/liveCssService.js: 10 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -14,15 +14,18 @@
   */
  let LiveCssService = function () {};

  LiveCssService.prototype.save = function (data) {
  LiveCssService.prototype.save = function (code, admin) {

    let deferred = $.Deferred();

    $.ajax({
      url: '/live_css/save',
      type: 'POST',
      dataType: 'text',
      data: data,
      dataType: 'json',
      data: {
        'css': code,
        'admin': admin,
      },
      success: function (data) {
        deferred.resolve(data);
      },
@@ -34,13 +37,16 @@
    return deferred.promise();
  };

  LiveCssService.prototype.getCss = function () {
  LiveCssService.prototype.getCss = function (admin) {

    let deferred = $.Deferred();

    $.ajax({
      url: '/live_css/get',
      type: 'GET',
      data: {
        admin: admin,
      },
      dataType: 'text',
      success: function (data) {
        deferred.resolve(data);
+4 −3
Changes for js/simple_live_css.behaviors.js: 4 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -2,14 +2,15 @@
 * @file
 */

(function ($) {
(function ($, Drupal, drupalSettings) {

  Drupal.behaviors.simple_live_css = {
    attach: function (context, settings) {
      const isAdmin = drupalSettings.simple_live_css.admin;
      $('.js--live-css', context).once('simple_live_css').each(function () {
        new LiveCssEditor();
        new LiveCssEditor(isAdmin);
      });
    }
  }

}(jQuery));
}(jQuery, Drupal, drupalSettings));
Loading