Posts by bfavaretto • 64,705 points
902 posts
-
33
votes6
answers9431
viewsA: When should var be used in Javascript?
The var is key to distinguishing local variables from global variables. Without it, all variables will be global - worse, they will be global implicit, since the code does not make clear the scope.…
javascriptanswered bfavaretto 64,705 -
29
votes6
answers66760
viewsA: "foreach" in Javascript
First of all, PHP arrays are different from Javascript arrays An example of traditional matrix would be: var matriz = [1,2,3,4]; Whereas in PHP is an associative array, in Javascript is an object:…
-
22
votes2
answers609
viewsQ: Could current Javascript engines optimize "tail" recursive calls?
In functional programming, it is very common to use functions recursive. Certain languages, such as Scheme, do not even have control structures for loops, depending on recursion to iterate over…
-
8
votes2
answers638
viewsA: How to do an action after three dynamic elements are filled with jQuery/javascript?
You can check the event change of the three selects, starting with a check of the value of each one of them. So for example: $(document).on('change', '#cbExercicio, #cbEquipe, #cbResponsavel',…
-
22
votes2
answers454
viewsQ: Self-referential global object: what is it for and why does it exist?
The object window in browsers has a property window that is self-reference: window.window === window; // true And there are other similar properties in browsers: self === window; // true top ===…
javascriptasked bfavaretto 64,705 -
39
votes4
answers18382
viewsA: What is the difference between null and Undefined?
Semantic difference As already pointed out in the answers of Calebe Oliveira and of Alexandre Marcondes, there is a semantic difference between null and undefined: the value null is used to indicate…
-
26
votes4
answers7004
viewsA: Create a triangle with CSS
The trick to solving this is quite interesting. It is based on the fact that when two edges of an element meet, they form an angle of 45 degrees to each other. Imagine your square of 40px without…
-
4
votes3
answers269
viewsA: How to prevent a method from printing data when calling a third-party API?
Has a gambit to inhibit the impression of mistakes on own core PHP, which is to use error control operator @ before the command: $retorno = @$this->soapClient->testFunction($params);…
-
5
votes1
answer1241
viewsA: Copying record of table in itself via vba
Answer originally put by the questioner in the question itself It was just a syntax error, follow the correct code: sql = "INSERT INTO Produtos ( Produto, Preco )" _ & " SELECT '" &…
-
0
votes5
answers1562
viewsA: Optimize function to include classes also looking in sub-directories
There are several ways to solve this. Some are iterative, but this comes at a price in terms of performance. I would do something similar to what proposes o Calebe Oliveira, but without using the…
-
12
votes2
answers629
viewsQ: Why does jQuery fadein not work if the element has zero opacity?
I have an element with zero opacity defined via Javascript. In practice, this is equivalent to: <div style="opacity: 0"></div> My intention is to use jQuery to make an effect of fade-in…
-
4
votes1
answer109
viewsA: Incorrect form method generated by Cakephp 2.4
I’m not sure, but I believe Cakephp got confused when you passed 'method'=> 'POST' as an option. The standard parameter, according to documentation, is type, and not method (which is the name of…
-
11
votes5
answers14927
viewsA: How to not allow a character to be typed in the textbox, with Javascript/jQuery?
You probably tried to intercept the key at the event keyup. If you use the keydown, the comma does not appear. Example in jQuery: $('input').keydown(function(e) { if(e.which === 188 || e.which ===…
-
10
votes4
answers11030
viewsA: Edit directly via FTP with Sublime Text
This feature is not available on core Sublime Text, but it is possible with plugins. A Google search found two among the first results: Sublimetext2-Ftpsync Free but no SFTP support Sublime SFTP…
-
3
votes2
answers280
viewsA: Trigger an action when a hash is found in the URL
You can monitor the event hashchange: window.onhashchange = function() { alert(window.location.hash); }; Example in Jsfiddle Within the function you can check the hash and act accordingly. Details:…
-
11
votes2
answers1581
viewsA: Difference between method ". attr()" and ". date()"
The two methods are completely different .data() The .data() was created for the purpose of associating arbitrary data to a DOM element. In fact, this method is an interface to the $.data, that is…
-
9
votes3
answers14251
viewsA: Select elements containing a particular "date" attribute
You can use the following: div[data-my-target] This searches for elements that contain this attribute. It is also possible to filter the attribute by value. For example: div[data-my-target="John"]…
-
6
votes4
answers2589
viewsA: Is it possible to create an 'abstract class' in Javascript?
In Javascript there are no static classes, properties or methods. Closest to this are properties and methods assigned directly to a constructor (as you did), or a simple literal object. If you use a…
-
8
votes2
answers570
viewsA: Handle 1-pixel edge to avoid double edge (1+1 pixels) with side-by-side elements
With certain CSS3 rules it is possible to affect only some of the edges to achieve the desired result: /* apaga todas as bordas direitas e inferiores */ li a { border-right-color: transparent;…
-
8
votes2
answers1038
viewsA: How to use databases in Cakephp without complying with naming conventions?
You can force the table name in the model definition: class MeuModel extends AppModel { public $useTable = 'minha_tabela'; } Columns can have the name you want, and it is recommended that the table…
-
3
votes3
answers1076
viewsA: Is anchoring a TR possible?
If you wrap the <tr> in a <a>, your HTML will become invalid. I suggest you place the URL in an attribute data, and use a very similar code to Sergio’s to navigate to the destination.…
-
9
votes2
answers28027
viewsA: Is there any way to enable full screen browser with Javascript?
It is possible to enable full screen via Javascript at certain browsers. Even, you can place a single element in fullscreen (like a video), or the entire document. Example for the whole document…
javascriptanswered bfavaretto 64,705 -
8
votes6
answers1877
viewsA: Code refactoring to convert GPS coordinates into DMS format into an array
It seems to me a good case to apply a regular expression, which already validates and captures the importing part of the input, ignoring the separators. I thought of something along these lines (but…
-
18
votes1
answer409
viewsA: Why doesn’t Google Chrome allow you to copy a reference to the console.log function?
The problem is that the Chrome console wants log be called in the context of console - that is to say, with console as this -, but you’re calling the value-less function set to this. A quick…
-
0
votes3
answers837
viewsA: Disable Auto Redirect after logging into Cakephp 2.4
I’m not sure, but I think Cake’s behaving the way he’s supposed to - from his point of view. You can try to intercept access to the action in the controller itself and force a redirect. In the…
-
16
votes2
answers2406
viewsA: "margin-top" and "margin-bottom" overlapping, why?
When there are stacked blocks, the lower edge of the top block is combined with the upper margin of the bottom. The effective value is the highest margin, not the sum of the two. This is called…
-
7
votes1
answer114
viewsA: How to select partially distinct lines?
If either item will be selected for each name/reference, it is possible to achieve this result with SUBSTRING_INDEX: SELECT * FROM refs GROUP BY SUBSTRING_INDEX(reference, '/', 1)…
-
11
votes2
answers1662
viewsA: In HTML5, should null elements be closed with ">" or "/>"?
There is no need to include the slider at the end of the widget, although this is permitted in the case of null items, for the joy of XML fanatics: [About opening tags syntax] 6. Then, if the…
-
2
votes1
answer197
viewsA: How to remove a field already added to a 'Formdata'?
The FormData only has method append. However, in this scenario it would be better not to populate it in the onchange. If necessary, you can maintain an array with the objects File, and the array can…
-
3
votes1
answer58
viewsA: How to update the value of a column by substituting in all rows of the table?
It is possible to perform the operation in a simple way using the REPLACE , which is part of the Mysql text manipulation functions: UPDATE i18n SET constant = REPLACE(constant, 'LANG_', 'I18N_');…
-
2
votes2
answers210
viewsA: How to change a query so that it is executed for each row of table X?
I think the query can be simplified like this (or I misunderstood the context): INSERT INTO `cart_lines` ( `line_id` , `cart_id` , `book_id` , `book_reference` , `book_name` , `book_type` ,…
-
1
votes2
answers2405
viewsA: Paging inside modal window in bootstrap
Try the following Javascript/jQuery: $(document).on('click', '.pagination a', function(e){ e.preventDefault(); $.get(this.href, function(data) { $('table').replaceWith(data); }); });…
-
13
votes2
answers3908
viewsA: How can I get the first element of each parent element?
There are several ways to do this with jQuery. To select both spans from the example: Using the pseudo-class :first-child on the selector: var primeiros = $(".container .iconset:first-child"); Using…
-
7
votes4
answers1488
viewsA: How to close a dropdown if the user clicks another page location?
A variation of Talles response, without jQuery, to IE9+ and other modern browsers: document.addEventListener('mouseup', function(e) { var aEsconder = document.querySelector('[seu seletor]'); var…
-
20
votes3
answers3888
viewsA: Why is using global variables not good practice?
The main problem is name collisions. If you write a code that depends on a global variable qualquer, and later includes a script made by someone else who also uses a global of the same name, one…
-
6
votes3
answers1404
viewsA: How to compare HTML elements by real z-index?
Considering only elements that have z-indexes explicitly defined, it is possible to simplify a lot the algorithm of the CSS specification. Basically, when comparing two elements, it is necessary to…
-
42
votes7
answers3681
viewsA: What are the implications of not declaring variables in PHP?
Strictly speaking, there is no variable declaration in PHP. That is, there is no one in the language statement as var to declare variables. In practice, variables are initialized in the first use.…
-
10
votes3
answers90884
viewsA: Attribute "href" for Javascript links: "#" or "javascript:void(0)"?
Don’t use any of the options Why? First, the allocation of Event Handler should not be made inline. HTML is for marking and structuring content, all behavior should be separated, in Javascript…
-
3
votes1
answer517
viewsA: Is there a safe way to check the loading of frames in an HTML page?
My solution was to scroll through this "frame tree" by adding listeners to identify when each frame was loaded. This is the only solution, there is no magic or voodoo that checks at once if an…
-
3
votes6
answers5183
viewsA: How to reverse the position of a div(and its content and attributes) with another div?
This is a function that can reverse any sibling elements in the DOM, without using cloning: function inverterPosicoes(el1, el2) { el1 = $(el1); el2 = $(el2); var prev = el1.prev(); var parent =…
-
10
votes3
answers20561
viewsA: How to create functions in jQuery?
jQuery is only a library built with Javascript, and functions are a language feature, not jQuery. His two examples are valid ways of creating functions, and there are still other ways. While ways of…
-
3
votes3
answers946
viewsA: Run function for each class you find
You need a loop: $('.thumb img').each(function(){ var img = $(this); var proporcao = img.width() / img.height(); // Retrato if(proporcao > 1) { img.css({ maxWidth:'100%',…
-
12
votes2
answers603
viewsA: How to get the identity of an object in Javascript?
The specification ECMA-262 does not foresee this functionality in the language, and I have no knowledge of any Javascript engine that implements it. If you want to implement yourself, a starting…
javascriptanswered bfavaretto 64,705 -
2
votes1
answer191
viewsA: Simulate another environment by using the `Composer update`command
I would try to include this package explicitly by passing the desired version. It is quite possible that this has priority over the dependency chain that Composer is using. I believe that those who…
-
15
votes11
answers8299
viewsA: Should I write my program in English or Portuguese?
I think it depends on the project. If it’s an open source project, using only English is more appropriate, especially if the code is available on some global site like Github. If it’s a closed…
-
3
votes4
answers265
viewsA: How to set --no-ri --no-rdoc as default when using Gem install?
A more generic alternative to the jpkrohling solution is to define an alias in your terminal. In bash, for example, you can add the following in your file . bash_profile: alias gi="gem install…
-
3
votes4
answers512
viewsA: Debug applications in Nodejs
The Node has a Debugger, that you spin like this: node debug myscript.js
-
10
votes3
answers1559
viewsA: How to condition the insertion of a record in SQL Server?
You can use a MERGE (available from SQL Server 2008): MERGE DatasBase AS existentes USING (SELECT '2013-12-13', '2013-12-14') AS novos (DateBase, DataAtualizacao) ON (existentes.DateBase =…
-
1
votes4
answers1969
viewsA: How to save Ctrl+S to Vim?
In Vim you save like this (only need the ESC if you are not in command mode): ESC:wENTER
vimanswered bfavaretto 64,705 -
21
votes3
answers3264
viewsA: Invert the order of a jQuery widget list
In a row: [].reverse.call($('ul li')).appendTo('ul'); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul> <li>Item 1</li>…