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 from collapsing (Bootstrap override) */
.navbar-nav>li, .navbar-nav {
    float: left !important;
}

.navbar-right {
    float: right !important;
}

See a real example:

Unhide automatically one topic per week in Moodle

automatic-unhide-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 hide every week after that one.

:not(.editing) .weeks>li.current ~ li {
    display: none;
}

.editing .weeks>li.current ~ li {
    display: inline;
}

It’s working since Moodle 2.7.1 up to 2.9.1+.

See a real example:

Furthermore, if you want to have different students in different weeks in the same course (e.g. John in the second week and Jennifer in the last one) you can use “Self enrolment” to make courses start depending on when the students want to start the course and “Cohort” to avoid “Self enrolment” access to some courses.

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 DOM.
// It's trying to get [HTMLInputElement].data-gns

See a real example:

Upload a file with jQuery without opening a new page

ajax-with-jquery

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"));
        });
        e.preventDefault(); // Avoid launch new page
    });

Here if you want you can download my AJAX logo and use it for free: AJAX logo