cdruan / tw5-captivate

TiddlyWiki theme with easy color customization
https://cdruan.github.io/tw5-captivate/
MIT License
18 stars 3 forks source link

Compatibility with krystal horizontal layout plug in #1

Closed arunnbabu81 closed 2 years ago

arunnbabu81 commented 3 years ago

Thanks for this excellent theme. You might not have released it for public use yet. So take these as just my suggestions.

I use krystal horizontal layout plug-in in some of my my wikis. I wish to use this theme in those wikis. But topbar contents in krystal and this theme are different. I like the the way its done in krystal to open 'Open' 'Recent' tiddlers as dropdown as suggested in these links 1 and 2 . Can this be done if i am using your theme. Even if this is not added into the theme, can you suggest some hacks so that, i can implement it?

cdruan commented 3 years ago

Do you want to use krystal layout but would like to incorporate colors generated by this theme? If so, here are two easy options:

There are probably CSS adjustments you might need to make in either case. For example, if you'd like to color the topbar, you can create a tiddler tagged with $:/tags/Stylesheet and add the following:

.krystal-header { 
  background-color: <<colour primary>>; 
}

.krystal-header .tc-site-title, 
.krystal-header .tc-site-subtitle,
.krystal-header .tc-btn-invisible svg, 
.krystal-header .tc-tiddlylink { 
    fill: <<colour on-primary>>;
    color: <<colour on-primary>>;
} 

Would these suggestions work for you?

arunnbabu81 commented 3 years ago

The first suggestion works for me. Also i modified the topbar as suggested by you. Thanks for both.

Further i liked the search box in the topbar of your theme. I tried to change the default search in the topbar of krystal ($:/plugins/rmnvsl/krystal/search) with yours ($:/themes/cdr/captivate/ui/TopBar/Search)

But if I type something in that search box, the focus is lost from the search box while typing. Can you help about that. I have attached a demo wiki krystal.zip

cdruan commented 3 years ago

The focus is stolen by another input box in the search dropdown. The fix is to prevent it from displaying. So here's the fix:

Add to your stylesheet:

.krystal-header .cv-search-bar .tc-search { 
    display: none !important; 
}
arunnbabu81 commented 3 years ago

Thank you for the help. It works perfectly

arunnbabu81 commented 2 years ago

@cdruan

I have tweaked my wiki for using krystal horizontal layout plug in and captivate theme together with the help of tips you have given before.

For desktop use, I have applied the captivate theme along with the default page layout instead of the captivate left sidebar layout You can see the implementation in this demo wiki - https://krystal.tiddlyhost.com/

In mobile, I want to hide the Krystal header and show the captivate left sidebar and bottom bar.

I was able to hide krystal header in mobile by using this tip

Now I want to know how to apply the captivate sidebar and bottom bar( ie the captivate left sidebar layout ) in mobile automatically.

cdruan commented 2 years ago

Hi @arunnbabu81

You can use Nicolas Petton's strategy you mentioned in the tip, but instead of setting the default theme, you set the default layout depending on the size of the screen. Since you already have a mystartup.js, you can insert the following code:

/*\
title: mystartup.js
type: application/javascript
module-type: startup

Sets plugin behavior

\*/
(function () {

...

exports.platforms = ["browser"];
exports.before = ["render"];

var mobileLayout = "$:/themes/cdr/captivate/ui/PageLayout";
var desktopLayout = "$:/core/ui/PageTemplate";

var breakpoint = 960;

exports.startup = function() {
    ...

    var layout;
    if (document.documentElement.clientWidth <= breakpoint) {
        layout = mobileLayout;
    } else {
        layout = desktopLayout;
    }

    $tw.wiki.addTiddler({title: "$:/layout", text: layout});
};

...
})();

Note that timing of mystartup.js is changed to run before the render module.

arunnbabu81 commented 2 years ago

I tried these two

/*\
title: mystartup.js
type: application/javascript
module-type: startup

Sets plugin behavior

\*/
(function () {
  const MAXIMIZED_TIDDLER_CLASS = "krystal-tiddler__frame--maximized";

  exports.after = ["render"];

  exports.startup = function () {
    $tw.hooks.addHook("th-navigating", restoreMaximizedTiddler);
    $tw.hooks.addHook("th-new-tiddler", restoreMaximizedTiddler);
  };

  function restoreMaximizedTiddler(event) {
    const tiddler = document.querySelector(
      `div[class~="${MAXIMIZED_TIDDLER_CLASS}"]`
    );
    if (tiddler) {
      tiddler.classList.remove(MAXIMIZED_TIDDLER_CLASS);
    }
    return event;
  }

})();

/*\
title: mystartup.js
type: application/javascript
module-type: startup

Sets plugin behavior

\*/
(function () {

...

exports.platforms = ["browser"];
exports.before = ["render"];

var mobileLayout = "$:/themes/cdr/captivate/ui/PageLayout";
var desktopLayout = "$:/core/ui/PageTemplate";

var breakpoint = 960;

exports.startup = function() {
    ...

    var layout;
    if (document.documentElement.clientWidth <= breakpoint) {
        layout = mobileLayout;
    } else {
        layout = desktopLayout;
    }

    $tw.wiki.addTiddler({title: "$:/layout", text: layout});
};

...
})();
/*\
title: mystartup.js
type: application/javascript
module-type: startup

Sets plugin behavior

\*/
(function () {

...

exports.platforms = ["browser"];
exports.before = ["render"];

var mobileLayout = "$:/themes/cdr/captivate/ui/PageLayout";
var desktopLayout = "$:/core/ui/PageTemplate";

var breakpoint = 960;

exports.startup = function() {
    ...

    var layout;
    if (document.documentElement.clientWidth <= breakpoint) {
        layout = mobileLayout;
    } else {
        layout = desktopLayout;
    }

    $tw.wiki.addTiddler({title: "$:/layout", text: layout});
};

...
})();

But both were not working.

cdruan commented 2 years ago

@arunnbabu81

Seems that I wasn't clear about the instruction. Previous example needs to be "merged" into your existing tiddler. Try replacing your current mystartup.js body with the following:

/*\
title: mystartup.js
type: application/javascript
module-type: startup

Sets plugin behavior

\*/
(function () {
  const MAXIMIZED_TIDDLER_CLASS = "krystal-tiddler__frame--maximized";

  var mobileLayout = "$:/themes/cdr/captivate/ui/PageLayout";
  var desktopLayout = "$:/core/ui/PageTemplate";

  var breakpoint = 960;

  exports.platforms = ["browser"];
  exports.before = ["render"];

  exports.startup = function () {
    $tw.hooks.addHook("th-navigating", restoreMaximizedTiddler);
    $tw.hooks.addHook("th-new-tiddler", restoreMaximizedTiddler);

    // determine layout programmatically
    var layout;
    if (document.documentElement.clientWidth <= breakpoint) {
        layout = mobileLayout;
    } else {
        layout = desktopLayout;
    }

    $tw.wiki.addTiddler({title: "$:/layout", text: layout});
  };

  function restoreMaximizedTiddler(event) {
    const tiddler = document.querySelector(
      `div[class~="${MAXIMIZED_TIDDLER_CLASS}"]`
    );
    if (tiddler) {
      tiddler.classList.remove(MAXIMIZED_TIDDLER_CLASS);
    }
    return event;
  }

})();

I've tested the code on a local copy of your wiki. It should work...

arunnbabu81 commented 2 years ago

@arunnbabu81

Seems that I wasn't clear about the instruction. Previous example needs to be "merged" into your existing tiddler. Try replacing your current mystartup.js body with the following:

/*\
title: mystartup.js
type: application/javascript
module-type: startup

Sets plugin behavior

\*/
(function () {
  const MAXIMIZED_TIDDLER_CLASS = "krystal-tiddler__frame--maximized";

  var mobileLayout = "$:/themes/cdr/captivate/ui/PageLayout";
  var desktopLayout = "$:/core/ui/PageTemplate";

  var breakpoint = 960;

  exports.platforms = ["browser"];
  exports.before = ["render"];

  exports.startup = function () {
    $tw.hooks.addHook("th-navigating", restoreMaximizedTiddler);
    $tw.hooks.addHook("th-new-tiddler", restoreMaximizedTiddler);

    // determine layout programmatically
    var layout;
    if (document.documentElement.clientWidth <= breakpoint) {
        layout = mobileLayout;
    } else {
        layout = desktopLayout;
    }

    $tw.wiki.addTiddler({title: "$:/layout", text: layout});
  };

  function restoreMaximizedTiddler(event) {
    const tiddler = document.querySelector(
      `div[class~="${MAXIMIZED_TIDDLER_CLASS}"]`
    );
    if (tiddler) {
      tiddler.classList.remove(MAXIMIZED_TIDDLER_CLASS);
    }
    return event;
  }

})();

I've tested the code on a local copy of your wiki. It should work...

This one works. Thank you.