quickly.js demonstration
Demonstrates how quickly.js works.
HTML
<p id="get">Retrieving data...</p>
<p id="ajax">Retrieving data...</p>
<button id="conceal">Conceal Data</button>
<button id="display">Display Data</button>
CSS
body {
font-family: Helvetica;
}
#get {
-webkit-transition: opacity 1s;
transition: opacity 1s;
opacity: 1;
}
JavaScript
// quickly.js
/* Copyright Techurify 2016. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var _ = {
get: function(url, callback) {
return _.ajax(url, "GET", null, callback);
},
ajax: function(url, method, data, callback) {
callback = callback || function () {};
try {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
callback(this.responseText);
}
};
xmlhttp.open(method, url, true);
xmlhttp.send(data);
} catch (err) {
callback(null, err);
}
}, dom: {
createElement: function (tagname, attributes, children) {
var element = document.createElement(tagname);
attributes = attributes || {};
Object.keys(attributes).forEach(function(key) {
element.setAttribute(key, attributes[key]);
});
var innerHTML = "";
for (var i = 0; i < children.length; i++) {
if (typeof children[i] === "string") {
innerHTML += children[i];
} else if (children[i] instanceof Element) {
innerHTML += children[i].outerHTML;
}
}
element.innerHTML = innerHTML;
return element;
},
}
};
Element.prototype.conceal = function(ms) {
ms = ms || 0;
this.style.opacity = 0;
var thisStyle = this.style;
setTimeout(function() {
thisStyle.display = "none";
}, ms);
};
Element.prototype.display = function() {
this.style.display = "";
this.style.opacity = 1;
};
// Testing code
_.ajax("/echo/json", "GET",...