lördag 30 januari 2016

Sluggo Beat XP - WIP - Sluggo North Star: The Home of Logotypes - Part 1

UPDATE (2016-02-09)
The Sluggo North Star is finished, and the codes below are changed. I'll rewrite this bloggpost and put the new codelines in.

---------- Old post -------------

Time to build the home of the logtype Sluggo North Star.

I thought I had the perfect solution, but when I started to work with the code it didn't work out.

The biggest challenge is to scale the logotype proportional when the #Header changes. I don't want the user to figure out were to change things or how much to make it look nice in all browsers - the function should do the heavy work.



My spec looks like this:

  1. The logotype must be scaleable without any input from the user. 
  2. The ability to choose Source- and Target-tags.
  3. There should be, at least, three basic horizontal alignment - right, left and center. 
  4. The ability to use padding. 
  5. Sluggo North Star must work independently and integrated with Sluggo Family 


Basic code:

HTML

<div id="Logotype">
<div id="Logotype_Container">
<img id="LogoImg" src="http://steffo.info/css/portfolio-logotype.png">
</div>
</div>

Script

function SluggoNorthStar()
{
var Logotype_H = $("#Logotype").height();
var Logotype_W = $("#Logotype").width();
var LogoUrlSrc = $("#LogoImg").attr("src");

var LoadingImg = new Image();
LoadingImg.onload = function() {
var LogotypeImg_H = this.height;
var LogotypeImg_W = this.width;
var Perc_H =  (Logotype_H-LogotypeImg_H)/LogotypeImg_H;
var Width_Diff = Perc_H*LogotypeImg_W;
var New_Width = LogotypeImg_W+Width_Diff;
$("#LogoImg").css("height",Logotype_H).css("width",New_Width);
}
LoadingImg.src = LogoUrlSrc;
}


The old solution nearly worked. The part that was missing was the ability to adjust the size exactly as I wanted (or as the user wants). I needed to rethink. It became a small journey into Math 101...

Walkthrough

var Logotype_H = $("#Logotype").height();

The first line picks up the height of the logotype container #Logotype. Why? Because the script need to wait until the image has loaded to have access to the width and height data. This has not happen yet.

The lack of non-loaded image, the .height(); will only generate a value of 0 (zero) and cannot be used in this case. The fundamental idea is that the logotype image scales when the user alters the height. I need a reference to start with if I want to change it..

var LoadingImg = new Image();

To get proper information from the image I need to get it loaded. new Image(); creates a new image to pull information from. More about this technique: TechRepublic: Preloading and the JavaScript Image() object.

LoadingImg.src = $("#LogoImg").attr("src");

This gets the source attribute from the image with id-tag LogoImg. The information that I want to use is the image height.

LoadingImg.onload = function() {

When the new image is loaded, it will run the function.

var LogotypeImg_H = this.height;
var LogotypeImg_W = this.width;

Two variables is created. They contains the width and height of the new image, that will the base unit when to get the difference between the first logotype in the HTML, <img id="LogoImg" src="http://steffo.info/css/portfolio-logotype.png">,but also be used when the new logotype will be build, based on #Logotype height.

var Perc_H =  (Logotype_H-LogotypeImg_H)/LogotypeImg_H;

Time to do some math. The variable generates the difference in height between the first logotype in HTML and #Logotype and returns the result in percent. Now we know how much the logotype must be scaled.

var Width_Diff = Perc_H*LogotypeImg_W;

The percentage is used to calculate the width difference in pixels.

var New_Width = LogotypeImg_W+Width_Diff;

The pixels is added to the logotype width to scale it proportionally.

$("#LogoImg").css("height",Logotype_H).css("width",New_Width);

The first logotype in HTML gets it new width and height.

Conclusion

It was somehow easy to get a basic setup. I think the heavy work is done, and relatively easy to add padding and positioning. 


söndag 24 januari 2016

Sluggo Beat XP - WIP - Adjust the Sluggo Plates

After my séjour with Sluggo Pins Mark II, I'm now back on track with Sluggo Beat.

I've nearly lost my track, so I started with an easy part - adjusting the textcolumns.


The Beat is sketchy in this part and the code is long-winded. I'll let it be, for now, because it works, and return to it later on and work it through. Maybe I'll find a pattern and make a function to get rid of some codelines. 

The Beat has ten basic wireframes/grids. Every grid have five parts - aka Sluggo Plates - one header, one footer, two main content plates and one aside plate. 

Every Plate is slightly different and will act a little bit on its own, but still have the feeling of being a part of the same family.

The Main Plates with responsive text columns.


I've put my effort on each Plate to deliver the best seamless user experience from zero pixel to infinity width. 

The challenge is to constantly check everything at every width. 

My goal with the textcolumns is to make the most pleasent reading experience at any screen size. The lines must have a comfortable width and should not be to long or to short. Sluggo Beat is intendend to be a smooth lean machine and every detail must be considered (or be taken away). 

Content is still King and every bump on that road must be even out. 

lördag 23 januari 2016

Sluggo Pins Mark II -The Launch!

I was ready to launch when the code started to crumble and fall apart. 

Something went wrong with the core code that listed the pins, and without a proper code I haven't got a solid product to use. 

I wrote and rewrote the code and finally got a new core and a lot of new insights. The code went even better and shorter than I hoped for. It fulfilled my expectations by far. 

Finally - the Sluggo Pins Mark II is released!

Download your copy at Codepen today:

lördag 16 januari 2016

Sluggo Pins Mark II - Pre-launch 2

Ehhh... No... Aaand... No...

The padding won't work. Nor the margins.

My calculations got too complicated.

And they didn't work properly.

Went out for a walk and suddenly I got it.

Tables...

Oh, man... Tables... Of course...

All the pins structured between columns and the space will also be definied in separat columns. The table can have various width and still have constant space between columns.

Feels like going back to basic and throw away all complicated-calcutated-spaces-did-not-work-anyway.

So simple...

Love it.

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
}
</style>
</head>
<body>

<table style="width:100%">
  <tr>
    <td>Pin Row 1</td>
    <td style="width:10px">Space</td>
    <td>Pin Row 2</td>
  </tr>
</table>
</body>
</html>

torsdag 14 januari 2016

Sluggo Pins Mark II - Pre-launch

The new Sluggo Pin-version is on its way. I'm tuning and tweaking the last lines to make it pixel-perfect and small-sized. Got rid of 45 lines of code when I fixed the problem with columns not lined up properly. 

Discovered the the columns lined up differently depending on where source and target tags are in the HTML. But not always - three-in-a-row lines up just perfectly...

I also put some if-statements through a JS-minifier and got rid of 40 more lines. Instead of:

if (Columns == "1R" ){
if (ColWidth > 0){Columns = 1;}}

...I got:

"1R"==Columns&&(ColWidth>0&&(Columns=1));

...And a new way to write code more efficient. 

It's just the final touch left and the last doublecheck before the launch. 

Sluggo Pins Mark II - WIP - Solve the padding problem between pins

Just when I thought I was done and ready for launch, I got a drawback - if all the pictures are equal in size the pins become different in height. I've never seen it before because I've used different sized pictures. 

So, why did it happen?


Padding problems

The major problem is that the columns have different kinds of padding. Left and right columns have only left or right padding, but the columns in the middle have left and right padding. This gives the  left and right columns some extra space and therefore makes them slightly smaller.


Why did I do that? 

Well, in Mark I there where padding around all sides of the columns. The problem comes when the user wants a wide padding. The left padding of the left column and right padding on the right column makes them not lined up with the other objects on the page.

My first attempt to fix this was to put padding on all pins but the first one. The padding turned out very well, but the far left column still needed some extra padding, and I couldn't put that padding anywhere - either the left margin gets to wide or there will be too much space between column 1 and 2.


Margins mayhem

So I tried to adjust the margins, but ended up with more mess than before. The big problem was that added margins pushes columns to the right. The last column won't fit so it is placed underneath the others, leaving a gap.

When I got rid of all padding and margins, everything looks fine and dandy. So I have to figure out what I can do to solve this problem besides margins and padding.

Constant columns

Sluggo Pins columns is based on constant numbers. 1/50 is 50% of the target div, 1/25 is 25% and so on.

To predefine the numbers is a great way to make all columns constant - until you want som space between. And the different kind of space, acts differently.


  • Padding will shrink the inner content, because the outline of the div is constant. 
  • Margins will push the divs to the side. 


My solution

My solution is to get rid of the constant numbers when I build the columns. The most important issue is that the spaces between the pins is equal to the input from the user. 

My thought is something like this:
(Target Width - (Padding value*(Columns-1)))/Columns = Columns Width

This will get:
  1. Space between columns that doesn't push the pins. The pins will shrink equally. 
  2. An accurate width of the columns. The width is based on the current target.
  3. No padding on the far left or far right side.  
Update
The right calculation is:
var WidthOut = (ColWidth-(PadIn*(Columns-1)))/Columns;

(ColWidth is the value from  $(Target).width();)

Right on spot...

onsdag 13 januari 2016

Sluggo Beat XP - WIP - Hotdish Navigation

The basic mobile version number 1 of Sluggo Hotdish is set. 

Went trough some minor issus about the logotype and the hamburger-icon. I wanted them horizontal AND vertical centered. 

My first idea was a function that calculated the height of the navigation-bar and the height of the logotype and hamburger-icon to give equal padding on all sides. 

The result turned our terrible - the logotype made a jump when it positioned after the page where loaded. For my defence I could only say that it was late at night...

The perfect solution just involve this easy CSS (Thank God!):

#Logotype
{
width:80%;
height:100%;
position: relative;
}

#Logotype img
{
position: absolute;
top: 50%; left: 50%;
transform: translate(-50%, -50%);
}

söndag 10 januari 2016

Sluggo Pins Mark II - WIP - Margins

Todays work has been tweeking, tweeking and tweeking the margins for the release of Sluggo Pins Mark II this week. 

More tweeking tomorrow...


Sluggo Beat XP - WIP - Navigation

Ahhh... Responsive navigation menu. My Nemesis. My shadow. My agony.  I've done dozens of them and they are different everytime. None of them works flawlessly. 

Navigation is The Great Blue of webdev - big, deep and endless. There is help to get - if you have the time and put som effort to it - but for me none of them fits like I wanted them to. 

Time to develop a real tesponsive navigation -  Sluggo Hotdish...



The Vision of Sluggo Hotdish
My vision for Sluggo Hotdish (besides the responsive part):

1. Easy to use
2. Easy to integrate
3. Easy to maintain

Easy to use
The easy to use issue is the most important part in every Sluggo product. I know by experince the power of easy to use. The user often wants a quick and solid solution and that's what Sluggo is all about. 

The markup must be easy to understand and the input from the user must be well documented and semantic. 

I work very hard to make smartness in the script and not force the user to understand what they should do with the snippets. 

Easy to integrate
My goal is the make it easy to Copy & Paste the codes. I prefer snippets that gives me an instant solution of my problem. 

I don't have time to read pages and complicated examples, when all I want is an easy integration. 

Sluggo Hotdish will be easy to use by itself and to be a part of the Sluggo Family. 

Easy to maintain
This on is mostly for for me. Sometimes things can be better and by that time I don't want to rewrite the whole code ( if it's not necessary). 

It's not only important to make a userfriendly product, it's also important to make you friend to yourself. 

You won't hate yourself when you want to update the code because you know that the code is well written and easy to follow.