lang stringclasses 4
values | desc stringlengths 2 8.98k | code stringlengths 7 36.2k | title stringlengths 12 162 |
|---|---|---|---|
JS | I can not navigate to /users in my app , because it doesn ` t trigger fetching of all queries that I would expect it should . My app consists of an App component and some components that contain actual content like Dashboard or UserList . There is also an EnsureAuthenticationContainer but this is just a component that ... | const ViewerQueries = { viewer : ( ) = > Relay.QL ` query { viewer } ` } ; < Router history= { browserHistory } render= { applyRouterMiddleware ( useRelay.default ) } environment= { Relay.Store } > < Route path= '' / '' component= { App } queries= { ViewerQueries } > < Route path= '' login '' component= { Login } / > <... | Relay : How to merge instead of override queries in nested routes ? |
JS | MDN suggested that `` When the iterator 's next ( ) method is called , the generator function 's body is executed until the first yield expression '' and I do understand this example : However , I am confused when I come across another example : If the first next ( ) only execute code BEFORE the first yield , the value... | function* logGenerator ( ) { console.log ( 0 ) ; console.log ( 1 , yield ) ; console.log ( 2 , yield ) ; console.log ( 3 , yield ) ; } var gen = logGenerator ( ) ; gen.next ( ) ; // 0gen.next ( 'pretzel ' ) ; // 1 pretzelgen.next ( 'california ' ) ; // 2 californiagen.next ( 'mayonnaise ' ) ; // 3 mayonnaise const foo ... | Does the first next ( ) in js generator function always execute until the first yield ? |
JS | I want to set string properties on my array.E.g.The idea is to store some meta-data on the array itself.Is this a good approach ? Am I creating any problems by doing this ? | function readInput ( arr ) { var data = db.query ( 'something ' ) ; arr.itemType = data.itemType ; // - > This arr.push.apply ( arr , data.list ) ; } var myArr = [ ] ; readInput ( myArr ) ; | What are the drawbacks of setting string properties on arrays ? |
JS | Using jQuery when changing .html ( ) of an < option > inside a < select > ( Which I had previously set selectedIndex property to -1 ) resets selectedIndex property of < select > from '-1 ' to ' 0'http : //jsbin.com/filowe/2/edit ? html , output | < ! DOCTYPE html > < html > < head > < script src= '' //code.jquery.com/jquery-2.1.1.min.js '' > < /script > < meta charset= '' utf-8 '' > < title > JS Bin < /title > < /head > < body > < select id= '' myselect '' class= '' drpmnu '' > < option id= '' one '' > ( 01 ) < /option > < option id= '' two '' > ( 02 ) < /optio... | Changing .html ( ) of < option > resets selectedIndex property of < option > from '-1 ' to ' 0 ' |
JS | I came across this gist today , and in the comments the author mentioned thatis unnecessary , because in Javascript you can just use log to access the DOM element . Is this true across all browsers ? Is there a name/reference for this technique ? | var log = document.getElementById ( 'log ' ) ; | Is document.getElementById ( 'id ' ) or $ ( ' # id ' ) still necessary to select an element by ID ? |
JS | I was trying to implement a functionality where a user can reset a password . I have tried the below code and while I am not getting any error , its not updating the password . The password is the same ie the old password.my User model file is as follows : -My routes file is as follows : -I am a bit confused where I ha... | const mongoose = require ( 'mongoose ' ) ; var passportLocalMongoose = require ( `` passport-local-mongoose '' ) ; const LoginUserSchema = new mongoose.Schema ( { name : { type : String , required : true } , email : { type : String , unique : true , required : true } , password : { type : String , required : true } , d... | NodeJs : - Getting `` missing credentials '' error while using local passport |
JS | I need to set a datetime-local picker 's default value to the current local time . Native JS seems to output in local time by default : However functions like toISOString ( ) output in UTC , and although I can pull out individual components locally , I do n't really want to fiddle around with padding and such . So I tr... | new Date ( $ .now ( ) ) ; // `` Sat Nov 12 2016 22:36:52 GMT+1100 ( AEDT ) '' moment ( ) .local ( ) .format ( ) ; // `` 2016-11-12T22:34:05+11:00 '' moment ( ) .local ( ) .format ( 'YYYY-MM-DThh : mm ' ) ; // `` 2016-11-12T10:39 '' | Moment.js formats locally until I specify the format |
JS | I looking for why closest ( ) find first itself element before traversing tree . For example : I would like fadeOut the parent div element when i click on children element , but the children element is too a div and so is the children who fadeOutWhy is itself element who fadeOut and no the parent div element ? I know p... | $ ( document ) .on ( `` click '' , `` .close '' , function ( ) { $ ( this ) .closest ( `` div '' ) .fadeOut ( ) ; } ) ; .feed { width : 200px ; height : 200px ; background : red ; position : relative ; } .close { position : absolute ; top : 0 ; right : 0 ; } < script src= '' https : //ajax.googleapis.com/ajax/libs/jque... | Why closest ( ) find first itself element before travesing tree |
JS | I am trying to populate the < mdt-column > inside of < mdt-header-row > dynamically with an array from controller . This piece of code does n't seem to work properly : hide-column-by-default= '' c.selector_hidden '' When loading the table default columns are not displayed . Some columns are set as default and are exclu... | < mdt-header-row > < mdt-column hide-column-by-default= '' c.selector_hidden '' exclude-from-column-selector= '' c.selector_exclude '' column-sort= '' c.sort '' sortable-rows-default= '' c.sort_default '' column-key= '' { { c.key } } '' align-rule= '' { { c.align } } '' column-definition= '' { { c.definition } } '' ng-... | Default Column are not displayed in Material Design Data Table ( iamisti/mdDataTable ) |
JS | I am still on my chart , and I need to default close the level 2 & 3 nodes , and keep the expand/collapse function on click.Depending on the node clicked and its level , run a specific action ( change color for example ) . My link must be a value of my data object ( var pubs in my codepen ) as you can see bellow ( leve... | { `` name '' : `` TOOLS '' , `` children '' : [ { `` name '' : `` Localization '' , `` url '' : `` http : // # '' , `` children '' : [ { `` name '' : `` FRANCE '' , `` url '' : `` http : //france.fr '' } ... | Add event listener per nodes level on d3 chart |
JS | In JavaScript , it seems : Why is it not 4294958077 ? It suggests that there 's some sort of overflow kicking in ( although as I understand it a JavaScript Number type 's range is +/- 9007199254740992 so that 's odd in itself . ) Even if it was an overflow , surelyshould evaluate as true - but it doesn't.Help please | ( 4294958077 | 0 ) == -9219 ( 4294958077 | 0 ) == 4294958077 | Why is JavaScript bitwise OR behaving strangely ? |
JS | While experimenting with some different methods for generating JavaScript arrays , I stumbled on a weird result . Using map to push an array of self-references ( DEMO ) : I get the following result ( in Chrome ) : Can anyone explain why ? | a= [ 1,1,1,1,1,1,1,1,1,1 ] ; a=a.map ( a.push , a ) ; [ 13,16,19,22,25,28,31,34,37,40 ] | Array Self-Referencing Map - Very Bizarre Result |
JS | I 'm looking for a better way to manage global component/plugin/widget initialization in a large project . It has many jQuery-powered components that I would like to initialize quickly & efficiently and after scouring the internet , I 've only really found short-sighted examples that are only realistic/performant in sm... | $ ( function ( ) { $ ( '.widget-one ' ) .widgetOne ( ) ; } ) ; $ ( function ( ) { $ ( '.widget-two ' ) .widgetTwo ( ) ; } ) ; $ ( function ( ) { $ ( '.widget-three ' ) .widgetThree ( ) ; } ) ; $ ( function ( ) { $ ( '.widget-four ' ) .widgetFour ( ) ; } ) ; $ ( function ( ) { $ ( ' # WidgetOne ' ) .widgetOne ( ) ; } ) ... | jQuery , A search for a smarter way to Initialize |
JS | The table header is fixed , but it is at the top of the page after scrolling . It works exactly how I want it , except the thead is fixed in the wrong place.The table has an overflow-x : auto and the TD are using white-space : nowrap so the table expands to handle the content.I need it to be fixed 140 pixels from the t... | ; ( function ( $ ) { $ .fn.fixMe = function ( ) { return this.each ( function ( ) { var $ this = $ ( this ) , $ t_fixed ; function init ( ) { $ this.wrap ( ' < div class= '' container '' / > ' ) ; $ t_fixed = $ this.clone ( ) ; $ t_fixed.find ( `` tbody '' ) .remove ( ) .end ( ) .addClass ( `` fixed '' ) .insertBefore ... | Table Header Fixed beneath Fixed Page Header |
JS | I 'm trying to solve this puzzle minded Javascript OOP problem.So I have the following class : When I call every method I expect to print the name of it , right ? But here is what i get : But when my class looks like this : Why is this happening ? | var ClassA = function ( ) { this.initialize ( ) ; } ClassA.prototype = { methods : [ 'alpha ' , 'beta ' , 'gama ' ] , initialize : function ( ) { for ( var i in this.methods ) { this [ this.methods [ i ] ] = function ( ) { console.log ( this.methods [ i ] ) ; } } } } var a = new ClassA ( ) ; a.alpha ( ) ; // returns ga... | Javascript classes and variable references |
JS | I want to let users enter the vehicle number and then read the data and show the vehicle details to the user . I do n't want to do it in a webview . I am able to fill the data using this code : Here is the website which shows the data for this app.https : //parivahan.gov.in/rcdlstatus/vahan/rcstatus.xhtmlNow I am tryin... | webView = ( WebView ) findViewById ( R.id.webView1 ) ; webView.getSettings ( ) .setJavaScriptEnabled ( true ) ; webView.loadUrl ( `` https : //parivahan.gov.in/rcdlstatus/vahan/rcstatus.xhtml '' ) ; webView.setWebViewClient ( new WebViewClient ( ) { public void onPageFinished ( WebView view , String url ) { String reg1... | Fill website data and click button and parse response |
JS | I have created a simple Hello world app using Angular 4 ( 4.3.0 ) . Angular files : — app.component.ts— app.component.html— app.module.ts TypeScript file Webpack fileHere is the full file but the important parts are : And DiagnosticsBefore optimization - When I run > webpack ( without webpack -- env.MODE=prod ) in cmd ... | @ Component ( { selector : 'app-root ' , templateUrl : './app.component.html ' , styleUrls : [ './app.component.css ' ] } ) export class AppComponent { myTitle : string ; constructor ( ) { this.myTitle = ` Hello world ` ; } } < h1 > { { myTitle } } < /h1 > import { BrowserModule } from ' @ angular/platform-browser ' ; ... | Angular4 & Webpack - 300kb ( after optimization ) for a simple `` hello world '' app ? |
JS | I 've been pouring over my code over and over again and I just ca n't see why it 's not working correctly ... Can someone enlighten me ? What 's the issue here ? I just do n't see it.The code should allow the user to enter various values into textboxes to change some of the image 's features such as border size , color... | < html > < head > < title > Image Properties < /title > < script type= '' text.javascript '' > function changeImage ( ) { //applies a new border size document.getElementById ( 'img ' ) .border = document.getElementById ( 'bs ' ) .value ; //applies a new border color document.getElementById ( 'img ' ) .style.borderColor... | Javascript image properties |
JS | Just experimenting with different inheritance techniques in JS , and came across something mildly discomfiting about Crockford 's Prototypal Inheritance pattern : It 's all good - except when you log to console - the object appears as F. I 've seen classical emulation in which you can repoint the constructor - is there... | function object ( o ) { function F ( ) { } F.prototype = o ; return new F ( ) ; } var C , P = { foo : 'bar ' , baz : function ( ) { alert ( `` bang '' ) ; } } C = object ( P ) ; | Minor drawback with Crockford Prototypical Inheritance |
JS | I have two JSON objects defined in a controller ( NotificationsController ) . One with all the notifications and another one with only the ID of the newest notifications ( last 3 days ) .Format of object `` notifications '' : ( t_notifications ) Format of object `` newest notifications '' : ( newest_notifications ) I '... | [ { `` 0 '' : '' 1 '' , '' 1 '' : '' 4 '' , '' 2 '' : '' 14-APR-16 '' , '' 3 '' : '' ALERT 1 '' , '' ID '' : '' 1 '' , '' ID_USER '' : '' 4 '' , '' DATE '' : '' 14-APR-16 '' , '' NOTIFICATION '' : '' ALERT 1 ! `` } , { `` 0 '' : '' 2 '' , '' 1 '' : '' 1 '' , '' 2 '' : '' 07-APR-16 '' , '' 3 '' : '' ALERT 2 ! `` , '' ID... | Searching through JSON Object with ng-class ( AngularJS ) |
JS | I have this function : How do I fix this with ES6+ destructuring ? I know I need something like ( on line 4 ) : const { basketItem : quantity } = quantity ; but I ca n't get line 3 working | const calculateTotal = ( items ) = > { return items.reduce ( ( totalPrice , basketItem ) = > { const price = basketItem.product.price ; const quantity = basketItem.quantity ; const total = price * quantity ; return totalPrice + total ; } , 0 ) ; } ; | Prefer destructuring es-lint error |
JS | I was looking at some of the AJAX calls that GMail does , and I noticed that sometimes the return value of the calls started with a number . Example : ( note that there 's is no semi-colon after the first line ) If I were to enter this into a JavaScript console , I 'd get undefined returned back . However , if the seco... | 3 [ 1 , 2 ] ; 34 | Why does `` 3 [ 1 , 2 ] ; '' return undefined in JavaScript ? |
JS | So I know what this does : Now I have seen people doing this lately : Are these two ways of doing the same thing ? I see an anonymous function being declared inside a jquery selector here , but never actually being invoked , yet by the way the page runs it seems that this may just run on pageload . | $ ( document ) .ready ( function ( ) { // Your code here ... } ) ; < script type= '' text/javascript '' > $ ( function ( ) { // Your code here ... } ) ; < /script > | What is the difference between $ ( document ) .ready ( function ( ) and $ ( function ( ) ? |
JS | Recently , I read the ECMAScript Language Specification . I did n't plan to read the whole specification , I just picked up some parts . I came cross many questions , one of them is like this : ToLengthAs I understand , it should be like this : I did n't understand what the meaning of ReturnIfAbrupt ( len ) is , and I ... | 1.Let len be ToInteger ( argument ) .2.ReturnIfAbrupt ( len ) .3.If len ≤ +0 , then return +0.4.Return min ( len , 2^53-1 ) . var len = ToInteger ( argument ) ; // step 1len = ReturnIfAbrupt ( len ) ; // step 2// step 3if ( len < =0 ) { return +0 ; //-0 is OK too ? } return Math.min ( len , Math.pow ( 2,53 ) -1 ) ; // ... | ECMA-262 ReturnIfAbrupt |
JS | When using higher order function of the Array API in javascript ( forEach , map , filter , etc . ) there are 2 means to pass `` this '' variable : OrWhich one is the better ? What are the pros and cons ? Example : http : //jsfiddle.net/TkZgX/ | myArray.forEach ( function ( value ) { this.aContextualFunction ( ) ; } , this ) ; var self = this ; myArray.forEach ( function ( value ) { self.aContextualFunction ( ) ; } ) ; | javascript higher order functions ; `` this '' parameters vs external `` self '' variable |
JS | I was working with query params , and got introduced to URLSearchParams . I am using it to form this kind of object to query , Here , I dont want to have that c= , as it 's ugly , and my API does n't need that.So , I want this result a=hello+World & b=23 ( without empty query string ) But , I could n't find anything on... | const x = { a : 'hello World ' b : 23 c : `` } let params = new URLSearchParams ( x ) ; console.log ( params.toString ( ) ) // a=hello+World & b=23 & c= const x = { a : 'hello World ' , b : `` , c : `` } ; let params = new URLSearchParams ( x ) ; params.forEach ( ( v , k ) = > { // never reaches ` c ` console.log ( k ,... | How to remove empty query params using URLSearchParams ? |
JS | I want to get the id of the first div ( it 's bar1 here ) when li is clicked . And there are more lis same as above . All those lis also have the CSS class `` intro-item '' When I click each of these , I want to get the id of first div.The idea is like this | < li class= '' intro-item '' > < a href= '' ... '' > Something < /a > < div id= '' bar1 '' > < /div > < div id= '' bar2 '' > < /div > < div id= '' bar3 '' > < /div > < div id= '' bar4 '' > < /div > < div id= '' bar5 '' > < /div > < /li > $ ( 'li.intro-item ' ) .click ( function ( ) { alert ( $ ( ' ( this ) div : first ... | get the id of the first div within the clicked li |
JS | We 've been using the Page Object pattern for quite a while . It definitely helps to organize the end-to-end tests and makes tests more readable and clean.As Using Page Objects to Organize Tests Protractor documentation page shows us , we are defining every page object as a function and use new to `` instantiate '' it ... | `` use strict '' ; var HeaderPage = function ( ) { this.logo = element ( by.css ( `` div.navbar-header img '' ) ) ; } module.exports = HeaderPage ; `` use strict '' ; var HeaderPage = require ( `` ./../po/header.po.js '' ) ; describe ( `` Header Look and Feel '' , function ( ) { var header ; beforeEach ( function ( ) {... | Canonical way to define page objects in Protractor |
JS | I just started using async/await and is confused on how it interacts with callback . For example , vs Must fooMethod be written in a specific way so that it can handle an async function as callback ? if fooMethod is a public library , how do I know that it is safe to add async keyword to the function ? FOLLOW UPExpress... | fooMethod ( function ( ) { return Promise.resolve ( `` foo '' ) ; } ) ; fooMethod ( async function ( ) { //add async keyword return `` foo '' ; } ) ; app.get ( '/foo ' , function ( req , res ) { return res.send ( `` foo '' ) ; } ) ; app.get ( '/foo ' , async function ( req , res ) { return res.send ( `` foo '' ) ; } ) ... | Async function as callback |
JS | I have the following script which fetches data ( branch names ) asynchronously via database : HTMLEverything is working perfectly , When user clicks link the data ( branch name ) gets added to the text input field , which is exactly what needs to happen , however ... My ProblemAfter user has clicked on desired link ( b... | $ ( document ) .ready ( function ( ) { $ ( `` # pickup '' ) .on ( 'keyup ' , function ( ) { var key = $ ( this ) .val ( ) ; $ .ajax ( { url : 'modal/fetch_branch.php ' , type : 'GET ' , data : 'keyword='+key , beforeSend : function ( ) { $ ( `` # results '' ) .slideUp ( 'fast ' ) ; } , success : function ( data ) { $ (... | Ajax / Javascript - Remove Links After 1 Link Has Been Clicked |
JS | I 'm working with the Configure javascript defaults example from the monaco editor playground.https : //microsoft.github.io/monaco-editor/playground.html # extending-language-services-configure-javascript-defaultsWhen I start typing the pre-defined class , I get autocompletion , but I need to hit ctl+space one time to ... | monaco.languages.typescript.typescriptDefaults.addExtraLib ( [ '/** ' , ' * Know your facts ! ' , ' */ ' , 'declare class Facts { ' , ' /** ' , ' * Returns the next fact ' , ' */ ' , ' static next ( ) : string ' , ' } ' , ] .join ( '\n ' ) , 'filename/facts.d.ts ' ) ; | Always show the `` Show more '' section in monaco-editor |
JS | My query is used in cases that `` ( function ( ) { ... } ) ( ) ; '' Given that I am not a plugin . For example `` http : //piecesofrakesh.blogspot.com/2009/03/downloading-javascript-files-in.html '' OrThank you . | ( function ( ) { var s = [ `` /javascripts/script1.js '' , `` /javascripts/script2.js '' ] ; var sc = `` script '' , tp = `` text/javascript '' , sa = `` setAttribute '' , doc = document , ua = window.navigator.userAgent ; for ( var i=0 , l=s.length ; i < l ; ++i ) { if ( ua.indexOf ( `` MSIE '' ) ! ==-1 || ua.indexOf ... | When should I use the syntax `` ( function ( ) { ... } ) ( ) ; '' ? |
JS | It is well-known that declaring objects with JSON notation makes them `` inherit '' from ( or , more precisely , to be built like ) the base Object : myobj= { a:1 , b:2 } ; which is nearly equivalent to myobj = Object.create ( Object ) ; myobj.a=1 ; myobj.b=2 ; and than : Object.getPrototypeOf ( myobj ) prints the foll... | Object __defineGetter__ : function __defineGetter__ ( ) { [ native code ] } __defineSetter__ : function __defineSetter__ ( ) { [ native code ] } __lookupGetter__ : function __lookupGetter__ ( ) { [ native code ] } __lookupSetter__ : function __lookupSetter__ ( ) { [ native code ] } constructor : function Object ( ) { [... | Why *not* `` inherit '' /extend from Object in JavaScript ? |
JS | I am writing a few functions to simplify my interaction with Javascript Nodes , here is the source-code so far : Everything is working great and I am quite content with these functions , I have managed to prevent a lot of headaches without the usage of Javascript frameworks ( a hobby project ) .Now , I would like to be... | Node.prototype.getClasses = function ( ) { return this.className ? this.className.split ( `` `` ) : `` '' ; } ; Node.prototype.hasClass = function ( c ) { return this.getClasses ( ) .indexOf ( c ) > = 0 ; } ; Node.prototype.addClass = function ( c ) { if ( ! this.hasClass ( c ) ) { this.className += `` `` + c ; } retur... | How to concatenate two NodeList objects into one , avoiding duplicates |
JS | I cam upon this code in an example for the EaselJS library - what it does is it assigns the namespace of the entire createjs library to `` window '' .My question is this : Is setting the namespace of a library to window a really dumb idea ? Does n't it just get rid of the whole point of using a namespace by making all ... | < script > var createjs = window ; < /script > stage = new Stage ( canvas ) ; stage = new createjs.Stage ( canvas ) ; | Set Javascript Namespace to Window : Bad idea ? Or Brilliant ? |
JS | I am using Auth0 as my authentication provider for a SPA using React . I have followed the Auth0 react tutorial and this more detailed tutorial from their blog.I am currently just using just email/password authentication . And the authentication works as expected for login/logout , retrieving user info etc.However , wh... | authorize ? client_id=VALUE & redirect_uri=VALUE & scope=openid % 20profile % 20email & response_type=code & response_mode=web_message & state=VALUE & nonce=VALUE & code_challenge=VALUE & code_challenge_method=S256 & prompt=none & auth0Client=VALUE export default function Routes ( ) { const { isLoading , isAuthenticate... | Auth0 does not persist login on page refresh for email/password |
JS | I 've got a simple application with a simple css animation which works like a charm in AngularJS 1.2.2 + ngAnimate 1.2.2 : - > Runnable demo works like a charm.For ( maybe ) no reason the same codes does n't work with AngularJS 1.6.4 + ngAnimate 1.6.4 : - > Broken animation demoThe animation css classes were not added ... | < ! DOCTYPE html > < html > < head > < meta charset= '' utf-8 '' > < script src= '' https : //ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js '' > < /script > < script src= '' https : //ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-animate.min.js '' > < /script > < link rel= '' stylesheet '' href= ... | ngAnimate stopped working in AngularJS 1.6.4 |
JS | So I have an Angular view that has the following markup : The vm.handheldKeys when page is loaded is an array with two values [ 0,24 ] .When the page loads , the rendered HTML is the following ( tabbed for readability ) : This , of course , is what you 'd expect.Now , through some business logic , after the user has in... | < select id= '' ddlHandheldIds '' name= '' ddlHandheldIds '' class= '' form-control '' ng-model= '' vm.handheldPayment.handHeldId '' ng-options= '' id as id for id in vm.handheldKeys track by id '' required title= '' select hand held id '' > < option value= '' '' > select hand held id < /option > < /select > < select i... | Angular ng-options gives empty select option on splice |
JS | I maintain a greasemonkey script that monitors the current track playing as well as the progress on Soundcloud . Previously , I could just do require ( `` lib/audiomanager '' ) to get access to an object that would allow me to view the state of the entire page such as playing track info . The issue is , Soundcloud has ... | webpackJsonp ( [ 6060 ] , { 0 : function ( e , t , n ) { window.aman = n ( 726 ) ; e.exports = function ( abc ) { console.log ( `` Exports called '' ) ; } ; } } ) ; 726 : function ( e , t , n ) { ( function ( t ) { function i ( e ) { var n = t ( e.getContainerElement ( ) ) , i = e.getState ( ) === r.States.ERROR ; n.to... | Accessing soundcloud 's lib/audiomanager via on-page JS |
JS | Is the notion/concept of `` immediate events '' something that exists in Javascript implementations ? BackgroundIn this this answer to the question `` Is javascript guaranteed to be single-threaded ? '' the auther mentions something he refers to as immediate events . Such an immediate event is a callback function ( i.e... | // ( 1 ) Setup a `` immediate event '' ( a callback for `` resize '' ) ; window.onresize = function ( ) { console.log ( `` log resize '' ) ; } ; // ( 2 ) Run some code which contains a blocking alert ( ) console.log ( `` log A '' ) ; console.log ( `` log B '' ) ; alert ( `` alert '' ) ; console.log ( `` log C '' ) ; lo... | Is there something as `` immediate events '' in Javascript ? |
JS | I want to get the html including the selector that I am using to get the htmllet 's say I havewhen I do $ ( ' # foo ' ) .html ( ) I getIs there a way in jquery to get the whole html including the parent ( selector div ) I want this whole html | < div id= '' foo '' > < div id= '' bar '' > content < /div > < /div > < div id= '' bar '' > content < /div > < div id= '' foo '' > < div id= '' bar '' > content < /div > < /div > | Get full html instead of just innner html |
JS | I have built an app with SammyJs . It currently works perfectly in the browser . However , when I package it to Android using PhoneGap , the routes does not work anymore.I have found this SO question . However , the solution given does not work : Has anyone ever experienced the same issue ? EDITI am also using jquery m... | ( function ( $ ) { var app = $ .sammy ( ' [ role=main ] ' , function ( ) { this.disable_push_state = true ; ... } ) ; } < script type= '' text/javascript '' > // DISABLE JQM ROUTER $ ( document ) .bind ( `` mobileinit '' , function ( ) { $ .mobile.ajaxEnabled = false ; $ .mobile.linkBindingEnabled = false ; $ .mobile.h... | Sammyjs routes not working with Phonegap |
JS | I started learning react-redux-immutable couple of days ago and I am still quite confused about structuring my application . I have php ( symfony/laravel MVC background ) so it is not easy to get my head around some javascript concepts.1 ) I have lines WrapperComponent:2 ) That is connected to WrapperContainer3 ) Then ... | export default function ( props ) { const style = { position : `` relative '' } ; const lines = props.lines ; return ( < div className='wrapper ' style= { style } > { lines.map ( line = > ( < Line key= { line.get ( `` id '' ) } { ... line.toObject ( ) } / > ) ) } < Board / > < /div > ) ; } import Wrapper from '../compo... | React Redux Responsibilities |
JS | I have this code below that is a HTML page consisting of a tab i want to use my JavaScript multidimensional Array and get each first name and age to populate the < h3 > separately is there any simple way to accomplish this any suggestion would be greatly appreciated ! | function openCity ( evt , cityName ) { var i , tabcontent , tablinks ; tabcontent = document.getElementsByClassName ( `` tabcontent '' ) ; for ( i = 0 ; i < tabcontent.length ; i++ ) { tabcontent [ i ] .style.display = `` none '' ; } tablinks = document.getElementsByClassName ( `` tablinks '' ) ; for ( i = 0 ; i < tabl... | Display javascript object in tab |
JS | I wonder how the site jsfiddle.net is handling their textareas . When you resize one , the others shrink/gain size . I 've been trying to do it regularly with css but when I resize one , the other textarea pops under the first textarea . Something like this.so the other textarea goes down . The | are ment to be the sid... | | [ ] [ ] |resize work ... .| [ ] | [ ] | I am wondering how js fiddle is handling their textareas concerning resizing and their layot |
JS | I have an array of arrays below . With ES6 , how can I get a count of each value Good , Excellent & Wow into a new array e.g [ { name : Good , count : 4 } { name : Excellent , count : 5 } , { name : Wow , count:2 } ] in dynamic style . I am attempting to use Object.assign but I am failing to `` unique '' out the count ... | let k = 0const stats = { } const remarks = [ [ { name : `` Good '' } ] , [ { name : `` Good '' } , { name : `` Excellent '' } ] , [ { name : `` Good '' } , { name : `` Excellent '' } , { name : `` Wow '' } ] , [ { name : `` Good '' } , { name : `` Excellent '' } , { name : `` Wow '' } ] , [ { name : `` Excellent '' } ]... | Get count from Array of arrays |
JS | This problem is so specific I am not sure any search would find a similar answer , so I am asking as though it is a new problem.The expected behavior : Click button 'mySol ' makes div My solution visibleClick button 'YASS ' makes div My solution hidden and div YASS solution visibleClick button 'Tak ' makes div YASS sol... | function visInvis ( id ) { var a = document.getElementById ( 'mySol ' ) ; var b = document.getElementById ( 'YASS ' ) ; var c = document.getElementById ( 'Tak ' ) ; var e = document.getElementById ( id ) ; if ( e == a & & e.style.display == 'none ' ) { b.style.display = 'none ' ; c.style.display = 'none ' ; } if ( e ==... | Function that tests if DIV is showing only works the second time |
JS | I added bundleconfig.json to ASP.NET Core application . It has the following structure : Both scripts has been minified and merged into main.min.js . But after minification all async modifiers has been removed from result script . Function such as have been turned into : How do I avoid removing async modifier ? | [ { `` outputFileName '' : `` wwwroot/js/main.min.js '' , `` inputFiles '' : [ `` wwwroot/js/scripts/first.js '' , `` wwwroot/js/scripts/second.js '' ] , `` minify '' : { `` enabled '' : true , `` renameLocals '' : true } , `` sourceMap '' : false } ] async function foo ( ) { await /* some promise */ ; } function foo (... | ASP.NET Core BundleMinifier removes async modifier after minification |
JS | Following up on this thread : Lots of null values in an array mean any harm ? I did this with node.js : And I got So that leaves me with the question ( I could n't find it on Yahoogle ) how much memory is actually allocated for a null entry in an array in node . I do not plan to use 1000000000 entries , not even close ... | arr= [ ] arr [ 1000 ] =1arr [ 1000000000 ] =2arr.sort ( ) FATAL ERROR : JS Allocation failed - process out of memory | how much memory does node allocate for null values in arrays |
JS | Given Why is name identifier cast to string when using var at object destructuring assignment ? But not using let or const ? We can avoid this unexpected result by defining a different identifierthough curious as to the significance of var returning different results than let or const for the name identifier at a brows... | let obj = { name : 1 } ; console.log ( typeof obj.name , obj.name ) ; // ` `` number '' ` , ` 1 ` let obj = { name : 1 } ; var { name } = obj ; console.log ( name , typeof name ) ; // ` 1 ` ` string ` let obj = { name : 1 } ; let { name } = obj ; console.log ( name , typeof name ) ; let obj = { name : 1 } ; var { name ... | When using object destructuring assignment , why is a property `` name '' cast to string ? |
JS | I want to select the right-most , bottom-most cell in a < table > using jQuery.It 's not as easy as $ ( ' # tableId td ' ) .last ( ) , because a cell may span several rows . It should also handle < th > cells.Here 's my attempt so far : | function fixLastCell ( $ table ) { var $ lastCell = $ table.find ( 'td , th ' ) .last ( ) ; $ lastCell.css ( 'background-color ' , 'red ' ) ; } fixLastCell ( $ ( ' # t0 ' ) ) ; fixLastCell ( $ ( ' # t1 ' ) ) ; fixLastCell ( $ ( ' # t2 ' ) ) ; fixLastCell ( $ ( ' # t3 ' ) ) ; < script src= '' https : //ajax.googleapis.c... | How can I find the bottom-right-most cell in a table using jQuery ? |
JS | http : //a2.twimg.com/a/1302724321/javascripts/widgets/widget.js ? 1302801865It is setup like this at a high level : public namespace : Then a closure : Within the application closure : Some methods are marked public , others private , and the only difference seems to be the naming convention ( private starts with unde... | TWTR = window.TWTR || { } ; ( function ( ) { ... } ) ( ) ; // # end application closure TWTR.Widget = function ( opts ) { this.init ( opts ) ; } ; ( function ( ) { // Internal Namespace . var twttr = { } ; } ) ( ) ; | Help understanding twitters widget.js file , a closure within a closure ? |
JS | I have a simple rectangular anchor tag . I used jQuery to respond to click and touchstart events with the following : The HTML looks like this : The CSS is simple : I built this as a demo to show the problem I 'm talking about.When you tap the edge of the rectangular anchor , only the click event is fired . When you ta... | $ ( document ) .ready ( function ( ) { $ ( `` # button '' ) .on ( `` click touchstart '' , function ( e ) { $ ( `` # log '' ) .append ( e.type + `` < br/ > '' ) ; } ) ; } ) ; < div id= '' wrapper '' > < a id= '' button '' href= '' # '' > & nbsp ; < /a > < /div > < div id= '' log '' > Log : < br > < /div > # wrapper { p... | Why does Android click area have a wider radius than touchstart ? How can I make it consistent ? |
JS | If I declare a variable in a function using var then a slot for that variable is added to the LexicalEnvironment defined by that function.In the above code the LexicalEnvironment associated with the function contains a slot with a key foo and a value of undefined.If I use a block-scoped declaration , how is the surroun... | function ( ) { var foo ; } function ( ) { { let foo ; // How does this affect the LexicalEnvironment ? } } | How is block scope managed in the lexical environment ? |
JS | I 'm new to d3js , but am familiar with javascript and the principles of data-visualisation.I 've tried to achieve an effects to visualize 2 dimensions of data using the aster plot diagram , but ca n't really get this thing to work like expected.Attached you 'll find the diagram I 'm trying to recreate and my example c... | var testData = { maxPoints : 10 , color : ' # bababa ' , border : { width : 1 , color : ' # ffffff ' } , items : [ { name : 'Looks ' , color : ' # 2976dd ' , weight : 0.37 , points : 8 } , { name : 'Charm ' , color : ' # 87bd24 ' , weight : 0.03 , points : 5 } , { name : 'Honesty ' , color : ' # 406900 ' , weight : 0.1... | d3js - Creating Asterplot-like Charts ( example included ) |
JS | for meta data on the page using attribute names like table : rowNum : < name > , eg , have been using colon-delimited names ( eg , name='emp:1 : emp_id ' ) for years with good success , but today got bit with colon delimited attribute namesin particular : are special character like ' : ' illegal in dom attribute names ... | var row = document.createElement ( 'tr ' ) ; row.setAttribute ( 'tup ' , 'emp:1 ' ) ; row.setAttribute ( 'emp:1 : pkid ' , '123 ' ) ; var el2 = row.parentNode.querySelector ( `` [ emp:1 : pkid ] '' ) ; = > ` Error : SYNTAX_ERR : DOM Exception 12 ` > row.parentNode.querySelector ( ' [ emp:1 : pkid ] ' ) ; Error : SYNTAX... | in javascript dom , are there rules to attribute names ? |
JS | I understand that num1 being an object has a property .__proto__ via which it gets access to .toString ( ) by going down the prototype ( .__proto__ ) chain . In above case , num is a primitive type number . It means that it wo n't have any properties and methods . Then how 's it able to get access to .toString ( ) meth... | var num1 = new Number ( 5 ) ; typeof ( num1 ) ; //returns `` object '' num1.toString ( ) ; //returns `` 5 '' var num = 5 ; typeof ( num ) ; //returns `` number '' num.toString ( ) ; //returns `` 5 '' | How does primitive types in Javascript have methods and Properties ? |
JS | I 'm new to javascript and could use your help . The first time my PJAX page loads , my tooltips work : They become stuck unless I do the following : I 've tried to reinitialize them on pjax : end or pjax : complete with no luck . I get a strange-looking tooltip if I hover a long time , but not a bootstrap tooltip.How ... | $ ( document ) .ready ( function ( ) { $ ( document ) .pjax ( ' a ' , ' # main ' , { cache : false } ) ; $ ( ' [ data-toggle= '' tooltip '' ] ' ) .tooltip ( ) ; } $ ( document ) .on ( 'pjax : start ' , function ( event ) { $ ( ' [ data-toggle= '' tooltip '' ] ' ) .tooltip ( 'dispose ' ) ; } ) ; | Bootstrap 4 tooltips stop working after jquery-pjax AJAX call |
JS | I want to rotate element onclick by adding CSS class to it . Problem is , when that same CSS class is removed , element is rotated for the second time.fiddle : https : //jsfiddle.net/L3x2zhd1/1/JS : CSS : How can I avoid this ? | var el = document.getElementById ( 'el ' ) ; el.onclick = function ( ) { el.className = 'rotate ' setTimeout ( function ( ) { el.className = `` } ,1000 ) } ; # el { width : 50px ; height : 50px ; background-color : red ; -webkit-transition : -webkit-transform 1s ; transition : transform 1s ; } .rotate { -webkit-transfo... | How to avoid css transformation ( rotate ) when removing class ? |
JS | How come this Javascript selectordocument.getElementsByClassName ( 'first-class class-child second-child ' ) looks identical to this jQuery selectoryet it does n't work the same way ? | $ ( '.first-class .class-chlid .second-child ' ) ; | Javascript class selection |
JS | I have created a map using d3.js . I want to show a curved line between two locations . I am able to show a line , but sometimes it does not form a perfect curve . For some lines , the lines curve behind the map ( across the anti-meridian ) to their destination.Here 's a code pen demonstrating the problem : https : //c... | var projection = d3.geoEquirectangular ( ) ; var path = d3.geoPath ( ) .projection ( projection ) ; arcGroup.selectAll ( `` myPath '' ) .data ( links ) .enter ( ) .append ( `` path '' ) .attr ( `` class '' , `` line '' ) .attr ( `` id '' , function ( d , i ) { return `` line '' + i ; } ) .attr ( `` d '' , function ( d ... | line on d3 map not forming a curve |
JS | I have a hex code 1f610 , so the format string is \u { 1f610 } with in display . But how can I unescape it from the hex code ? I didwhat should I do to unescape it to ? | var code = '1f610 ' ; unescape ( ' % u ' + code ) ; //= > ὡ0unescape ( ' % u ' + ' { ' + code + ' } ' ) ; //= > % u { 1f610 } | javascript unescape hex to string |
JS | I am using the angular-fullstack generator to generate new routes for my application . The syntax is really unfamiliar and uses a class-like structure . How do I work with this to inject things like $ scope and $ watch ? The main thing I want to do is watch for a change for a particular variable . The syntax is below .... | 'use strict ' ; ( function ( ) { class MainController { constructor ( $ http ) { this. $ http = $ http ; this.awesomeThings = [ ] ; $ http.get ( '/api/things ' ) .then ( response = > { this.awesomeThings = response.data ; } ) ; } addThing ( ) { if ( this.newThing ) { this. $ http.post ( '/api/things ' , { name : this.n... | How do I work with $ scope and $ watch with angular-fullstack generator syntax ? |
JS | The Context : A hook is defined and returns an object that contains the timestamp of the last time a file was modified . I calculate the difference from the timestamp until now to show the user how long it was been since they have last saved . The Problem : The calculated difference from the timestamp until now does no... | const StageFooter = ( props ) = > { const [ , , meta ] = useMetadata ( `` Tenant Setup Data '' , `` setupData '' ) return ( < StageControls > < div id= '' footer-start '' > < /div > < SavingBlock key= { meta ? .modified } > { ` Last saved $ { meta.modified ! == undefined ? formatDistanceToNow ( meta.modified ) : `` `` ... | How can you trigger a rerender of a React js component every minute ? |
JS | I have the following Javascript : Inside a .click ( ) function . This works fine . However I have the following HTML in the cloned area : Now , in the above jQuery I have this.checked=false ; which makes any cloned checkbox unchecked . But unfortunately , The label.button-array still has the class of active , which mea... | $ ( `` div.duplicate-fields : last-child '' ) .clone ( ) .find ( 'input ' ) .each ( function ( ) { this.name = this.name.replace ( /\ [ ( \d+ ) \ ] / , function ( str , p1 ) { return ' [ ' + ( parseInt ( p1,10 ) +1 ) + ' ] ' } ) ; this.value = `` '' ; this.checked = false ; } ) .removeClass ( `` active '' ) .end ( ) .a... | Cloning a DIV with jQuery |
JS | I have a pretty basic jQuery ajax thing happening , but I want to mix form data that is retrieved by JS with some PHP variables and have them all sent as part of the ajax GET . Should this work ? : Currently , when create.php tries to echo the variables back , they 're empty.UPDATEAfter checking the source as suggested... | var longform = $ ( `` input : text '' ) .serialize ( ) ; $ .ajax ( { url : 'actions/create.php ' , data : longform + `` domain= < ? php echo $ domain ; ? > & useragent= < ? php echo $ useragent ; ? > & ip= < ? php echo $ ip ; ? > & cookieuser= < ? php echo $ cookieuser ; ? > '' , data : longform + `` & domain=example.c... | mixing javascript and php variables in ajax |
JS | Recently I have implemented a ebook like function web app runs on ipad . One function is to make a viewport to drag the book . I used this viewport plugin ( with demo ) : http : //borbit.github.com/jquery.viewport/The problem is the content can not drag .This work perfectly on desktop but not ipad.There are two level o... | < div id= '' view '' style= '' height : 385px ; width : 1422px ; position : relative ; overflow : hidden ; display : block ; '' > < div class= '' viewportBinder '' style= '' position : absolute ; overflow : hidden ; height : 2541px ; top : -1078px ; width : 1247px ; left : 88px ; '' > < div class= '' viewportContent ui... | Implement Jquery viewport on ipad |
JS | In my Yesod project i have the following route : I want to request it on the client side with javascript : But i ca n't use @ { ApiHideTHreadR } because Yesod requires it 's arguments on compile time . What is the proper solution for this , if i want API URLS to look like api/board/1/1 and not api/board ? bid=1 & tid=1... | /api/hide/thread/ # Text/ # Int ApiHideThreadR GET function hideThreadCompletely ( threadId , board ) { $ .getJSON ( `` /api/hide/thread/ '' +board+ '' / '' +threadId , function ( data ) { $ ( ' # thread-'+threadId ) .hide ( ) ; } ) ; } | Yesod : Using typesafe URLs in AJAX calls |
JS | I basically want to write the following code in ES6 fashion.I have tried using a property like the following but the _onNeonAnimationFinish callback is never fired.So what is the correct way ? | listeners : { 'neon-animation-finish ' : '_onNeonAnimationFinish ' } , class MyElement { get behaviors ( ) { return [ Polymer.NeonAnimationRunnerBehavior ] ; } beforeRegister ( ) { this.is = 'my-element ' ; this.properties = { name : { type : String } } ; this.listeners = { 'neon-animation-finish ' : '_onNeonAnimationF... | How to write listeners in ES6 in Polymer ? |
JS | I 've been trying for the last few days to make my code work , but I just ca n't find the problem.I want to make communication with the Wikipedia server and get their JSON API so I can make a list of items corresponding to the input value of searchInput.I 've been looking into JSONP , finding in the end that I can add ... | < ! DOCTYPE HTML > < html lang= '' en '' > < head > < meta charset= '' UTF-8 '' > < title > Object Oriented JavaScript < /title > < script src= '' https : //cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js '' > < /script > < /head > < body > < h1 > Wikipedia viewer < /h1 > < a href= '' http : //en.wikipedia.or... | Accessing Wikipedia API with JSONP |
JS | I 've been working with the Grunt cssmin plugin . I had a block in my Gruntfile which looks approximately like this : For a while this was working fine ; but I moved this to another machine and did n't set up my bower components correctly - the html5-boilerplate/css/main.css file was missing - and yet the task still co... | cssmin : { target : { files : { ' < % = config.target % > /mytarget.css ' : [ 'bower_components/normalize.css/*.css ' , 'bower_components/html5-boilerplate/css/main.css ' , ' < % = config.src % > /css/*.css ' ] } } } | Is there a way to cause a Grunt plugin to fail if input files are missing ? |
JS | I have an application that has this format scattered around but I dont know what kind it is . It 's not jQuery , so what is it ? I get this in firebug and I know the element is present : | $ ( 'some_edit ' ) .style.display = `` block '' ; $ ( 'some_views ' ) .style.display = `` none '' ; $ ( `` some_edit '' ) .style is undefined | What kind of JavaScript is this ? |
JS | I was working on canvas and came across the Idea of changing dimensions of the cube . So , by using HTML5 Canvas I made up this cube which has two squares joined by the lines to make it look like a cube.What I want is when I select a cube type from select the cube should automatically change itself depending on the len... | var canvas = document.querySelector ( 'canvas ' ) ; canvas.width = 500 ; canvas.height = 300 ; var contxt = canvas.getContext ( '2d ' ) ; //squares/*contxt.fillRect ( x , y , widht , height ) ; */contxt.strokeStyle = 'grey ' ; var fillRect = false ; contxt.fillStyle = 'rgba ( 0 , 0 , 0 , 0.2 ) ' ; contxt.rect ( 80 , 80... | Change dimension of canvas depending on selected option |
JS | I want to achieve a way to get all the content between one open span tag and it 's close tag . The problem is that sometime I can have nested span and I want to be sure that my regex do n't stop a the first ending span it see.To see my problem look at this : Regex101 : nested spanI want to be sure that I get everything... | < p style=\ '' text-align : justify\ '' > < span style=\ '' font-size:12pt\ '' > < span style=\ '' color : Green\ '' > < span style=\ '' font-family : Verdana\ '' > There is some content for a mm advertisment.There is some co < /span > < span style=\ '' font-family : Times New Roman\ '' > ntent for a mm advertisment. <... | Using XRegExp.matchRecursive for nested spans |
JS | I made a slideshow with php and javascript and it slides the images just fine , but i 'm a bit stuck at the back and forward functionalities and i would be grateful if you could help me a bit here.This is what i 've done so far : PHP : Javascript : HTML : As you can see i tried to make an onclick event to change the ' ... | $ dir = 'images/slideshow ' ; $ images = scandir ( $ dir ) ; $ i = 0 ; echo ' < div id= '' slideshow-wrapper '' > ' ; echo ' < div id= '' slideshow-beta '' > ' ; foreach ( $ images as $ img ) { if ( $ img ! = ' . ' & & $ img ! = '.. ' ) { $ i++ ; echo ' < img src= '' ../images/slideshow/'. $ img . ' '' class= '' img_'.... | Add back and forward functionalities in slideshow |
JS | In a spelling game I have created there is a grid that is populated with words . The aim of the game is to spell the words by clicking on the letters on the side , which animate into the empty spaces in the grid . Words are highlighted if they are to be spelt , so the user can see where to go next . The aim of the game... | if ( score.right == 3 ) { ... ... ... ... ... . ... ... ... ... ... . } setTimeout ( function ( ) { jQuery ( '.next-question ' ) .trigger ( 'click ' ) ; } , 1500 ) ; | jQuery/JavaScript program breaks after completion number is changed |
JS | We all know javascript does funky conversions when testing for equality , but what exactly happens under the hood ? Yes , it was naive of me to expect transitivity from == operator . | > [ 0 ] == 0true > 0 == [ [ 0 ] ] true > [ 0 ] == [ [ 0 ] ] false | If both [ 0 ] == 0 and 0 == [ [ 0 ] ] are true than why is [ 0 ] == [ [ 0 ] ] false ? |
JS | I have the following : Output isI 'd like it to output : How do I do this ? Thanks . | var tags = [ `` Favorite '' , `` Starred '' , `` High Rated '' ] ; for ( var tag in tags ) { console.log ( tag ) ; } 012 FavoriteStarredHigh Rated | How do I reference the string in a array of strings ? |
JS | I 'm reading the book Javascript : The Good Parts . And I 'm confused by the following code.Where is the null in slice.apply ( arguments ) ? | Function.method ( 'curry ' , function ( ) { var slice = Array.prototype.slice , args = slice.apply ( arguments ) , that = this ; return function ( ) { return that.apply ( null , args.concat ( slice.apply ( arguments ) ) ) ; } ; } ) ; | Why apply ( ) here takes only one argument instead of two ? |
JS | Here 's my situation . I 've created several panels stacked side by side which are wrapped in a main container . Each panel takes 100 % the viewport width and height . My goal is to be able to scroll horizontally to each panel when I click on their respective link . This works fine using a pure css approach . However ,... | < div class= '' mainWrapper '' > < section class= '' panel '' id= '' panel-1 '' > < /section > < section class= '' panel '' id= '' panel-2 '' > < /section > < section class= '' panel '' id= '' panel-3 '' > < /section > < section class= '' panel '' id= '' panel-4 '' > < /section > < /div > .mainWrapper , .panel { positi... | How do I obtain a floating element 's left offset while it is outside the viewport ? |
JS | I want to be able to start my express server directly via : But I also want to able to require that file , and have it return the app instance but actually not start the server . Then I can start later it with some options.I 'm basically looking for the equivalent of this ruby snippet , but in node.js.Is there an idiom... | $ node app.js app = require './app'app.listen options.someCustomPort if __FILE__ == $ 0 app.listen options [ : some_custom_port ] end | How do I make node.js execute some code only if my file is the running file ? |
JS | I have been developing a chrome extension using Polymer for some time now and I have a couple of concerns about releasing it in it 's current state . I would like to hear about some strategies for preventing the following problems I have been facing : 1 ) Loading Polymer into the page leaks into the global namespace . ... | function loadUrl ( url ) { return new Promise ( function ( resolve , reject ) { var link = document.createElement ( 'link ' ) ; link.setAttribute ( 'rel ' , 'import ' ) ; link.setAttribute ( 'href ' , url ) ; link.onload = function ( ) { resolve ( url ) ; } ; document.head.appendChild ( link ) ; } ) ; } loadUrl ( chrom... | Problems loading Polymer 1.0 in a chrome extension |
JS | Checking the HTML source of a question I see for instance : And then in the javascript source : It seems that all the user click events are binded this way.The downsides of this approach are obvious for people browsing the site with no javascript but , what are the advantages of adding events dynamically whith javascri... | < a id= '' comments-link-xxxxx '' class= '' comments-link '' > add comment < /a > < noscript > & nbsp ; JavaScript is needed to access comments. < /noscript > // Setup our click events.. $ ( ) .ready ( function ( ) { $ ( `` a [ id^='comments-link- ' ] '' ) .click ( function ( ) { comments.show ( $ ( this ) .attr ( `` i... | Why Stackoverflow binds user actions dynamically with javascript ? |
JS | I 'm taking a course on AngularJS on Coursera . The code that the instructor demonstrated in the videos works but for some reason I could n't get to run on my environment : Page Layout ( partial ) : Snippet A ( demonstrated by professor that I could n't get to work ) : When I would run this function , I do n't get any ... | < div class= '' media-body '' > < h2 class= '' media-heading '' > { { dish.name } } < span class= '' label label-danger '' > { { dish.label } } < /span > < span class= '' badge '' > { { dish.price | currency } } < /span > < /h2 > < p > { { dish.description } } < /p > < /div > var app = angular.module ( 'confusionApp ' ... | What 's the difference between these 2 Angular code snippets ? |
JS | How to use switch for assignment in coffescript ? Tried many ways but could n't make it work.even this does n't worktried this way alsoAt last found this also does n't workAm I missing something ? | item = { name : `` ahola '' } arr = `` coffee_script '' switch arr when arr.match /script/ item.type = arr alert item.name + `` : `` + item.type # alerts `` ahola : undefined '' item = { name : `` ahola '' } arr = `` coffee_script '' switch arr when arr == `` coffee_script '' item.type = arralert item.name + `` : `` + ... | variable assignment with switch in coffescript |
JS | I want to change the opacity of an object instead of fading in content that was completely hidden so I changedtoand the css from display : none to opacity : 0 ; ( in all browsers ) but I noticed that the numeral value 1000 isnt doing anything at all.. Maybe it is and I 'm not noticing , but I have changed that form 1 t... | $ ( `` .thumb '' ) .each ( function ( i ) { $ ( this ) .delay ( 500*i ) .fadeIn ( 1000 ) ; } ) ; $ ( `` .thumb '' ) .each ( function ( i ) { $ ( this ) .delay ( 500*i ) .animate ( { 'opacity ' : 1 } , 1000 , function ( ) { } ) ; } ) ; //Showcase $ ( ' # showcase ' ) .animate ( { 'opacity ' : 0 } , 0 ) ; fadeInDivs ( [ ... | Why are n't fadeIn and animate duration working for my code ? |
JS | If I run this code within the Chrome Developer Tools : why is privateFunction1 in scope at the breakpoint , while privateFunction2 is not ? | var test = ( function ( ) { var publicFunction , privateFunction1 , privateFunction2 ; privateFunction1 = function privateFunction1 ( ) { return true ; } ; privateFunction2 = function privateFunction2 ( ) { return true ; } ; publicFunction = function publicFunction ( ) { privateFunction1 ( ) ; debugger ; } ; return { p... | Debugging Revealing Module Pattern : functions not in scope until called ? |
JS | In Restangular if I declare a service , and do a PUT/PATCH/POST operation it uses the id of the item by default as a primary key . But what if we want to use a custom key ? Like a slug or a number ? | // GET to /usersUsers.getList ( ) .then ( function ( users ) { var user = users [ 0 ] ; // user === { id : 1 , number : 123456 , name : `` Tonto '' } user.name = `` Gonto '' ; // PUT to /users/1 < -- Here the id is used . But I 'd like to use number to post to PUT to /users/123456 user.put ( ) ; } ) | Restangular - Specify custom ID key |
JS | I am using Chromeless to retrieve a piece of information on a website and load a corresponding file : but the file read instructions are executed immediately when I launch the script and do not wait for the web crawling to be finished.In javascript I think I would need to use callback functions to prevent that but is t... | async function run ( ) { const chromeless = new Chromeless ( ) const screenshot = await chromeless .goto ( 'http : //www.website.com ' ) title = await chromeless.inputValue ( 'input [ name= '' title '' ] ' ) var fs = require ( 'fs ' ) ; var data = fs.readFileSync ( title , '' utf8 '' ) ; ... await chromeless.end ( ) } | Chromeless - wait before executing instructions |
JS | I 'm trying to render a partial with ajax , but for some reason it returns this error : I 'm very confused because I accomplished something with an essentially identical format before , and I never had any problems with it . Does anyone see anything wrong with my code ? I can render a string with the ajax ; it 's only ... | ActionController : :UnknownFormat in ThingsController # upvoterandomActionController : :UnknownFormat < div id= `` randomajax '' > < div id= '' randajax '' > < % = link_to @ rand.name , thing_path ( @ rand ) % > < % = link_to image_tag ( `` UpArrowGray.jpg '' , class : `` rand_up_vote '' ) , remote : true , % > < scrip... | j ( render ( @ partial ) ) returns error : ActionController : :UnknownFormat |
JS | I 'm trying to implement a 'Tag Editor ' field in my app , the same way as SO does.Right now i got this : EDIT : I have coded this into a jQuery plugin at : https : //github.com/fernandotenorio/tagme.gitFiddlehttp : //jsfiddle.net/FernandoTen/PnYuF/htmljs } ) cssThe problem is , how can i handle the 'hidden ' content u... | < div style= '' margin-left : auto ; margin-right : auto ; width : 400px ; '' > < span style='color : # 333 ; font-size : small ' > Tags [ a-z A-Z 0-9 # + . - ] < /span > < div id='tags_container ' > < span id='tags_queue ' > < /span > < input type='text ' id='tf ' / > < /div > < /div > $ ( document ) .ready ( function... | Emulate SO tag editor |
JS | I have a function that I 'm using to prevent multiple postbacks of a form : In the CanSubmit method , I need to interrogate the button that was clicked to determine whether I should allow the submit or not.Note that I ca n't bind to specific click events - see this previous question for more details.In Firefox , I can ... | var submitted = false ; $ ( function ( ) { $ ( 'form ' ) .bind ( 'submit ' , function ( e ) { if ( ! submitted & & CanSubmit ( e ) ) { submitted = true ; return true ; } else { return false ; } } ) ; } ) ; | How can I find the button that was clicked from the form submit event in jquery ? |
JS | HtmlJavascriptOf course when I click anywhere in the div , it performs 'do magic ' . Thanks to return false , if I click on any link in the div , it still performs 'do magic ' and does n't change the page , which is the expected behavior.But there is one link that is suppose to actually change the page , the owner link... | < div class='item_container ' > [ ... bunch of links and pictures ... ] < a class='item_owner ' > John Doe < /a > < /div > /** Bind the onclick only if you hover on the item since we got a lot of items and several events and plugins to setup on them . */ $ ( '.item_container ' ) .live ( 'mouseenter ' , function ( e ) {... | How to attach a onclick callback to a div but not on a link inside the div ? |
JS | I have found this code snippet : In here : http : //www.dofactory.com/products/javascript-jquery-design-pattern-framework ( sorry , no id-s have been found on the page ) I do n't understand what these parts are doing : the `` 100 % '' in the second linethe var _true_ = true ; and var _false_ = false ; assignments in th... | ; 100 % function ( $ ) { // WTF ? var _true_ = true ; // WTF ? var _false_ = false ; // WTF ? var go = function ( location , date ) { location || ( location = { } ) ; var result = _false_ ; if ( date & & date.day ) { result = geoService.go ( location , date ) ; } return ! ! result ; } var process = function ( func ) { ... | Strange javascript code |
JS | This is a question for the guru of JavaScript . I 'm trying to do work with JavaScript prototype model more elegant . Here is my utility code ( it provides real chain of prototypes and correct work with instanceof operator ) : It allows me to do such thigns : My question is : Is there more simple way to do this ? | function Class ( conf ) { var init = conf.init || function ( ) { } ; delete conf.init ; var parent = conf.parent || function ( ) { } ; delete conf.parent ; var F = function ( ) { } ; F.prototype = parent.prototype ; var f = new F ( ) ; for ( var fn in conf ) f [ fn ] = conf [ fn ] ; init.prototype = f ; return init ; }... | How do I do JavaScript Prototype Inheritance ( chain of prototypes ) |
JS | I do n't understand why fooA and fooB outcome different.does foo.prototyp = { } override the method defined in front of it ? Why fooA is state in front of prototype.x , it inherit the result , but not y and z ? | var foo = function ( ) { } fooA = new foo ( ) ; foo.prototype.x = 1 ; foo.prototype = { y : 2 , z : 3 } ; console.log ( fooA.x , fooA.y , fooA.z ) ; // 1 , undefined , undefinedfooB = new foo ( ) ; console.log ( fooB.x , fooB.y , fooB.z ) ; // undefined , 2 , 3 | Different between foo.prototyp.x = & foo.prototype = { x : } |
JS | I am new to javascript.I am trying to make an simple toggle up div With user selection direction ill place the toggle div.After some googling I found one working fiddle But not as expected See the below screenshot to see the differenceWhen I select Some text on the front of the paragraph It works fine Like thisBut when... | import React from 'react'import { render } from 'react-dom ' ; export default class App extends React.Component { constructor ( props ) { super ( props ) ; this.state = { display : 'none ' , top : '' , bottom : '' , left : '' , right : '' , diplayForDown : 'none ' } ; this.handleOnMouseDown = this.handleOnMouseDown.bin... | How to find a user selection weather forward or backward in javascript ? |
JS | I 've written a fairly simple script that will take elements ( in this case , < p > elements are the main concern ) and type their contents out like a typewriter , one by one . The problem is that as it types , when it reaches the edge of the container mid-word , it reflows the text and jumps to the next line ( like wo... | function formatText ( html ) { var textArray = html.split ( `` `` ) ; var assembledLine = `` '' ; var finalArray = new Array ( ) ; var lastI = 0 ; var firstLine = true ; for ( i = 0 ; i < = textArray.length ; i++ ) { assembledLine = assembledLine + `` `` + textArray [ i ] ; $ ( ' # ruler ' ) .html ( assembledLine ) ; v... | Pre-formatting text to prevent reflowing |
JS | I 'm extending Object like this : All works as expectedbut , whenthis keyword on the is_a ( ) function is same as foo right ? Why does it return different results ? | Object.prototype.is_a = function ( x ) { return this instanceof x ; } `` foo '' .is_a ( String ) // true '' foo '' .is_a ( Object ) // true '' foo '' .is_a ( Array ) // false '' foo '' .is_a ( Function ) // false '' foo '' .is_a ( Boolean ) // false '' foo '' .is_a ( Date ) // false '' foo '' .is_a ( Number ) // false ... | What is the difference between ` this instanceof String ` and ` `` foo '' instanceof String ` ? |
JS | I am trying to fetch all events ( maximized , maximize etc ) . I have a suitable code for this from this link How to Detect Window On Minimize/Maximize Event in Chrome Extension ? .But the problem when switch tab ( using alt+tab ) window.chrome.onFocusChanged listener is not firing.My code : Is there a solution for thi... | chrome.windows.onFocusChanged.addListener ( function ( windowId ) { console.log ( `` focus change '' , windowId ) ; } ) ; | chrome.windows.onFocusChanged.addListener not firing on tab switching |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.