lang
stringclasses
4 values
desc
stringlengths
2
8.98k
code
stringlengths
7
36.2k
title
stringlengths
12
162
JS
I am having trouble googling this . In some code I see/ [ \ [ ] / looks to be 1 parameter . What do the symbols do ? It looks like it 's replacing [ ] with \ [ \ ] but what specifically does / [ \ [ ] / do ?
name = name.replace ( / [ \ [ ] / , '' \\\ [ `` ) .replace ( / [ \ ] ] / , '' \\\ ] '' ) ;
What does / [ \ [ ] / do in JavaScript ?
JS
LIVE : http : //jsbin.com/ibofis/1/editthis working ok , but i would like add for this addClass for 3 next elements.For example if i click on c then class .red should add for : c , d , e and f.How can i make it ?
< tr > < td > < div class= '' click '' > a < /div > < /td > < /tr > < tr > < td > < div class= '' click '' > b < /div > < /td > < /tr > < tr > < td > < div class= '' click '' > c < /div > < /td > < /tr > < tr > < td > < div class= '' click '' > d < /div > < /td > < /tr > < tr > < td > < div class= '' click '' > e < /di...
next 3 from this
JS
I want to build an object obj1 with property obj2 , which is another object . To avoid redeclaring obj1 and obj2 , I use the following code : Assume , obj1 and obj1.obj2 are n't defined yet , the code causes the browser to report the error `` obj1 is not defined '' .If I change the code to : Then there 's no error , wh...
if ( ! obj1 ) obj1 = { } ; if ( ! obj1.obj2 ) obj1.obj2 = { } ; // code to use obj1 if ( typeof obj1==='undefined ' ) obj1 = { } ; if ( ! obj1.obj2 ) obj1.obj2 = { } ; // code to use obj1
Inconsistent behavior in JavaScript 's conditional checking
JS
I am trying to delete all even numbers from the array but it just doesnt delete all of them . not sure whyconsole.log ( arr ) ; gives this - [ 3 , 45 , 7 , 56 , 345 ] instead of this [ 3 , 45 , 7 , 345 ] Any ideas ?
var arr = [ 3,45,56,7,88,56,34,345 ] ; for ( var i = 0 ; i < arr.length ; i++ ) { if ( arr [ i ] % 2 === 0 ) { arr.splice ( i,1 ) ; } }
Can not delete even numbers from my array
JS
I have a feeling that this is a just a harmless bug but I 'd still like to understand what 's going on.I was playing with some code to render a Peano curve on a canvas that involves expressing logical coordinates in base 3 when I noticed that a function was returning absurdly long strings in Chrome . Looking more close...
( .1 ) .toString ( 3 )
Why does Chrome produce 1099 digits after the dot for ( .1 ) .toString ( 3 ) ?
JS
I am trying to generate a template using slush , my code repo is here : https : //github.com/NaveenDK/slush-template-generator/blob/master/templates/react-native-app/MediaButtons.js Even though the template files run fine on its own , when I try to generate using slush with the following lines in the MediaButtons.js fi...
let match = /\ . ( \w+ ) $ /.exec ( filename ) ; let type = match ? ` image/ $ { match [ 1 ] } ` : ` image ` ;
Variable with reg expression is not recognized in js
JS
Trying to solve this question on Codewars.I 've seen other articles that deal with shuffling / scrambling a string randomly . But what about scrambling a string according to the values in a given array ? I.e . abcd given the array [ 0 , 3 , 2 , 1 ] will become acdb because : a moves to index 0b moves to index 3c moves ...
function scramble ( str , arr ) { let newArray = str.split ( `` '' ) ; let finalArray = [ ] ; for ( let i = 0 ; i < str.length ; i++ ) { console.log ( newArray ) ; finalArray.push ( newArray.splice ( arr [ i ] , 1 ) ) ; } return finalArray ; } console.log ( scramble ( `` abcd '' , [ 0 , 3 , 1 , 2 ] ) ) ;
Scramble String According to Array Values - Javascript
JS
I have problem where I have to add a parent node by selection of multiple elements.I have : Now in the above structure i have to select some elements which have class Node by their ids and add a parent single parent element for them.It should look something like this , if I select Node 2 & 3 for example : Is there some...
< g class= '' group '' > < g class= '' Node '' id= '' 1 '' > ... < /g > < g class= '' Node '' id= '' 2 '' > ... < /g > < g class= '' Node '' id= '' 3 '' > ... < /g > < g class= '' Node '' id= '' 4 '' > ... < /g > < /g > < g class= '' group '' > < g class= '' Node '' id= '' 1 '' > ... < /g > < g class= '' Grp '' > < g c...
Add single parent node by selecting multiple elements in D3
JS
I have a function that I want it execute alternating processes every time it 's triggered . Any help on how I would achieve this would be great .
function onoff ( ) { statusOn process /*or if on*/ statusOff process }
What is the best way to have a function toggle between two different processes ?
JS
I am new to HTML5 canvas and looking to make a few circles move in random directions for a fancy effect on my website . I have noticed that when these circles move , the CPU usage is very high . When there is just a couple of circles moving it is often ok , but when there is around 5 or more it starts to be a problem.H...
export default function Circle ( { color = null } ) { useEffect ( ( ) = > { if ( ! color ) return let requestId = null let canvas = ref.current let context = canvas.getContext ( `` 2d '' ) let ratio = getPixelRatio ( context ) let canvasWidth = getComputedStyle ( canvas ) .getPropertyValue ( `` width '' ) .slice ( 0 , ...
Optimise canvas drawing of a circle
JS
So , here is the issue.I have something like : Am I perfectly safe knowing no script can tamper or access __hostObject ? ( If they can , I have an CSRF vulnerability or worse . ) Note 1 : This is for a browser extension . I have better hooks than other scripts running on the page . I execute before them and I 'm done b...
// Dangerous __hostObject that makes requests bypassing // the same-origin policy exposed from other code . ( function ( ) { var danger = __hostObject ; } ) ( ) ; delete __hostOBject ;
JavaScript completely `` tamper safe '' variables
JS
So , a junior programmer on my team today wrote the following piece of code : Which is obviously not going to do what he intended , which was this : But what I ca n't explain is why exactly the first snippet of code would n't work ! Or why it evaluates to true if 'status ' is set to 'incomplete ' but to false when it '...
if ( status === ( `` incomplete '' || `` unknown '' ) ) if ( status === `` incomplete '' || status === `` unknown '' ) )
checking a variable value using an OR operator
JS
I try to implement the Lucas–Lehmer test ( LLT ) primality test for Mersenne numbers ( https : //en.wikipedia.org/wiki/Lucas % E2 % 80 % 93Lehmer_primality_test ) . It should be polynomial and hence fast . Here is my code : Here is attempt to use the algorithm implemented above : https : //oobarbazanoo.github.io/findPr...
function countPrimeNumberWithDigits ( numberOfDigits ) { if ( numberOfDigits < 1 ) { return `` Please give a valid input ! `` ; } var shouldBeMoreThanThis = Math.pow ( 10 , numberOfDigits-1 ) , n = 3 , M = countMWithIndex ( n ) ; while ( M < shouldBeMoreThanThis ) { n += 2 ; M = countMWithIndex ( n ) ; } console.log ( ...
Problems with implementing Lucas–Lehmer primality test
JS
If I have a plugin that makes reference to the same JQuery objects constantly I figure I should cache the reference.I was wondering if anyone knew off hand how much memory a jquery reference takes up ? Also I do understand that the price of the JQuery lookup far exeeds the price of the reference itself.vs
$ ( 'sameElement ' ) this.sameElement = $ ( 'sameElement ' ) ; this.sameElement
Hom much memory does a Jquery Element Reference Take Up ?
JS
Let 's say that I want to get a list of all the variables in the window that are user-defined . In other words , they 're not properties or objects that the browser has created or defined in ECMAScript.For example , let 's say there 's this script on a page : I would like to be able to loop through window and get a lis...
< script > window.__ $ DEBUG = true ; var Analytics = function ( ) { } ; < /script > var nonNatives = ( function nonNative ( scope ) { var result = { } ; for ( var child in scope ) { if ( ! isNative ( child ) ) { result [ child ] = scope [ child ] ; } } return result ; } ) ( window ) ;
JavaScript : Enumerate non-native objects in given scope
JS
Possible Duplicate : What is the ! ! ( not not ) operator in JavaScript ? I 'm looking through some code and see an IF statement that looks like the one below . Can anyone tell me why there are two ! ! s instead of one ? I 've never seen this before and ca n't dig anything up on Google because it 's ignoring the specia...
if ( ! ! myDiv & & myDiv.className == 'visible ' ) { }
Why two ! ! s in an IF statement when using & & ?
JS
I try to use the raster reprojection of a map following this example . If I change the example kavrayskiy7 projection by the Azimuthal Equidistant projection , it should project the Earth onto a disc ( the image of the projection map ) . However , the raster reprojection goes beyond that disc and fills the entire canva...
var projection = d3.geo.azimuthalEquidistant ( ) .scale ( 90 ) .translate ( [ width / 2 , height / 2 ] ) .clipAngle ( 180 - 1e-3 ) .precision ( .1 ) ; if ( λ > 180 || λ < -180 || φ > 90 || φ < -90 ) { i += 4 ; continue ; } var path = d3.geo.path ( ) .projection ( projection ) ; var bdry = svg.append ( `` defs '' ) .app...
How to fix map boundaries on d3 cartographic raster reprojection ?
JS
I understand that the following code wraps a number into an object : I therefore expect and understand the following : However , I also understand that an object is a list of key/value pairs . So I would have expected the following to be different : What does the structure of x look like ? And why does it not appear to...
var x = Object ( 5 ) ; alert ( x == 5 ) ; //truealert ( x === 5 ) ; //false alert ( JSON.stringify ( 5 ) ) ; //5alert ( JSON.stringify ( x ) ) ; //5
Understanding JavaScript Object ( value )
JS
This is the very simple modal window that I am using to select a task.There are three < select > s inside that are selectized . I can post this code if requested but I do not think it is relevant.Basically the problem is that the dropdowns extend beyond the bottom of the modal window in some cases ( this is what I want...
< div id= '' add_task_modal '' class= '' modal fade '' tabindex= '' -1 '' role= '' dialog '' > < div class= '' modal-dialog '' role= '' document '' > < div class= '' modal-content '' > < div class= '' modal-header '' > < h5 class= '' modal-title '' > Lookup Task < /h5 > < /div > < div class= '' modal-body '' > < select...
Selectize dropdown selection outside of bootstrap modal window causes the modal to close
JS
I have a really simple page with a form which I 'm trying to prevent from sending with jQuery , but the code is surprisingly not working . Any ideas ?
< ! DOCTYPE html > < html > < head > < script src= '' http : //code.jquery.com/jquery-2.1.1.min.js '' > < /script > < script > $ ( `` # searchForm '' ) .submit ( function ( e ) { e.preventDefault ( ) ; } ) ; < /script > < /head > < body > < form id= '' searchForm '' > < input name= '' q '' placeholder= '' Go to a Websi...
PreventDefault not preventing form to send
JS
When I run npm run-script build to bundle my React app , once the bundle is complete the following webpack bundle analyzer launches which shows what my app 's bundle is comprised of : Although I am not positive of it , this seems like a fairly large build , which may be slowing down my app . It appears that d3 is one o...
import React , { Component } from 'react ' ; import * as d3 from 'd3 ' ; import * as d3Hexbin from 'd3-hexbin ' ; class SomeClassHere extends Component { ...
Reducing size of React / MERN Stack Bundle - mainly removing duplicative D3
JS
I am creating a simple interactive doll dress up game where the user can pick different attributes to assign to the doll through three separate drop down menus , such as hair colour , dress type , etc.I have a base image that is in a div which I want to overlay the images onto.The images are called by a function : I ha...
< div id= '' display_here '' > < img src= '' base.png '' / > < /div > function createDoll ( userChoice ) { var output = document.getElementById ( `` display_here '' ) ; output.innerHTML = `` '' ; var links = [ `` redhair.png '' , `` blondehair.png '' , `` brownhair.png '' , ] ; var choices = [ `` Red '' , `` Blonde '' ...
Overlaying image in HTML
JS
I made an HTML5 game that consists of many small levels . When the player get 's to the doors , another level is loaded . When a level is loading it basically just sets all the instance arrays to [ ] and then pushes stuff into them , by creating new instances of things , for example : But , it has come to my attention ...
enemies = [ ] //this has previously been full of pointers from the old levelfor ( i = 0 ; i < n_enemies ; i ++ ) enemies.push ( new Enemy ( ) ) ;
In Javascript , should I delete previous level 's instances after loading a new one ?
JS
I have two really long arrays containing `` picture names '' and `` picture files '' . The first one represents the actual name of the pictures , while the second one is just the file name . For example : I have about 1000 items in each array in several languages ( the picture files are always the same ) . I 'm `` recy...
picturenames [ 0 ] = ' 0 - zero ' ; picturenames [ 1 ] = ' 1 - one ' ; picturenames [ 2 ] = ' 1 o\'clock ' ; ... picturefiles [ 0 ] = 'numbers-zero.jpg ' ; picturefiles [ 1 ] = 'numbers-one.jpg ' ; picturefiles [ 2 ] = 'time-1.jpg ' ; ... var matches = picturenames.filter ( function ( windowValue ) { if ( windowValue )...
how can I filter an array without losing the index ?
JS
I want to make a rotated animation of a font icon , but I can not let the center be the right place , The rotation is always offset a little.Here is the example : JSFiddle : https : //jsfiddle.net/217z69sm/2/
@ keyframes circle { from { transform : rotate ( 0deg ) ; } to { transform : rotate ( 360deg ) ; } } div { padding:0 ; margin:0 ; } .container { position : absolute ; top:50px ; left:50px ; border:1px solid red ; font-size:20px ; } .inner { line-height:0 ; animation-name : circle ; animation-duration : 1s ; animation-i...
How to make font icon be full of a block element ?
JS
I 'm working with older versions of material-ui with no possibility to upgrade.I am trying to change the background of the Paper component based on a few combinations of the props . I do n't think it 's complicated to require use of the makeStyles HOC . Is this possible ? I think the problem is this line : classes= { {...
import React from `` react '' ; const correctBackgroundColor = { root : { width : 30 , height : 30 , border : `` 1px solid lightgrey '' , backgroundColor : props = > { if ( props.ledIsOn === true & & props.ledColorType === `` Green '' ) { return `` # 00FF00 '' ; } if ( props.ledIsOn === true & & props.ledColorType === ...
React class components - conditional styling based on props
JS
Given the following snippet : In Safari , it will display only this : In other browsers , like Chrome and Firefox , it will display the someProperty property , along with native properties like length : It 's worth mentioning that things like console.dir , console.table or console.log ( JSON.stringify ( myArray ) ) wo ...
const myArray = [ `` foo '' , `` bar '' , `` baz '' ] ; myArray.someProperty = `` foobar '' ; console.log ( myArray ) [ `` foo '' , `` bar '' , `` baz '' ] ( 3 ) Array ( 3 ) 0 : `` foo '' 1 : `` bar '' 2 : `` baz '' someProperty : `` foobar '' length : 3
Displaying array properties in Safari 's console
JS
I have next code ( the borders should be shown , i do n't know why they dissapeared in demo ) , the screen is separated in 8 equal parts and on each part should be ripple effect . All works fine in Chrome , Mozzila , Opera , Safari , but ripple overflows the element in IE . How can i fix it ?
$ ( document ) .ready ( function ( ) { $ ( `` .button_line '' ) .on ( 'click ' , `` .menu_button '' , function ( e ) { DoRipple ( $ ( this ) , e ) ; } ) ; } ) ; var parent , ink , d , x , y ; function DoRipple ( parent , e ) { if ( parent.find ( `` .ink '' ) .length == 0 ) { parent.prepend ( `` < span class='ink ' > < ...
CSS animation overflows the div
JS
This question is simply to curiosity.Via consolereturnsandreturnsAlsoreturnsWhere is the trick ? Thanks
parseInt ( 1111111111111111,2 ) // 16 1 's 65535 parseInt ( 11111111111111111,2 ) // 17 1 's 65535 // 16 1 's 17 1'sif ( parseInt ( 1111111111111111,2 ) === parseInt ( 11111111111111111,2 ) ) true
Why this is true : parseInt ( 1111111111111111,2 ) === parseInt ( 11111111111111111,2 )
JS
As far as I know there are three ways of finding out if an object is an Arrayby isArray function if implementedby toStringand by instanceofIs there any reason to choose one over the other ?
Array.isArray ( ) Object.prototype.toString.apply ( obj ) === `` [ object Array ] '' obj instanceof Array
Whats the best way to find out if an Object is an Array
JS
I 'm validating a form , but I 'm having problems with this particular select validation.Here 's the JS for the validation : It does n't submit , but it does n't add the class error either . A fiddle .
< div class= '' control-group '' id= '' sukupuoli '' > < label class= '' control-label '' > Sukupuoli < /label > < div class= '' controls '' > < select name= '' sukupuoli '' > < option value= '' Valitse '' > Valitse < /option > < option value= '' Naaras '' > Naaras < /option > < option value= '' Uros '' > Uros < /optio...
Validate select field
JS
I am trying to plot 2 line series data in ZingChart feed.Below is my script code.It gets displayed , but looses the line nature of the graph.Is this the right way ? Is there a better method ? . Later I am planning to let user decide how many plots to be allowed in chart at runtime.Is there something in ZingChart that I...
< script > var chartData = { `` type '' : '' line '' , `` refresh '' : { `` type '' : `` feed '' , `` transport '' : `` js '' , `` url '' : `` feed ( ) '' , `` interval '' : 1000 } , `` series '' : [ { `` values '' : [ ] } , { `` values '' : [ ] } ] } ; window.onload = function ( ) { zingchart.render ( { id : `` chartD...
Zing feed plotting multiple series in 1 chart
JS
Is it expected that fordiv the div.data ( ) would be an empty object ? Demo : http : //jsfiddle.net/nWCKt/What are the requirements for data- attributes names ? Created a ticket in jquery bug tracker : http : //bugs.jquery.com/ticket/14376
< div data-foo-42= '' bar '' > < /div >
Data attribute name with digits
JS
I have a JavaScript object with a privileged method . When this method has completed , I would like it to call itself ( after a small timeout ) and continue running indefinitely . Unfortunately , the method only runs twice , then it stops without any error ( tested in Chrome and IE with the same results ) .The code is ...
function Test ( ) { // ... private variables that testMethod needs to access ... this.testMethod = function ( ) { alert ( `` Hello , from the method . `` ) ; setTimeout ( this.testMethod , 2000 ) ; } ; } var myTest = new Test ( ) ; myTest.testMethod ( ) ;
Why wo n't this Javascript method keep calling itself ?
JS
I have a problem with event object passed to the function in drop event . In my code , div # dropArea has it 's drop event handled by firstDrop function which does some animations and then calls the proper function dropFromDesktop which handles the e.dataTransfer.files object . I need this approach in two separate func...
function firstDrop ( ev ) { var $ this = $ ( this ) ; //when I call the function here , it passes the event with files inside it //dropFromDesktop.call ( $ this , ev ) ; $ this.children ( '.welcomeText ' ) .animate ( { opacity : ' 0 ' , height : ' 0 ' } , 700 , function ( ) { $ ( ' # raw .menu ' ) .first ( ) .slideDown...
Event object eaten by jQuery animation callback
JS
I have an array of start/stop times . I basically want to display the time it took for each entry , as well as the total time for all of them . Here is the code I wrote to try to do that : However , I am losing accuracy . As you can see , the individual times do n't add up to the mainTimer value . It is always off by ....
function timeFormatter ( milliseconds ) { const padZero = ( time ) = > ` 0 $ { time } ` .slice ( -2 ) ; const minutes = padZero ( milliseconds / 60000 | 0 ) ; const seconds = padZero ( ( milliseconds / 1000 | 0 ) % 60 ) ; const centiseconds = padZero ( ( milliseconds / 10 | 0 ) % 100 ) ; return ` $ { minutes } : $ { se...
Formatting timers without losing accuracy ?
JS
For example , if I want a grabbing icon for my cursor , in CSS I would use this : But let 's say , I want to implement this via JavaScript but still being able to cover all three , how do I do this ? Do I just assign them in three lines -- does JavaScript fallback to the previous assignment ?
div { cursor : -moz-grabbing ; cursor : -webkit-grabbing ; cursor : grabbing ; } document.getElementById ( 'theDiv ' ) .style.cursor = '-webkit-grabbing ' ; document.getElementById ( 'theDiv ' ) .style.cursor = '-moz-grabbing ' ; document.getElementById ( 'theDiv ' ) .style.cursor = 'grabbing ' ;
Updating CSS via plain JavaScript ... how do I update if the property uses vendor prefixes ?
JS
In our internal angularjs project , one of the services has $ http.head ( ) call which I 'm trying to test.For testing , I 'm using Fake HTTP backend provided by angular-mocks . Here is the relevant code : Running the test results into the following error : After digging a little bit , I 've found the relevant github i...
it ( 'handle status code 200 ' , inject ( function ( $ httpBackend , ConnectionService ) { spyOn ( Math , 'random ' ) .andReturn ( 0.1234 ) ; httpBackend = $ httpBackend ; httpBackend.expectHEAD ( 'ping ? rand=1234 ' ) .respond ( 200 ) ; ConnectionService.sendRequest ( ) ; httpBackend.flush ( ) ; expect ( ConnectionSer...
expectHEAD is documented but not implemented ?
JS
I am capturing natural language user input and I need to check it against a predefined `` correct '' version . This much is trivial , but I am unsure about how to handle variations in contractions in the English language.Suppose I 'm expecting the sentence I 'm positive you do n't know what you 're doing . The match ne...
`` I 'm positive you do n't know what you 're doing . `` `` I am positive you do n't know what you 're doing . `` `` I am positive you do not know what you 're doing . `` `` I am positive you do not know what you are doing . `` `` I 'm positive you do n't know what you are doing . `` ...
How to deal with English contractions programmatically [ Regex , JS , Ruby ]
JS
I 'm trying to determine if a string contains a word from an array by using jQuery 's inArray function , which is shown here https : //stackoverflow.com/a/18867667/5798798In my example below , it should print 'hi ' to the console twice as the word 'Hello ' is in the string twice and is in the array , however it does n'...
var array = [ `` Hello '' , `` Goodbye '' ] ; a = document.getElementsByClassName ( `` here '' ) ; for ( i = 0 ; i < a.length ; i++ ) { itag = a [ i ] .getElementsByTagName ( `` i '' ) [ 0 ] ; if ( jQuery.inArray ( itag.innerHTML , array ) ! == -1 ) { console.log ( 'hi ' ) ; } } < script src= '' https : //ajax.googleap...
Unable to determine if a string contains a word from an array
JS
Html code : here validations are working fine . but not the confirm code.Javascript code : confirm displays dialog but onclick of 'ok ' button it is not submitting the form is there any way to submit form on confirm dialog using javascript function . Thanks in advance .
< form action='save.php ' method= '' post '' onsubmit= '' return validate ( this ) '' > some inputs here ... < /form > function validate ( theForm ) { validations here for input fields ... . /*confirm dialog*/ var sure = confirm ( `` Are you sure to proceed ? `` ) ; if ( sure == false ) { return false ; } else { return...
How to give confirm dialog onsubmit of a form element using javascript function
JS
I have a very simple html and javascript.The result displays a Hello and good bye string . I moved the goodbye function to its own file `` goodbye.js '' So my first html now looks like thisNow if I run the html again , it only displays Hello . I did not expect that . What happened ?
< html > < body > < h1 > Test function < /h1 > < p > Hello < /p > < script > function goodbye ( ) { document.write ( `` good bye '' ) ; } goodbye ( ) ; < /script > < /body > < /html > < html > < body > < h1 > Test function < /h1 > < p > Hello < /p > < script src='goodbye.js ' > goodbye ( ) ; < /script > < /body > < /ht...
Did I violate some javascript rule ?
JS
There is this Javascript function that I 'm trying to rewrite in Java : My Java adaptation : When I pass -1954896768 , Javascript version returns 70528 , while Java returns -896768 . I 'm not sure why . The difference seems to start inside the if condition : in Javascript function after the if encodingRound2 = 23400705...
function normalizeHash ( encondindRound2 ) { if ( encondindRound2 < 0 ) { encondindRound2 = ( encondindRound2 & 0x7fffffff ) + 0x80000000 ; } return encondindRound2 % 1E6 ; } public long normalizeHash ( long encondindRound2 ) { if ( encondindRound2 < 0 ) { encondindRound2 = ( ( ( int ) encondindRound2 ) & 0x7fffffff ) ...
Javascript function rewritten in Java gives different results
JS
I am looking for a regex to find some words that contains some letters.I have the word start , and by regex it should find words that contains ( s , two t 's , a , r ) , that has at least 3 letters . So it should return all these words : start , tarts , arts , art . So it should be at least three letters and contains o...
/ ( ( [ ^s ] *s ) { 1 } ) ( ( [ ^t ] *t ) { 2 } ) ( ( [ ^a ] *a ) { 1 } ) ( [ ^r ] *r ) { 1 } /g [ star ] { 3 , }
Regex to find words that contains these letters
JS
Just by seeing what I 've wrote now , I can see that one is much smaller , so in terms of code golf Option 2 is the better bet , but as far as which is cleaner , I prefer Option 1 . I would really love the community 's input on this.Option 1Option 2
something_async ( { success : function ( data ) { console.log ( data ) ; } , error : function ( error ) { console.log ( error ) ; } } ) ; something_async ( function ( error , data ) { if ( error ) { console.log ( error ) ; } else { console.log ( data ) ; } } ) ;
Which is a better way of writing callbacks ?
JS
I am tryng to fix a css bug for mobile screenswhen I click section 1 content opens and if i move till the bottom of the section one content and after that if I click section 1 content closes.but I dont see section 2 after that I see section 3 since the screen moves upwards.how to retain the section 2 in our screen.am I...
.television .chromecast .sun .sunItem > .bulb { overflow : hidden ; transition : transform .5s , max-height .5s ; transform : scaleY ( 0 ) ; box-sizing : border-box ; max-height : 0 ; transform-origin : center top ; } .television .chromecast .sun .sunItem.selected > .bulb { transform : scaleY ( 1 ) ; max-height : 100 %...
scaleY property not maintained properly for small screens
JS
I am trying to learn JavaScript ES6 which is a very cool language and I thought that I should practice a bit but I am not able to make an exercise.So how can I use object literal to copy a class.For example the class is : And I want to do something here using object literal to make the output true .
class Point { constructor ( x , y ) { this.x = x , this.y = y } add ( other ) { return new Point ( this.x + other.x , this.y + other.y ) } } var fakePoint = YOUR_CODE_HEREconsole.log ( fakePoint instanceof Point )
How can I use an object literal to make an instance of a class without useing the constructor in JavaScript ES6 ?
JS
I 'm trying to perform animation on click of box which is expected as belowWhen box is clicked it must move to the right to either 300px or right most then it should go to the bottom . Note : if it is achieved using tweenMax ( GSAP ) . Then solution is most welcomed . As described in image : Here is codepen : https : /...
$ ( function ( ) { $ ( '.box ' ) .on ( 'click ' , function ( ) { $ ( ' # wrapper ' ) .append ( this ) ; $ ( this ) .addClass ( 'elementToAnimate ' ) ; } ) ; } ) ; div.box { height : 100px ; width : 200px ; background : red ; display : inline-block ; text-align : center ; color : # fff ; font-size:26px ; margin : 0px ; ...
Why Animation is not happening as expected to place box to bottom
JS
I have html like this : and I would like to remove all elements that are n't bold . I 've tried with this code : and a couple other variations but they all either error out or remove everything . btw , are jquery selectors and jsoup selectors 100 % compatible ? I 'd like to use the answer to this in jsoup as well .
< div id= '' divTestArea1 '' > < b > Bold text < /b > < i > Italic text < /i > < div id= '' divTestArea2 '' > < b > Bold text 2 < /b > < i > Italic text 2 < /i > < div > < b > Bold text 3 < /b > < /div > < /div > $ ( '* : not ( b ) ' ) .remove ( ) ;
Jquery remove everything except for bolded
JS
In my HTML hereIn my code here , How do I prevent the alert from showing up if I clicked on the buttons , But anything except the buttons can be alerted .
$ ( document ) .click ( function ( ) { alert ( 'Document Clicked ' ) ; } ) < script src= '' https : //ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js '' > < /script > < body > < button type='button ' > CLICK [ NO ALERT ] < /button > < button type='button ' > ME [ NO ALERT ] < /button > < /body >
Onclick on document and not specific element Alert
JS
I was wonder by that when worked with chrome devtools.But it seems that typeof < object > is a `` function '' . I have n't found any explanation or references.Here is the simple example : https : //jsfiddle.net/fez34zbf/HTML : JS : console results will be : Any ideas ?
< object > < /object > < video > < /video > console.log ( typeof document.querySelector ( 'object ' ) ) ; console.log ( typeof document.querySelector ( 'video ' ) ) ; function object
Why type of < object > is a function ?
JS
I ’ d like to measure the time it takes until a DOM change done by a javascript acually is displayed.Consider this example svg file : This displays two rects which act as “ buttons ” that change the color of a circle . The additional rects and the blur and opacity are for making it more slow.The script : Now when click...
< ? xml version= '' 1.0 '' encoding= '' UTF-8 '' standalone= '' no '' ? > < svg xmlns= '' http : //www.w3.org/2000/svg '' xmlns : xlink= '' http : //www.w3.org/1999/xlink '' width= '' 1600 '' height= '' 1000 '' version= '' 1.1 '' > < script xlink : href= '' clicktest.js '' / > < defs > < filter id= '' filterBlur '' x= ...
Measure Rendering Time of Change initiated by Javascript
JS
I see a lot that function returns NOT the result but the function . The example below shows that function getWindow returns function . Why it ca n't just return variable `` win '' ? When I return result and when function ? Thank you .
var A = function ( ) { } ; A.prototype= { getWindow : function ( ) { var win = new B.window ( ) ; return ( this.getWindow = function ( ) { return win ; } ) ( ) ; } }
When function returns result and when function in JavaScript
JS
I have some code at here : html : Javascript : Actually , I 've using JQuery 2.0.2 also.In my understanding , When I click the button click me , `` < p > This is paragraph < p > '' will be replaced by < p > hello world < /p > .The first click is successful . However , many hello world with the growth rate of progressio...
< body > < p > This is a paragraph. < /p > < button > click me < /button > < /body > $ ( document ) .ready ( function ( ) { $ ( `` button '' ) .click ( function ( ) { $ ( `` p '' ) .hide ( ) .after ( ' < p > hello world < /p > ' ) ; } ) ; } ) ; < p style= '' display : none ; '' > This is a paragraph. < /p > < p > hello...
Curious about hide ( ) .after ( `` '' ) in jQuery
JS
DataEach object represents a range . I need to remove the ranges that are contained into another.That is , between two redundant objects I need to keep the longer range.I wrote this code , but I wonder if there is a better way to achieve this using lodash.Output
var ranges = [ { start : 2 , end : 5 } , { start : 8 , end : 12 } , { start : 15 , end : 20 } , { start : 9 , end : 11 } , { start : 2 , end : 6 } ] ; var Range = { contains : function ( r1 , r2 ) { return r2.start > = r1.start & & r2.end < = r1.end ; } } ; var result = _.chain ( ranges ) .filter ( function ( r2 ) { re...
Filter redundant objects from array with lodash
JS
I have this code that works : However , when I use getElementById instead of getElementsByName then it stops working . That is the method would not show the alert dialog.Of course I added a id attribute on the same tag with the name , like id= '' email '' name= '' email '' This method is called when the submit button i...
< script type= '' text/javascript '' language= '' javascript '' > function doStuff1 ( ) { var eml=document.getElementsByName ( 'email ' ) [ 0 ] .value ; msg=document.getElementsByName ( 'message ' ) [ 0 ] ; msg.value = eml + ' ' + msg.value ; alert ( 'Message has been submitted ' ) ; return true ; //return false to tes...
Replace getElementsByName with getElementsById not working
JS
I 'm writing a JavaScript interpreter for extremely resource-constrained embedded devices ( http : //www.espruino.com ) , and every time I think I have implemented some bit of JavaScript correctly I realise I am wrong.My question now is about [ ] . How would you implement one of the most basic bits of JavaScript correc...
var a = [ ] ; a [ 5 ] = 42 ; a [ `` 5 '' ] ; // 42a.length ; // 6 var a = [ ] ; a [ `` 5 '' ] = 42 ; a [ 5 ] ; // 42a.length ; // 6 var a = [ ] ; a [ `` 05 '' ] = 42 ; a.length ; // 0
How does JavaScript [ ] really work ?
JS
Ok so very new to Javascript . Trying to learn the code by simply changing the text on a button using an external javascript file . But I ca n't even get javascript to read the buttons valueexternally , in Chrome 's debug tools I see my button value is btn= '' '' . It reads the button object but ca n't read its propert...
< html > < head > < title > Test < /title > < script type= '' text/javascript '' src= '' Gle.js '' > < /script > < /head > < body > < div > < canvas id= '' Gle '' width= '' 800 '' height= '' 600 '' > < /canvas > < /div > < div > < h2 > Enter the mass and coordinates < /h2 > < input id= '' txtbox '' type= '' text '' / >...
Javascript will not pass information into function from html
JS
I 'm new to Handlebars and using version 4.1.2 . I 'm trying to move some templates which were written in PHP to Handlebars.The source of my data is a JSON feed and the structure is like this : The output of my HTML template ( in the PHP version ) was as follows : EuropeGroup 1FF1AFF1BGroup 2FF2AAsiaGroup 999FF999AFF99...
[ { `` regulations_label '' : `` Europe '' , `` groups_label '' : `` Group 1 '' , `` filters_label : `` FF1A '' } , { `` regulations_label '' : `` Europe '' , `` groups_label '' : `` Group 1 '' , `` filters_label : `` FF1B '' } , { `` regulations_label '' : `` Europe '' , `` groups_label '' : `` Group 2 '' , `` filters...
Handlebars - calculation based on array key within a template
JS
What is a dom event like window.onload that fires when all assets are loaded including those with async= '' true '' ?
< ! doctype html > < html lang= '' en '' > < head > < script src= '' index.js '' type= '' text/javascript '' async= '' true '' > < /script > < /head > < body > < script type= '' text/javascript '' > window.onload = function ( ) { } // run when index.js loaded ? ? ? < /script > < /body > < /html >
onload event that fires when all assets are loaded , including those with async=true
JS
I am looking through some code that someone else have written and I noticed this strange javascript if syntax.. Basicly , it looks like this : This is one of those things that is hard to google.. Any Javascript gurues that can explain this ?
// This is understandable ( but I dont know if it have relevance ) var re = new RegExp ( `` ^ '' + someVar + `` _ '' , `` i '' ) ; // ! ! ~ ? ? ? What is this black magic ? if ( ! ! ~varA.search ( re ) ) { ... }
Javascript - Weird if syntax
JS
I have these lines in my view.cshtml : But now there is a red line under ; in javascript codes and the error is Syntax error.What is the problem ?
$ ( `` document '' ) .ready ( function ( ) { @ { var cx = Json.Encode ( ViewBag.x ) ; var cy = Json.Encode ( ViewBag.y ) ; } var x = @ cx ; var y = @ cy ; } ) ;
How to fill javascript variables with c # ones ?
JS
I am trying to write a Firefox add-on for personal use and to learn a bit more about both JavaScript and the Firefox Add-on SDK . The add-on should open a vivo.sx URL and then automatically start the player , but I have 2 issues . I hope you guys can help me.The relevant add-on-code : content-scriptThe first problem is...
function vivoplay ( ) { pageMod.PageMod ( { include : `` https : //vivo.sx/* '' , contentScriptFile : `` ./vivoplay.js '' , onAttach : play } ) ; function play ( worker ) //Fires 2 Times { console.log ( `` Timeout '' ) ; tmr.setTimeout ( sendplay , 14000 ) ; function sendplay ( ) { var a = 0 ; worker.port.emit ( `` sta...
How to use Flowplayer functions in a content script ?
JS
Crockford had this example to keep myArray from being in the global scope : Q : I do n't get why it isn'tQ : When I call myName ( 3 ) , is n't `` var myArray= '' executed a 2nd time ? Suppose it 's not executed a 2nd time because JavaScript knows that it 's already been defined ... What about a loop or some other logic...
var myName = ( function ( ) { var myArray = [ 'zero ' , 'one ' , 'two ' , 'three ' , 'four ' ] ; return function ( X ) { return myArray [ X ] ; } } ( ) ) ; // This function is invoked immediatelyresult = myName ( 3 ) ; // Now invoke it `` for real '' var myName = ( function ( X ) {
I do n't understand this example of a closure
JS
There are two helpers that can be used to add content while rendering : The problem is that in the first helper , React always discards the entire subtree and creates it again from scratch , as can be seen here : The demoI know , the first way is syntax sugar for React.createElement so a new component is created each r...
... const DisplayA = ( ) = > < div className= { 'containerA ' } > < button onClick= { handleToggleA } > { `` A toggled : `` + toggledA.toString ( ) } < /button > < /div > const displayB = ( ) = > < div className= { 'containerB ' } > < button onClick= { handleToggleB } > { `` B toggled : `` + toggledB.toString ( ) } < /...
Why does React discard the entire DOM subtree and recreate it from scratch ?
JS
I have a JavaScript class : Outside of the class , I have the following code : What does this in the above code refer to ? Does it refer to prototype , or to the Person class ?
function Person ( n ) { // ... } Person.prototype.shower = function ( ) { this.dirtFactor=2 }
What does ` this ` refer to ?
JS
Just as title reads , I need to check whether the number of unique entries within array exceeds n.Array.prototype.some ( ) seems to fit perfectly here , as it will stop cycling through the array right at the moment , positive answer is found , so , please , do not suggest the methods that filter out non-unique records ...
const res = [ 1,1,2,1,1,3,1,1,4,1 ] .some ( ( e , _ , s , n=2 ) = > s.indexOf ( e ) ! = s.lastIndexOf ( e ) ? false : n -- ? false : true ) ; console.log ( res ) ; .as-console-wrapper { min-height : 100 % }
Checking whether the number of unique numbers within array exceeds n
JS
In one of the tests , we need to assert that one of the 3 elements is present . Currently we are doing it using the protractor.promise.all ( ) and Array.reduce ( ) : Is there a better way to solve it with Jasmine without resolving the promises explicitly ? Would we need a custom matcher or it is possible to solve with ...
var title = element ( by.id ( `` title '' ) ) , summary = element ( by.id ( `` summary '' ) ) , description = element ( by.id ( `` description '' ) ) ; protractor.promise.all ( [ title.isPresent ( ) , summary.isPresent ( ) , description.isPresent ( ) ] ) .then ( function ( arrExists ) { expect ( arrExists.reduce ( func...
Assert an array reduces to true
JS
I 'm trying to create a phantom script to automate testing of the following form : https : //travel.tescobank.com/My script completes the required fields correctly and then clicks the button that should submit the form , unfortunately no matter what I have tried it wo n't submit the form and display the next page.I 've...
var page = require ( 'webpage ' ) .create ( ) ; page.open ( `` https : //travel.tescobank.com/ '' , function ( status ) { var currentLocation = page.evaluate ( function ( ) { return window.location.href ; } ) ; // click the button for single trip var tripType = page.evaluate ( function ( ) { var trip = $ ( `` # single-...
Phantomjs and HTML 5 fire click event and submit form fails
JS
I have some code that glitches initially when menus are expanded on top of each other . If you select option two in the first menu , the second option appears . If you then go to open the first menu , you will see it glitches as it opens - there is almost a shutter-like delay . Maybe it has something to do with the z i...
const selected = document.querySelectorAll ( `` .selected '' ) ; const optionsContainer = document.querySelectorAll ( `` .options-container '' ) ; for ( let i = 0 ; i < selected.length ; i++ ) { selected [ i ] .addEventListener ( `` click '' , ( ) = > { optionsContainer [ i ] .classList.toggle ( `` open '' ) ; selected...
Javascript & CSS - opening menu has glitchy transition
JS
There are a lot of syntax highlighters out there but something I have not seen is one that supports highlighting query strings ! I 'm looking for something to use when documenting my API and well being an API there are a lot of query strings involved . so . What good javascript or PHP syntax highlighters are there that...
/oauth/authorize ? client_id=wG2X7q1qz74zdSbgiFkyL5JFOeloQwg2opfrPfaJ & response_type=code & redirect_uri=https % 3A % 2F % 2Fmyapplication.com % 2Foauth & scope=account % 2Ccompetition % 2Cvideos & state=d41d8cd98f00b204e9800998ecf8427e
Javascript or PHP syntax highlighting of query strings ?
JS
I have been studying framework development for a few weeks , and I ran across what is highly suggested and pressured in the world of lib development , Immediately-invoking Anonymous Functions . I never can get it to work , and I have failed to find a resource that explains in-detail the use and logic behind it . Here '...
( function ( window , document , undefined ) { window.myThingy = myThingy ; var myThingy = function ( ) { } ; myThingy.prototype = { constructor : myThingy , create : function ( elementToBeCreated ) { return document.createElement ( elementToBeCreated ) ; } } ; } ) ( window , document ) ; myThingy ( ) .create ( `` div ...
Can not wrap my head around Immediately Invoking Anonymous Functions in Javascript
JS
var chartByProduct = { `` type '' : '' hbar '' , `` title '' : { `` text '' : `` TOP & BOTTOM 5 PRODUCTS BY CM '' , `` text-align '' : `` center '' , `` font-family '' : '' arial '' , `` font-color '' : `` # 5b5b5b '' , `` font-size '' : `` 18px '' , `` padding '' : `` 25px '' , `` background-color '' : `` none '' } , ...
} , } , `` plotarea '' : { `` adjustLayout '' : true , `` marginLeft '' : '' 30 % '' , `` marginRight '' : '' 30 % '' , `` marginBottom '' : '' 15 % '' , `` marginTop '' : `` 15 % '' , } , `` scale-x '' : { `` offset-end '' : '' 50 % '' , `` offset-x '' : '' 50 % '' , alpha:1 , tick : { alpha:0 } , `` label '' : { `` t...
How to shift labels in graph so that they appear on bottom of bars in bar graph ?
JS
The revision of the MDN guide on working with objects from July 15th , 2014 , states : If an object is created with an object initializer in a top-level script , JavaScript interprets the object each time it evaluates an expression containing the object literal.However , in the snippet below , when objLit2.val2 is eval...
var i = 1000 ; function iPlus3 ( ) { alert ( `` iPlus3 '' ) ; return i + 3 ; } var objLit2 = { val : iPlus3 , val2 : i = i + 1 } ; function setValue ( ) { i = 10 ; console.log ( `` objLit2Val1 '' , objLit2.val ( ) , objLit2.val2 ) ; // Outputs 13 1001 and not 13 11 i = 100 ; console.log ( `` objLit2Val2 '' , objLit2.va...
Why is an expression in an object initializer not re-evaluated each time the property is read ?
JS
SOLVED ! ! ( look at my last edit ) I want to make an army fight of 20.000 vs 20.000 units on canvas . So , for every unit data is : And i would to see this fight in real time ( 25 frames per second ) .If i generate 1 frame with Json and save on file , it is 2.5mb size ( 40k such units with this data ) . 1 second ( 25 ...
{ 'id ' = > 17854 , ' x ' = > 1488 , ' y ' = > 1269 , 'team ' = > 'red ' , 'health ' = > 10 , 'target ' = > [ 1486 , 1271 ] } class Simulator { private $ units ; private $ places = [ ] ; private $ oldPlaces = [ ] ; public function initiateGame ( ) { $ this- > createUnits ( ) ; $ this- > startMoving ( ) ; } private func...
playing 40.000 unit army for game
JS
Hi I try to make a pong game.but my collide method does n't work I ca n't see what i 'm doing wrong.The ball pass through the player . The collide method seems good to me
if ( player.left < ball.right & & player.right > ball.left & & player.top < ball.bottom & & player.bottom > ball.top ) { ball.vel.x = -ball.vel.x ; } class Vec { constructor ( x = 0 , y = 0 ) { this.x = x ; this.y = y ; } } class Rect { constructor ( w , h ) { this.pos = new Vec ; this.size = new Vec ( w , h ) } get le...
pong game collision in javascript
JS
I have created a small imperative vanilla JavaScript script to block distracting news websites I feel an addiction-like behavior to : The script basically works ( a popup takes over the DOM ) , but my problem is that it only blocks sites after all their DOM content was both parsed and rendered , while I am interested t...
// ==UserScript==// @ name blocksite// @ match * : //*.news_site_1.com/*// @ match * : //*.news_site_2.com/*// ==/UserScript==function blocksite ( ) { document.body.innerHTML = ` < div dir= '' ltr '' ; style= '' font-size:100px ; font-weight : bold ; text-align : center '' > Blocked ! < /div > ` ; } setTimeout ( blocks...
Prevent all or some DOM content to be parsed , per website domain
JS
This question is primarily focused on how to manage code as you are developing , making it highly adaptable etc . Let me explain through this example , and it will make more sense . ' I will add bounty , if I need to'.Our server is strapped for memory , and we are pushing a lot of sorting work onto the client side with...
var sortSubSite = $ ( '.AccessSitesLinks.False ' ) ; var subArr = sortSubSite.map ( function ( _ , o ) { return { t : $ ( o ) .text ( ) , h : $ ( o ) .attr ( 'href ' ) , c : $ ( o ) .attr ( 'class ' ) } ; } ) .get ( ) ; sortSubSite.each ( function ( i , o ) { var classList = $ ( o ) .attr ( 'class ' ) .split ( /\s+/ ) ...
Sorting Based on Multiple CSS Classes , and Designing code with Jquery
JS
I want to make a String method , which accepts a RegExp and a callback , then splits String by RegExp , and inserts callback 's return in split array . In short , it would do something like this : In case the String does n't match the RegExp , it should return an array , like this : I wrote this code , but it does n't ...
`` a 1 b 2 c '' .method ( /\d/ , function ( $ 1 ) { return $ 1 + 1 ; } ) = > [ a , 2 , b , 3 , c ] `` a b c d e '' .method ( /\d/ , function ( $ 1 ) { return $ 1 + 1 ; } ) = > [ `` a b c d e '' ] String.prototype.preserveSplitReg = function ( reg , func ) { var rtn = [ ] , that = this.toString ( ) ; if ( ! reg.test ( t...
Why does the statement if ( ! condition ) { console.log ( condition ) } display true
JS
I have this piece of VBNet code that i would like to translate into javascript : my translated result : However when i run it it has error Uncaught SyntaxError : Invalid regular expression : : Nothing to repeat ( my VbNet code does n't have any error though ) Does anyone know what 's causing the problem ?
Dim phone_check_pattern = `` ^ ( \+ ? | ( \ ( \+ ? [ 0-9 ] { 1,3 } \ ) ) | ) ( [ 0-9.//- ] |\ ( [ 0-9.//- ] +\ ) ) + ( ( x|X| ( ( e|E ) ( x|X ) ( t|T ) ) ) ( [ 0-9.//- ] |\ ( [ 0-9.//- ] +\ ) ) ) ? $ '' System.Diagnostics.Debug.WriteLine ( System.Text.RegularExpressions.Regex.IsMatch ( `` test input '' , phone_check_pa...
Errors translating regex from .NET to javascript
JS
I am working on a functionality where I want to show elements in a div of height 1000px . There are multiple records coming from DB but height of each element is not fixed . When height of records displayed cross 1000px , they should be wrapped in one DIV . Next records should be wrapped in another DIV till the height ...
< div class= '' record '' > .. < /div > < div class= '' record '' > ... .. < /div > < div class= '' record '' > ... < /div > < div class= '' record '' > ... . < /div > < div class= '' record '' > .. < /div > < div class= '' page > < div class= '' record '' > .. < /div > < div class= '' record '' > ... .. < /div > < div...
How to wrap all HTML elements in a DIV depending on total height of those HTML elements using jQuery ?
JS
I am having issues playing mp3s on my iphone 6 using phonegap.I am downloading a zip file from the server which contains 1 mp3 file and 3 image files.All seem to download correctly but I am not too sure about the mp3 file as it just wont play.To test if the files are there I am doing this : The 3 images show up so I kn...
< img src= '' cdvfile : //localhost/persistent/audio/1.jpg '' alt= '' '' / > < br > < img src= '' cdvfile : //localhost/persistent/audio/2.jpg '' alt= '' '' / > < br > < img src= '' cdvfile : //localhost/persistent/audio/3.jpg '' alt= '' '' / > < br > < a href= '' cdvfile : //localhost/persistent/audio/1.mp3 '' > MP3HE...
Phonegap download / unzip issues with mp3 playing
JS
A comparator function ascending accepts two arguments - a and b . It must return an integer comparing the two.I have a list that I want to sort by name , so I wrote the following functions . Is there a functional idiom I can use to combine these two functions , rather than having byName take responsibility for composin...
const ascending = ( a , b ) = > a.localeCompare ( b ) ; const byName = ( i ) = > i.get ( 'name ' ) ; const useTogether = ( ... fns ) = > ... ; // is there an idiomatic function like this ? // usageitems.sort ( useTogether ( byName ( ascending ) ) ) ;
Can this be refactored to use generic functional principles ?
JS
I 'm working on some mega simple weather app in Angular for practice reasons and i 'm stuck..i have a angular json feed like this : and it loads the feed in to the index.html . its all working and what i wand now is a input form on index that changes the Amsterdam part of the url on js/services/forcast.js where the abo...
app.factory ( 'forecast ' , [ ' $ http ' , function ( $ http ) { return $ http.get ( 'http : //api.openweathermap.org/data/2.5/weather ? q=Amsterdam , NL & lang=NL_nl & units=metric ' ) .success ( function ( data ) { return data ; } ) .error ( function ( err ) { return err ; } ) ; } ] ) ;
AngularJs json URL changer
JS
I am using the fontpicker found here . I put it inside a modal and it worked fine . Now , I 've put tab navigation inside the modal and the fontpicker does n't display properly . ( The button for the first modal is the broken one . The button for second modal is an example of the same thing , but w/out the tabbed navig...
< ! doctype html > < html lang= '' en '' > < head > < meta charset= '' utf-8 '' / > < script > $ ( document ) .ready ( function ( ) { $ ( 'select # fonts1 ' ) .fontSelector ( { } ) ; $ ( 'select # fonts2 ' ) .fontSelector ( { } ) ; } ) ; < /script > < /head > < body > < ! -- Button to trigger modal -- > < a href= '' # ...
How do I get this fontpicker to display properly inside a bootstrap modal w/ a tab
JS
I load images from the internet as such : I noticed that some images take a long time to load if the network is slow , and some take a long time to load and then fail.Sometimes , the domain is down all together . If the server is down , this works well , because an error will be thrown pretty quickly and I can catch th...
img.src = 'some_path '
How long does it take an image to fail - ?
JS
The code within the attached fiddle removes all URLs within a < textarea > .Is it possible for the code to remove all URLs , except if the URL is inside of a parentheses — e.g . ( google.com ) — within the < textarea > dynamically ? If possible , I would be appreciate an updated fiddle as I am new to coding.Fiddle
$ ( function ( ) { $ ( `` # txtarea '' ) .keyup ( function ( ) { console.log ( this.value ) ; this.value = this.value.replace ( / ( https ? : \/\/ ) ? ( [ \da-z\.- ] + ) \. ( [ a-z\ . ] { 2,6 } ) ( [ \/\w \.- ] * ) *\/ ? /mg , ' ' ) ; } ) } ) ; < script src= '' https : //ajax.googleapis.com/ajax/libs/jquery/1.11.1/jque...
How to remove un-parenthesized URLs from a < textarea >
JS
In JavaScript , why would one want to attach properties directly to the constructor ? I 've got this question after looking at CoffeeScript ‘ s __extend helper function , which contains , among the lines : which copies properties / methods to the subclassed object directly from the constructor object . But why would an...
var Human = function ( ) { } ; Human.specie = `` Homo Sapience '' ; for ( var key in parent ) { if ( __hasProp.call ( parent , key ) ) child [ key ] = parent [ key ] ; }
When would I want to use “ class ” ( static ) methods or properties in JavaScript ?
JS
Possible Duplicate : Firefox setTimeout ( func , ms ) sending default parameters to callback I have been wondering this for a long time . When I type in the following line in FF , then I get : arguments outputs an array with a random number in it , and this number is different from the value of the timer . When I try o...
var timer = setTimeout ( function ( ) { console.log ( arguments ) } , 500 ) ;
The mystery arguments passed by setTimeout in Firefox
JS
I would like to simulate the C # Any ( ) method , which can be used to determine whether if a collection has any matching objects based on a lambda expression.I used jQuery 's $ .grep to make things easier : I know that eval ( ) is bad practice for obvious reasons . But is it ok in this case , since I wo n't use this w...
Array.prototype.any = function ( expr ) { if ( typeof jQuery === 'undefined ' ) throw new ReferenceError ( 'jQuery not loaded ' ) ; return $ .grep ( this , function ( x , i ) { return eval ( expr ) ; } ) .length > 0 ; } ; var foo = [ { a : 1 , b : 2 } , { a:1 , b : 3 } ] ; console.log ( foo.any ( ' x.a === 1 ' ) ) ; //...
Simulate C # Lambda methods in Javascript
JS
I was looking through a solution to a problem in javascript , namely parsing a string into its constituent names , operators , and brackets , when I saw this expression : What is that _|_ ? Is that using node 's _ feature ? I 've looked for documentation but not found any.When I try using it myself , this happens : As ...
return accept ( `` ) '' ) ? _|_ : e ; > 55 > true ? _|_ : 0ReferenceError : _ is not defined at eval:1:1 at eval at n. < anonymous > function tokenise ( string ) { const tokens = string.match ( / [ a-z ] +|\ ( |\ ) | [ ! # $ % & *+\-\/ < = > @ ^_. , ; ] +/gi ) || [ ] ; const accept = s = > s===tokens [ 0 ] & & tokens.s...
What is the javascript ` _|_ ` ?
JS
I am integrating the swagger UI in my project . I need to pass the token to make a request.With the above code I am getting the successful response but the problem is curl command is showing as undefined like below imageIf I removed the following part of code the curl command is showing but the response is throwing the...
const mytoken = `` heareismytoken '' ; const ui = SwaggerUIBundle ( { url : `` /swagger/v2/swagger.json '' , dom_id : ' # swagger-ui ' , deepLinking : true , requestInterceptor : function ( req ) { var key = mytoken ; if ( key & & key.trim ( ) ! == `` '' ) { req.headers.Authorization = 'Bearer ' + key ; console.log ( '...
Curl command showing as undefined with token in swagger UI . ?
JS
Since I could not comment , I am forced to write this post . I got the below code which delays/waits exactly 1 seconds or 1000 milliseconds -But how can I delay it i*1000 seconds instead of fixed 1000 milliseconds so the waiting depends on iteration number ? For example , if n= 5 , then I want the loop delay 1 second i...
let n = 5 ; for ( let i=1 ; i < n ; i++ ) { setTimeout ( function timer ( ) { console.log ( `` hello world '' ) ; } , i*1000 ) ; }
How to Change Interval Time Dynamically in For Loop According to Index/iteration Number ?
JS
I 'm trying to make a progress bar that looks like emptying glass of beer . Unfortunately I 'm not very artistic person but I 'm doing my best.My concept goes like this : There is a < div > with `` beer '' background , 100 % high vertically . It hides any overflowInside there 's another < div > , positioned relatively ...
Promise.timeout = function ( delay ) { return new Promise ( ( resolve ) = > { setTimeout ( resolve , delay ) ; } ) ; } ; Promise.animationFrame = function ( ) { return new Promise ( ( resolve ) = > { requestAnimationFrame ( resolve ) ; } ) ; } ; ( async function ( ) { const progress = document.querySelector ( `` div.to...
Getting my `` beer '' vertical progress bar to work
JS
I 've been toying with node.js lately and I ran into a weird behavior about the usage of this in the global scope of a module.this is bound to module.exports in the global scope : But this is bound to global in a method scope : This also lead to this confusing behavior : I guess that the solution is to never use this i...
console.log ( this === exports ) ; // - > true ( function ( ) { console.log ( this === global ) ; } ) ( ) ; // - > true this.Foo = `` Weird '' ; console.log ( Foo ) ; // - > throws undefined ( function ( ) { this.Bar = `` Weird '' ; } ) ( ) ; console.log ( Bar ) ; // - > `` Weird ''
node.js : Confusing usage of 'this ' in the global scope
JS
I have two variables defined as : I know that I can use $ ( `` # div1 , # div2 '' ) .hide ( ) to hide both divBut is there a way I can hide them through defined variables like ( div1 , div2 ) .hide ( ) ?
var div1 = $ ( `` # div1 '' ) ; var div2 = $ ( `` # div2 '' ) ;
How to hide elements defined as variables ?
JS
I have a simple form in HTML . There are 3 sections ( Section A , B and C ) . As the user fills out the form each section is calculated by displaying total points and percentage . I would like to rank the scores and display it in the ranking column but can not seem to figure how to do it . For example if Section A has ...
function calcA1R ( ) { var Aa1 = document.getElementById ( 'Aa1 ' ) ; var Ab1 = document.getElementById ( 'Ab1 ' ) ; var Ac1 = document.getElementById ( 'Ac1 ' ) ; var Aa1Val = Aa1.options [ Aa1.selectedIndex ] .value ; var Ab1Val = Ab1.options [ Ab1.selectedIndex ] .value ; var Ac1Val = Ac1.options [ Ac1.selectedIndex...
How to rank results in an HTML form using Javascript ?
JS
I 'm in a scenario where I have to get data from the server in parts in sequence , and I would like to do that with the help of Promises . This is what I 've tried so far : The first fetch is successful , but subsequent calls to server.getData ( ) does not run . I presume that it has to do with that the first then ( ) ...
function getDataFromServer ( ) { return new Promise ( function ( resolve , reject ) { var result = [ ] ; ( function fetchData ( nextPageToken ) { server.getData ( nextPageToken ) .then ( function ( response ) { result.push ( response.data ) ; if ( response.nextPageToken ) { fetchData ( response.nextPageToken ) ; } else...
Looping with Promises
JS
I have this commandscares me a little bit b/c I am afraid of merging a file where whitespace matters . Is there a way to limit it to certain files , something like this :
git merge -Xignore-all-space origin/dev git merge -Xignore-all-space *.js origin/dev
Ignore whitespace for only certain file extensions when merging
JS
Only JavaScript , No jquery.Code goes like : Now , I want to disable the 'click ' for 5 seconds when the function 'func ( ) ' is running . And , then after the 'func ( ) ' is completely executed , the click should again be enabled automatically.How to do this only using JavaScript ?
window.onload = addListeners ; function addListeners ( ) { for ( var i = 0 ; i < document.getElementsByClassName ( 'arrow ' ) .length ; i++ ) { if ( window.addEventListener ) { document.getElementsByClassName ( 'arrow ' ) [ i ] .addEventListener ( 'click ' , func , false ) ; } else { document.getElementById ( 'arrow ' ...
How to disable a click event handler for particular time ?