Entries by Génesis

Avoid switch statement when you don’t need logic

Arrays are faster when you don’t need logic, you can also use an string but it’s a little more triky. // JS var array = [“Enero”, “Febrero”, “Marzo”, “Abril”, “Mayo”, “Junio”, “Julio”, “Agosto”, “Septiembre”, “Octubre”, “Noviembre”, “Diciembre”]; $(“div”).text(months_array.indexOf(“Febrero”) + 1); See a real example:

Avoid Navbar in Bootstrap from collapsing

Create a simple Bootstrap Navbar without collapsing in cell phones and tablet devices. <!– Simple Bootstrap Navbar without collapsing –> <header class=”navbar navbar-default container-fluid”> <ul class=”nav navbar-nav navbar-left”> <li><a class=”navbar-brand”>My App</a></li> <li><a>Tasks</a></li> </ul> <ul class=”nav navbar-nav navbar-right”> <li><a>12/12/99</a></li> <li><a href=”#”>@</a></li> </ul> </header> You just need to add this code to your style.css /* Avoid Navbar […]

Unhide automatically one topic per week in Moodle

We can hide and unhide manually topics in Moodle but we cannot do it automatically, maybe it will be developed in next versions but till then you can do it by yourself easily. Using Weekly format with Bootstrap default theme you can get “Current Week Class” (current), so the only thing you have to do it’s just […]

Which is the different between property and attribute?

A property is in the DOM; an attribute is in the HTML that is parsed into the DOM. HTML Attributes Syntax: <body onload=”foo()”> DOM Properties Syntax: document.body.onload = foo; Using jQuery If we have: <!– HTML –> <input class-gns=”brand”> // jQuery $(“input”).attr(“data-gns”); // return “brand” $(“input”).prop(“data-gns”); // return “undefined” because it is not in the […]

Upload a file with jQuery without opening a new page

In this example we are going to upload a file to our url using AJAX with jQuery. // We need to select the file in our form before pressing submit $(“#form-import”) .submit(function(e) { $.ajax({ url: “/upload/file.txt”, type: “POST”, data: new FormData(this), processData: false, contentType: false }).done(function() { dialogmessage.show($._(“File uploaded”)); }).fail(function() { dialogmessage.show($._(“Fail uplading the file”)); }); […]