Any ideas on how to create an Ember / Handlebars project with suport for multiple themes / skins that can be changed through a dropbox in the UI?
Current version of Ember is 1.0.0-rc.2
Thanks
Nothing too unique to Ember here. Use CSS for themes/skins, and change the current theme stylesheet when the dropbox changes.
FYI, there is a switch stylesheet ember-cli that you can use:
https://www.npmjs.com/package/ember-theme-changer
Install Theme Changer
ember install ember-theme-changer
Modify the code below in ember-cli-build.js:
// ember-cli-build.js
outputPaths: {
app: {
css: {
'light': '/assets/light.css', // FOR LIGHT THEME => app.scss
'dark': '/assets/dark.css' // FOR DAR THEME => dark.scss
}
}
},
Create your own SCSS with difference configuration.
Go to app/styles folder
Create dark.css and app.scss
dark.scss
body{
background-color: black;
}
app.scss
body{
background-color: light;
}
All you need just to make two button to switch the css file that you apply to
Think of it this easy way:
In Html template application.hbs
<link href="light.css" rel="stylesheet" type="text/css" >
<button class='light'>LIGHT MODE</button>
<button class='dark'>DARK MODE</button>
In Javascript File
$('.light').click(function (){
$('link[href="light.css"]').attr('href','black.css');
});
$('.black').click(function (){
$('link[href="black.css"]').attr('href','light.css');
});
comments: You can use other addon (more complicated) which it can be found on:
https://www.emberaddons.com/
https://www.npmjs.com/package/ember-themed-syntax
Related
I am building a web application using the Django framework and installed Tailwind CSS using this tutorial: https://django-tailwind.readthedocs.io/en/latest/installation.html. It worked fine initially, but now when I reload my project after closing VScode, my colors stop working.
For an example,
I'll be creating a new line of HTML and use:
<body>
<div class="bg-blue-400 font-bold p-4 text-4xl">
<h1>Hello</h1>
</div>
</body>
and the background just goes immediately to white. I have tried uninstalling/reinstalling and checking my directories and still have no solution.
I have also found that only my custom colors work when I reload my project.
/** #type {import('tailwindcss').Config} */
module.exports = {
content: [
'../templates/**/*.html',
'../../templates/**/*.html',
'../../**/templates/**/*.html',
],
theme: {
extend: {
colors: {
'jcblue1': '#5CB5FD',
'spook': '#3C4856',
}
},
},
plugins: [],
}
^this is my tailwind.config file.
The problem:
When I resize the window the images will only sometimes change. It's almost like they get stuck / the resize event is not being captured properly by foundation. If I start resizing the window like a rabid monkey it will occasionally swap the image. If I resize the window according to the media queries and then refresh the page the correct image renders. This appears to be a resize only issue.
Other details:
I have just a regular .html file (new site hosted from IIS on a separate machine) with a simple demo of Interchange image swapping.
If I manually call: $(document).foundation("interchange", "resize"); the image will swap correctly.
Foundation version 5.3.1
Testing in Chrome 36 and Firefox 31.
So far the only built in media query that works is (default). (medium), (large) etc. do nothing, I have to write out the actually query to get it to work (or manually create them using named_queries. This may be an unrelated problem but does seem strange to me.
<html>
<head>
<title>Interchange</title>
<script src='//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
<script type='text/javascript' src='/foundation.js'></script>
<script type='text/javascript' src='/foundation.interchange.js'></script>
<link rel='stylesheet' href='/foundation.css' />
<link rel='stylesheet' href='/normalize.css' />
<script type='text/javascript'>
$(function () {
$(document).foundation();
$(document).on('replace', function (e, newVal) {
console.log(newVal);
});
// Adding this horrible hack will make it work 100% of the time.
// BUT THIS SHOULD NOT BE NECESSARY!
//$(window).resize(function(){
// $(document).foundation("interchange", "resize");
//})
});
</script>
</head>
<body>
<img data-interchange="[/images/space-small.jpg, (default)], [/images/space-medium.jpg, (only screen and (min-width: 641px))], [/images/space-large.jpg, (only screen and (min-width: 1000px))]">
</body>
</html>
I found the answer to my own question and it was indeed that odd media queries issue I described in the OP that lead me to the problem.
Foundation's javascript is dependent on the Foundation CSS existing before it initializes.
All I had to do was make sure the CSS link was above the script include and everything started working as expected.
Not sure this will help anyone, but I was getting the same issue but ONLY on Chrome. I added the foundation.min.css to my page like b1j suggested and voila! unfortunately though as I used the SASS version I couldn't just leave this included into the page as I would have double the amount of css included into my page. So I pasted the foundation.css contents into a style tag in the head of my document and deleted its contents bit by bit until I found the piece of css that fixed it. Here it is:
meta.foundation-mq-small {
font-family: "/only screen/";
width: 0em; }
meta.foundation-mq-medium {
font-family: "/only screen and (min-width:40.063em)/";
width: 40.063em; }
meta.foundation-mq-large {
font-family: "/only screen and (min-width:64.063em)/";
width: 64.063em; }
meta.foundation-mq-xlarge {
font-family: "/only screen and (min-width:90.063em)/";
width: 90.063em; }
meta.foundation-mq-xxlarge {
font-family: "/only screen and (min-width:120.063em)/";
width: 120.063em; }
Not sure why this wasn't compiled into my CSS but I will look, but incase anyone needs a quick fix, this should do it!
I am trying out ember-cli to get an ember project going, however I have previously relied on rails and the asset pipeline to compile all my js and (s)css for previous projects.
I admit a weak understanding of js build tools, so apologies if the question is basic: How can I see what dependencies are being compiled/included in the build? Specifically, I want to include both zurb-foundation and ember-leaflet in my project. I am not sure if they are there (at least the leaflet map is not showing up in the project --- using a basic example that worked with both rails and rail-eak).
The files (ember-leaflet, etc) are in the vendor directory of the project and were placed there thru bower install (I assume?); do I have to manually include them in the root bower.json file (currently they are not); is the order in bower.json important?
Thanks in advance.
DJ
After some digging and a lot of reading I found the solution here and got ember-leaflet to work.
1.) Download the libs
bower install --save leaflet
bower install --save ember-leaflet
Note: It's probably not neccessary to download leaflet, since ember-leaflet seems to have it included (leaflet-dist).This is the part I did manually a few times, so you may or may not have vendor/leaflet-dist. Just change accordingly.
2.) Configure building the assets
Add the import lines in your Brocfile.js before the module.exports line
app.import('vendor/leaflet-dist/leaflet-src.js')
app.import('vendor/leaflet-dist/leaflet.css')
app.import('vendor/ember-leaflet/dist/ember-leaflet.js')
module.exports = app.toTree();
3) make Leaflet and EmberLeaflet known to Ember (.jshintrc)
{
"predef": {
...
"L": true,
"EmberLeaflet": true
}
...
}
4) create a view
export default EmberLeaflet.MapView.extend({
classNames : ['ember-leaflet-map']
});
5) create a template using the view (where view name corresponds to the file name, here views/mapview.js)
<div id="map">
{{view 'mapview'}}
</div>
6) check / add vendor style sheet to app/index.html (should be present with recent versions of ember-cli)
<head>
...
<link rel="stylesheet" href="assets/vendor.css">
</head>
7) run Ember
ember server
8) Bonus: In case you are using Twitter Bootstrap 3 here's the css I had to add to app/styles/app.css (could probably be simplified)
html,
body {
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
padding-top: 20px;
height: 100%;
}
.page-content {
padding: 40px 15px;
height: 100%;
}
.row {
margin-bottom: 1.5em;
}
#map {
height: 100%;
}
.ember-leaflet-map {
height: 100%;
}
body > .ember-view {
height: 100%;
}
It seems like somebody just created an ember-cli addon: https://www.npmjs.org/package/ember-cli-ember-leaflet
I'm going to try it :)
I have some JavaScript that I'm testing with Jasmine. I want to run the tests in the browser window when a user presses "run tests". With Jasmine 1.3, I have successfully set that up as shown in this JSFiddle with this code:
run tests
<script type="text/javascript">
window.jasmineEnv = (function () {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
jasmineEnv.specFilter = function (spec) {
return htmlReporter.specFilter(spec);
};
return jasmineEnv;
})();
</script>
Jasmine 2.0 offers some new capabilities that I really need. However, I cannot figure out how to get it setup such that the tests run when someone clicks a "run tests" button. I'm using the new boot.js file. However, I'm not having any luck. Can someone please help me migrate that sample from Jasmine 1.3 to Jasmine 2.0?
Thank you
Test cases execution is triggered by below snipped in file boot.js:
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
htmlReporter.initialize();
env.execute();
};
Either you can modify this implementation in boot.js file itself to execute under a function call or you can write your custom boot code inspired from actual boot.js.
Can't post this as a comment yet!
Jasmine 2.0 in jsfiddle http://jsfiddle.net/88Xa6/4/ As mentioned by #user3037143 initialization is handled at boot.js.
Ensure the library files are in place:
<script type='text/javascript' src="/libs/jasmine/2.0.0/jasmine.js"></script>
<script type='text/javascript' src="/libs/jasmine/2.0.0/jasmine-html.js"></script>
<link rel="stylesheet" type="text/css" href="/libs/jasmine/2.0.0/jasmine.css">
<!-- Add any custom reporters (Console / Junit / etc) here.
Ensure necessary initialization triggers are set in
boot when adding more reporters. -->
<script type='text/javascript' src="/libs/jasmine/2.0.0/boot.js"></script>
You can either choose to include the spec or have them defined inline:
<script src="spec.js"></script>
or
<script type='text/javascript'>
describe("My Suite", function() {
it("Should be true", function() {
expect(1).toBe(1);
});
});
</script>
We're having trouble getting some form of visual indication that a 'page' is loading in our Ember App.
Tried both a gif method and also Spin JS. Both fail as they are very laggy and only fully load when all the Ember objects have loaded. A similar problem to this question.
What methods are other people using in their public facing builds?
Edit: This is when the app is loading for the first time. The initial load is long enough to require some form of visual indication.
You could add an overlay to your document with an loading indicator. When you add it via CSS it is loaded before Ember is initialized. After ember is initialized you could remove the overlay.
Below an example how I might implement it:
HTML:
<html>
<head> ... load dependencies ... </head>
<body class="loading"> ... handlebars templates ... </body>
</html>
CSS:
body.loading:after {
content: '';
background: rgba(255,255,255,.3) url(images/loader.gif) 50% no-repeat;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 10;
}
Ember code:
App.ApplicationView = Ember.View.extend({
removeLoader: function() {
$('body').removeClass('loading');
}.on('didInsertElement')
});
This way before Ember is initialized an loading indicator is showed, but when Ember is done initializing the loader is removed.
You can use jQuery ajax callbacks for this:
$(document).ajaxStart(function(){ console.log("ajax started")})
$(document).ajaxStop(function(){ console.log("ajax stopped")})
This will work for all ajax requests.