utorok 22. septembra 2015

Creating a drag application using HTML, CSS and JavaScript

  Hello, I'm here again, and today I will create a application with dragging application using HTML5, CSS3 and JavaScript.
  First, you will need create a folder and name it as you want to, for example Drag.
  Than you need to download this picture below and name it bin.jpg
Than you need to create three files named: index.html
                                                                     demo.js
                                                                     demo.css

Open demo.js in your text editor and type or copy this code:


var addEvent = (function () {
  if (document.addEventListener) {
    return function (el, type, fn) {
      if (el && el.nodeName || el === window) {
        el.addEventListener(type, fn, false);
      } else if (el && el.length) {
        for (var i = 0; i < el.length; i++) {
          addEvent(el[i], type, fn);
        }
      }
    };
  } else {
    return function (el, type, fn) {
      if (el && el.nodeName || el === window) {
        el.attachEvent('on' + type, function () { return fn.call(el, window.event); });
      } else if (el && el.length) {
        for (var i = 0; i < el.length; i++) {
          addEvent(el[i], type, fn);
        }
      }
    };
  }
})();

(function () {

var pre = document.createElement('pre');
pre.id = "view-source"

// private scope to avoid conflicts with demos
addEvent(window, 'click', function (event) {
  if (event.target.hash == '#view-source') {
    // event.preventDefault();
    if (!document.getElementById('view-source')) {
      // pre.innerHTML = ('<!DOCTYPE html>\n<html>\n' + document.documentElement.innerHTML + '\n</html>').replace(/[<>]/g, function (m) { return {'<':'&lt;','>':'&gt;'}[m]});
      var xhr = new XMLHttpRequest();

      // original source - rather than rendered source
      xhr.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
          pre.innerHTML = this.responseText.replace(/[<>]/g, function (m) { return {'<':'&lt;','>':'&gt;'}[m]});
          prettyPrint();
        }
      };

      document.body.appendChild(pre);
      // really need to be sync? - I like to think so
      xhr.open("GET", window.location, true);
      xhr.send();
    }
    document.body.className = 'view-source';
    
    var sourceTimer = setInterval(function () {
      if (window.location.hash != '#view-source') {
        clearInterval(sourceTimer);
        document.body.className = '';
      }
    }, 200);
  }
});
  
})();



Than, open your demo.css file and type or copy this code:

body { 
  font: normal 16px/20px "Helvetica Neue", Helvetica, sans-serif;
  background: rgb(237, 237, 236);
  margin: 0;
  margin-top: 40px;
  padding: 0;
}

section, header, footer {
  display: block;
}

#wrapper {
  width: 600px;
  margin: -41px auto;
  background: #fff url(shade.jpg) repeat-x center bottom;
  -moz-border-radius: 10px;
  -webkit-border-radius: 10px;
  border-radius: 10px;
  border-top: 1px solid #fff;
  padding-bottom: 76px;
}

h1 {
  padding-top: 10px;
}

h2 {
  font-size: 100%;
  font-style: italic;
}

header,
article > *,
footer > * {
  margin: 20px;
}

footer > * {
  margin: 20px;
  color: #999;
}

#status {
  padding: 5px;
  color: #fff;
  background: #ccc;
}

#status.fail {
  background: #c00;
}

#status.success {
  background: #0c0;
}

#status.offline {
  background: #c00;
}

#status.online {
  background: #0c0;
}

/*footer #built:hover:after {
  content: '...quickly';
}
*/
[contenteditable]:hover:not(:focus) {
  outline: 1px dotted #ccc;
}

abbr {
  border-bottom: 0;
}

abbr[title] {
  border-bottom: 1px dotted #ccc;
}

li {
  margin-bottom: 10px;
}

#promo {
  font-size: 90%;
  background: #333 url(../images/learn-js.jpg) no-repeat left center;
  display: block;
  color: #efefef;
  text-decoration: none;
  cursor: pointer;
  padding: 0px 20px 0px 260px;
  border: 5px solid #006;
  height: 160px;
}

#promo:hover {
  border-color: #00f;
}

#ih5 {
  font-size: 90%;
  background: #442C0D url(../images/ih5.jpg) no-repeat left center;
  display: block;
  color: #F7FCE4;
  text-decoration: none;
  cursor: pointer;
  padding: 1px 20px 1px 260px;
  border: 5px solid #904200;
}

#ih5:hover {
  border-color: #CF6D3B;
}

#ffad section {
  padding: 20px;
}

#ffad p {
  margin: 10px 10px 10px 100px;
}

#ffad img {
  border: 0;
  float: left;
  display: block;
  margin: 14px 14px 0;
}

#ffad .definition {
  font-style: italic;
  font-family: Georgia,Palatino,Palatino Linotype,Times,Times New Roman,serif;
}

#ffad .url {
  text-decoration: underline;
}

button, input {
  font-size: 16px;
  padding: 3px;
  margin-left: 5px;  
}

#view-source {
  display: none;
}

body.view-source {
  margin: 0;
  background: #fff;
  padding: 20px;
}

body.view-source > * {
  display: none;
}

body.view-source #view-source {
  display: block !important;
  margin: 0;
}

#demos {
  width: 560px;
  border-collapse: collapse;
}

#demos .demo {
  padding: 5px;
}

#demos a {
  color: #00b;
  text-decoration: none;
  font-size: 14px;
}

#demos a:hover {
  text-decoration: underline;
}

#demos tbody tr {
  border-top: 1px solid #DCDCDC;
}


#demos .demo p {
  margin-top: 0;
  margin-bottom: 5px;
}

#demos .support {
  width: 126px;
}

.support span {
  cursor: pointer;
  overflow: hidden;
  float: left;
  display: block;
  height: 16px;
  width: 16px;
  text-indent: -9999px;
  background-image: url(../images/browsers.gif);
  background-repeat: none;
  margin-right: 5px;
}

.support span.selected {
  outline: 1px dashed #75784C;
}

.support span.safari {
  background-position: 0 0;
}

.support span.chrome {
  background-position: 16px 0;
}

.support span.firefox {
  background-position: 32px 0;
}

.support span.ie {
  background-position: 48px 0;
}

.support span.opera {
  background-position: 64px 0;
}

.support span.nightly {
  opacity: 0.5;
  filter:alpha(opacity=50);
}

.support span.none {
  opacity: 0.1;
  filter:alpha(opacity=10);
}

#demos .tags {
  width: 140px;
}

.tags span {
  font-size: 11px;
  color: #6E724E;
  padding: 2px 5px;
  border: 1px solid #D7D999;
  background: #FFFFC6;
  -moz-border-radius: 10px;
  -webkit-border-radius: 10px;
  border-radius: 10px;
  cursor: pointer;
}

.tags span:hover,
.tags span.selected {
  border: 1px solid #75784C;
  background: #FF7;  
  color: #333521;
}

#tags span {
  margin-right: 2px;
}

#tags {
  font-size: 14px;
}

#html5badge {
/*  display: none;*/
  margin-left: -30px;
  border: 0;
}

#html5badge img {
  border: 0;
}

.support span.yourbrowser {
  width: 16px;
  height: 16px;
  background: none;
}

.support span.yourbrowser.supported {
  background: url(../images/yourbrowser.gif) no-repeat top left;
}

.support span.yourbrowser.not-supported {
  background: url(../images/yourbrowser.gif) no-repeat top right;
}

#carbonads-container {
  position: fixed;
  margin-left: 620px;
  margin-top: -2px;
}

/** Pretty printing styles. Used with prettify.js. */
pre { font-size: 14px; }
.str { color: #080; }
.kwd { color: #008; }
.com { color: #800; }
.typ { color: #606; }
.lit { color: #066; }
.pun { color: #660; }
.pln { color: #000; }
.tag { color: #008; }
.atn { color: #606; }
.atv { color: #080; }
.dec { color: #606; }

Now you ask why we need to do CSS3 and JavaScript files at first. It is because we will connect it in the HTML5 code. So, now we will open index.html and type or copy this code to this file:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=620">
<title>HTML5 Drag and drop</title>
<link rel="stylesheet" href="demo.css">
<script src="demo.js"></script></head>
<body>
<section id="wrapper">
    <header>
      <h1 align="center"> HTML5 Drag and drop</h1>
    </header>

<style type="text/css">
h1{
color:green;
}
li {
  list-style: none;
}

li a {
  text-decoration: none;
  color: #000;
  margin: 10px;
  width: 150px;
  background: #2ABD48;
  padding: 10px;
  display: block;
}

*[draggable=true] {
  -moz-user-select:none;
  -khtml-user-drag: element;
  cursor: move;
}

*:-khtml-drag {
  background-color: rgba(238,238,238, 0.5);
}

li a:hover:after {
  content: ' (Drag Me)';
}

ul {
  margin-left: 328px;
  min-height: 300px;
}

li.over {
  border-color: #333;
  background: #ccc;
}

#bin {
  background: url(bin.jpg) top right no-repeat;
  height: 250px;
  width: 245px;
  float: left;
  position: relative;
  margin-top: 0;
}

#bin.over {
  background: url(bin.jpg) top left no-repeat;
}

#bin p {
  font-weight: bold;
  text-align: center;
  position: absolute;
  bottom: 20px;
  width: 245px;
  font-size: 32px;
  color: #fff;
  text-shadow: #000 2px 2px 2px;
}
</style>
<article>
 <p align="center">Drag list of items on dust bin</p>
  <div id="bin"></div>
  <ul>
    <li><a id="one" href="#"><span style="display: inline-block">Music</span></a></li>
    <li><a href="#" id="two">Docs</a></li>
    <li><a href="#" id="three">Videos</a></li>
    <li><a href="#" id="four">Images</a></li>
    <li><a href="#" id="five">Others</a></li>
  </ul>
  <ol>
</article>
  <script>

 // var eat = ['yum!', 'Wow', 'LOL', 'yeh!'];
  var yum = document.createElement('p');
  var msie = /*@cc_on!@*/0;
  yum.style.opacity = 1;

  var links = document.querySelectorAll('li > a'), el = null;
  for (var i = 0; i < links.length; i++) {
    el = links[i];
  
    el.setAttribute('draggable', 'true');
  
    addEvent(el, 'dragstart', function (e) {
      e.dataTransfer.effectAllowed = 'copy'; // only dropEffect='copy' will be dropable
      e.dataTransfer.setData('Text', this.id); // required otherwise doesn't work
    });
  }

  var bin = document.querySelector('#bin');

  addEvent(bin, 'dragover', function (e) {
    if (e.preventDefault) e.preventDefault(); // allows us to drop
    this.className = 'over';
    e.dataTransfer.dropEffect = 'copy';
    return false;
  });

  // to get IE to work
  addEvent(bin, 'dragenter', function (e) {
    this.className = 'over';
    return false;
  });

  addEvent(bin, 'dragleave', function () {
    this.className = '';
  });

  addEvent(bin, 'drop', function (e) {
    if (e.stopPropagation) e.stopPropagation(); // stops the browser from redirecting...why???

    var el = document.getElementById(e.dataTransfer.getData('Text'));
    
    el.parentNode.removeChild(el);

    // stupid nom text + fade effect
    bin.className = '';
    yum.innerHTML = eat[parseInt(Math.random() * eat.length)];

    var y = yum.cloneNode(true);
    bin.appendChild(y);

    setTimeout(function () {
      var t = setInterval(function () {
        if (y.style.opacity <= 0) {
          if (msie) { // don't bother with the animation
            y.style.display = 'none';
          }
          clearInterval(t); 
        } else {
          y.style.opacity -= 0.1;
        }
      }, 50);
    }, 250);

    return false;
  });

  </script>
</section>
</body>
</html>

Drag all file into your folder your created before (if you haven't dragged before). Now open this folder and open your index.html file. You don't need to open your CSS3 and JavaScript files since they are connected to your HTML5 file. If every thing is correct, the application would work like this:

So, we are finished and I hope you enjoyed it, goodbye.

utorok 15. septembra 2015

Bootstrap Form Control States

  Hello, and this blog we will talk about Bootstrap Form Control States.
What is Bootstrap
  For those which don't know what Bootstrap is, Bootstrap is a free and open-source collection of tools for creating websites and web applications. It is written in HTML, CSS, LESS, Sassand and JavaScript.
What will you need
  When starting your Bootstrap program, don't forget to be connected to internet, because the program won't work properly. Also you need to know at least a bit from HTML, CSS, LESS, Sassand and JavaScript.

What we will do
Today we will do two types of Bootstrap Form Control States. 1st will be looking like this:
and second one will look like this:
Coding:
  Do not forget to save your program with extension .html, since Bootstrap does not have it's own extension.
  Don't expect having max. 20 lines of code. Bootstrap codes have at minimum 30. If you don't believe me, I had on one code for Bootstrap 101 lines.
  
  The code for the first one looks like this:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Horizontal form: control states</h2>
  <form class="form-horizontal" role="form">
    <div class="form-group">
      <label class="col-sm-2 control-label">Focused</label>
      <div class="col-sm-10">
        <input class="form-control" id="focusedInput" type="text" value="Click to focus...">
      </div>
    </div>
    <div class="form-group">
      <label for="inputPassword" class="col-sm-2 control-label">Disabled</label>
      <div class="col-sm-10">
        <input class="form-control" id="disabledInput" type="text" placeholder="Disabled input here..." disabled>
      </div>
    </div>
    <fieldset disabled>
      <div class="form-group">
        <label for="disabledTextInput" class="col-sm-2 control-label">Disabled input and select list (Fieldset disabled)</label>
        <div class="col-sm-10">
          <input type="text" id="disabledTextInput" class="form-control" placeholder="Disabled input">
        </div>
      </div>
      <div class="form-group">
        <label for="disabledSelect" class="col-sm-2 control-label"></label>
        <div class="col-sm-10">
          <select id="disabledSelect" class="form-control">
            <option>Disabled select</option>
          </select>
        </div>
      </div>
    </fieldset>
    <div class="form-group has-success has-feedback">
      <label class="col-sm-2 control-label" for="inputSuccess">Input with success and glyphicon</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="inputSuccess">
        <span class="glyphicon glyphicon-ok form-control-feedback"></span>
      </div>
    </div>
    <div class="form-group has-warning has-feedback">
      <label class="col-sm-2 control-label" for="inputWarning">Input with warning and glyphicon</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="inputWarning">
        <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
      </div>
    </div>
    <div class="form-group has-error has-feedback">
      <label class="col-sm-2 control-label" for="inputError">Input with error and glyphicon</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="inputError">
        <span class="glyphicon glyphicon-remove form-control-feedback"></span>
      </div>
    </div>
  </form>
</div>

</body>
</html>




The code for the second program looks like this:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Inline form: control states</h2>
  <form class="form-inline" role="form">
    <div class="form-group">
      <label for="focusedInput">Focused</label>
      <input class="form-control" id="focusedInput" type="text">
    </div>
    <div class="form-group">
      <label for="inputPassword">Disabled</label>
      <input class="form-control" id="disabledInput" type="text" disabled>
    </div>
    <div class="form-group has-success has-feedback">
      <label for="inputSuccess2">Input with success</label>
      <input type="text" class="form-control" id="inputSuccess2">
      <span class="glyphicon glyphicon-ok form-control-feedback"></span>
    </div>
    <div class="form-group has-warning has-feedback">
      <label for="inputWarning2">Input with warning</label>
      <input type="text" class="form-control" id="inputWarning2">
      <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
    </div>
    <div class="form-group has-error has-feedback">
      <label for="inputError2">Input with error</label>
      <input type="text" class="form-control" id="inputError2">
      <span class="glyphicon glyphicon-remove form-control-feedback"></span>
    </div>
  </form>
</div>

</body>
</html>



nedeľa 6. septembra 2015

HTML5 Site Codes Position

    Hello everybody, it was a long time I haven't upload anything. Everybody who wants to code in HTML, probably wondered where to put CSS3, HTML5 and JavaScript codes. Here in this tutorial, I will show you this:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Something</title>
    CSS3 code
    (JavaScript code in some cases)
  </head>
  <body>
    HTML5 code
    JavaScript code
    (HTML5 code)
  </body>
</html>

    The reason I put the second HTML5 code in () is because is not necessary. In some cases JavaScript code and HTML5 code can be switched, but those are different cases.
    For today it is enough, good bye.