lang
stringclasses
4 values
desc
stringlengths
2
8.98k
code
stringlengths
7
36.2k
title
stringlengths
12
162
JS
Possible Duplicate : Use of .apply ( ) with 'new ' operator . Is this possible ? I have 5 or 6 variable assignments of the formAs you can see , a significant amount of portion of these constructors are very much alike . It would be nice if I could create a little generic currying builder that would allow me to do somet...
var analyteSelection = new TemplatedSelectionContainer ( $ ( '.analyte-container ' , this ) , helpers , optionsTemplate ) ; var instrumentSelection = new AssetBackedSelection ( $ ( '.instrument-container ' , this ) , helpers , optionsTemplate , Assets.instruments , 'Instrument ' ) ; var methodSelection = new AssetBacke...
Use apply with a function constructor
JS
Assume such situation : In C and C++ this is undefined behaviour , as described here : Undefined behavior and sequence pointsHowever , how does this situation look in : JavaScript , Java , PHP ... C # well , any other language which has compound operators ? I 'm bugfixing a Javascript - > C++ port right now in which th...
int a = ( -- t ) * ( t-2 ) ; int b = ( t/=a ) +t ;
How do languages handle side effects of compound operators ?
JS
I am using `` nashorn '' javascript engine in java8 to evaluate some expressions during runtime . I have a util class for this with method : for which I created some unit tests . One of them goes like this : It worked fine for me while I was using java version `` 1.8.0_91 '' . But someone who used java version `` 1.8.0...
public static String evaluateJavaScriptExpression ( String expression ) throws ScriptException { if ( expression == null ) { return null ; } ScriptEngineManager scriptEngineManager = new ScriptEngineManager ( ) ; ScriptEngine javaScriptEngine = scriptEngineManager.getEngineByName ( JAVASCRIPT_ENGINE ) ; return String.v...
JDK 1.8.0_92 Nashorn JS engine indexOf behaviour
JS
Im facing an issue after upgrading to Symfony 4.1 and switching to Encore.I tried to search for a source of problem and only after removing everything with jquery include from compose.js ( and includes ) the Error disappeared . But of course I need jquery ... As soon as I 'import jQuery from 'jquery '' or 'Encore.autoP...
Uncaught RangeError : Maximum call stack size exceededat _typeof ( bundle.js ? v=1.6565:3454 ) at _typeof ( bundle.js ? v=1.6565:3454 ) at _typeof ( bundle.js ? v=1.6565:3454 ) at _typeof ( bundle.js ? v=1.6565:3454 ) at _typeof ( bundle.js ? v=1.6565:3454 ) at _typeof ( bundle.js ? v=1.6565:3454 ) at _typeof ( bundle....
Webpack Encore Jquery Maximum call stack size
JS
I am using a closure to create an object with private and public methods . It looks like this -But now I would like to have an object that has only private functions and that is inherited by another object . But is this possible in JavaScript ?
var Dog = ( function ( ) { function Dog ( ) { } var size = 'big ' ; var _privateSaySize = function ( ) { return ' I am a ' + size + ' dog . ' ; } Dog.prototype.publicSaySize = function ( ) { return _privateSaySize ( ) ; } return Dog ; } ) ( ) ;
Can you inherit private functions in JavaScript ?
JS
So I 'm writing this node.js application and I 'm trying to make it super fast and with a low memory footprint . I 've got a lot of string concatenation going on , functions like : If I do this like 100 million times right on the inner loop of my application , does the Javascript engine allocate and have to free that s...
function f ( pt ) { return pt.x + ' + ' + pt.y ; } var plus = ' + ' ; function f ( pt ) { return pt.x + plus + pt.y ; }
Should I statically allocate Javascript strings for memory performance ?
JS
I have a form in HTML which contains multiple same name fields . For example : Now on the server side ( C # ) , I have an action method and a model class Product : Now my question is : I am submitting the form using jquery $ .ajax method . On the server side the action method accepts a Product class array . Now how can...
< form action= '' '' method= '' post '' id= '' form '' > < div class= '' itemsection '' id= '' item1 '' > < input type= '' text '' name= '' Price '' / > < input type= '' text '' name= '' Name '' / > < input type= '' text '' name= '' Catagory '' / > < /div > < div class= '' itemsection '' id= '' item2 '' > < input type=...
How to serialize the form fields and send it to server , jquery ?
JS
I have this code that I 've stumbled upon . All the time I 've been working with arrow functions I 've seen on a { } format , what does this ( ) wrapper mean ?
const actionsMap = { [ GET_USER ] : ( state , action ) = > ( { post : action.msg } ) } ;
What does the arrow function with a ( ) after means ?
JS
I am working on [ this ] [ 1 ] d3 project . Basically I am trying to create a SQL like query builder . I can drop boxes to the drawing area & other operators inside the box . Then I should be able to connect them all . I am trying to translate 2 images which are nested in groups . I want to move the small items inside ...
< g id= '' draw '' > < rect class= '' container '' height= '' 400 '' width= '' 400 '' x= '' 0 '' y= '' 0 '' style= '' fill : gray '' > < /rect > < g class= '' qbox '' id= '' qbox '' > < line id= '' dummyLine '' x1= '' 0 '' x2= '' 0 '' y1= '' 0 '' y2= '' 0 '' visibility= '' hidden '' style='stroke : red ; stroke-width:4...
d3js transforming nested group images
JS
For this question , I 'm not expecting a solution to solve something but would like to understand things better .. Some quote from the specifications : Edition 5.1 ( Link ) §15.2.3.5 Object.create ( O [ , Properties ] ) The create function creates a new object with a specified prototype . When the create function is ca...
function F ( ) { } var x=Object.create ( F ) ; // a minimal testalert ( x.prototype.constructor===F ) ; // truealert ( x instanceof Function ) // truealert ( typeof x ) // 'object ' x ( ) ; // x is not a function
x is not a function ... what would you expect Object.create to do with a constructor
JS
I have following 2 directives . In DirectiveA I am getting some data from remote server and then rendering a template with that data as anchor tag . Now when user click on any of the link , I broadcast event and listen to that event in DirectiveB . In DirectiveB I want to make another ajax request and when I receive re...
angular.module ( 'app ' ) .directive ( 'DirectiveA ' , function ( $ http ) { 'use strict ' ; return { restrict : ' E ' , templateUrl : '/templates/templateA.html ' , controller : function ( $ scope ) { $ scope.showDetails = function ( num ) { // < -- this executes in ng-click in template $ scope. $ broadcast ( 'season ...
execute/render a directive from another directive
JS
How can I make the left column in a table disappear using plain JS ? This is my approach : It works , but I have to use `` ugly '' loops.Maybe there is a more efficient way by just saying column [ 0 ] .display = `` none '' .Here is the fiddle .
< table id= '' tab '' border= '' 1 '' > < tr > < td > abc < /td > < td > def < /td > < /tr > < tr > < td > ghi < /td > < td > jkl < /td > < /tr > < tr > < td > mno < /td > < td > pqr < /td > < /tr > < /table > < button onclick= '' inv ( ) '' > invisible < /button > < button onclick= '' vis ( ) '' > visible < /button > ...
Make entire column disappear
JS
Using C # for ASP.NET and MOSS development , we often have to embed JavaScript into our C # code . To accomplish this , there seems to be two prevalent schools of thought : The other school of thought is something like this : Is there a better way than either of these two methods ? I like the second personally , as you...
string blah = `` asdf '' ; StringBuilder someJavaScript = new StringBuilder ( ) ; someJavaScript.Append ( `` < script language='JavaScript ' > '' ) ; someJavaScript.Append ( `` function foo ( ) \n '' ) ; someJavaScript.Append ( `` { \n '' ) ; someJavaScript.Append ( `` var bar = ' { 0 } ' ; \n '' , blah ) ; someJavaScr...
How do you embed other programming languages into your code ?
JS
I use the following code to show tree items , https : //github.com/microsoft/vscode-extension-samples/tree/master/tree-view-sampleThe items which is shown in the tree is related to a file , if the file changed the number of the tree items should be changed accordingly ( using createFileSystemWatcher which works ok ) , ...
export class TaskTreeDataProvider implements vscode.TreeDataProvider < TreeItem > { private _onDidChangeTreeData : vscode.EventEmitter < TreeItem | null > = new vscode.EventEmitter < TreeItem | null > ( ) ; readonly onDidChangeTreeData : vscode.Event < TreeItem | null > = this ._onDidChangeTreeData.event ; private eeak...
vsCode refresh tree when adding new Item
JS
What I 'm trying to do : I want to use Node to fire up two child processes in a particular order at a particular time , console logging their stdout as they stream , occasionally switching between the two . The output I want : Of course it 's super easy to do . Imperatively . But it 's also really ugly & stateful and j...
` Proc 1 log # 1 `` Proc 1 log # 2 `` Proc 1 log # 3 `` Proc 1 log # 4 `` Proc 2 log # 1 `` Proc 2 log # 2 `` Proc 2 log # 3 `` Proc 2 log # 4 `` Proc 1 log # 9 `` Proc 1 log # 10 `` Proc 1 log # 11 `` Proc 1 log # 12 `` Proc 1 log # 13 `` Proc 1 log # 14 `` Proc 1 log # 15 `` All procs have finished ! ` // main _ : : ...
Why does this console log twice ?
JS
I updated jquery so i could play with the new jquery mobile ui 1.3 and for some reason my form no longer update page any more , it worked previously but it was n't through ajax , it simply submitted the form without ajax , I would however like ajax to just fetch the new data and append it to the div instead of reloadin...
< ! -- Load Json data and events -- > < script type= '' text/javascript '' > jQuery ( ' # new_rave ' ) .live ( 'submit ' , function ( event ) { $ .ajax ( { url : 'http : //whoops/goodtimes ' , type : 'POST ' , dataType : 'json ' , data : $ ( ' # new_rave ' ) .serialize ( ) , success : function ( data ) { for ( var id i...
Ajax Form Submit not loading newly submitted data
JS
Possible Duplicate : How to encode a URL in JavaScript ? I am trying to send a url using the following code to a php code , but as the url include & a=12 & b=4 once I get the value of the `` a '' variable in my php code the last part of address is removed.url = http : //www.example.com/help.jpg ? x=10 & a=12 & b=4but t...
function upload ( url ) { if ( window.XMLHttpRequest ) { // code for IE7+ , Firefox , Chrome , Opera , Safari xmlhttp=new XMLHttpRequest ( ) ; } else { // code for IE6 , IE5 xmlhttp=new ActiveXObject ( `` Microsoft.XMLHTTP '' ) ; } xmlhttp.onreadystatechange=function ( ) { if ( xmlhttp.readyState==4 & & xmlhttp.status=...
how to send a url using Javascript ajax ?
JS
Here is my code below : I am using ajaxFileUpload and here is my code to upload the same : This fileElementId is referring to image . Where image is picked only once . Tried assigning image to images [ ] as we do it from plain HTML . But still no luck as ajaxFileUpload.js throwing error as id not found with images [ ] ...
let colNames = [ 'ID ' , 'Image ' , 'Title ' , 'Description ' ] ; let colModel = [ { name : 'id ' , index : 'id ' , width : 30 , editable : true , editoptions : { size : `` 30 '' , maxlength : `` 50 '' } } , { name : 'image ' , index : 'image ' , align : 'left ' , editable : true , edittype : 'file ' , editoptions : { ...
How to upload multiple files from jqgrid and Laravel ?
JS
I 'm trying to use a visualization as a selector on a D3 costum chart . I 'm following the SDK documentation Here , and I ca n't make my example work.Basicly I star by declaring `` me '' var and enable the `` use as filter '' option.Then , when appending de svg element , I add the clear and end selecion methods : When ...
var me = this ; this.addUseAsFilterMenuItem ( ) ; var g = d3.select ( this.domNode ) .append ( `` svg '' ) .attr ( `` width '' , width + margin.left + margin.right ) .attr ( `` height '' , height + margin.top + margin.bottom ) .append ( `` g '' ) .attr ( `` transform '' , `` translate ( `` + margin.left + `` , '' + mar...
Microstrategy Using a visualization as a selector D3 costum chart
JS
I 'm looping through files in a directory and storing the file details to an array data . The following code populates the array if I do n't attempt to run fs.stat to get things like the file create/edit date : If I move the data.push ( ... ) outside the fs.stat the array returns with the file data . Inside the fs.stat...
fs.readdir ( '../src/templates ' , function ( err , files ) { if ( err ) { throw err ; } var data = [ ] ; files .forEach ( function ( file ) { try { fs.stat ( '../src/templates/'+file , ( error , stats ) = > { data.push ( { Name : file , Path : path.join ( query , file ) } ) ; } ) ; } catch ( e ) { console.log ( e ) ; ...
Store fs.stat while looping through files into an array , in Node JS
JS
JSlint does n't like the use of Array constructors and there are no JSLint options for allowing them . Therefore , to create an Array of length n , the following is not allowed : Is the below the only way I can get around this ? In normal circumstances this is not a big deal ( using two lines of code instead of one ) ,...
var arr = new Array ( n ) ; var arr = [ ] ; arr.length = 5 ; function repeat ( str , times ) { return new Array ( times + 1 ) .join ( str ) ; }
Creating an n-sized Array while making JSLint happy ?
JS
I have this code : Why does foo.bar ( ) alert 2 while [ foo.bar ] [ 0 ] ( ) alerts undefined ?
var foo = { x : 2 , bar : function ( ) { alert ( this.x ) ; } } ;
Call a function from javascript array
JS
I want to upgrade to the lasted stable angular branch 1.4.7 . I am coming from 1.2.13.there is a angular-leaflet-directive in my project that was customized for the application . I am trying to figure out how to change the syntax in a function so it does not throw a error . console messagesfunctionerror is at 'markers ...
Error : [ $ parse : syntax ] Syntax Error : Token '.50465 ' is an unexpected token at column 8 of the expression [ markers.50465 ] starting at [ .50465 ] .http : //errors.angularjs.org/1.4.7/ $ parse/syntax ? p0=.50465 & p1=is % 20an % 20unexpected % 20token & p2=8 & p3=markers.50465 & p4=.50465at angular.js:68at Objec...
how to correct syntax after angular update
JS
In one of the tests , I need to scroll into view of an element which can be done via scrollIntoView ( ) method parameterizing the script with an element located via Protractor : But , we can also find the element directly via getElementById ( ) : What is the difference between the two approaches ? The scrollIntoView ( ...
var elm = element ( by.id ( `` myid '' ) ) ; browser.executeScript ( `` arguments [ 0 ] .scrollIntoView ( ) ; '' , elm.getWebElement ( ) ) ; browser.executeScript ( `` document.getElementById ( 'myid ' ) .scrollIntoView ( ) ; '' ) ;
Locating elements in Protractor vs directly in JavaScript
JS
EDIT**In my word game there is a grid with 3 letter words . The aim of the game is to spell the words by clicking on the corresponding letters on the side . When an area in the grid is highlighted it indicates to the user the word to spell . The user clicks the letters on the side of the grid and they move to the highl...
if ( guesses [ word ] .length == 3 ) { if ( guesses [ word ] .join ( `` ) == word ) { $ ( 'td [ data-word= ' + word + ' ] ' ) .addClass ( 'wordglow2 ' ) ; } else { $ ( 'td [ data-word= ' + word + ' ] ' ) .addClass ( `` wordglow4 '' ) ; target.splice ( 0 , guesses [ word ] .length ) ; } } ) ; if ( target.length ) { $ ( ...
Accepting the animation
JS
Here is the code . You can test in Chrome ( F12 ) : This return an invisible character , this should be `` µ '' . It works fine in IE . But why ? In Chrome , returns `` '' ( not empty string , an invisible character ) In IE , returns `` µ '' In Firefox , return `` M '' ( not letter M )
`` µ '' .toUpperCase ( )
Javascript toUpperCase mess up in chrome for latin character
JS
Assume , for the sake of this question , that I want to be able to create a function in Javascript that appends all of the elements of one array to another array . One way to achieve this , if you have access to the destination array , is to say : Now , since Array.prototype.push.apply is pretty ugly , I want to alias ...
var destination = [ 1,2,3 ] ; var source = [ 4,5 ] ; Array.prototype.push.apply ( destination , source ) ; console.log ( destination ) ; // [ 1,2,3,4,5 ] var pushAll = Array.prototype.push.apply ; pushAll ( destination , [ 6,7 ] ) ; TypeError : Function.prototype.apply was called on [ object global ] , whichis a object...
Why is apply not already bound to functions in Javascript ?
JS
I have to create a function to sort a string of numbers based on the 'weight ' of each number -- the 'weight ' is the digits of the numbers added together ( the weight of 99 would be 18 , the weight of 100 would be 1 , etc etc ) . This means that a string `` 100 54 32 62 '' would return `` 100 32 62 54 '' .I can get an...
function orderWeight ( str ) { var arr = str.split ( `` `` ) ; var sortArr = [ ] ; arr.forEach ( t = > sortArr.push ( t.split ( `` '' ) .map ( s = > parseInt ( s , 10 ) ) .reduce ( add , 0 ) ) ) ; }
How to sort one array based on how another gets sorted ? ( Javascript )
JS
I 've used FireBug to test the two cases and they seem pretty similar by result : But I 'm pretty sure there is some difference between these two , maybe even performance related difference . Bottom line - I 'd like to know if there is a difference between { active : `` yes '' } and { `` active '' : `` yes '' } .
> > > var x = { `` active '' : `` yes '' } > > > x.active '' yes '' > > > var x = { active : `` yes '' } > > > x.active '' yes ''
What is the difference between { active : `` yes '' } and { `` active '' : `` yes '' } ?
JS
I have a problem with touchstart in my jquery code . My jquery code does n't allow me to click any button , input or other elements when I open the page with a mobile phone . Please click this DEMO . You can click the inputs and you can write something on there . But open chrome developer console now click the input bo...
( function ( b ) { b.fn.XSwitch = function ( d ) { return this.each ( function ( ) { var f = b ( this ) , e = f.data ( `` XSwitch '' ) ; if ( ! e ) { e = new c ( f , d ) ; f.data ( `` XSwitch '' , e ) ; } if ( b.type ( d ) === `` string '' ) { return e [ d ] ( ) ; } } ) ; } ; b.fn.XSwitch.defaults = { selectors : { sec...
I can not write any value from input on mobile device
JS
How do I write shorthand for else if statements ? I know to write when there 's only if and else . But How do I write this when there 's an else if statement ?
if ( showvar == `` instock '' ) { //show available } else if ( showvar == `` final3 '' ) { //show only 3 available } else { //show Not available } ( showvar == `` instock '' ) ? //show available : //show Not available
Shorthand with else if
JS
I am creating a datatable module and I am aiming for a particular implementation . I want to be able to import the module , and use it 's components like so : randomcomponent.component.htmlHere are the components from the datatable module : datatable.component.html ( < datatable > ) column.component.html ( < datatable-...
< datatable [ data ] = '' tableData '' > < datatable-column > < ng-template let-row= '' row '' > < label > { { row.value } } < /label > < /ng-template > < /datatable-column > < /datatable > < table class= '' datatable '' > < thead > < tr > < th *ngFor= '' let header of tableData ? .headers '' > { { header ? .title } } ...
How to pass data through nested ng-containers & ng-templates ?
JS
I 'm using jQuery to do ajax calls - many of which are working fine , but I 've just run into an odd problem trying to send a string to the server . I 've narrowed the code down to just this : When it hits the server however , the request variables are as follows : where Request [ `` f [ 0 ] '' ] contains `` u '' etc.C...
var x = new String ( 'updateGroup ' ) ; var y = 'updateGroup ' ; $ .post ( 'page.aspx ' , { f : x , f2 : y } , function ( data ) { } ) ; Request [ `` f '' ] null stringRequest [ `` f2 '' ] `` updateGroup '' stringRequest.Form.AllKeys { string [ 12 ] } string [ ] [ 0 ] `` f [ 0 ] '' string [ 1 ] `` f [ 1 ] '' string [ 2...
JavaScript String object is being split into an array on jQuery.post
JS
i just read meteor 's accounts config options , `` restrictCreationByEmailDomain '' option is awesomei want to know can i use a list of domains separated by comma or array in place of 'school.edu'is there any simple tutorial for meteor accounts system ? pls help
Accounts.config ( { restrictCreationByEmailDomain : 'school.edu ' } )
how meteor 's restrictCreationByEmailDomain option work ?
JS
So I have 2 check-boxes : When I click a checkbox it adds it to a JavaScript list , if it 's already in the list I want to overwrite it with another value ( 123 in this example ) .But when I click the second one ( does n't matter the order , the 2nd element is always 123 for some reason.Where as I would expect if I cli...
var statusList = [ ] ; function updateStatusString ( x ) { if ( statusList ! = null ) { if ( statusList.length > 0 ) { for ( var i = 0 ; i < statusList.length ; i++ ) { if ( parseInt ( statusList [ i ] ) == parseInt ( x ) ) { statusList [ i ] = 123 ; } else { statusList.push ( x ) ; } } } else { statusList.push ( x ) ;...
Why is Javascript equating 5 == 8 as true ?
JS
This is the situation : I modified it this way and it works as expected : I am wondering if there is a more elegant way to write this , maybe something that has a property check . [ UPDATE ] : There are various ways to solve this.If you do n't need to retain user properties : or the proposal spread property : Otherwise...
user.username = body.username ; user.name = body.name ; user.surname = body.surname ; user.email = body.email ; user.password = body.password ; user.privilege = body.privilege ; user.pin = body.pin ; user.rfidTag = body.rfidTag ; for ( let propt in body ) { user [ propt ] = body [ propt ] ; } user = Object.assign ( { }...
Best way to handle multiple assignment of the same property in javascript
JS
Can anyone explain what this statement means ? Specifically , This appears in a chunk of code I am looking at . I 'm not at a complete loss , however My understanding is that it assigns both e and window.event ( or x/whatever ) to e. It 's only natural , right ? But what is the value in assigning e to e ? Should n't e ...
e = e || x e = e || window.event
Can someone please explain e = e || x ? Why assign e to e ?
JS
Say I had the following markup : And I use the following to retrieve them : How is it possible that I am able to retrieve the respective DOM element by using the [ ] syntax and also be able to call methods on the jQuery object such as .first ( ) ? I 'm asking this question because it looks to me that divs is a jQuery o...
< div > < /div > < div > < /div > < div > < /div > var divs = $ ( 'div ' ) ; var div_one = divs [ 0 ] ;
How does jQuery allow you to use [ ] on a jQuery object ?
JS
In my local domain 's webpage , bothjq.src = `` https : //cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js '' ; jq.src = http : //127.0.0.1/js/jquery-3.3.1.min.jscan be loaded . In the stackoverflow 's webpage , right click to enter into chrome 's inspect -- console.The remote jquery.js file can be loaded , now to...
const jq = document.createElement ( 'script ' ) ; jq.src = `` https : //cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js '' ; document.head.appendChild ( jq ) ; jq.addEventListener ( 'load ' , ( ) = > { console.log ( `` hello world '' ) ; console.log ( $ === jQuery ) ; } ) ;
Why ca n't load js file in my local apache2 server ?
JS
Do Windows 8 JavaScript apps support GIF images ? If so , how can I display the GIF image ? I tried this below code but it was n't working : UpdateI do n't need a C # app . I need a JavaScript app .
< img id= '' backround '' src= '' images/header.gif '' / >
Do Windows 8 JavaScript apps support GIF images ?
JS
I have many difficulties in doing this kind of formatting in the field . I have a form field : The intention is to make this field be in the following format , when a person enters 2 numbers the field automatically places a `` / `` forming the following type `` 2 / 2 / 4 `` insofar as the person is typing . However the...
< div class= '' form-group col-md-12 col-sm-12 col-xs-12 '' > < div class= '' col-md-2 col-sm-2 col-xs-2 form-label '' > { { Form : :label ( 'data ' , 'Data ' ) } } < /div > < div class= '' col-md-10 col-sm-10 col-xs-10 '' > { { Form : :date ( 'data ' , null , [ 'class ' = > 'form-control ' ] ) } } < /div > < /div >
Date format with onchange
JS
I added a video background , everything works except that Google Chrome and Firefox are showing black edges when I 'm playing the video ( see image ) . When I ran the page on Edge and internet explorer the edges did not appear.EDIT : I know the black edges are because I put the container as a black background but I don...
$ ( document ) .ready ( function ( ) { // Resive video scaleVideoContainer ( ) ; initBannerVideoSize ( '.video-container .poster img ' ) ; initBannerVideoSize ( '.video-container .filter ' ) ; initBannerVideoSize ( '.video-container video ' ) ; $ ( window ) .on ( 'resize ' , function ( ) { scaleVideoContainer ( ) ; sca...
Google chrome showing black edges when playing video
JS
I 'm looking to get all the elements that end with a number.So for an example we have a < a > with this href.Now I can get all of the occurences of the href with : However that also gives me results such asSo what I want is that I can only get the hrefs ending with a number to an array . I really would n't want to crea...
href= '' artist.php ? id=8932 document.querySelectorAll ( `` [ href^='artist.php ? id= ' ] '' ) artist.php ? id=8932 # comments
How to search for href ending with numbers with querySelectorAll ( )
JS
I 'm trying to build a responsive footer , but this is maybe interesting for other responsive elements , too.Is there a possibility to hide an element , if the line breaks at its position ? I want for wide screens : And for smaller screens then for example : oretc.So the dividing dot disappears if there is a line break...
< footer > John Doe · Main Street 123 · Sometown · +12 3456 789 < /footer > John Doe · Main Street 123 · Sometown · 012 3456 789 John Doe · Main Street 123 · Sometown012 3456 789 John Doe · Main Street 123Sometown · 012 3456 789 < footer > John & nbsp ; Doe < span class= '' hide-when-linebreak '' > · < /span > Main & n...
hide element after line-break
JS
I have the back to top button that appears when you reach a point on the page , which is working fine , however , when it appears the text is on two lines until the box has finished the animation to appear . So , is there anyway to prevent this ? What I mean by the animation is : btt.show ( 'slow ' ) ; Code : Example :...
$ ( document ) .ready ( function ( ) { var btt = $ ( '.back-to-top ' ) ; btt.on ( 'click ' , function ( e ) { $ ( 'html , body ' ) .animate ( { scrollTop : 0 } , 500 ) ; btt.hide ( 'slow ' ) ; e.preventDefault ( ) ; } ) ; $ ( window ) .on ( 'scroll ' , function ( ) { var self = $ ( this ) , height = self.height ( ) , t...
Javascript button appear animation
JS
I know a lot of JavaScript libraries are depending on `` ontouchstart '' to detect if it 's on tablet or a desktop.Here 's an example of code I 'm talking about : For now , I had to comment out all the tablet detection code for it to work.What would be the best way of detecting a tablet vs a desktop ? Thanks !
var hasTouch = ( `` ontouchstart '' in window ) ;
Chrome 22 confuses tablets and desktops
JS
I am currently working with minification of JS files for improvement of page speed . I have been able to find the simplest method that works with almost all my js files in exception of two . The problem is with the js files for a wmd editor I am trying to implement to my site . The js files wmd.js and showdown.js are n...
< ? phperror_reporting ( E_ERROR ) ; // see http : //web.archive.org/web/20071211140719/http : //www.w3.org/2005/MWI/BPWG/techs/CachingWithPhp// $ lastModifiedDate must be a GMT Unix Timestamp// You can use gmmktime ( ... ) to get such a timestamp// getlastmod ( ) also provides this kind of timestamp for the last// mod...
Compression and mergin of JS files with PHP- Text editor
JS
I 'm trying to apply image filters to an image and have the file element be recreated every time a filter is clicked . Thus , the would be pseudo code . Its still saying the file field is null and im not sure why . I 'm trying to pass the file to my php script that handles uploads but im not sure how to do that in the ...
< div id= '' uploadPic '' class= '' modal fade '' > < form method= '' post '' id= '' fileinfo '' name= '' fileinfo '' onsubmit= '' return submitForm ( ) ; '' > < div class= '' modal-dialog '' > < div class= '' modal-content '' > < div class= '' modal-header '' style= '' background : # f3f3f3 ; '' > < button type= '' bu...
Uploading a cloned canvas photo by dynamically creating a html file element with the default value being the canvas image
JS
I 've seen others using the following pattern . But why ? I can see the point if both were declared , but they 're not . Why is the reason ?
var bar = function foo ( ) { } ; console.log ( bar ) ; // foo ( ) console.log ( foo ) ; // ReferenceError : foo is not defined
Why JavaScript function declaration ( and expression ) ?
JS
I understand that styles can be conditionally rendered such as : This does not look DRY - How can I ( is it possible ) render an entire block of css styles based on props ? Something like :
const HelloWorldLabel= styled ( `` div '' ) < { centered ? : boolean } > ` display : $ { ( { centered } ) = > ( centered ? `` block '' : `` flex '' ) } ; ; margin : $ { ( { centered } ) = > ( centered ? `` auto 0 '' : `` unset '' ) } ; padding : $ { ( { centered } ) = > ( centered ? `` 0 15px '' : `` unset '' ) } ; ` ;...
Styled Components - Conditionally render an entire css block based on props
JS
I have a problem , and I would like you to guide me to solve it if you do not mind ... In my HTML source code had several pieces of css codes here and there . So I decided to put together into a file called principal.css and do the following in the head sectionThis has worked wonderfully ! My idea was to do the same wi...
< link href= '' css/principal.css '' rel= '' stylesheet '' type= '' text/css '' / > $ ( `` [ data-slider ] '' ) .each ( function ( ) { var input = $ ( this ) ; $ ( `` < span > '' ) .addClass ( `` output '' ) .insertAfter ( $ ( this ) ) ; } ) .bind ( `` slider : ready slider : changed '' , function ( event , data ) { $ ...
Move JS code from HTML to source in HEAD section
JS
I have an application that is written around the MEAN web stack . I have created an API that depending upon the URL a JSON data set is returned for given weights . This is interconnected with my Mongo database . There are two returned JSON types , one for all weights and another for weights that fall between two dates ...
< div class= '' container-fluid '' > < h1 class= '' text-center '' > Graphs < /h1 > < div class= '' container '' > < div class= '' col-sm-12 '' ng-controller= '' weights '' > < input type= '' text '' ng-change= '' change ( ) '' ng-model= '' model '' / > < input type= '' daterange '' ng-change= '' change ( { { myDateRan...
Why will a change on $ scope.data on a onChange callback not re-plot chart.js ?
JS
I understand when using arrays of Components the key property is assumed to be the index of the array , and should be explicitly set . Are the children of those children recommended to be explicitly set ?
{ arr.map ( item , i ) = > { < Parent key= { item.ID } > < Child key= { ` child $ { item.ID ` } //required to ensure correct reconciliation ? / > < /Parent > }
nested key property requirements in React
JS
I have the following array : I want to have the following output : How can I achieve this in JavaScript ? Already tried with recursive loop , but it does not work , gives me undefined.Thanks
var sampleArray = [ `` CONTAINER '' , `` BODY '' , `` NEWS '' , `` TITLE '' ] ; var desiredOutput = [ { `` CONTAINER '' : [ { `` BODY '' : [ { `` NEWS '' : [ { `` TITLE '' : [ ] } ] } ] } ] } ] ; dataChange ( sampleArray ) ; function dataChange ( data ) { for ( var i = 0 ; i < data.length ; i++ ) { changeTheArray [ dat...
Flat array to multi dimensional array ( JavaScript )
JS
what is the difference between this regular expressions are the replaceable ? background to this question : The javascript WYSIWYG editor ( tinymce ) fails to parse my html codein Firefox ( 23.0.1 and 25.0a2 ) but works in in Chrome.I found the regular expression to blame : which I modified , replacingwithand withthe r...
( ( ? : [ ^\ '' ] ) * ) ( [ ^\ '' ] * ) attrRegExp = / ( [ \w : \- ] + ) ( ? : \s*=\s* ( ? : ( ? : \ '' ( ( ? : [ ^\ '' ] ) * ) \ '' ) | ( ? : \ ' ( ( ? : [ ^\ ' ] ) * ) \ ' ) | ( [ ^ > \s ] + ) ) ) ? /g ; ( ( ? : [ ^\ '' ] ) * ) ( [ ^\ '' ] * ) ( ( ? : [ ^\ ' ] ) * ) ( [ ^\ ' ] * ) attrRegExp = / ( [ \w : \- ] + ) ( ?...
regular expressions difference between ( ( ? : [ ^\ '' ] ) * ) and ( [ ^\ '' ] * )
JS
I have simple data grid like so : * Note that I have a header and footer in seperate tables in divs above and below the uiGridContent div . That are not required for this example.The idea being that as the user scrolls down the table , it will load in the next page when they reach the bottom of the last tbody in the gr...
< div class= '' uiGridContent '' > < table > < tbody id= '' page-1 '' > < tr > < td > Cell 1 < /td > < td > Cell 2 < /td > < td > Cell 3 < /td > < /tr > < /tbody > < /table > < /div > var nextPage = 1 , lastScrollTop = 0 , st ; $ ( '.uiGridContent ' ) .scroll ( function ( ) { var st = $ ( this ) .scrollTop ( ) ; // We ...
Load and remove pages of content based on scroll direction and height
JS
Well , we have a page running RequireJS , which loads the dependencies , creates the approuter and well , all backbone load.On html page , we load : And this , in principle does not fail ( Say 'Done ' ) , but it does not run any more.It not executes the code ( In main.js ) : This happens only with AdBlocks , not with A...
< script > require.config ( { baseUrl : `` /source/js '' } ) ; require ( [ `` /source/js/main.js '' ] , function ( ) { alert ( 'Done ' ) ; } ) ; < / script > require ( [ 'routers/approuter ' , 'shared ' ] , function ( AppRouter , SharedObject ) { var app_router = new AppRouter ; etc ... ..
AdBlock blocks requirejs / backbone code ( Locks the entire page )
JS
I am having trouble figuring out how to pass the objects method rather than sort `` generic prototype '' method when doing callback.I am passing the onLogin method but well it does not work . This is code I have re-written . Previously I nested all methods inside the Client function but well , I learned that that is no...
function Client ( ) { this.name = `` hello '' ; } Client.prototype.apiCall = function ( method , params , callback ) { callback ( ) ; } Client.prototype.onLogin = function ( error , data ) { console.log ( this.name ) ; // undefined ! ! ! ! } Client.prototype.start = function ( ) { var self = this ; self.apiCall ( 'rtm....
Using callback function with prototype functions
JS
I 'm using angular 1.6.5 for my angular application and came across a very strange behavior.The thing I want to achieve is : when ngroute is being changed , I must remove active class from current view , wait for leave animation to complete , then add active class to the new view.I have set up app and routs in the conf...
var app = angular.module ( 'app ' , [ 'ngAnimate ' , 'ngRoute ' ] ) ; app.config ( function ( $ routeProvider ) { $ routeProvider .when ( '/ ' , { templateUrl : '' home.html '' , reloadOnSearch : false } ) .when ( '/about-us ' , { templateUrl : '' about.html '' , reloadOnSearch : false } ) .when ( '/contact ' , { templ...
Angular not updating ng-class on ng-view
JS
I 'm working on a script that allows the user to draw with the mouse : http : //jsfiddle.net/ujMGu/The problem : If you move the mouse really fast it jerks and skips a few places . Is there any way to capture all the points without any skipping black spaces in between the drawing line ? CSSJS/JQHTML
# myid { background : none repeat scroll 0 0 # 000000 ; color : # FFFFFF ; display : block ; height : 1000px ; margin : 3 % ; position : relative ; text-indent : -1100px ; } ​ $ ( ' # myid ' ) .css ( 'position ' , 'relative ' ) .unbind ( ) .die ( ) .bind ( 'mousemove mouseover ' , function ( e ) { var top = parseInt ( ...
How can I prevent fast mouse movement from breaking a line in my drawing app ?
JS
I 'm using browserify-rails and I 'm trying to get sprockets to preprocess a file that contains a sprockets directive , so that when I require ( ) it using browserify , it will contain the generated JavaScript.The sprockets directive tries to include the output of the gem js-routes , in order to allow me to access the ...
system/ rails_routes.jsapplication.js var rr = require ( `` ./system/rails_routes.js '' ) ; //= require js-routesconsole.log ( `` Does this work ? `` ) ;
Requiring a sprockets-preprocessed file with Browserify and browserify-rails
JS
i 'm trying to have a component only render when I have used a search button . The code below is my current codeUpdateMade the changes , Now receiving this error.error ] ERROR in /home/holborn/Documents/Work/Portfolio/Data_Scraping/Eldritch/client/pages/index.tsx ( 21,19 ) :21:19 Can not find name 'Product ' . 19 | int...
JSX element type 'void ' is not a constructor function for JSX elements . 262 | 263 | return ( > 264 | < Output columns= { columns } message= { message } handleSearch= { handleSearch } searchRef= { searchRef } productList= { productList } / > | ^ 265 | 266 | ) ; 267 | }
Conditional Rendering in React wo n't work , state not working properly ?
JS
I am trying to create an extension off jest-node-environment as a CustomTestEnvironment but am getting the following error when trying to run jestI believe this error means it does n't recognize this as a typescript file , and has n't transpiled it . ( I am using the latest version of jest 26.0.1 ) Based on discussions...
● Test suite failed to run ~/git/my-application/tests/environment/custom-test-environment.ts:1 import NodeEnvironment from 'jest-environment-node ' ; ^^^^^^ SyntaxError : Can not use import statement outside a module at runTestInternal ( ../node_modules/jest-runner/build/runTest.js:226:5 ) import NodeEnvironment from `...
How to create Jest Custom Environment with Typescript ?
JS
I have a question regarding checking the string.The string is from a ckeditor so user can input anything.The variable name is htmlData and it is like : I want to detect if user add a table structure and I have triedbut it does n't show anything in my console . Can anyone gives a hint on this ? Thanks so much !
test here < br / > < table border= '' 1 '' cellpadding= '' 1 '' cellspacing= '' 1 '' style= '' width : 500px ; '' > < tbody > < tr > < td > 111 < /td > < td > 222 < /td > < /tr > < tr > < td > 333 < /td > < td > 444 < /td > < /tr > < tr > < td > 555 < /td > < td > 666 < /td > < /tr > < /tbody > < /table > < br / > seco...
Detect if a string contains a table
JS
I saw this piece of code in React , likebut I failed to google any explanation.Probably the question is dumb , but I appreciate any help , maybe links to some existing explanations or examples .
connect ( mapStateToProps , { test : ( ) = > { return { type : 'TEST_ACTION ' } } } ) ( Index ) ;
What does the notation ( ) = > mean and how to use it ?
JS
I have a RadioButtonList with `` Not Applicable '' , `` Not Available '' , `` Leave '' and `` Available '' options.I am throwing confirm message box on click of `` Leave '' in RadioButtonList from Server side as belowIf user clicks `` Cancel '' , then it will automatically selects `` Available '' with below code . The ...
protected void rdlUser_SelectedIndexChanged ( object sender , EventArgs e ) { radWindowManager.RadConfirm ( `` Are you sure you want to take leave ? `` , `` confirmLeave '' + this.ClientID , 300 , 100 , null , `` '' ) ; } function confirmLeave < % =this.ClientID % > ( arg ) { if ( arg == true ) { alert ( `` User has se...
RadioButtonList not firing SelectedIndexChanged every time
JS
I am attempting to write a function that will convert anything into a function . The function should work as follows : Check to see if it already is a function and if so just returns it.Check to see if it is a string and if so is there a global function with that name , if so return that.Check to see if the string can ...
function canEval ( str ) { try { eval ( str ) ; } catch ( e ) { return false ; } return true ; } function toFunc ( v ) { if ( typeof ( v ) == `` function '' ) return v ; if ( typeof ( v ) == `` string '' ) { if ( window [ v ] ! = undefined & & typeof ( window [ v ] ) == `` function '' ) return window [ v ] ; if ( canEv...
In JavaScript , can I check to see if a string can be evaluated without actually evaluating it ?
JS
I want to do something on all clicks except on a certain element . I 've created a very simple example which demonstrates the issue : http : //jsfiddle.net/nhe6wk77/.My code : I 'd expect all click to on < a > to be ignored , but this is not the case.Am I doing something wrong or is this a bug on jQuery 's side ?
$ ( 'body ' ) .on ( 'click ' , ' : not ( a ) ' , function ( ) { // do stuff } ) ;
Delegated events do n't work in combination with : not ( ) selector
JS
I want to programmatically hide and show my embedded aframe scene . The scene is hidden when the website is loaded , however I only get it to work with a delay like this : When I do n't add this delay , the scene remains hidden , even after setting it to 'visible ' again . Specifically , the size of the canvas seems to...
window.onload = function ( ) { setTimeout ( function ( ) { document.getElementById ( `` scene-page '' ) .setAttribute ( `` hidden '' , `` '' ) ; } , 500 ) ; } < canvas class= '' a-canvas a-grab-cursor '' data-aframe-canvas= '' true '' width= '' 0 '' height= '' 0 '' style= '' width : 0px ; height : 0px ; '' > < /canvas ...
Hiding an embedded aframe scene
JS
I 've a sample example below , I 'm not sure why the first example ( using div 's ) did n't get the text when the second one ( using span 's ) could achieve that with the same JS code using closest ( ) : First snippet ( using div 's ) cant get the text using closest ( ) : Second snippet ( using span 's ) getting the te...
$ ( '.class-1 ' ) .closest ( 'div ' ) .find ( '.class-2 ' ) .text ( ) console.log ( $ ( '.class-1 ' ) .closest ( 'div ' ) .find ( '.class-2 ' ) .text ( ) ) ; < script src= '' https : //ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js '' > < /script > < div > < div class= '' class-1 '' > Div 1 Content < /div > <...
closest ( ) method not working as expected
JS
Would someone explain why formatting the same dateString differently gives a different date ?
> new Date ( `` 04/08/1984 '' ) < · Sun Apr 08 1984 00:00:00 GMT-0600 ( Mountain Daylight Time ) > new Date ( `` 1984-04-08 '' ) < · Sat Apr 07 1984 18:00:00 GMT-0600 ( Mountain Daylight Time )
Javascript new Date ( dateString ) handling
JS
I 've inherited a rather large Javascript/ExtJS3 code base , and there are many instances of invoking events inside of the overridden initComponent method , after the call to `` ... superclass.initComponent.apply ( this , arguments ) '' . Specific events are being invoked on specific objects in a manner such as the fol...
this.filter.on ( 'filterUpdated ' , function ( filter , params ) if ( this.tpl ) { if ( ! this.tpl.compile ) { this.tpl = new Ext.XTemplate ( this.tpl ) ; } if ( this.data ) { this.tpl [ this.tplWriteMode ] ( contentTarget , this.data ) ; delete this.data ; } } this.afterRender ( this.container ) ;
Is publishing/subscribing to events after UI rendering a best practice regardless of framework ?
JS
GoalI would like to write a javascript library ( framework ) , but need OOP and mixins.Was giving a go to typescript , but it does n't support mixins ( the handbook says it does , but the compiler/specifications has nothing that is mixin related ) .TypescriptIn typescript , the following code : Compiles to : Then clien...
class Greeter { greeting : string ; constructor ( message : string ) { this.greeting = message ; } greet ( ) { return `` Hello , `` + this.greeting ; } } var Greeter = ( function ( ) { function Greeter ( message ) { this.greeting = message ; } Greeter.prototype.greet = function ( ) { return `` Hello , `` + this.greetin...
Can dart produce readable javascript libraries ?
JS
I do n't know if this is possible in css , I am sure that it can be done in js but i do n't know how ... I have a div with a background and a text that is in another div with another background . What I would like is the text to be transparent and have the first-background as the text background . I do n't know if this...
< div id= '' first-background '' > < div id= '' second-background '' > < h1 > This text should be transparent and have the first-background as its background and ignore the second background. < /h1 > < /div > < /div >
Transparent text which ignores the first background
JS
So basic desctucturing is fine , { a , b } = obj transpiles to a = obj.a ; b = obj.b.My question is around a bit of an odd syntax that I accidentally ran across and I 'm wondering if someone can point me at spec since I ca n't find it : That does the two a , b assignments and then returns obj.c . It 's actually quite u...
( { a , b } = obj ) .c let width = ( { bytes } = intDecode ( bytes ) ) .number ;
Is Babel 's implementation of ES6 object destructuring correct ?
JS
I have a form with two fields : The error div is always displayed when the password field is empty - I only want it to display if the password has been focused and then blurred . Is there a simple change I can make to enable this ?
< form name= '' form '' > < input type= '' email '' ng-model-options= '' { updateOn : blur } '' required / > < input type= '' password '' ng-model-options= '' { updateOn : blur } '' required / > < div ng-show= '' form.password. $ error.required '' > Password required < /div > < /form >
Angular Form - `` Required '' with ng-model-options
JS
My ultimate goal is to use Yarn Workspaces in a project using Browserify and Babel 7 . This is a minimal reproduction of a problem I 'm having . Basically it seems that the presence of a package.json file in a subfolder ( which is one of the things that you have when using Yarn Workspaces ) breaks my Browserify build ,...
$ npm install $ npm run build > browserify-babelify-yarn-workspaces @ 1.0.0 build /home/user/projects/browserify-babelify-yarn-workspaces > browserify a/index.js -t babelify -- outfile bundle.js $ echo `` { } '' > a/package.json $ npm run build > browserify-babelify-yarn-workspaces @ 1.0.0 build /home/user/projects/bro...
Yarn Workspaces and Browserify - package.json in subfolder breaks the build
JS
I am very confused as to why only the last element is inserted when I try to append multiple elements within a for loop.I have created a JsFiddle showcasing my inability to get it to work . I expect 100 anchor tags to be inserted , yet only the last element is inserted.For posterior 's sake , here 's the relevant JavaS...
Math.randomNumber = function ( max ) { return Math.round ( Math.random ( ) * max % max ) ; } var Door = { $ el : $ ( ' < a > ' , { class : 'door selectable ' } ) , number : null , isSelected : false , containsZonk : true , bind : function ( ) { var that = this ; this. $ el.on ( 'click tap ' , function ( ) { that.isSele...
How to insert multiple elements into one element via append in a for loop ?
JS
I have a process to get images in node.js using either jsdom or Canvas . During the download process , I want to extract swatches using Vibrant.js in the backend . Neither of my code below works.Using jsdomUsing CanvasI could use URL in Vibrant.js but that 's another http GET using Bluebird and I need to avoid calling ...
const Vibrant = require ( 'node-vibrant ' ) ; const request = require ( 'request ' ) ; var jsdom = require ( `` jsdom '' ) .jsdom ; var window = jsdom ( ) .defaultView ; var document = jsdom ( ' < html > < body > < /body > < /html > ' , { features : { FetchExternalResources : [ 'img ' ] } } ) ; var imgDom = document.cr...
Get Vibrant.js swatches using jsdom or Canvas for node.js
JS
People is a nested class . Its parent class is Family.I get the error that Family.People is undefined . Could someone correct the code above ?
Family = function ( name ) { this._Name = name ; } Family.prototype = { getName : function ( ) { return this._Name ; } , People : function ( num ) { this._Number = num ; } } Family.People.prototype = { clearNumber : function ( ) { this._Number = 0 ; } }
Javascript prototype and issues accessing class
JS
is it OK to use the more than 1 time in the javascript code ?
$ ( document ) .ready ( function ( ) { // some code } ) ;
Jquery - More than 1 `` $ ( document ) .ready '' = dirty code ?
JS
Is there a better way to check if an object is empty ? I 'm using this :
function isObjEmpty ( obj ) { for ( var p in obj ) return false ; return true ; }
Empty JS Object
JS
My Angular app is developed using a boilerplate of this yeoman generator.Routing and all things working fine but I could not get to working $ scope only on navbar-controller.js and footer-controller.js . Please tell me if you need more information to give a clue about this.Index.htmlnavbar-controller.jsnavbar-module.js...
< ! DOCTYPE html > < html lang='en ' data-ng-app='app ' > < head > < title > App < /title > < meta name='viewport ' content='width=device-width , minimum-scale=1.0 , initial-scale=1.0 , user-scalable=yes ' > < ! -- inject : head : js -- > < ! -- endinject -- > < ! -- inject : html -- > < ! -- endinject -- > < ! -- bowe...
$ scope not working in my nav bar controller ?
JS
I 'm having an issue that only appears to affect IE and Edge ( tested on IE9-11 & Edge 12-13 ) . I 'm animating an SVG stroke offset with Snap.svg which seems to run fine but at certain points the stroke appears to go `` out of bounds '' and disappear . It 's odd since the viewBox is set to clearly fit the line ( it wa...
// SSSSSNAKEvar snake = Snap ( ' # snake-preview svg ' ) ; var bodyPath = snake.select ( ' # snake-body ' ) ; var bodyPathBreakfast = snake.select ( ' # snake-body-breakfast ' ) ; var bodyPathLunch = snake.select ( ' # snake-body-lunch ' ) ; var bodyPathDinner = snake.select ( ' # snake-body-dinner ' ) ; var headPath =...
SVG animation appears `` out of bounds '' on IE & Edge
JS
Is there a better way than this to create a callback function for some random function ? The callback function does n't have any parameter when I utilize it , I only do like this :
var showObj = function ( obj , callback ) { return setTimeout ( function ( ) { if ( opts.centerObj == true ) { var cssProps = getProps ( obj ) ; obj.css ( cssProps ) .fadeIn ( 'slow ' ) ; } else { obj.fadeIn ( 'slow ' ) ; } if ( typeof callback == 'function ' ) { callback.call ( this ) ; } } , 1500 ) ; } showObj ( obj ...
Best Way To Create A Callback Function
JS
I am having some weird issue with ng-class , and I am suspecting that it has to do with race condition.Here is plunker exampleHere is the relevant js codeHere is the relevant htmlHere is the animation.This is a simple app that slide a list of number left and right.If the left button is pressed , the numbers slide left....
self.slideLeft = function ( ) { if ( self.end_index < self.list_of_stuff.length ) { self.direction = 'left ' ; debugger ; self.start_index = self.start_index + 4 ; self.end_index = self.end_index + 4 ; self.display_list = self.list_of_stuff.slice ( self.start_index , self.end_index ) ; } } self.slideRight = function ( ...
Race condition with ng-class and animation
JS
Is it possible to configure ESLint in WebStorm so functions , variables , etc . are parsed also from files in the same folder ? In my build process , I concatenate all files in the same folders into big closures , for example : I would like ESLint to treat all those files just like one , so I do n't get `` undef '' err...
src/ main/ === > `` main.js '' api.js init.js ui.js constants.js . . renderer/ === > `` renderer.js '' core.js events.js
Use all files in a folder like a one big JS
JS
I have recently been assigned to take over and clean up an Angular project that is already complete and in production . This is my first time using Angular.Everything I 've read so far on Angular ... https : //www.airpair.com/angularjs/posts/top-10-mistakes-angularjs-developers-makehttp : //nathanleclaire.com/blog/2014...
( function ( ) { app.controller ( 'MenuController ' , function ( $ scope ) { ... $ scope.openMenu = function ( ) { $ ( '.off-canvas-wrap ' ) .addClass ( 'offcanvas-overlap-right ' ) ; } ; ... } ) ; } ( ) ) ;
How do I properly implement DOM manipulation in Angular ?
JS
I have an application which allows users to pick some time slots . By default the timeslots are empty , and my .NET back-end has default generated values of type DateTimeOffset , which by default are set to `` 0001-01-01T00:00:00+00:00 '' .Now , when I populate a date on the front-end with this value , it generates a d...
console.log ( new Date ( `` 2001-01-01T00:00:00+00:00 '' ) .toString ( ) ) // Mon Jan 01 2001 02:00:00 GMT+0200 ( Eastern European Standard Time ) console.log ( new Date ( `` 1001-01-01T00:00:00+00:00 '' ) .toString ( ) ) //Thu Jan 01 1001 02:02:04 GMT+0202 ( Eastern European Standard Time ) console.log ( new Date ( ``...
Wrong minutes and seconds in a JavaScript date before year 1925
JS
It is clear , how does the method work : But , why do I need such mechanism ? For which use-cases ?
f = [ ' a ' , ' b ' , ' c ' , 'd ' , ' e ' , ' f ' , ' g ' , ' h ' ] ; console.log ( f.copyWithin ( 4,2,5 ) ) ; // copy elements between 2 ( start ) & 5 ( end ) - > to target - > 4 // [ ' a ' , ' b ' , ' c ' , 'd ' , ' e ' , ' f ' , ' g ' , ' h ' ] < -- original array// ^ ^ ^// | | | < -- [ 2,5 [ = c , d , e// 0 - 1 - ...
For which use cases does Array.prototype.copyWithin ( ) exist ?
JS
People here are using visual studio for performance testing . Now there are some small issues with some javascript parts : they are not able to check the performance of the javascript part with visual studio web-performance testing.I never used visual studio performance test , so I really have no idea how to bench stuf...
var begin = new Date ( ) ; functionA ( ) ; functionB ( ) ; functionX ( ) ; var end = new Date ( ) ; var bench = end - begin ;
Read JS variable in C # / Forwarding JS variable to visual studio performance test ?
JS
I do n't know exactly how to name this or how to explain it , so I 'll give you some examples of what I have and what I want to create ... I have a list of divs , all of them with an own style , in a way that they look as Forums and sub-forums ... Here I 'll show a picture of what I have : The code is simple : And the ...
< div id= '' Forums '' > < div class= '' category '' > Category < /div > < div class= '' forum '' > Forum < /div > < div class= '' sub-forum '' > Sub-forum < /div > < div class= '' sub-forum '' > Sub-forum < /div > < div class= '' sub-forum '' > Sub-forum < /div > < div class= '' forum '' > Forum < /div > < /div > .cat...
Dashed-styled list linking divs
JS
I 'm trying to duotone an image and plaster it onto a canvas.Works in desktop browsers : ChromeFirefoxSafariInternet ExplorerFails in mobile browsers : AndroidWorkable demo on JSFiddle , this example works in Chrome but fails in Android 's default browser . The code is : The summary is : set the background color to gra...
< style > body { background-color : gray ; } < /style > < canvas id= '' mycanvas '' width= '' 64 '' height= '' 64 '' > < /canvas > < script > var image = new Image ( ) ; image.src = 'image.png ' ; image.onload = function ( ) { //once the image finishes loading var context = document.getElementById ( `` mycanvas '' ) .g...
Image alpha on default Android browser
JS
trying to set up random background images for my Jumbotron . Here is what I have so far . This works however on page load the styles defined in my css sheet seem to be overwritten ? Is there a way to load these random images and keep the other styles already defined ? Also , another quick question.. I used getElementsB...
function randomImage ( ) { var images = [ `` https : //encrypted-tbn0.gstatic.com/images ? q=tbn : ANd9GcTZwkTaJg28-Bxidgfm6FbHyEZ8D5ya1hGMroF05htuwvQqJsY9sQ '' , `` http : //www.shunvmall.com/data/out/193/47120931-random-image.png '' , `` https : //s-media-cache-ak0.pinimg.com/originals/2b/05/14/2b05140a776f25a8047c88...
Javascript Random Image Losing Styling
JS
I was trying to make a pipe in typescript that would split a PascalCase string , but it would be nice if this would also split on digits as well . I would also like it to split on consecutive capital letters . I have this pipe , which works great , except it only works in Chrome and not Firefox , evidently only Chrome ...
transform ( value : string ) : string { let extracted = `` ; if ( ! value ) { return extracted ; } const regExSplit = value .split ( new RegExp ( ' ( ? < = [ a-z ] ) ( ? = [ A-Z ] ) | ( ? < = [ A-Z ] ) ( ? = [ A-Z ] [ a-z ] ) | ( ? < = [ 0-9 ] ) ( ? = [ A-Z ] [ a-z ] ) | ( ? < = [ a-zA-Z ] ) ( ? = [ 0-9 ] ) ' ) ) ; for...
Split a string on a capital letter or numbers
JS
I 'm trying to display the image using cover simulation in canvas . I 've found some cool answer on how to do it.The thing is when I do it with a large picture , it 's being displayed ugly . How to fix that ? Here 's my CodepenHTMLCSSJS
< canvas id= '' canvas '' > < /canvas > canvas { width : 100 % ; height : 100vh ; } var ctx = canvas.getContext ( '2d ' ) , img = new Image ; img.onload = draw ; img.src = 'https : //upload.wikimedia.org/wikipedia/commons/0/0f/2010-02-19_3000x2000_chicago_skyline.jpg ' ; function draw ( ) { drawImageProp ( ctx , this ,...
Getting ugly image while simulating cover in canvas
JS
Question is bit crazy . Is there any possibility to using variable name instead of another , clearly , consider the following code where I have to switch over to any variable name `` people '' or `` student '' accordingly
var people= [ { name : '' akash '' , age:25 } , { name : '' abi '' , age:22 } ] ; var student = [ { name : '' Sanjai '' , age:25 } , { name : '' Ravi '' , age:35 } , { name : '' Bopara '' , age:36 } ] ; var variables= [ `` people '' , '' student '' ] ; var result= _.find ( variables [ 0 ] , function ( o ) { return o.ag...
using variable name in lodash collection
JS
I have a class like so : How would I turn the send method into a promise , which returns a value from the socket 's data event ? The server only sends data back when data is sent to it , other than a connection message which can easily be suppressed.I 've tried something like : Obviously this wo n't work because resolv...
import net from 'net ' ; import { EventEmitter } from 'events ' ; import Promise from 'bluebird ' ; class MyClass extends EventEmitter { constructor ( host = 'localhost ' , port = 10011 ) { super ( EventEmitter ) ; this.host = host ; this.port = port ; this.socket = null ; this.connect ( ) ; } connect ( ) { this.socket...
How can I control program flow using events and promises ?
JS
I 'm attempting to create something of a tree structure.I wish to access my data as follows : However , key1 and key2 have a symmetric relationship ; the following is always true : More specifically , I have data [ key1 ] [ key2 ] and data [ key2 ] [ key1 ] pointing to the same object , such that changes to one affect ...
data [ key1 ] [ key2 ] data [ key1 ] [ key2 ] == data [ key2 ] [ key1 ] delete data [ key1 ] [ key2 ] ;
javascript - objects immutable ?
JS
I 'm working on a project that uses MongoDB , but I 've never worked with it.I understand that by using javascript , you can manipulate the database . I made a script that removes some fields and adds some others , but it does n't work properly : When db.floor.save ( doc ) is called , my floor is saved . All tiles now ...
db.floor.find ( { _id : '' 003 '' } ) .forEach ( function ( doc ) { // Find floor with id = 003. var tiles = doc.tiles ; // Get tiles from floor . for ( var i = 0 ; i < tiles.length ; i++ ) { // Loop through tiles . var tile = tiles [ i ] ; // Get tile at index i. if ( tile.nodeType ) { // If tile has a field `` nodeTy...
MongoDB adding and removing fields in array