lang
stringclasses
4 values
desc
stringlengths
2
8.98k
code
stringlengths
7
36.2k
title
stringlengths
12
162
JS
I have a multiline plot in bokeh and I 'd like to select some multilines using the lasso tool.This does not work by default : The lasso tool does not select any lines.Of course , the question is how a line should be considered as selected : Is it selected if one point of the line is in the lasso area or if all points a...
from bokeh.io import output_file , showfrom bokeh.plotting import figurefrom bokeh.models import MultiLineplot = figure ( plot_width=400 , plot_height=400 , tools= '' lasso_select '' ) renderer = plot.multi_line ( [ [ 1 , 2 , 3 , 4 , 5 ] , [ 0,1 ] ] , [ [ 2 , 5 , 8 , 2 , 7 ] , [ 1,0 ] ] ) selected_circle = MultiLine ( ...
Select Multilines using Lasso Tool
JS
I 've got a situation where a div is being hidden even though I just executed code that shows all other divs with the same suffix : $ ( `` [ id $ ='-input-container ' ] '' ) .show ( ) Regardless of this , one particular div remains hidden : $ ( `` # single-colorRange-color-input-container '' ) . I thought maybe it was ...
console.log ( $ ( `` # single-colorRange-color-input-container '' ) .css ( 'display ' ) ) ; $ inputContainers.show ( ) ; console.log ( $ ( `` # single-colorRange-color-input-container '' ) .css ( 'display ' ) ) ; console.log ( $ ( `` # single-colorRange-color-input-container '' ) [ 0 ] .hidden ) ; console.log ( $ ( `` ...
How can .css ( 'display ' ) be block , [ 0 ] .hidden be false , and .is ( ' : hidden ' ) be true ?
JS
This is my string . It contains some HTML : First sentence . Here is a < a href= '' http : //google.com '' > Google < /a > link in the second sentence ! The third sentence might contain an image like this < img src= '' http : //link.to.image.com/hello.png '' / > and ends with ! ? The last sentence looks like < b > this...
[ 0 ] = First sentence . [ 1 ] = Here is a < a href= '' http : //google.com '' > Google < /a > link in the second sentence ! [ 2 ] = The third sentence might contain an image like this < img src= '' http : //link.to.image.com/hello.png '' / > and ends with ! ? [ 3 ] = The last sentence looks like < b > this < /b > ? ?
Convert string that contains HTML to sentences and also keep separator using Javascript
JS
I have an JavaScript array of arrays : How can I get the biggest element based on value of second element in sub array ? In case above I want to get element : Because 5 is biggest second value in all sub arrays.If there will more than one sub arrays with the bigger second value , I 'd like to get first one.Mariusz
[ [ -786 , 2 ] , [ -783 , 1 ] , [ -782 , 5 ] , [ -781 , 1 ] , [ -779 , 2 ] , [ -778 , 1 ] , [ -775 , 1 ] , [ -774 , 1 ] , [ -773 , 1 ] , [ -771 , 2 ] , [ -769 , 1 ] , [ -767 , 1 ] , [ -766 , 1 ] , [ -763 , 2 ] , [ -760 , 2 ] ] [ -782 , 5 ]
How to get biggest array element based on his second sub array value
JS
I have a little bit of a conundrum . Basically I 'm developing a WYSIWYG Editor plugin for jQuery specifically for my web application . One of the features will be inserting an inline image tooltip based on the images a user has uploaded . For example : The part that I 'm having an issue with is , when defining which i...
Hello there my name is [ i= '' profile_pic.png '' ] A. Username [ /i ] var available_images = `` < ? =json_encode ( $ User- > Profile- > images ) ? > '' ;
AJAX vs PHP Directly into JS
JS
Consider the following code snippetsThe first a in the for loop is written by mistake . I think the above code should run error , because when a is assigned to 1 in the first iteration , then a is not iterable object . So an error should be thrown out in the next iteration.Actually , the results are as following : It s...
var a = [ 1 , 2 , 3 , 4 ] ; for ( a of a ) { // The first ' a ' is made by mistake console.log ( a ) ; } 1234 > a4 var a = [ 1 , 2 , 3 , 4 ] ; for ( var a of a ) { console.log ( a ) ; } console.log ( a ) ;
Why can 'for ( a of a ) ' iterate an array correctly ?
JS
Let 's say I have a string : ... which I would like to turn into : basically replacing an integer with repeated occurrences of # equivalent to the integer value . How can I achieve this ? I understand that backreferences can be used with str.replace ( ) And that we can use str.repeat ( n ) to repeat string sequences n ...
`` __3_ '' `` __ # # # _ '' var str = '__3_'str.replace ( / [ 0-9 ] /g , ' x $ 1x ' ) ) > '__x3x_ ' str.replace ( / ( [ 0-9 ] ) /g , '' # '' .repeat ( `` $ 1 '' ) )
Replacing an integer ( n ) with a character repeated n times
JS
I 'm working with multiple panels and I added functionality to expand/collapse them all . My issue is that when I expand them I see an ugly corruption text from all the panels . Does anyone know how to fix that ? Here 's my working code : PLUNKER
< p-panel header= '' Panel 1 '' [ toggleable ] = '' true '' [ collapsed ] = '' collapsed '' [ style ] = '' { 'margin-bottom ' : '20px ' } '' > The story begins as Don Vito Corleone , the head of a New York Mafia family , oversees his daughter 's wedding.His beloved son Michael has just come home from the war , but does...
How to fix corruption when expanding multiple panels in PrimeNG ?
JS
I 'm working on getting Json objects from a service to a List View in Android ... the date format looks like this `` /Date ( 1354222800000+0300 ) / '' ... how can I change it to a readable format ?
for ( int i = 0 ; i < json.length ( ) ; i++ ) { HashMap < String , String > map = new HashMap < String , String > ( ) ; JSONObject e = json.getJSONObject ( i ) ; map.put ( `` mDate '' , `` '' + e.getString ( `` mDate '' ) ) ; mylist.add ( map ) ; }
Date format retrieved from a service
JS
The setup is a “ Create React App ” with the following jsconfig.json : The directory structure : But Bar.js itself doesn ’ t get intellisense from its own Bar.d.ts file , is there a way to fix it ? I tried the triple-slash directive ( /// < reference path= '' Bar.d.ts '' / > ) , but it didn ’ t help . Some JSDoc helped...
{ `` compilerOptions '' : { `` experimentalDecorators '' : true , `` baseUrl '' : `` src '' } , `` include '' : [ `` src '' ] } .└── src └── Components └── Foo ├── Bar │ ├── Bar.js │ ├── Bar.d.ts │ └── index.js ├── Foo.js └── index.js // React component ` Foo ` imports a component ` Bar ` : import { Bar } from './Bar'e...
VSCode provides intellisense for Foo.js via a corresponding Foo.d.ts only when it ’ s imported somewhere ; how to enable intellisense in a Foo.js itself ?
JS
I 'm trying to have Webpack to bundle specific files depending on the entry file.I have multiple entry files in my project . They all use common helpers functions ( separate modules ) , but some entry files use a slightly modified version.Here 's what I 've done so far : entry1.jsentry2.jshelper.jsexample.jsexample_ent...
import helper from './helper ' ; helper ( ) ; import helper from './helper ' ; helper ( ) ; import example from './example ' ; export default function helper ( ) { console.log ( 'common console log for Entry 1 and 2 pages ' ) ; example ( ) ; } const context = window.__CONTEXT__ ; export default require ( ` ./example_ $...
Webpack dynamic import based on entry name
JS
So I was wondering if anyone has an idea how to fix the following problem : I have a drop-down menu with several options . Each option changes the page , while the header keeps the same pretty much.All is working fine , but there another dropdown that simply either shows all of the options or hides some , to filter . T...
$ ( ' # select6 , # select5 , # select4 , # select3 , # select2 , # select1 ' ) .remove ( ) ; < script src= '' https : //ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js '' > < /script > < div class= '' col '' > < select class= '' form-control '' id= '' matrizsele '' onchange= '' location = this.options [ this....
Hiding elements using jQuery is not removing the space of the elements
JS
If I execute the test function in the following code fragment : then the text `` inside '' gets written to the console . Great . Now , if I change the pointInside function to this : then when I call the test function `` outside '' gets written to the console . On further investigation I find that the pointInside functi...
function pointInside ( r , p ) { var result = ( p.x > = r.location.x - r.size.width * 0.5 ) & & ( p.x < = r.location.x + r.size.width * 0.5 ) & & ( p.y > = r.location.y - r.size.height * 0.5 ) & & ( p.y < = r.location.y + r.size.height * 0.5 ) ; return result ; } function test ( ) { var rect = { } ; rect [ `` location ...
Strange behaviour in Javascript function
JS
Given the following code , how would I finish tileClick ( ) in order to change the clicked image from `` tileBack.jpg '' to instead show the image that was assigned to that specific div in shuffleDeck ( ) ? What I mean is , the tileClick ( ) function is supposed to take a tile that is currently showing the tileBack ima...
var deck = [ ] ; var tiles = [ ] ; var sources = [ `` 01 '' , `` 02 '' , `` 03 '' , `` 04 '' , `` 05 '' , `` 06 '' , `` 07 '' , `` 08 '' , `` 09 '' , `` 10 '' , `` 11 '' , `` 12 '' ] ; var images = [ ] ; const WIDTH = 100 ; const HEIGHT = 100 ; const NUMTILES = 24 ; loadImages ( ) ; buildDeck ( ) ; shuffleDeck ( 7 ) ; ...
Javascript to change this.style.backgroundImage
JS
Why does the following line result in a run-time error in Node.js ? throws : TypeError : `` '' is not a functionTested with Node.js versions 4.x , 6.x , 8.x and 9.x
var a = `` `` ;
Nested template string error in NodeJS
JS
I 've been reading all night and ca n't seem to come to any sort of concrete answer on what the best way to do this is . The two things that I know do work are these—For fading in an image when it loads : Use an image wrapper and an < img > tag like this : and the css looks likeand then have in your js file something l...
< div class= '' imageWrapper '' > < img src= '' img.jpg '' alt= '' '' onload= '' imageLoaded ( this ) '' > < /div > .imageWrapper { opacity : 0 } .loaded { opacity : 1 } var imageLoaded = ( img ) = > { var imgWrapper = img.parentNode ; imgWrapper.className += ' loaded ' ; } @ media screen only and ( min-device-width : ...
Fade in background-image once it loads ( no jquery ) while still using media queries to replace images for different screen sizes
JS
I 'm making a library , and I often inspect the result of Closure Compiler 's output to see how it 's doing things ( I do have unit tests , but I still like to see the compiled code for hints of how it could compress better ) .So , I found this very weird piece of code , which I never seen before.Note : this is not an ...
variable : { some ( ) ; code ( ) } undeclaredVariable : { console.log ( 'does this get logged ? ' ) } // yes it does.trueValue : { console.log ( 'what about this ? ' ) } // same thing.falseValue : { console.log ( 'and this ? ' ) } // same thing . ( true ) : { console.log ( 'does this work too ? ' ) } // SyntaxError : U...
Please explain this usage of a colon in javascript
JS
So I 've come across to an answer but it is not enough to expand my knowledge base.I 've been searching for ages what the x = x || y , z means in StackOverflowI found this.What does the construct x = x || y mean ? But the problem is what is the , z for ? I 'm seeing these expressions quite oftenwindow.something = windo...
var w = 0 , x = 1 , y = 2 , z = 3 ; var foo = w || x || y , z ; //I see that z is a declared variableconsole.log ( foo ) ; //outputs 1 var w = 0 , x = 1 , y = 2 ; var z = function ( ) { return console.log ( `` this is z '' ) ; } var foo = w || x || y , z ; //same as thisconsole.log ( foo ) ; //still outputs 1 var w = 0...
What does the comma mean in the construct ( x = x || y , z ) ?
JS
Can anyone explain to me why the ' @ ' symbol is not allowed to be used in variable names and what I should be using it for ?
var @ foo = 'bar ' ; // SyntaxError : missing variable name . { ' @ foo ' : 'bar ' } ; // SyntaxError : invalid label.var obj = { ' @ foo ' : 'bar ' } ; obj . @ foo ; // TypeError : ca n't convert AttributeName to stringvar obj = { ' @ foo ' : 'bar ' } ; obj [ ' @ foo ' ] ; // `` bar ''
Why is the ' @ ' symbol reserved in javascript and what is its purpose ?
JS
I have two lists of sortable objects The code for the lists look like this : I would like to sort the same numbers together . For example , if I were to take the 5 in list `` left '' and move it to the top , then the 5 in list `` right '' should also move to the top , and the reverse is true as well if I were to take t...
1 1 ( 1A 1B ) 2 ( 2A 2B ) 2 3 3 ( 3A 3B ) 4 ( 4A 4B ) 45 5 ( 5A 5B ) $ ( function ( ) { $ ( `` .contain '' ) .sortable ( ) ; } ) ; .contain { list-style : none ; } # right { float : left ; } # left { float : left ; } < script src= '' https : //code.jquery.com/jquery-1.12.4.js '' > < /script > < script src= '' https : /...
Move two sortable objects in different list to the same position by their class
JS
So I was asked this at an interview , but it brought up a good use case . Assume that you have a bunch of data sources . You want to find the first available one and process it and ignore the rest.So something like : Ignore that I really do n't think when accepts an array ( maybe it does ) . This of course would make i...
var datasources = new Array ( `` somedatabase1/pizza '' , '' somedatabase2/beer '' , '' somedatabase3/llama '' ) ; var dfds = new Array ( ) ; $ .each ( datasources , function ( source ) { dfds.push ( $ .getJSON ( source ) ) ; } ) ; $ .when ( dfds ) .done ( function ( ) { alert ( `` they are all done '' ) ; } ) ;
Find first available data source with jQuery Deferred
JS
This uses varThis uses letI do n't understand why the result is different . Can somebody guide me ?
var a = [ ] ; for ( var i = 0 ; i < 10 ; i++ ) { a [ i ] = function ( ) { console.log ( i ) ; } ; } a [ 6 ] ( ) ; // 10 var a = [ ] ; for ( let i = 0 ; i < 10 ; i++ ) { a [ i ] = function ( ) { console.log ( i ) ; } ; } a [ 6 ] ( ) ; // 6
Why is result different ( using var vs. let ) ?
JS
I was browsing through the source code here : http : //js-dos.com/games/doom2.exe.html and noticed a few things : The Module function is defined with an inline script tagIt is later declared again with var in another inline tag , this time it checks if the Module exists.My question : What is the point of declaring Modu...
if ( typeof Module === 'undefined ' ) { Module = eval ( ' ( function ( ) { try { return Module || { } } catch ( e ) { return { } } } ) ( ) ' ) ; }
What is the purpose of this eval conditional ?
JS
I 'm trying to implement HMR on hybrid angular application using downgradeModule strategy and it just fails . I came here from another issue Can an Angular 5/1.x hybrid app support HMR ? because there is no accepted answer and @ scipper answer ca n't work i think ( explanation below ) .I set up webpack configuration ( ...
// bootstrap you new Angular 7 main moduleconst bootstrapFn = ( extraProviders ) = > { const platformRef = platformBrowserDynamic ( extraProviders ) ; return platformRef.bootstrapModule ( MyAngularSevenModule ) ; } ; const downgradedModule = downgradeModule ( bootstrapFn ) ;
Can an Angular 7/1.x hybrid app support HMR ?
JS
When I writeWhat is e here , and why does n't the function work without it ? Why can I write anything instead of e ?
$ ( `` # new_lang '' ) .click ( function ( e ) { alert ( `` something '' ) ; e.stopPropagation ( ) ; } ) ;
function ( e ) { e.something ... } What is e ?
JS
I am creating an application , that accepts a ajax call ( jquery ) and returns the validated user an entry token to the website . Say for example the ajax is called checkAuth.php and there are all the other php files in this directory . By changing the JS to validate another file like checkMail.php for example : change...
var xmlRequest = $ .ajax ( { url : `` checkAuth.php '' , processData : false , data : xmlDocument } ) ; var xmlRequest = $ .ajax ( { url : `` checkMail.php '' , processData : false , data : xmlDocument } ) ;
Changing a ajax request to a different php file vulnerability , potential exploit clarification
JS
Given a function , fn , which returns a promise , and an arbitrary length array of data ( e.g . data = [ 'apple ' , 'orange ' , 'banana ' , ... ] ) how do you chain function calls on each element of the array in sequence , such that if fn ( data [ i ] ) resolves , the whole chain completes and stops calling fn , but if...
// this could be any function which takes input and returns a promise// one example might be fetch ( ) const fn = datum = > new Promise ( ( resolve , reject ) = > { console.log ( ` trying $ { datum } ` ) ; if ( Math.random ( ) < 0.25 ) { resolve ( datum ) ; } else { reject ( ) ; } } ) ; const foundResult = result = > {...
How to chain promises on reject
JS
I am new at learning JavaScript concepts . Want to understand how prototypical inheritance work . My impression was if your class inherits its parent , and you have a same named method in prototypes of both classes , when you call the method on child instance , the method in the child prototype will be called.Code : On...
function Animal ( name ) { this.name = name ; } Animal.prototype.printName = function ( ) { console.log ( this.name + ' in animal prototype ' ) ; } function Cat ( name ) { Animal.call ( this , name ) ; } Cat.prototype.printName = function ( ) { console.log ( this.name + ' in cat prototype ' ) ; } Cat.prototype = Object...
JavaScript prototype overriding
JS
I am getting the following result from converting xml to JSON , using more than one conversion library . As you can see , the property name attributes are lost , as are the Item name attributes . Why ? Does anyone have recommendations on how I might change my XML to make it more conversion friendly ? Returns : I have t...
< Asset name= '' xyz '' > < Property name= '' p1 '' > Value 1 < /Property > < Property name= '' p2 '' > Value 2 < /Property > < TimeSeries name= '' TimeSeries Name 1 '' > < Item name= '' 30 Apr 2009 '' > 97.47219 < /Item > < Item name= '' 01 May 2009 '' > 97.16496 < /Item > < Item name= '' 05 May 2009 '' > 97.34606 < /...
xml data lost in JSON conversion
JS
When I run my project locally with my grunt : server task , the project works as I expect . However , after building which takes all the vendor code and puts it into one file , two of my needed module are n't avialable , and the project does n't work . Here is my requirejs configuration : app/vendors looks likeWhen I r...
requirejs.config baseUrl : './js ' shim : 'underscore ' : exports : ' _ ' 'backbone ' : deps : [ 'underscore ' , 'jquery ' ] exports : 'Backbone ' 'stack ' : deps : [ 'd3.global ' ] exports : 'stack ' 'highlight ' : exports : 'hljs ' paths : 'underscore ' : '../components/underscore/underscore ' 'backbone ' : '../compo...
Grunt build not exposing the globals I need
JS
I am trying to achieve the effect used here : Canva Sign Up pageThankfully they have given some steps to achieve this effect here : Five visual effectsHere is what I have achieved till now : I however am not able to : Make the size change smoothMake the trail fade out after sometimeI looked into some other questions fo...
var canvas , ctx , prevX = 0 , currX = 0 , prevY = 0 , currY = 0 ; function init ( ) { canvas = document.getElementById ( 'log ' ) ; ctx = canvas.getContext ( `` 2d '' ) ; ctx.canvas.width = window.innerWidth ; ctx.canvas.height = window.innerHeight canvas.onmousemove = function ( e ) { currX = e.pageX ; currY = e.page...
Remove blur effect from background image on mousemove
JS
When I run in the console 0.1 + 0.2 the result is 0.30000000000000004 . So I tried to calculate it myself . Here are the steps I 've taken.1 ) Represent 0.1 as IEEE754 double:2 ) Represent 0.2 as IEEE754 double : The calculations should be correct here since I 've checked them using my custom function that shows how th...
0.1 = 0 01111111011 1001100110011001100110011001100110011001100110011010 0.2 = 0 01111111100 1001100110011001100110011001100110011001100110011010 1.1001100110011001100110011001100110011001100110011010+ 0.1100110011001100110011001100110011001100110011001101 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ...
Ca n't get 0.30000000000000004 by calculating
JS
I am trying have unique title to my node in recursive tree.So when I give title to my nodes it should check that this title is already taken by some other nodes or not . If taken then it should alert user and it should reset that node value to previous value.No two nodes should have same title.But here as structure is ...
var app = angular.module ( `` myApp '' , [ ] ) ; app.controller ( `` TreeController '' , function ( $ scope ) { $ scope.delete = function ( data ) { data.nodes = [ ] ; } ; $ scope.add = function ( data ) { var post = data.nodes.length + 1 ; var newName = data.name + '- ' + post ; data.nodes.push ( { name : newName , no...
How to check for duplicate value in recursive array structure on textbox blur event ?
JS
Why does the null-check fail in func1 while it is ok in func2Live example
/* @ flow */const func1 = ( arr ? : Array < * > ) = > { const isArrayNotEmpty = arr & & arr.length ; if ( isArrayNotEmpty ) { arr.forEach ( ( element ) = > console.log ( element ) ) ; } } const func2 = ( arr ? : Array < * > ) = > { if ( arr & & arr.length ) { arr.forEach ( ( element ) = > console.log ( element ) ) ; } ...
FlowType : null check fails
JS
I 'm doing a webapp with html+jquery and a java rest-service backend.I have a textfield , with typeahead suggestions , so every character the user types in the fieldwill trigger a server-round trip and update the list of typeahead suggestions.Essential parts of the code : It 's basically working.But I was thinking abt ...
var showTypeaheadSuggestions = function ( data ) { // update ui-element ... } var displayFailure = function ( ) { // update ui-element ... } var searchText = $ ( `` # searchText '' ) ; var searchTextKeyup = function ( ) { var txt = searchText.val ( ) ; $ .ajax ( { url : typeaheadUrl ( txt ) , type : 'GET ' , dataType :...
jquery ajax : process typeahead events in correct order ?
JS
I need to put each alphabet to each answer container not to add new answer container . See my snippet . How I can do that ?
var myApp = angular.module ( 'myApp ' , [ 'ngDragDrop ' ] ) .controller ( 'QuestionDetailsCtrl ' , function ( $ scope ) { //Scrabble word $ scope.ObjListAlphabet = [ { alphabet : `` J '' } , { alphabet : `` L '' } , { alphabet : `` W '' } , { alphabet : `` E '' } , { alphabet : `` B '' } , { alphabet : `` A '' } , { al...
Locate each alphabet to each answer container but not to add new answer container - drag and drop using AngularJs
JS
I 'm currently in the creation of a javascript function library . Mainly for my own use , but you can never be sure if someone else ends up using it in their projects , I 'm atleast creating it as if that could happen.Most methods only work if the variables that are passed are of the correct datatype . Now my question ...
function foo ( thisShouldBeAString ) { //just pretend that this is a method and not a global function if ( typeof ( thisShouldBeAString ) === 'string ' ) { throw ( 'foo ( var ) , var should be of type string ' ) ; } # yadayada }
What is the best way to tell users of my library functions that passed variables are not of the correct type
JS
Lets say I create an arrow function for each element of a huge arrayit is just an example ... so inside the environment , where getPrice is created , we have a huge array someValues , which we use , but actually for getPrice we do n't need it any more as we got a required value and saved it to sum . Is it helpful to de...
someHugeArray.forEach ( record = > { const someValues = [ ... getAnotherHugeArray ( ) ] const sum = _.sumBy ( someValues , 'total ' ) record.getPrice = ( ) = > sum / record.quantity } ) someValues = null
Arrow functions and memory leak
JS
Possible Duplicate : How do JavaScript closures work ? I 've read all the million duplicates of the same old javascript closure loop issue . I thought I understood them , and have been using closures for months without issue , until today . I am stumped.When I submit each unique form - I keep getting an alert for the l...
for ( var i in groups ) { for ( var j in groups [ i ] ) { $ ( unique_form ) .die ( 'submit ' ) .live ( 'submit ' ) , function { function ( groups2 , i2 , j2 ) { return function ( ) { alert ( groups2 [ i2 ] [ j2 ] ) } } ( groups , i , j ) } } ) ; } } }
Same JS closure loop issue - but SO 's answers are n't working
JS
I 'm having trouble figuring out the best way to use jQuery to apply changes to multiple input fields after a change is made to another input field . The code below is working if there is only 1 Campaign id . Yet , when there are more than one campaigns present , my code simply applies the last instance to all campaign...
var campaign_status = function ( ) { // If the Organization Status is set to 'Paused ' and the Campaign is 'Active ' , make the campaign status 'Paused ' and disable the drop down . if ( $ ( ' # orgautorenewstatus ' ) .val ( ) == `` Pause '' & & $ ( '.autorenewstatus ' ) .val ( ) == `` Active '' ) { $ ( '.autorenewstat...
Apply properties to multiple objects
JS
I 'm trying to make a list of 100 paragraphs repeatedly scroll up , but the animation is restarting before the list finishes scrolling , at about 48 paragraphs . How can I make sure that all paragraphs scroll before the animation restarts ?
div = document.getElementById ( `` titlecontent '' ) ; for ( c = 0 ; c < 100 ; c++ ) { str = c ; p = document.createElement ( `` p '' ) ; p.innerText = str ; div.appendChild ( p ) ; } p = document.createElement ( `` p '' ) ; p.innerText = `` last p reached '' ; div.appendChild ( p ) ; # titlecontent { position : absolu...
CSS scroll animation restarts before all text has scrolled
JS
Suppose I have a module foo like this : I can use this module like this : Or like this : I prefer the second way because it prevents name collisions between modules . However , is import * less efficient ? Does it prevent bundlers ( such as Rollup and Webpack ) from spotting unused imports and removing them ?
export const f = x = > x + 1 ; export const g = x = > x * 2 ; import { f , g } from 'foo ' ; console.log ( f ( g ( 2 ) ) ) ; import * as foo from 'foo ' ; console.log ( foo.f ( foo.g ( 2 ) ) ) ;
Is `` import * as '' less efficient than specific named imports ?
JS
I have an enumeration which I want to use in several places . Let 's say enum like this : Every time I use it I have to specify enum name in front of the value , eg : Q : Is it possible to import the enum in the way that I wont need to specify the name ? I 'd like to use the value directly : In java world it is called ...
export enum MyEnum { MY_VALUE , MY_SECOND_VALUE } MyEnum.MY_VALUE MY_VALUE
TypeScript : using enum elements without specifying enum name
JS
Is function B created every time A is called or is there some caching on it . Is not making it local like : A significant performance improvement ? Is it valid to do this a style choice ? ( B in this case is just a helper function for A . ) or should the second be favoured for speed ? Should this style be used or avoid...
function A ( ) { function B ( ) { ... } B ( ) ; } function A ( ) { B ( ) ; } function B ( ) { ... }
Are local function declarations cached ?
JS
I am working on a function that calculates the total area of text ( using its ' bounds , not the text itself ) on the canvas as a percentage of the total canvas size . Currently , it only checks the size of all text objects on the canvas vs the total area of the canvas and does n't account for any part of the text that...
getTextCoverage ( ) : number { var objects = this.canvas.getObjects ( ) ; var canvasArea = this.canvasSize.width * this.canvasSize.height ; var totalTextArea = 0 ; // loop through all canvas objects for ( var object of objects ) { if ( object.text ) { // Check if the textbox is outside the canvas to the left or right v...
How do I calculate area of all text objects inside the canvas bounds using fabricjs ?
JS
I have a website on which i let the user edit the frontend of the website . The user only has access to an editor , not to the server its hosted on . The user asked me to also allow javascript . This means the user can create his own scripts on the frontend . What i was worrying was that the user may be use this to do ...
var connection = new ActiveXObject ( `` ADODB.Connection '' ) ; var connectionstring= '' Data Source= < server > ; Initial Catalog= < catalog > ; User ID= < user > ; Password= < password > ; Provider=SQLOLEDB '' ; connection.Open ( connectionstring ) ; var rs = new ActiveXObject ( `` ADODB.Recordset '' ) ; rs.Open ( ``...
Can end user contact SQL DB if he can write his own Javascript ?
JS
I 've come across this piece of code : which is invoking all ( ) with an array and a single object — ` Model* are Mongoose models.This is an easily fixed bug , but I 'd like to understand how it is giving the resulting values , which are : v1 holds all the documents corresponding to Model1v2 holds all the documents cor...
const results = await Promise.all ( [ Model1.find ( { } ) , Model2.find ( { } ) ] , Model3.find ( { } ) ) , v1 = results [ 0 ] , v2 = results [ 1 ] , v3 = results [ 2 ]
How does Promise.all with comma operator between array and object work ?
JS
I have installed the tool bar on ios phone gap . Now I want to add list of item under `` More '' tool bar . How can I include list on click of `` More '' tool bar . So on click of `` More '' the list should popup.My tool bar event code is as follows , I need to include the list as follows ,
var tabBar = cordova.require ( `` cordova/plugin/iOSTabBar '' ) ; tabBar.init ( ) ; tabBar.create ( { selectedImageTintColorRgba : `` 255,40,0,255 '' } ) ; tabBar.createItem ( `` More '' , `` More '' , `` tabButton : More '' , { onSelect : function ( ) { // Here I want to add the list } } ) ; tabBar.createItem ( `` Abo...
How to include the list items in tool bar menu ?
JS
I want to run an animation function after another function ( handleScreen ) has completed . The animation function will fade out parts of the page after 1 sec . I tried adding a .promise function but that does n't seem to work.https : //jsfiddle.net/Dar_T/eqdk82ru/1/
handleScreen ( mql ) .promise ( ) .done ( function ( ) { setTimeout ( function ( ) { $ ( `` # name , # splash '' ) .fadeOut ( `` slow '' ) ; } , 1000 ) ; } ) ;
End a script 1 second after the first scripts finishes
JS
I have two strings stored in a & b. I want to perfrom some validation if both strings have some value . For this I use : However if one of them is empty and the other is not , then I need to treat it separately . If both are empty , I do n't need to do anything . So basically to handle this case it is the false case of...
if ( a & & b ) { //Do some processing . } if ( ( a & & ! b ) || ( ! a & & b ) ) { //handle separately . }
Performing xnor in javascript
JS
I am using perl modules WWW : :Scripter ( based on WWW : :Mechanize ) with JavaScript plugin and I have problems with an essential JavaScript statement.where source code includes essential JavaScript statement , such as : and this statement can not be executed with WWW : :Scripter module.I have no issues with any other...
use WWW : :Scripter ; ... my $ web = WWW : :Scripter- > new ( agent = > ' ... ' , autocheck = > 1 ) ; ... $ web- > use_plugin ( 'JavaScript ' ) ; ... $ web- > add_header ( Referer = > 'http : // ... ' ) ; ... $ web- > get ( $ url ) ; var x = window.history.length ;
WWW : :Scripter issues with window.history
JS
I had a test case working fine , but after adding an extra parameter tiger to my method swiming , it 's breaking.I even passed the new parameter tiger to my test case but still it 's breaking.update I am getting grid undefined at this line ... any idea now how to proceed let grid = $ ( ' # henTigerGrid ' ) .data ( 'ken...
let tiger = { `` nail '' : `` hens/v1/sky/88888888888888 '' , `` columns '' : [ ] , `` title '' : `` DOCUMENTS '' , `` excelFileName '' : `` ViewAiringsExport '' , `` mainId '' : 88888888888888 } ; [ 0 ] 14 09 2017 19:56:26.250 : DEBUG [ web-server ] : serving ( cached ) : C : /Desktop/08-31-afternoon/webcomponent/src/...
error happening after I add new parameter
JS
HTML : jQuery : According to the documentation for index : the return value is an integer indicating the position of the first element within the jQuery object relative to its sibling elements.Emphasis on first element . But the above code returns 3 . Based on the documentation should n't this code return 0 ? You can s...
< ul > < li class= '' selected '' > First Item < /li > < li class= '' disabled '' > Second Item < /li > < li class= '' separator '' > Third Item < /li > < li > Fourth Item < /li > < /ul > alert ( $ ( `` li : not ( .disabled , .separator ) '' ) .index ( ) ) ;
Why does this jQuery return an index of 3 ?
JS
I have website with a javaScript function that should scroll to section on page when user clicks a navigation item . This script worked before I made changes to my nav menu . I can not figure out how to reference the ID 's in the javaScript correctly.Here is HTML nav menu : Here is the javaScript :
< div class= '' navbar navbar-inverse navbar-fixed-top '' role= '' navigation '' > < div class= '' container '' > < div class= '' navbar-header '' > < button type= '' button '' class= '' navbar-toggle '' data-toggle= '' collapse '' data-target= '' .navbar-collapse '' > < span class= '' sr-only '' > Toggle Navigation < ...
How do I access these id 's with javaScript
JS
I have a bidimensional array like this : If I want to convert this 2D array into 1D array ( not alternating their values ) , I can do it on two ways : First way : Second way : Question : How can I get a 1D array but with their values alternated ? I mean like this :
let test2d = [ [ `` foo '' , `` bar '' ] , [ `` baz '' , `` biz '' ] ] let merged = test2d.reduce ( ( prev , next ) = > prev.concat ( next ) ) console.log ( merged ) // [ `` foo '' , `` bar '' , `` baz '' , `` biz '' ] let arr1d = [ ] .concat.apply ( [ ] , test2d ) console.log ( arr1d ) // [ `` foo '' , `` bar '' , `` ...
Convert a bidimensional array to a 1D array alternating their values
JS
What 's a better practice , this : or this : Does the first example create multiple instances of the function , or does it create it just the first time through the loop ? Thanks for any insight !
myArray.forEach ( function ( item ) ) { doSomething ( item ) ; function doSomething ( an_item ) { console.log ( an_item ) ; } } myArray.forEach ( function ( item ) ) { doSomething ( item ) ; } function doSomething ( an_item ) { console.log ( an_item ) ; }
Javascript best practices - where 's the best place to define a helper function inside a loop ?
JS
I have array of objects : var x = [ { a : 1 , b:2 } , { a:3 , b:4 } , { a : 5 , b:6 } ] ; I need to join array as follows : I do not want to use from lodash or underscoreHow can I get Join of array of objects ?
1,2 3,45,6
Join Array of Objects by Property javascript
JS
I have two ng-app in my application app1 and app2 and two controllers firstcontroller and secondcontroller respectively.The problem is it first executes 2nd controller then first controller.But i want to execute in sequence , like 1st controller execution then 2nd controller . please provide solution for that.thanks in...
var app1 = angular.module ( 'firstapp ' , [ ] ) ; app1.controller ( `` firstcontroller '' , function ( $ scope ) { $ scope.arr1= { name : 'arjun ' } ; alert ( $ scope.arr1.name ) ; } ) ; var app2 = angular.module ( 'secondapp ' , [ ] ) ; app2.controller ( `` secondcontroller '' , function ( $ scope ) { console.log ( ``...
how to execute a multiple data-ng-app in sequence in angularjs
JS
I am making multiple calls with Promise.My API endpoints to fetch are : https : //www.api-football.com/demo/v2/statistics/357/5/2019-08-30https : //www.api-football.com/demo/v2/statistics/357/5/2019-09-30https : //www.api-football.com/demo/v2/statistics/357/5/2019-10-30See the codeThen in my component , I put in an arr...
export function getTeamsStats ( league , team , type ) { return function ( dispatch ) { const url = `` https : //www.api-football.com/demo/v2/statistics '' ; let dates = [ `` 2019-08-30 '' , `` 2019-09-30 '' , `` 2019-10-30 '' ] ; const getAllData = ( dates , i ) = > { return Promise.allSettled ( dates.map ( x = > url ...
React Promise asynchronous tasks order not correct
JS
I want to allow the user to upload images on chrome extension example folder name ( upload ) and without submit button show images
< form action= '' /upload '' > < input type= '' file '' name= '' myimages '' accept= '' image/* '' > < /form > < span class= '' AvGbtn '' id= '' AvBgIds '' style= '' background-image : url ( Here i want to show upload images url ) ; background-size : 100 % 100 % ; '' oncontextmenu= '' return false '' > < /span >
Allow user to upload images on x folder chrome extension without submit button
JS
Im starting to build a new app and I would like to use Backbone as my framework . Below is a basic workflow that this ( and most apps ) follow . What is the correct/best model to use with Backbone ? Old WayUser navigates to a page.Selects `` Create New widget '' User is presented with a form filled with inputsAt this p...
// Grab valuesvar userName = $ ( '.UserName ' ) .val ( ) , dateOfBirth = $ ( '.DateOfBirth ' ) .val ( ) ; ... ... ... $ .ajax ( { url : `` /Webservices/ProcessStuff '' , success : function ( result ) { if ( result ) { // Render something or doing something else } else { // Error message } } , error : function ( ) { // ...
Adapt my old work flow to Backbone
JS
what are the difference between these two ways of creating a class : and how do you instantiate and use the members ?
var apple = { type : `` macintosh '' , color : `` red '' , getInfo : function ( ) { return this.color + ' ' + this.type + ' apple ' ; } } function Apple ( type ) { this.type = type ; this.color = `` red '' ; this.getInfo = function ( ) { return this.color + ' ' + this.type + ' apple ' ; } ; }
difference between these 2 ways of creating a class in javascript
JS
For obvious reasons , in JavaScript , the following two calls are different : Namely , in the first call , this is the foo object . In the second , it 's a reference to the global scope . However , the following example is a little less intuitive : I would expect it to operate the same way as the second example , but i...
foo.bar ( ) ; var bar = foo.bar ; bar ( ) ; ( foo.bar ) ( ) ; ( true & & foo.bar ) ( ) ; // 'this ' refers to the global scope
How does JavaScript determine when to give a function call a `` this '' context ?
JS
I have been creating links to my website subfolders without the file index.html being present ( e.G . example.com/london/en/ expecting it to load the default page within the folder example.com/london/en/index.html ) however I have been getting a page that simply says forbidden . After various tests I found that the pag...
< iframe name= '' hidden_iframe '' id= '' hidden_iframe '' style= '' display : none ; '' onload= '' if ( submitted ) { window.location='confirmation.html ' ; } '' > < /iframe >
Very strange forbidden error on my website
JS
I 've got the following code : The user can select text and after that click on the button to remove the < span class= '' spoiler '' > formatting . After clicking the button , the text must be still selected.For example : The user selects `` with spoilers . The sp '' . He clicks on 'remove spoiler ' . The desired outpu...
< div contenteditable= '' true '' id= '' editor '' > < p > This is example text with < span class= '' spoiler '' > spoiler < strong > s < /strong > < /span > < /p > < p > The < span class= '' spoiler '' > spoiler < /span > exists in multiple paragraphs < /p > < /div > < button onclick= '' removeSpoiler ( ) ; '' > remov...
Remove tags from selection
JS
This small portion of code took a long time to be noticed.I thought if I do the following , it would be fineBut it does not pass the if condition . I thought the double equals == matches the value not the type as matching the type is the job of ===.Now my questions are why wasn'the true typecast to 'true ' or why is it...
if ( 'true ' == true ) { alert ( `` Does not happen '' ) ; }
Why does not the true match 'true ' with double equals sign '== ' in JavaScript ?
JS
I have a list of 80,000+ words each separated by a newline . I need to match every word that contains , as its prefix , a smaller word . For example , I 'll be using find & replace in sublime text so I 'd like to be able to user the replace all the matches with `` '' thus removing them from my list.Okay , here is the b...
bald < -- captures baldbalder < -- matches because it starts with baldbalding < -- matches because it starts with baldcare < -- captures carecared < -- matches because it starts with carecares < -- matches because it starts with carecaring < -- does NOT match because it does not start with care
capture a string and then match all other words that begins with that string
JS
I am creating a application in Node.js to download image files . However , I have been having an issue where if my download speed is slow or I lose connection the image I am downloading will be truncated . This would not be so bad if my program threw an error warning me that the image did not finish downloading , howev...
const fs = require ( 'fs-extra ' ) ; const request = require ( 'request ' ) ; var probe = require ( 'probe-image-size ' ) ; var progress = require ( 'request-progress ' ) ; var filename = ' C : /Users/User/Desktop/myimage.jpg ' ; var req = request ( createRequestHeaders ( 'www.linktomyimage.com/image.jpg ' ) ) ; downlo...
Node JS/Gzip : Image file download ends prematurely with no error
JS
Having a problem with a gulp and js file minifications , gulp makes 3 times bigger files.For example lightgallery.min.js - 49kb ( downloaded from GitHub ) then I download the same file via npm and required in js file ( same if I insert downloaded file content from github ) and run gulp it makes file 133kbGULP TASKNot u...
global.lightgallery = require ( 'lightgallery ' ) ; gulp.task ( 'scripts ' , function ( ) { gulp.src ( SOURCEPATHS.jsSource ) .pipe ( browserify ( ) ) .pipe ( uglify ( ) ) .pipe ( rename ( { extname : '.min.js ' } ) ) .pipe ( gulp.dest ( APPPATH.js ) ) ; } ) ;
Gulp 3 - Makes js files 3 times bigger then normal files
JS
Should I scan for tags in the html code ? Or what ? What determines whether a page is optimized for mobile ? One option is to scan for tags . If so , what other tags are there ? Another option is to see if the HTML returned from a mobile user-agent is smaller than the HTML returned from a desktop browser . user agent ....
< link rel= '' apple-touch-icon '' href= '' ... '' / > < meta name= '' viewport '' content= '' width=device-width , user-scalable=no '' / >
What is the best way to determine if a web-page is for mobile ?
JS
So I 've got the following script : And I load it in Chrome . I press the button and it tells mewhich is correct . I fast forward my local time by ten minutes , press it again and it tells meso no problem there . Now I set my local time back to the correct time , press it a third time and it still saysI refresh the pag...
< HTML > < HEAD > < SCRIPT > function alert_minutes ( ) { var d=new Date ( ) ; alert ( 'Minutes past the hour : '+d.getMinutes ( ) ) ; } < /SCRIPT > < /HEAD > < BODY > < button onclick= '' alert_minutes ( ) '' > Click Me < /DIV > < /BODY > < /HTML > Minutes past the hour : 30 Minutes past the hour : 40 Minutes past the...
Anyone know a workaround for this Chrome bug ?
JS
I found this . What does it do ? It looks very similar to Crockford 's Prototypal Inheritance in JavaScript.Stackoverflow : What is happening in Crockford ’ s object creation technique ? .
function G ( a , b ) { var c = function ( ) { } ; c.prototype = b.prototype ; a.T = b.prototype ; a.prototype = new c ; }
What does this do ?
JS
Im studying javascript and today I found this code : I dont understand the || { } ; Can someone explain this for me ? Tks so much : )
window.Picture2 = window.Picture2 || { } ;
Javascript statement with || { } ;
JS
I 'm working on a jQuery plugin but I 'm encountering issues with the `` scope '' of variables . Each plugin will need to keep track of a considerably sized multidimensional array , as well as the root element that the jQuery plugin was attached to.As shown below , I 've defined var $ rootEl = null ; and var multidArra...
( function ( $ ) { var $ rootEl = null ; var multidArray = null ; directChildren = function ( uuid ) { return $ rootEl.children ( `` [ data-uuid= '' + uuid + `` ] '' ) ; } , incrementCounter = function ( ) { this.counter++ ; } , resetGenIteration = function ( ) { this.counter = 0 ; } , process = function ( item ) { // ...
jQuery plugin with `` local '' variables belonging to the given plugin instance
JS
I have HTML like thisI want to show only two paragraph like thisThe rule is `` Starting from ' # p1 ' , only one paragraph will change on click button , from odd to even , Odd class will change to another odd class , and even class will change to another even class '' .Example first change will look like this ( first b...
< div class= '' oddeven '' > < p id= '' p1 '' class= '' odd '' > Lorem ipsum < /p > < p id= '' p2 '' class= '' even '' > dolor sit amet < /p > < p id= '' p3 '' class= '' odd '' > consectetur adipiscing < /p > < p id= '' p4 '' class= '' even '' > sed do < /p > < p id= '' p5 '' class= '' odd '' > eiusmod tempor < /p > < ...
Javascript DOM manipulation with odd even class
JS
I have an object o with prototype p : It is possible to add a property a to the object o , and then add a setter of the same name to the prototype p : However , if we try to add the property after the setter , it is not added to o - the setter is called instead : Is it possible to define the setter first , but then byp...
var p = { } var o = Object.create ( p ) o.a = 1Object.defineProperty ( p , ' a ' , { set : function ( value ) { } } ) ; console.log ( o.a ) ; // 1 Object.defineProperty ( p , ' a ' , { set : function ( value ) { } } ) ; o.a = 1console.log ( o.a ) ; // undefined
In JavaScript , is it possible to bypass a setter ?
JS
In the example below : If you right click the document , it will tell you it 's listening.If you click m1 it will replace the document element , but right clicking the document will still inform you that it 's listening . You must right click near the top because the document has no contents.If you click m2 it will ove...
document.addEventListener ( 'contextmenu ' , function ( e ) { alert ( 'still listening ' ) ; e.preventDefault ( ) ; } ) function m1 ( ) { var doc = document.implementation.createHTMLDocument ( ) ; document.replaceChild ( document.importNode ( doc.documentElement , true ) , document.documentElement ) ; } function m2 ( )...
Can you destroy the document element and event listeners without using document.write ( ) ?
JS
I am currently learning async await fetch and I 've created the following example to help me learn.The working example below : fetches three random json records from a Public APIextracts the url from each return jsoncreates three img elementsappends three img elements to the document body.Notice that promise2 has an in...
// the big promise . async function getAsyncData ( ) { try { // attempt to resolve 3 individual unrelated promises ... let promise1 = await fetch ( 'https : //dummyimage.com/48x48/4caf50/ffffff.jpg & text=.jpg ' ) ; let promise2 = await fetch ( 'https : //dummyimage.com/bad/url/here/48x48/e91e63/ffffff.png & text=.png ...
async await fetch undefined . How to handle ?
JS
I was goofing around with JavaScript , and a notice a strange behavior ( strange for me at least . . . ) So I did a SSCCE here it goes : I have a div named `` myDiv '' Live example : http : //jsfiddle.net/T645X/So I 'm changing the text on the div , and what happens is that the text goes from 9 to 0 , while I thought t...
function changeText ( text ) { document.getElementById ( `` myDiv '' ) .innerHTML=text ; } function recursiveCall ( counter ) { if ( counter ) { setTimeout ( function ( ) { recursiveCall ( -- counter ) ; changeText ( counter ) ; } ,750 ) ; } } recursiveCall ( 10 ) ;
How does Javascript manages recursive calls ?
JS
I just do n't know what to think anymore . It seems like the people who made javascript went out of their way to allow it to be written a million different ways so hackers can have a field day.I finally got my white list up by using html agility pack . It should remove As it is not in my white list plus any onclick , o...
< scrpit > < /script > < IMG SRC= '' javascript : alert ( 'hi ' ) ; '' > < IMG SRC= & # 106 ; & # 97 ; & # 118 ; & # 97 ; & # 115 ; & # 99 ; & # 114 ; & # 105 ; & # 112 ; & # 116 ; & # 58 ; & # 97 ; & # 108 ; & # 101 ; & # 114 ; & # 116 ; & # 40 ; & # 39 ; & # 88 ; & # 83 ; & # 83 ; & # 39 ; & # 41 ; > // will work app...
How do you fight against all these ways ? -Javascript and its million different ways you can write it
JS
As an example , let 's say I have a class that only emits three possible events – 'pending ' or 'success ' or 'failure ' . Additionally , the type of the argument received in the eventHandler depends on which event was emitted –if 'pending ' , the eventHandler receives no argumentif 'success ' , the eventHandler receiv...
// @ flowimport EventEmitter from 'events'type CustomEventObj = { | pending : void , success : number , error : Error| } declare class MyEventEmitter extends EventEmitter { on < K : $ Keys < CustomEventObj > > ( eventName : K , eventHandler : ( e : $ ElementType < CustomEventObj , K > , ... args : Array < any > ) = > v...
Limiting the type of ` eventName ` in a class that extends EventEmitter with Flow ?
JS
I built the following component in React : There is a table of friends here , and a form for adding friends.The table gets its data from the 'data ' array and displays it using the map function.For some reason , when I update the array the array becomes an object , and gets an error that data.map is not a function.What...
import React , { useState } from 'react ' ; export default function Exemple ( ) { var friend = function ( id , firstName , lastName ) { this.id = id ; this.firstName = firstName ; this.lastName = lastName } var [ data , setData ] = useState ( [ new friend ( 1 , 'jon ' , 'well ' ) ] ) var newFriend = new friend ( ) ; fu...
Why is data.map not a function ?
JS
I receive data like this from an API I 'm trying to display this in a bar chart using apex charts in my react app however I ca n't seem to format the data in the correct way to get apex to display anything . I have tried formatting in javascript like this : Which seems to be what the documentation suggest however it do...
{ `` Bob Knight '' : 30774.72000002 , `` Samuel Herman '' : 10310.61000004 , `` Lucie Perry '' : 26308.41 , `` Andreas Smith '' : 8960.189999999999 , `` Frederic Smith '' : 2029.5000000599998 , } { { x : `` Bob Knight '' , y : '' 30774.720002 '' } , ... } constructor ( props ) { super ( props ) ; this.state = { options...
Can not get data formatted correctly for apexcharts
JS
I have some JQuery plugins that need initialising , normally this could be done using $ ( document ) .ready ( function ( ) { } ) but this does n't appear to work when doing it within a vue components created event . With this in mind , I 've made use of this. $ nextTick ( function ( ) { } ) but this does n't seem to wo...
created : function ( ) { this. $ nextTick ( function ( ) { window.materialadmin.AppOffcanvas.initialize ( ) } ) } setTimeout ( function ( ) { window.materialadmin.AppOffcanvas.initialize ( ) } , 1000 )
Vuejs - When should jquery plugins be initialised
JS
In a legacy MVC 5 web app I want the user to be able to continue browsing after clicking a button which makes an ajax call to a long running action . ( Note : The action returns void - I am not interested in the response ) When I click the button I am unable to make any other requests until the action completes.Edit : ...
$ ( ' # EmailReport ' ) // .click ( function ( ) { $ .ajax ( { type : `` POST '' , url : '/Home/EmailReport ' , complete : function ( ) { console.log ( `` done '' ) } , async : true } ) ; } ) ; [ HttpPost ] public async Task EmailReport ( ) { // for testing - sleep for 10 seconds await Task.Delay ( TimeSpan.FromSeconds...
Why ca n't I browse to other pages after making an ajax call ?
JS
I am maing an ajax call via jquery and in server side I am using PHP . The purpose is to bring a big JSON data from server side . As the JSON size is big that is why I am using gzip compression while sending the data.In server side ; Now I am seeing significant amount of reduce in data size which is being transferred ....
ob_start ( 'ob_gzhandler ' ) ; header ( 'Content-Encoding : gzip ' ) ;
Sending data in gzip format caused the ajax progress stopped for a while
JS
I was just going through the code of jQuery and came across the function merge . I checked out the code of this function : Now if you go through the code , you will come across the following if check : This somehow does n't make sense to me , what exactly is this check for , and what is it doing ? len is clearly define...
merge : function ( first , second ) { var len = +second.length , j = 0 , i = first.length ; while ( j < len ) { first [ i++ ] = second [ j++ ] ; } // Support : IE < 9 // Workaround casting of .length to NaN on otherwise arraylike objects ( e.g. , NodeLists ) if ( len ! == len ) { while ( second [ j ] ! == undefined ) {...
Perplexing if condition in jQuery merge function
JS
I need something that takes a string , and divides it into an array.I want to split it after every space , so that this - '' Hello everybody ! '' turns into -- - > [ `` Hello '' , `` Everybody ! `` ] However , I want it to ignore spaces inbetween apostrophes . So for examples - `` How 'are you ' today ? '' turns into -...
function getFixedArray ( text ) { var textArray = text.split ( ' ' ) ; //Create an array from the string , splitting by spaces . var finalArray = [ ] ; var bFoundLeadingApostrophe = false ; var bFoundTrailingApostrophe = false ; var leadingRegExp = /^'/ ; var trailingRegExp = / ' $ / ; var concatenatedString = `` '' ; ...
Splitting string to array while ignoring content between apostrophes
JS
Imagine we have the following code in an HTML file : Is it possible to invoke function foo from the script tag with id tag-2 ? I 'm just curious to know if there is any cross-browser solution ? Thank 's guys.Ok we have two very relevant proposals - the one that I marked for accepted answer and another one of the commen...
< script id='tag-1 ' > function foo ( ) { alert ( `` this is foo-1 '' ) ; } < /script > < script id='tag-2 ' > function foo ( ) { alert ( `` this is foo-2 '' ) ; } < /script > < script id='tag-3 ' > function foo ( ) { alert ( `` this is foo-3 '' ) ; } < /script >
Is it possible to refer to function or object from particular script tag in HTML file
JS
I 'm developing a ReactJS application , and I can import classes from a library in two ways . The first is using one import clause and specifying the classes I want in brackets : The second one is specifying each class in a different import clause : What 's the difference between these two methods ? Which one is best ?
import { makeStyles , CssBaseline , Box } from ' @ material-ui/core ' ; import makeStyles from ' @ material-ui/core/makeStyles ' ; import CssBaseline from ' @ material-ui/core/CssBaseline ' ; import Box from ' @ material-ui/core/Box ' ;
Importing class by class or the whole module , which one is the best ?
JS
Consider I have an arrayI want to append json1 to first item of array1 so the resultant looks likeI am sure push does n't work here . I am not sure how to proceed further .
let array1 = [ { a:1 , b:2 } , { e:5 , f:6 } ] let json1 = { c:3 , d:4 } array1 = [ { a:1 , b:2 , c:3 , d:4 } , { e:5 , f:6 } ]
Append JSON data to existing array of objects in Node.js
JS
I know the question title is a bit confusing so please excuse me- hopefully I can explain my problem.I have a data structure like so : And my code is currently like this : ( Please bear in mind that I have a bigger , working version , but with an un-nested structure , so this is just for sandboxing ) .Anyway , so imagi...
{ `` _data '' : { `` Test Alignment Form '' : [ { `` review_form '' : `` Test Alignment Form '' , `` rvee_uid '' : `` 52 '' , `` firstName '' : `` Joe '' , `` lastName '' : `` Bloggs '' , `` status '' : `` NOT_STARTED '' , `` status_clean '' : `` Not started '' } , { `` review_form '' : `` Test Alignment Form '' , `` r...
Dynamically filtering by parent node in nested JSON ( BackboneJS )
JS
When I put the following code on my page.Then anything below will became nothing , can anyone tell me why ? Thanks alot.Sorry , I am very new in web development.Thanks
< script type= '' text/javascript '' src= '' ../../Scripts/jquery-1.4.1.js '' / >
Putting Javascript source , then immediately the page not working
JS
I have a select : Where p.value is [ 'AAAAA ' , 'BBBBB ' , 'CCCCC ' ] but when I select an option the select updates and shows a new bunch of options like : I 've obviously structured things wrong by using the same value in model and options . What is the correct way to do things ?
< select ng-model= '' p.value '' ng-options= '' q for q in p.value '' > < option value= '' '' > Select an animation < /option > < /select > < option > A < /option > < option > A < /option > < option > A < /option > < option > A < /option > < option > A < /option >
How do I prevent AngularJS binding recursively ?
JS
I have a simple list : From this I want to build 3 < select > < /select > .The first one will contain the first items of the array separated by _.So [ `` a '' , '' a '' , '' a '' , '' f '' , '' f '' , '' f '' ] The second [ `` b '' , '' b '' , '' e '' , '' t '' , '' t '' , '' u '' ] The third [ `` c '' , '' d '' , '' g...
$ scope.myArr = [ `` a_b_c '' , '' a_b_d '' , '' a_e_g '' , '' f_t_r '' , '' f_t_g '' , '' f_u_m '' ] ;
Angularjs : Select combination from a list
JS
I 've got an array of objects that looks like this : and where there are multiple objects for a given person - > I want to keep the top `` X '' . For example : a. top 1 result for a person Result would look like this : b. top 2 results for a person Result would look like this : Is there a way to achieve this using some...
[ { person : 'Fred ' , scoreTotal : 29 } , { person : 'Alice ' , scoreTotal : 34 } , { person : 'Alice ' , scoreTotal : 22 } , { person : 'Mary ' , scoreTotal : 14 } , { person : 'Bob ' , scoreTotal : 33 } , { person : 'Bob ' , scoreTotal : 13 } , { person : 'Bob ' , scoreTotal : 22 } , { person : 'Joe ' , scoreTotal :...
How can I remove an object from array of objects based on max value in javascript
JS
I am switching from jQuery 2.0.3 to 2.1.0.I noticed that in v2.1.0 the css transition property is ignored when setting css properties directly $ ( ' # someElement ' ) .css ( 'width ' , '100px ' ) ; In v2.0.3 , my element will maintain it 's css transition , whereas I lose that in v2.1.0.I am wondering why this is treat...
$ ( function ( ) { $ ( '.myClass ' ) .css ( 'width ' , '100px ' ) ; } ) ; .myClass { height : 50px ; width : 300px ; background-color : red ; transition : width 3s ; } < script src= '' https : //ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js '' > < /script > < div class= '' myClass '' > < /div > $ ( function ...
Changing css with jQuery 2.1+ ignores transition property
JS
So ... ES6¹ ( which happens to be standardized a few hours ago ) brings default parameters for functions similar to those in PHP , Python etc . I can do stuff like : MDN says that the default value for the parameter is evaluated at call time . Which means each time I call the function , the expression 'dum ' is evaluat...
function foo ( bar = 'dum ' ) { return bar ; } foo ( 1 ) ; // 1foo ( ) ; // 'dum'foo ( undefined ) ; // 'dum ' let x = { foo ( bar = this.foo ) { return bar ; } } let y = { z : x.foo } x.foo ( ) === y.z ( ) ; // what ? let x = ' x from global ' ; function bar ( thing = x ) { return thing ; } function foo ( ) { let x = ...
How does ` this ` work in default parameters ?
JS
I noticed that when enumerating the properties of an object , that it seems like a snapshot of the current properties is taken at start of the loop , and then the snapshot is iterated . I feel this way because the following does n't create an endless loop : demo http : //jsfiddle.net/kqzLG/The above code demonstrates t...
var obj = { a:0 , b:0 } , i=0 ; for ( var k in obj ) { obj [ i++ ] = 0 ; } alert ( i ) // 2 var obj = { a:0 , b:0 } , i=0 ; for ( var k in obj ) { i++ ; delete obj.b ; } alert ( i ) // 1
for in loop and the delete operator
JS
From my experience I know three different ways to execute a Javascript function when a user clicks on a linkUse the onclick attribute on the linkUse the href on the link Do n't touch the link , do everything in js ( in the Javascript we will stop the default event , and call the function ) Which one is better ? What ar...
< a href= '' # '' onclick= '' myfunction ( ) ; return false ; '' > click me < /a > < a href= '' javascript : myfunction ( ) ; '' > click me < /a > < a href= '' # '' > click me < /a >
What is the best way to execute a function when user clicks on a link ?