Canada’s Best Managed Companies: Platinum Winners

0
58
.bmc18-nav,
.bmc18-nav–row,
.bmc18-nav–item {
display: block;
font-family: sans-serif;
line-height: 1em;
}
.bmc18-nav {
margin-bottom: 1em;
}
.bmc18-banner–main {
display: block;
width: 100%;
border-bottom: solid 0.25em #fff;
}
.bmc18-nav–item {
text-align: center;
padding: 0.5em;
font-weight: bold;
text-decoration: none;
background-color: #ec3b9a;
color: #fff;
border-bottom: solid 0.25em #fff;
transition-property: background-color;
transition-duration: 0.2s;
}
.bmc18-nav–item:hover {
background-color: #39b54a;
color: #fff;
}
@media screen and (min-width: 480px) {
.bmc18-nav {
display: table;
width: 100%;
table-layout: fixed;
}
.bmc18-banner–main {
/*border-bottom: solid 0.5em #fff;*/
}
.bmc18-nav–row {
display: table-row;
}
.bmc18-nav–item {
display: table-cell;
vertical-align: middle;
border: solid 0.5em #fff;
}
.bmc18-nav–row > .bmc18-nav–item:first-child {
border-left: 0;
}
.bmc18-nav–row > .bmc18-nav–item:last-child {
border-right: 0;
}
}

[style*=”–aspect-ratio”] > :first-child {
width: 100%;
}
[style*=”–aspect-ratio”] > img {
height: auto;
}
@supports (–custom:property) {
[style*=”–aspect-ratio”] {
position: relative;
}
[style*=”–aspect-ratio”]::before {
content: “”;
display: block;
padding-bottom: calc(100% / (var(–aspect-ratio)));
}
[style*=”–aspect-ratio”] > :first-child {
position: absolute;
top: 0;
left: 0;
height: 100%;
}
}

a.bmc18-actionlink {
display: block;
text-align: center;
padding: .8em;
font-size: 1.2em;
font-family: sans-serif;
color: #fff;
background-color: #EC3B9A;
font-weight: 700;
text-decoration: none;
border-radius: 4px;
transition-property: background-color;
transition-duration: .2s
}

a.bmc18-actionlink:active,
a.bmc18-actionlink:hover {
background-color: #39b54a
}


Even more of Canada’s Best Managed Companies »

// API calls for recent posts to the ‘best-managed-companies’ tag. Grabs five of the given posts at random. NOTE: Post IDs are hard-coded below in `eligiblePosts`
‘use strict’;
var bodyClass = document.getElementsByTagName(‘body’)[0].getAttribute(‘class’);
var container = document.querySelector(‘#dynamicPosts’);
// tag id for ‘best-managed-companies’
// var tagID = 351657;
var postCount = 5;
var exclude = parseInt(( bodyClass.indexOf(‘postid’) >= 0 ? isolateID(bodyClass)[1] : 0));
var eligiblePosts = [1079843,1079845,1079849,1079851,1079853,1079855,1079857,1079859,1079861,1079863,1079865,1079867,1079869,1079873,1079875,1079877,1079879,1079881,1079885,1079887,1079889,1079891,1079893,1079895,1079897,1079899,1079901,1079903,1079905,1079907,1079909,1079911,1079913,1079915,1079917,1079919,1079921,1079925,1079923,1079927,1079929,1079931,1079933,1079935];
var chosenPosts = arrayRandomSubset(eligiblePosts, postCount, exclude); // subset of eligiblePosts, see function below
var endpoint = ‘http://www.canadianbusiness.com/wp-json/wp/v2/posts?’;
endpoint += ‘include=’ + chosenPosts.join(‘,’);
endpoint += ‘&_embed’;

fetch ( endpoint )
.then(function(response){
return response.json();
})
.then( function(data){
postsRender(data);
})
.catch(function( err ){
console.log(err);
});

function postsRender(data){

data.forEach(function(post){
// Define Post Elements
// post container
var thePost = document.createElement(‘div’);
thePost.classList.add(‘row’);
thePost.classList.add(‘bmc18-latest-post’);
// visual holder
var theVisual = document.createElement(‘div’);
theVisual.classList.add(‘col-xs-12’);
theVisual.classList.add(‘col-md-4’);
// visual link
var theImgLink = document.createElement(‘a’);
theImgLink.setAttribute(‘href’, post.link);
theVisual.appendChild(theImgLink);
// text holder
var theText = document.createElement(‘div’);
theText.classList.add(‘col-xs-12’);
theText.classList.add(‘col-md-8’);
theVisual.setAttribute(‘href’, post.link);
// the image
var theImage = document.createElement(‘img’);
theImage.setAttribute(‘src’, post._embedded[‘wp:featuredmedia’][0].source_url);
theImage.setAttribute(‘alt’, post._embedded[‘wp:featuredmedia’][0].alt_text);
theImgLink.appendChild(theImage);
// the headline
var theHed = document.createElement(‘h1’);
theHed.innerHTML = ‘‘ + post.title.rendered + ‘‘;
theText.appendChild(theHed);
// the dek
var theDek = document.createElement(‘div’);
theDek.innerHTML = post.excerpt.rendered;
theText.appendChild(theDek);
// the spacer
var theDivider = document.createElement(‘hr’);
//tack it all together
thePost.appendChild(theVisual);
thePost.appendChild(theText);
container.appendChild(thePost);
container.appendChild(theDivider);
});
}

// return the wordpress postID from the body class
function isolateID( string ){
var pattern = /postid-(d+)?/;
return string.match(pattern);
}

/**
* From a given array, provide a subset
* @param arr — the array from which to read the values
* @param n — the number of results required
* @param excl — a value to exclude from the results
*/

function arrayRandomSubset(arr, n, excl){
let out = [];
// for the specified count, loop over the given array, select values randomly, and add them to the output array, but only if they aren’t already included.
// NOTE: we temporarily increase the length of the loop to output an array of length n + 1. This is so that if there is an `excl` value provided
for ( var i = 0; i < n + 1; i++ ){
// select a random position in the array
let r = parseInt( Math.random() * arr.length );
// if the value at position `r` isn’t already in the output, add it
if ( out.indexOf(arr[r]) < 0 ) {
out.push(arr[r]);
// if the value IS already in the output, decrement the loop to try again.
} else {
i–;
}
}
// if the excluded value is not in the output, just trim to `n` results
if ( out.indexOf(excl) < 0 ) {
return out.splice(0, n);
// if it IS in the output, remove it.
} else {
let e = out.splice(out.indexOf(excl), 1);
return out;
}
}

The post Canada’s Best Managed Companies: Platinum Winners appeared first on Canadian Business – Your Source For Business News.

LEAVE A REPLY

Please enter your comment!
Please enter your name here