Showing posts with label CSS. Show all posts
Showing posts with label CSS. Show all posts

Sunday, 4 October 2015

Mid-semester break: style updates and more angular

I used the break to work on CSS/SASS and spend time with trove and the Wayback Time-machine.

Styles

  • fixed some style inconsistencies with p and h styles
  • fixed the logotype: h1 size ration (logotype in now larger)
  • looked at the design of the page and changed from the 'indigo' colour palette to 'blackboard green' to match the infographic
  • crop the category image using CSS


CSS Crop


Page design



Trove/Wayback machine

My next task for the break was sourcing material for our site.  We had already decided on the four categories (sport, arts, education, government) and my task was to find approx 3 websites per category and source appropriate illustrative images from Trove, and web historical content from the Wayback Time-machine.  I search a combination of Pandora and Wayback Time-machine to find good examples of sites for each categories.  I concentrated on local sites (Brisbane, Queensland, Australia).

Once I had selected the sites and made a list of the Wayback Machine addresses, I then went to Trove to find good search queries for each site.  Some were definitely easier than others.  I had AFL listed as one of the sport categories but was unable to find any images that were copyright free/retrievable with the Trove API.  I then proceeded to make the API calls, found the work IDs I needed, checked the calls work, and added the image URLs to an array to access for home.html.  

Problems and solutions

I used Plnkr to test adding real images to angular using a hard-coded array.  I then applied that to our real code but changed the hard coded array to the dynamic one constructed using API calls to Trove.

The complicated part of using this array is the combination of Angular and Trove loading times.  The angular repeat happens much quicker than the Trove API calls.  Given that a lot of the information about the website (the link, website name, alt text, etc) the order of the images in the image array is important. The first step was then to direct each API call to a specific place in the array that corresponded to the data in the angular file.  

e.g. imageArraySport[1]=olympicsImg;

Where imageArraySport is the array to store the images for the sports tab and olympicsImg is the variable storing the image for the Sydney Olympics website.

The next problem I had adding the images to the html generated by Angular.  I wrote a jQuery function that worked in plnkr that targeted a class and added the image source link from the links in the array.  This worked fine but wouldn't work when I used the real API calls instead of the hardcoded array.  I realised this was because the API calls came back at different times and when the function iterated over the array, it was not always full and returned a src link of nothing.

To counteract this, I ran the function in each AJAX API calland added an if statement to check if the array had the number of images.

e.g. if(imageArraySport.length == 3)

Where the sport category has 3 websites and the if statement checks this first before running the rest of the function.

Thursday, 17 September 2015

Week 8: SASS how-to

Initial set-up

  1. Download the source files from Bootstrap 
  2. Unzip them into the folder where you will be using them (in our case, I have set-up a 'SASS' folder in our git repo)
  3. Follow the instructions on tooling set-up on Bootstrap (repeated below)
    1. Download and install Node.js
    2. Using the command line (Terminal, iTerm, Powershell, what-have-you), install Grunt with npm install -g grunt-cli
    3. After a quick refresher in command line, navigate to the Bootstrap folder that you unzipped (for us: 'SASS' as above).  OK, so now you're using the command line and you're in the Bootstrap folder.  If you type ls it should look similar to this:

    4. Install the local dependencies listed in package.json by running npm install
    5. Next up is Ruby.  If you are on a mac, you should have it already installed but can check by typing ruby -v into the command line.  If you need to download or update there is info here and here.  But, if you need to install on Windows, we ran into a few problems and used this tutorial from Forward HQ to sort it out.
    6. Almost there! Two-parter for Bundler: 1) install in the command line by running gem install bundler and then 2) run bundle (for all the Ruby dependencies you will need).
  4. Last step, install SCSS Lint by running gem install scss_lint
Phew, you still with me?  You may (or hopefully not) have any errors.  You may need to prefix the command line with sudo (I know, I know, lots of people say you shouldn't), or might get other random errors (google is your friend), but hopefully you have the things installed.  Now for the fun part :)

Using SASS

In your Bootstrap folder (for our team 'SASS') is a folder called 'scss' which is filled with many, many .scss files.  Being Bootstrap, it is all fairly logically named so it shouldn't be too hard to find any CSS you need to change.  '_variables.scss' has all the colours and typography (amongst other things), etc, etc. Have a look at the SASS documentation for how to use variables, nesting, other syntaxy-things.

Once you've changed the things you need to, how do you get it to be a CSS (and JS) file to use on the website?  Back to the command line!

To compile the CSS/JS files:
  1. Using command line, navigate to the bootstrap folder we were working in before.  You may still be there :)  (I'm a broken record but "For our team it is the 'SASS' folder")
  2. run grunt dist and fingers crossed, 0 errors!
For our purposes, that's about it but there is more info on grunt commands in the Bootstrap documentation.

Notes for team

  • No need to copy/paste files or folders, the CSS and JS import links are now up to date!
  • Remember: sync git, make changes, sync git
  • The Bootstrap 4 documentation has lots of great info, start with Layout, Content, Components
  • Bootstrap also has a slack channel - a great place to go for help!


Sunday, 6 September 2015

Week 7: HTML imports and setting up CSS

Part of my tasks for this week included looking into web components or HTML imports for our header and starting on our CSS styles.

Header

The idea behind using web component or HTML import for our header was to reduce the amount of code we needed to write and maintain across the site.  Instead of creating the header on one page, copying it to other pages, and then editing every page when there was an update, I decided to look into alternatives.  I had a look at web components (I have used polymer in the past) but also something a bit simpler with HTML imports.

Requirements

  • header and nav consistent across every page
  • 'active' class needs to be applied to nav of current page
  • need a log in/log out view
As most of content is static for this section, I decided to go with HTML imports as I didn't need to create a template for content reuse.  I had a look at the following tutorials: treehouse, html5rocks, sitepoint, webcomponents.org.

Step 1: Create the header 

Create a separate HTML file for the header.  No need for head or body tags, just the parts that relate to the header.  I'll go into more detail about what I put into the header when I talk about styles. I saved this as header.html


Step 2: Import HTML

Import the HTML file into the head of your index page (or page you will use it on)


Step 3: Use the HTML import on your page

This step is quite varied depending on what you want to do and how.  I did this by creating a header section in the body, and then using javascript to target the header and insert header.html. I also added in a line of jQuery to target a particular child in the nav to add the active class.

I haven't added in any script for the login yet but feel it will be easy enough to do once it is ready.

The other thing to note is the HTML imports need to run on a local server when testing (you can't just open the HTML file in your browser).  I found some really good instructions at superuser (see answer by Jake Gould) and installed MAMP.

Styles

Last week at our team meeting, we briefly discussed styles and using material design as a template. I think it is a good idea but am not overly attached if we go in another direction.

I found a version of material design theme for bootstrap which I thought would be good for our project and went down the rabbit hole of installing things.

Material Design for bootstrap http://fezvrasta.github.io/bootstrap-material-design/#getting-started
and demo http://fezvrasta.github.io/bootstrap-material-design/bootstrap-elements.html

I used bower but also had to install Node.js and npm (good overview here), XCode.  I then installed bootstrap and finally material design for bootstrap (and their snackbar).

I'm looking to using SASS for our CSS variables and also installed Compass but haven't got any further on that yet.

I used the material design nav styles straight out of the box.  I'm sure we will change colours and other elements but for the moment the structure is there.