Category: javascript

jQuery prevent uploading too large file in Frontend 0

jQuery prevent uploading too large file in Frontend

afterRender:       // Only works on HTML5       $('#file').on('change', function() {         $("#upload-package").prop("disabled",  false);         var sizeLimit = 90;         if (this.files && this.files.length && this.files[0].size > sizeLimit*1024*1024) {           notifier.error_x("File size exceeds limit...

Mousewheel prevent body scroll on modal 0

Mousewheel prevent body scroll on modal

Solution #1   // prevent background of modal from scrolling   // DOMMouseScroll for Firefox equivalent   $(document).on("mousewheel DOMMouseScroll", ".modal-backdrop, .modal-body", function(event) {     event.stopPropagation();     event.preventDefault();   });   // prevent background of...

Single beforeEach() in Jasmine 0

Single beforeEach() in Jasmine

  << @philipraath @olignyf a beforeAll or beforeEach that is not inside of any describe will be applied to all suites/specs, as appropriate, during the execution of the suite. >> https://github.com/jasmine/jasmine/issues/811

Upgrade Jasmine 1.3 to 2.4 0

Upgrade Jasmine 1.3 to 2.4

Quick upgrade with those Regexp replaces /createSpyObj/ => " jasmine.createSpyObj" /createSpy/ => "jasmine.createSpy" /\.andCallFake/ => ".and.callFake" /\.andReturn/ => ".and.returnValue" /\.andCallThrough/ => ".and.callThrough" /toNotMatch/ => "not.toMatch" /this.addMatchers/ => "jasmine.addMatchers" /\.calls\[0\]\./ => ".calls.first()" /\.calls\[(\d)\]\./ => ".calls.all()[$1]"...

String manipulations in Javascripts 0

String manipulations in Javascripts

String.indexOf() Return value: -1 if not found 0 or higher than 0 as the index of the position found Remove one part of a string Method 1: String.replace(//, ""); Method 2: var indexEnd =...

Submit a form with ajax 0

Submit a form with ajax

This is a basic operation that you might have to do when upgrading an old web app. One solution is using jQuery .serialize() function   Method #1: Sent using CGI params key=value pairs: var...

Javascript hostname and ip validate 0

Javascript hostname and ip validate

Validating hostname and IP occurs pretty often. This is what I use for a field that can contain both IPV4 or hostname : if (value.length === 0 || value.length > 511) { return "Address...

Supporting IE 8 0

Supporting IE 8

Why would anyone care about IE8 ? Well sometime we have to if our clients is still on it, and yes in 2015, there are groups in the federal business that still only use...