lang
stringclasses
4 values
desc
stringlengths
2
8.98k
code
stringlengths
7
36.2k
title
stringlengths
12
162
JS
Below code takes long lots of minutes ; dtObjects.Rows.length = 900dtColumns.Rows.length = 1500dtTypes.Rows.length = 30Is there anyway to achieve ( filter ) this in seconds ?
var table = new Array ( ) ; for ( var i =0 ; i < dtObjects.Rows.length ; i++ ) { for ( var j=0 ; j < dtColumns.Rows.length ; j++ ) { for ( var k=0 ; k < dtTypes.Rows.length ; k++ ) { if ( ( dtObjects.Rows [ i ] .Id == dtColumns.Rows [ j ] .Id ) & & ( dtColumns.Rows [ j ] .xtype == dtTypes.Rows [ k ] .xtype ) ) table.pu...
Efficient way of filtering arrays in javascript
JS
I am trying to reorganize some information that is created by server-side code . The server is strapped for memory , and all sorting and displaying will need to be handled client-side with javascript/jquery . The html is along the lines of ... Here is my fiddle in progress https : //jsfiddle.net/ydc6ywuz/1/The overall ...
< div > < a href= '' https : //en.wikipedia.org '' class= '' AccessSitesLinks true 1 '' > Wikipedia Home < /a > < a href= '' https : //en.wikipedia.org/wiki/Gold '' class= '' AccessSitesLinks false 1 '' > Wikipedia Gold < /a > < a href= '' https : //google.com '' class= '' AccessSitesLinks true 2 '' > Google Home < /a ...
Sorting Elements Based on CSS Class and Text not working
JS
I 'm building a video game where a spaceship moves with controllers and it must avoid the fireball in order to continue to play . If it collides into the fireball the game must display `` Game Over '' and restart.At the beginning of the game , there is an input where the user puts his name . Then there is a countdown a...
< form id= '' askName '' title= '' Write your name '' > < label > Enter your username : < /label > < input id= '' input '' type= '' text '' maxlength= '' 10 '' autofocus > < button type= '' button '' onclick= '' countDown ( ) ; return Username ( ) '' id= '' begin-timer '' > Submit < /button > let icon = document.getEle...
Return previous instruction js
JS
I 'm using promise in the block of code below , 2 first then ( ) I dont return any value , so i wonder that is the function in the first then ( ) called before the function in the next then ( ) . Im using typescript in angular 2 . Thank you : D
Promise.resolve ( ) .then ( ( ) = > { this.getListStatus ( ) ; } ) .then ( ( ) = > { return this._laundryServiceOrderService.findAll ( true , offset , this.itemsPerPage , filterQuery ) } ) .then ( ( response ) = > { this.orders = response.data ; this.totalItems = response.totalItems ; } ) .catch ( error = > { FlashMess...
using then ( ) in promise
JS
So my project has ALOT of plugins installed with bowerAll of these are in their own custom folder all contained in the bower_components folderNow I wish to run a grunt script that basically takes all of these and uglify them.So I created the following script : Taken from another SO questionHowever whenever I run this I...
module.exports = function ( grunt ) { grunt.initConfig ( { pkg : grunt.file.readJSON ( 'package.json ' ) , copy : { dist : { files : [ { src : 'index.html ' , dest : 'dist/index.html ' } ] } } , 'useminPrepare ' : { options : { dest : 'dist ' } , html : 'index.html ' } , usemin : { html : [ 'dist/index.html ' ] } } ) ;...
grunt uglify bower_components folder
JS
The following in a Javascript console : Yields : Object foo= [ 1 ] I want to make a copy by value in b of each array for each key in a . Is there an easier way ?
var a = { 'foo ' : [ ] } ; var b = { } ; for ( var key in a ) { b [ key ] = a [ key ] ; } a [ 'foo ' ] .push ( 1 ) ; console.log ( b ) ;
Totally basic Javascript reference question
JS
The Number prototype object is itself a Number object ( its [ [ Class ] ] is `` Number '' ) whose value is +0.15.7.4Why would it be useful for Number.prototype to be a Number ? ( the same goes for every other built-in prototype which has the [ [ Class ] ] set to not Object ) I 'm picking on Number.prototype specificall...
( { } ) .toString.call ( Number.prototype ) === `` [ object Number ] ''
Why is Number.prototype a Number
JS
When my `` chartModel '' changes I want to update the `` globalModel '' .And vice versa , I want my chartModel to update when the globalModel changes.This results in a feedback loop when setting the globalModel . I could prevent this by setting { silent : true } .But here comes the problem . I have another Model that i...
chartModel.bind ( `` change '' , updateGlobalModel ) ; updateGlobalModel ( ) { globalModel.set ( obj ) } globalModel.bind ( `` change '' , updateChartModel ) ; updateChartModel ( ) { chartModel.set ( obj ) } globalModel.bind ( `` change '' , updateOtherModel ) ; set : function ( attrs , options ) { if ( ! ( `` setID ''...
Make Backbone.js Model change `` partially '' silent ?
JS
just out of fun I made that little toy top ( gyroscope ? ) , using Javascript and Canvas.Unfortunately there 's an ugly Moiré effect on it ( see screenshot below ) .http : //jsfiddle.net/8bac4s9v/1/I guess , that moiré effect comes from anti-aliasing . So I thought , I could get rid ofthat Moiré effect when I switch of...
function draw ( ) { var c = document.getElementById ( `` myCanvas '' ) ; var ctx = c.getContext ( `` 2d '' ) ; ctx.imageSmoothingEnabled = false ; var colors = [ [ 'blue ' , 'yellow ' ] , [ 'white ' , 'pink ' ] , [ 'green ' , 'red ' ] , [ 'white ' , 'black ' ] , [ 'green ' , 'blue ' ] , [ 'red ' , 'green ' , 'blue ' ] ...
Javascript and Canvas : How to get rid of that Moiré effect in my gyroscope
JS
Hi I am creating an Angular 2 app . It seems like the service is not getting injected correctly as I do n't see the page showing any results . I have set the risk-list.component.html as the startup page . Could somebody tell me what the problem is ? I have uploaded the code in a plunker as wellapp.module.tsapp.componen...
import { NgModule } from ' @ angular/core ' ; import { BrowserModule } from ' @ angular/platform-browser ' ; import { AppComponent } from './app.component ' ; import { RiskListComponent } from './components/risks/risk-list.component ' ; @ NgModule ( { imports : [ BrowserModule ] , declarations : [ AppComponent , RiskLi...
Service not getting injected correctly and page shows no results + angular 2
JS
I have a collection that looks something like this : … and later an object that looks like this : I ’ m trying to match the condition object against the nested conditions objects in collection to find the one that matches so I can retrieve the name property from the matching entry.The thing that ’ s throwing me for a l...
const collection = [ { name : 'THIS_ITEM ' , conditions : { oneCondition : false , anotherCondition : false , yourCondition : false , myCondition : false } } , { name : 'THAT_ITEM ' , conditions : { oneCondition : false , anotherCondition : false , yourCondition : true , myCondition : false } } , { name : 'THOSE_ITEMS ...
Find object in collection with fuzzy matching
JS
I am hitting up mongo ( via mongoose customer.find ( ) ) and getting back something that looks like Please note that this is the result from console.log directly . This is not something I am entering , this is the results from mongoDB . _id is being returned in this form by mongo and has absolutely nothing to do with t...
[ { _id : 5029a09e099fb5095fdb2d73 , clientId : 22 , company : ' X ' , email : ' X @ Y.ca ' , firstName : ' X ' , lastName : ' Y ' , quality : 'Sold ' , address : { phone : `` , alt : `` , street1 : `` , street2 : `` , city : `` , state : 'Ontario ' , country : 'Canada ' , code : `` } , comments : [ ] } ] { _id : 5029a...
Defined variable is undefined
JS
I need to sort an array based on Alphabets . I have tried sort ( ) method of javascript , but it does n't work since my array consists of numbers , lowercase letters and uppercase letters . Can anybody please help me out with this ? ThanksFor e.g my array is :
[ `` @ Basil '' , `` @ SuperAdmin '' , `` @ Supreme '' , `` @ Test10 '' , `` @ Test3 '' , `` @ Test4 '' , `` @ Test5 '' , `` @ Test6 '' , `` @ Test7 '' , `` @ Test8 '' , `` @ Test9 '' , `` @ a '' , `` @ aadfg '' , `` @ abc '' , `` @ abc1 '' , `` @ abc2 '' , `` @ abc5 '' , `` @ abcd '' , `` @ abin '' , `` @ akrant '' , ...
Sorting an array based on alphabets ?
JS
It 's better to write code that does n't rely on the timing of immediate callbacks ( like microtasks vs macrotasks ) , but let 's put that aside for the moment.setTimeout queues a macrotask , which , at a minimum , waits to start until all microtasks ( and microtasks that they spawn ) finish . Here 's an example : The ...
console.log ( 'Macrotask queued ' ) ; setTimeout ( function ( ) { console.log ( 'Macrotask running ' ) ; } ) ; Promise.resolve ( ) .then ( function ( ) { console.log ( 'Microtask running ' ) ; } ) ; console.log ( 'Microtask queued ' ) ; console.log ( 'Last line of script ' ) ;
How to queue a microtask if the browser does n't support native Promises ?
JS
The following controller works without problem . I tried to make it a little cleaner by using bind : Unfortunately , this form does not work as expected and $ scope is always supplied with an old version of $ scope in bound method ( bar here ) , even after $ scope has changed to refer to a different value . What is wro...
app.controller ( 'foo ' , [ ' $ scope ' , function ( $ scope ) { $ scope.delete = function ( ) { bar ( $ scope ) ; } } ] ) ; app.controller ( 'foo ' , [ ' $ scope ' , function ( $ scope ) { $ scope.delete = bar.bind ( null , $ scope ) ; } ] ) ;
JavaScript ` bind ` method does not work as expected
JS
When i see my console in Chrome it has a closure which has function first which also has a closure of itself ie it has repetitive loop of its own function in closure , Does anyone knows whats happening here , I am very much confused , Why there is infinte closure loop
function buildList ( list ) { var i = 0 ; var first = function ( ) { console.log ( `` in '' ) console.log ( i ) ; } var Second = function ( ) { console.log ( `` out '' ) first ( ) ; } return Second ; } var a = buildList ( [ 1 , 2 , 3 ] ) console.dir ( a ) ; a ( ) ; // Here closure is created which has function first , ...
Recursive closure in JavaScript
JS
ScenarioI have web interface ( in a large web application ) that allows a user to make a connection between two very large lists.List A - 40,000+ itemsList B - 1,000+ itemsList C - Contains a list of items in b that are connected to the selected item in list AThe CodeHere is a rough jsfiddle of the current behavior min...
$ ( '.name-listb input ' ) .add ( '.name-listc input ' ) .click ( function ( e ) { var lista_id = $ ( '.name-lista input : checked ' ) .val ( ) ; var listb_id = $ ( this ) .val ( ) ; var operation = $ ( this ) .prop ( 'checked ' ) ? 'create ' : 'delete ' ; var $ listb = $ ( '.name-listb .checkbox-list ' ) ; var $ listc...
What is a good strategy for handling large lists on websites without a pager ?
JS
I tried writing my own animation function to animate the counting up and down of a number using loops and the setInterval function . In Chrome , it seems to run very well , but on Firefox , it seems laggy , and to take much longer than the prescribed required completion time.I assume the difference lies in the two brow...
function tallyPrices ( ) { var current_total = parseFloat ( $ ( '.budget span ' ) .text ( ) ) ; var new_total = 0 ; var animation_options = { iterationTime : 10 , totalTime : 500 } $ ( ' # chosen-items li ' ) .each ( function ( ) { if ( $ ( this ) .attr ( 'data_price ' ) ! == ' n/a ' ) { new_total += parseFloat ( $ ( t...
How does jquery consistently execute animation functions in ( nearly ) exact time ?
JS
Some math calculations in JS problem solvingI am working on a zoom image functionality that creates a new div with a large image that is moved through x and y according to the mousemove on the image . The large image should move a certain % , which is what i am trying to figure out . How much should it move by.Here is ...
zoomObj.caluculateSizes = function ( ) { $ ( zoomObj.largeImage ) .load ( function ( ) { // zoomObj.callingEvent is the small image zoomObj.smlImgSize = zoomObj.callingEvent.width ( ) zoomObj.lrgImgSize = zoomObj.largeImage.width ( ) // How do i go from here ? } )
Calculate how much bigger image A is from image B
JS
While experimenting with JavaScript . I was testing around with some odd little code snippets , here are a few of my findings ( to help understand how I came upon -0 ) , While doing + [ ] in console , this returns 0 . I 'm not sure why , but it does.So , this implies the positive of a array is 0..After doing so , I got...
console.log ( - [ ] ) ; ( -0 ) + ( -0 ) = 0 ( -0 ) - ( -0 ) = -0 ( -0 ) * ( -0 ) = 0 ( -0 ) / ( -0 ) = NaN // of course
Why does -0 exist ?
JS
I 'm creating project in ASP.NET ( Framework 4.0 ) . I have used Asp LinkButton in Master Page & it has 2 page linked with it ( Home.aspx & service.aspx ) .Question As follows : That LinkButton1 works on Home.aspx and does n't work on service.aspx.User.master code as followUser.master.cs code for LinkButton1 ClickWhile...
< ul class= '' nav navbar-nav navbar-right '' > < li > < asp : LinkButton ID= '' LinkButton1 '' runat= '' server '' onclick= '' LinkButton1_Click '' AutoPostBack= '' true '' > Signout < i class= '' glyphicon glyphicon-off '' > < /i > < /asp : LinkButton > < /li > < li class= '' dropdown '' > < a href= '' # '' class= ''...
LinkButton on Master Page does n't fire on Second Child Page in ASP.NET
JS
What is the contexte ? I have a website , which is a single page , where I will present my activity and projectsAfter scrolling few sections we have a projects in a row.What I want to do ? I wan na swap the vertical scroll to horizonta when we arrive to my projects row . When you are at the end of the row it just has t...
< div className= '' projectsContainer '' > // < -- - height 100vh < div className= '' row projects '' > // < -- - Positioned in the middle of the parent ↑ < project1 / > < project2 / > < project3 / > < project4 / > < project5 / > < /div > < /div > componentDidMount ( ) { window.addEventListener ( 'wheel ' , ( this.hand...
Changing vertical scroll to horizontal at a point for a specific element
JS
I 've recently discovered an awesome ng-describe package that makes writing unit tests for AngularJS applications very transparent by abstracting away all of the boilerplate code you have to remember/look up and write in order to load , inject , mock or spy.Has somebody tried to use ng-describe with protractor ? Does i...
ngDescribe ( { inject : ' $ http ' , // for making test calls http : { get : { '/my/url ' : 42 , // status 200 , data 42 '/my/other/url ' : [ 202 , 42 ] , // status 202 , data 42 , '/my/smart/url ' : function ( method , url , data , headers ) { return [ 500 , 'something is wrong ' ] ; } // status 500 , data `` somethin...
Using ng-describe for end-to-end testing with protractor
JS
I am analyzing the following two urls from John Resig 's site , but I am not understanding how giving a name to the anonymous function has made a difference.My understanding is that the name given to an anonymous function can only be used inside the function definition , and nowhere outside of it , but in the following...
var samurai = { yell : ninja.yell } ; var ninja = { } ; assert ( samurai.yell ( 4 ) == `` hiyaaaa '' , `` The method correctly calls itself . '' ) ;
How does naming an anonymous function in JavaScript make a difference ?
JS
I '' m loading products via an infinite scroll in chunks of 12 at a time . At times , I may want to sort these by how many followers they have.Below is how i 'm tracking how many followers each product has . Follows are in a separate collection , because of the 16mb data cap , and the amount of follows should be unlimi...
var FollowSchema = new mongoose.Schema ( { user : { type : mongoose.Schema.ObjectId , ref : 'User ' } , product : { type : mongoose.Schema.ObjectId , ref : 'Product ' } , timestamp : { type : Date , default : Date.now } } ) ; var ProductSchema = new mongoose.Schema ( { name : { type : String , unique : true , required ...
$ inc follower count , or should I use an aggregate to track them ?
JS
I initialize noUiSlider with dataafter initialization slider value is 30679098761.50 why ? Demo here - https : //jsfiddle.net/serGlazkov/yrppsmvo/5/
var settings = { connect : `` lower '' , range : { max : 87654567890 , min : 0 } , start : 30679098762 , step : 1 }
noUiSlider long number rounding error
JS
I am rewriting one of javascript 's core methods : I want to dynamically get the name of the method ( in this case `` removeChild '' ) from inside of the function being dynamically rewritten . I use arguments.callee.name but it seems to return nothing , thinking that it is just an anonymous function . How do I get the ...
Element.prototype._removeChild = Element.prototype.removeChild ; Element.prototype.removeChild = function ( ) { callback ( ) ; this._removeChild.apply ( this , arguments ) ; }
Javascript metaprogramming : get name of currently executing function which was dynamically rewritten
JS
Why does typeof let return 'undefined ' and is not throwing an SyntaxError instead ? The unary typeof operator expects an expression . Am I missing something about the let statement ?
console.log ( typeof let ) ;
Why is typeof let === 'undefined ' ?
JS
I 'm trying to add a few interactive things the to Django admin page via a simple RESTful api and Javascript . Should be simple , but I 'm facing a weird issue where every single one of my requests from javascript is returning a 403 authorization error . Note that this only applies to js . I can hit the url from a brow...
$ .ajax ( { xhrFields : { withCredentials : true } , type : 'PATCH ' , url : 'path/to/my/endpoint , data : { aParam : someValue , 'csrfmiddlewaretoken ' : getCookie ( 'csrftoken ' ) } , success : doSomething , error : doSomething } ) ; class MyObjectDetail ( RetrieveUpdateDestroyAPIView ) : queryset = MyObject.objects....
Django Rest framework replacing my currently authenticated user with AnonymousUser whenever I call it via ajax ?
JS
I 'm migrating a database and part of cleaning up the old data structure , some of the values for some keys end up being literaly undefined . The key will still exist and will have the value undefinedI made this function but after modifying a class object with it , it will no longer be an instanceof the same class . Ho...
export const FilterUndefined = < T extends object > ( obj : T ) : T = > { return Object.entries ( obj ) .reduce ( ( acc , [ key , value ] ) = > { return value ? { ... acc , [ key ] : value } : acc ; } , { } ) as T ; } ; PROTOTYPE TestClass { } it ( 'should return the same type that it receives ' , ( ) = > { class TestC...
Ensure my function returns mutated object as instanceof the same class typescript ?
JS
Instead of having to create a custom logger for TRACE , e.g . following what methods were called and what classes were instantiated , is there an easy way to make all methods under a class log themselves ? This is for a node.js application.If I had my way , you 'd see 4 log messages instead of 2 ( thus having to write ...
class MyClass constructor : ( ) - > console.log 'MyClass : constructor ' doThat : ( ) - > console.log 'MyClass : doThat'exports.MyClass = MyClassmyClass = new MyClass ( ) myClass.doThat ( )
log every method ?
JS
I develop a restful API with nodeJS.The two functions execute the same code but not with the same parameters.I would like to avoid duplication in my code.How can do in order to avoid duplication of my code ?
exports.postCreature = function ( req , res ) { var creature = new Creature ( { name : req.body.name , id_user : req.user._id } ) ; creature.save ( function ( err ) { if ( err ) res.status ( 400 ) .send ( Error.setError ( 'impossible to save the your creature ' , err ) ) ; else res.status ( 201 ) .send ( ) ; } ) ; } ; ...
Polymorphism nodeJS
JS
While debugging javascript written by someone else , I came across some code that I 've not seen before . Here 's a sample : Is the purpose of the 2nd line in function doItNow ( ) to check if doSomething exists and then call it ? Like so : JSLint does not like it and I 'd rather not have bad code in my app . Any insigh...
function doSomething ( ) { //doing something here ... } function doItNow ( ) { //other logic ... doSomething & & doSomething ( ) ; // < === What 's this ? } function doItNow ( ) { //other logic ... if ( doSomething ) { doSomething ( ) ; } }
JavaScript coding technique or bad code ?
JS
Can I use id with `` ( `` and `` ) '' in jquery mobile ? for example : I have tried that id and want to access that element in js.but it did n't worked .
< div id= '' RSI ( 3,4 ) '' > < /div > $ ( `` # RSI ( 3,4 ) '' ) .html ( `` some text '' ) ;
div with the id= '' ( name ) '' can I use this or not ?
JS
I have a static image made interactive using the concept of HTML maps.Coordinates of the image set by uploading on https : //imagemap.org/Expected Behavior : An overlay should display on hover in its respective box . For example , when the mouse hovers over red box , the overlay text should come in the red box itself ,...
< body > < div class= '' interactive-map '' > < img src= '' https : //www.politicalmetaphors.com/wp-content/uploads/2015/04/blog-shapes-square-windows.jpg '' > < div class= '' card '' style= '' width:40 % ; height : 10 % ; '' > < div class= '' card-body '' > This is some text within a card body . < /div > < /div > < ma...
add overlay in specific position in HTML map
JS
Can I get some clarification on why I would want to use this ?
myVar = ! ! someOtherVar ;
myVar = ! ! someOtherVar
JS
I am using jQueryMobile 's $ .mobile.changePage ( ... ) method to switch to a different page within my project.When I run that method , the transition works perfectly but when I hit the browser 's return button I see no reverse transition.I played around with some of the parameters described in http : //jquerymobile.co...
$ .mobile.changePage ( `` # foo '' , { transition : '' slide '' } ) ;
Defining a return-transition between page changes
JS
Here is a naive implementation of a right fold : This is non-tail recursion and hence we can not apply a trampoline . One approach would be to make the algorithm iterative and use a stack to mimick the function call stack.Another approch would be to transform the recursion into CPS : This is still naive , because it is...
const foldr = f = > acc = > ( [ x , ... xs ] ) = > x === undefined ? acc : f ( x ) ( foldkr ( f ) ( acc ) ( xs ) ) ; const Cont = k = > ( { runCont : k } ) ; const foldkr = f = > acc = > ( [ x , ... xs ] ) = > Cont ( k = > x === undefined ? k ( acc ) : foldkr ( f ) ( acc ) ( xs ) .runCont ( acc_ = > k ( f ( x ) ( acc_ ...
How to adapt trampolines to Continuation Passing Style ?
JS
I have an issue where I am trying to build a system where people can see the realtime data like , if I put 500 grams of milk then people can see the value content of fat , sweets , solid in it and for that I have a test box of weight of milk and readonly textboxes for other things like fat , sweet , solids etc . now I ...
< td > < input type= '' text '' name= '' name '' placeholder= '' Weight '' class='smalltextbo onlynumbers ' id= '' w < ? = $ thedetails_array [ 'sno ' ] ? > '' onkeyup= '' return updatevalues ( this ) ; '' onkeypress= '' return isNumber ( event ) ; '' ; value= ' 1'/ > < /td > < td > < input type= '' text '' name='fat '...
value of a text box based on the value of other text box
JS
Possible Duplicate : Create an empty object in JavaScript with { } or new Object ( ) ? When I want to declare a new array I use this notationBut when testing online , for example on jsbin , a warning signals me to `` Use the array literal notation [ ] . `` I did n't find a reason to avoid using the constructor . Is in ...
var arr = new Array ( ) ;
Which one is the best practice to follow when declaring an array in Javascript ?
JS
I have a dropdown for different dates in dd/mm/yyyy format and i want to convert the selected date to javascript date format and increment by 1 using javascript . Can anyone please help me . Thanks in advance.Here is my code : HTMLJavascript
< select name= '' txtweek '' id= '' txtweek '' > < option > -- select -- < /option > < option > 31-08-2015 < /option > < option > 07-09-2015 < /option > < option > 14-09-2015 < /option > < option > 21-09-2015 < /option > < option > 28-09-2015 < /option > < option > 05-10-2015 < /option > < option > 12-10-2015 < /option...
how convert date from dropdown to javascript date format and increment by 1 day ?
JS
Here is the package I 'm working on currently.This is the first time I 'm trying to enforce the conventional changelog format and use semantic release versioning . The releasing itself works fine , I 'm having travis CI testing , building and publishing the package to npm , creating a new version and a git tag . There ...
$ conventional-changelog -p eslint-plugin-protractor -i CHANGELOG.md -w -r 0
Generate changelog for a semantically released package
JS
I have the following . For some reason , moment.js isnt validating my dates as expected . When i pass letters , it fails like its supposed to , but when using digits only , it always passes.I 'm using the MMDDYYYY format . How do I validate MMDDYYYY using moment ? Thanks
var dates = `` 08291975 '' ; //passes as it shouldvar passed = moment ( dates , 'MMDDYYYY ' , true ) .isValid ( ) ; console.log ( 'should pass ' + passed ) ; //actual output is 'should pass true'dates = `` 082919751 '' ; //one digit too many should fail but doesntpassed = moment ( dates , 'MMDDYYYY ' , true ) .isValid ...
validate MMDDYYYY format using Moment
JS
I have a dynamically populated div-based dropdown that extends past the end of the screen when the customer puts lots of entries in it , hiding the lower entries . It is on one column in a set of data entry rows ( td elements ) , so the available space varies on which row is being entered.Unfortunately this is an appli...
< div class= '' empform '' > < html : form action= '' /processBlank '' > < div id= '' divJobClass '' style= '' visibility : hidden ; position : absolute ; height= '' 50px '' border-color : # fff ; border-style : solid ; border-width : 1px ; background : white ; opacity : 1 '' > < table id= '' tableJobClass '' cellspaci...
How do I get a div-based dropdown to gain a scrollbar instead of extend past the end of the screen using JavaScript and CSS ? Struts are also involved
JS
Trying to figure out how to sort an array of letter grades properly [ ' A+ ' , ' A ' , ' A- ' , ' B+ ' , ' B ' , ' B- ' , ' C+ ' , ' C ' , ' C- ' , 'D+ ' , 'D ' , 'D- ' , ' F ' ] . Standard sorting function does n't do it . I 'm also looking to do this without setting a manual index for each letter grade.Expected outpu...
const grades = [ ' B+ ' , ' F ' , ' A- ' , ' A+ ' , ' B ' , ' B- ' , ' C+ ' , ' C ' , ' C- ' , 'D+ ' , 'D ' , 'D- ' , ' A ' ] grades.sort ( ( a , b ) = > { return a - b ; } ) ; console.log ( grades ) ;
How to sort letter grades in Javascript without a manual index
JS
I 'm using PHP to consume a service that is not mine . This service returns things that are almost , but not quite , entirely unlike JSON ( hat tip , HGG ) . i.e. , in their simplest form , they look like thisRunning the above string through json_decode returns NULLThe problem is that a is n't quoted . Does PHP ( eithe...
{ a : 8531329 } $ foo = json_decode ( ' { a : 8531329 } ' ) ; $ foo = json_decode ( ' { `` a '' : 8531329 } ' ) ;
Dealing with JSONish things in PHP
JS
I have been reading the code of a few javascript libraries . I 've noticed that AngularJS and Backbone.js both keep a local reference to array functions . e.g . : what is the point of doing this when arrays are a construct of the language and should be accessible globally ?
var push = [ ] .push // or array.push
Why do Javascript Libraries have local references to array methods ( push , slice , etc.. ) ?
JS
When importing/exporting data from ES6 modules , mutability of that data appears to be different between named imports and exports . Is there a reason for this or some fundamental difference I 'm not understanding ? In both scenarios , I would expect count to increment . However , this only happens when using named exp...
// counter.jsexport let count = 0 ; export const incrementCount = ( ) = > count += 1 ; export default count ; // main-default.jsimport count , { incrementCount } from './counter ' ; console.log ( count ) ; // 0incrementCount ( ) ; incrementCount ( ) ; console.log ( count ) ; // 0 // main-named.jsimport { count , increm...
Mutable difference between ES6 named and default exports
JS
I have the following example : For certain variable names , typescript ( right now Version 2.1.4 ) will not complain that they are not defined in your program ( In the method talk , name is being used without this. ) . name is one of those.If I rename the variable to , say , firstName , the compiler complains rightfull...
class Uncle { constructor ( public name : string ) { } talk ( ) { return `` Hello my name is `` + name ; } } let p : Uncle = new Uncle ( `` Jo '' ) ; console.log ( p.talk ( ) ) ;
Why does typescript not complain about certain undefined variables
JS
So I just downloaded the `` VSCode Cucumber ( Gherkin ) Full Language Support + Formatting + Autocomplete '' plugin to help with cucumber formatting inside my vscode editor . It seems like from their documentation , the `` VSCode Cucumber ( Gherkin ) ... '' plugin supports a feature which will let you see the relations...
src├── features│ ├── accessibility│ │ └── FeatureFile.feature│ ├── Directory│ │ ├── featureFile.feature│ │ ├── SomeDirectory│ │ │ ├── FeatureFile.feature│ ├── step_definitions│ │ ├── SomeDirectory│ │ │ ├── someFile.js│ │ │ ├── given.js│ │ │ └── then.js│ │ ├── given.js│ │ ├── someFeature.js│ │ ├── then.js│ │ └── when.js...
Mapping features to step definitions in the settings file for the `` VSCode Cucumber ( Gherkin ) Full Language Support + Formatting + Autocomplete '' plugin
JS
I have Float32Array textures which can be displayed through WebGL correctly . However , when I tried to convert them into Uint16Array , the problem occurs.Here is my conversion part .
var _floatToHalfFloat = function ( input , offset ) { var largestHalf = Math.pow ( 2 , 30-15 ) * ( 1 + 1023/1024 ) ; var m = new ArrayBuffer ( 4 ) ; var n = new Float32Array ( m ) ; var o = new Uint32Array ( m ) ; var f = 0.0 ; for ( var i = input.length - 1 - offset ; i > = 0 ; i -- ) { n [ 0 ] = input [ i ] ; f = o [...
Conversion from Float32Array to Uint16Array in WebGL
JS
The PHP code needs to fetch data from the table , decode it as JSON and then send it to AngularJS . Angular JS redirects if the login credentials are correct.However even if the credentials are incorrect , the user is still redirected ( true statement always passes ) .PHP Code : AngularJS Controller : HTML Form Code
< ? php $ data = json_decode ( file_get_contents ( `` php : //input '' ) ) ; $ username = $ data- > username ; $ password = $ data- > password ; /* * Collect all Details from Angular HTTP Request . */ require_once ( `` connection.php '' ) ; //must read from table $ connection = connectToMySQL ( ) ; //complete from here...
Login still directs even if incorrect credential with AngularJS and PHP
JS
I 'm working with an application that uses DataTables to generate a HTML table which is populated by data from an ajax request.This is fairly simple : There is a callback which DataTables provides , called rowCallback ( https : //datatables.net/reference/option/rowCallback ) which allows post processing of table rows a...
var substancesTable = $ ( ' # substancesTable ' ) .DataTable ( { `` processing '' : true , `` serverSide '' : true , `` searching '' : false , `` ajax '' : { `` url '' : `` /get-substances.json '' , `` method '' : `` POST '' , `` cache '' : false , `` dataSrc '' : function ( json ) { // Update non-Datatables UI element...
Using ajax in a callback where the parent process itself relies on an ajax call
JS
I made a page which pulls data from Contentful . The data is pulling correctly , but buttons which use functions from methods do n't work . Live updating of variables ( for example , using v-model ) does n't work either.I see this error in the console : I think this error is the problem . Does anyone know what 's wrong...
const contentful = require ( 'contentful ' ) const client = contentful.createClient ( { space : process.env.CONTENTFUL_ENV_SPACE_ID , accessToken : process.env.CONTENTFUL_ENV_ACCESS_TOKEN } ) module.exports = client export default { layout : `` landing_page '' , asyncData ( ) { return client .getEntries ( { content_typ...
Contentful with Nuxt.JS `` Expected parameter accessToken ''
JS
I set my images centred in CSS : But I want to know its top-position now after it is set to centre , how can I calculate that with jQuery or just plain javaScript ? Any ideas ?
background-position : center center ; .parallax3 { position : relative ; background-position : center center ; background-repeat : no-repeat ; background-size : cover ; background-image : url ( 'https : //picsum.photos/g/200/600 ' ) ; height : 100 % ; } .tagline { font-size : 2.5vw ; letter-spacing:0.05em ; padding : 2...
jQuery calculate image background-position top position ?
JS
Can anyone explain , why the following happens with ES6 array destructuring ? http : //codepen.io/ronkot/pen/WxRqXg ? editors=0011
let a , b , c [ a , b ] = [ ' A ' , ' B ' ] [ b , c ] = [ 'BB ' , ' C ' ] console.log ( ` a= $ { a } b= $ { b } c= $ { c } ` ) // expected : a=A b=BB c=C// actual : a=BB b=C c=undefined
ES6 Array destructuring weirdness
JS
What are the differences between ? Do the two JavaScript expressions always yield the same result , regardless of the content and state of myPromise and implementations of functions a and b ? Is there any situation where I should prefer using one over the other , other than code readability ?
myPromise.then ( a , b ) myPromise.then ( a ) .catch ( b )
Is Promise.then ( a , b ) the same as Promise.then ( a ) .catch ( b ) ?
JS
Can you guys help me determine the performance difference of each of thesestatements ? Which one would you use ? Making a new Array usingAppending element usingTernary operator or if ( ) { } else ( ) { } Trying to make isodd function , which is fasterforEach ( ) or normal iterationone morea= b = 3 ; or b=3 ; a=b ; [ ed...
- var new_list = new Array ( ) ; //or- var new_list = [ ] ; - push ( ' a ' ) - new_list [ i ] ; ( if i know the length ) ( ! ( is_even ) ) or ( x % 2 ! =0 )
JavaScript 's Statement Performance Questions
JS
In writing a test I was comparing strings . And the test came back as Failing . I manually copy pasted the string and it works ... Note the mysql string syntax ; but it never touches mysql up to this point . Console.logged copy+paste Both Strings look like this : It Should n't be failing but it does . So I wanted to se...
console.log ( replaced ) ; '' SELECT COUNT ( * ) FROM interaction WHERE ambassador_name LIKE ' % ' AND influencer_name = ? `` console.log ( sqlQuery0 ) ; '' SELECT COUNT ( * ) FROM interaction WHERE ambassador_name LIKE ' % ' AND influencer_name = ? '' it ( `` submits the proper first sql query '' , function ( ) { var ...
Javascript read `` % % '' both as `` % '' and `` % % '' ?
JS
I 'm attempting to build a basic JS plugin that can be called after a click event to disable a button ( to prevent users firing multiple API calls ) and to give feedback that something is loading/happening . Here is how it looks : This works great on an individual basis , but I want to re-write it as a plugin so I can ...
let originalBtnText ; export function showBtnLoader ( btn , loadingText ) { const clickedBtn = btn ; const spinner = document.createElement ( 'div ' ) ; spinner.classList.add ( 'spin-loader ' ) ; originalBtnText = clickedBtn.textContent ; clickedBtn.textContent = loadingText ; clickedBtn.appendChild ( spinner ) ; click...
Basic ES6 Javascript Plugin - reuse variable between functions
JS
Am currently developing a mute function for asterisk which I can run from my web front end using asterisk ARI.But every time I try to run/call the mute function it gives me the following error : But it is , as far as am aware am passing the channel data directly to this function but to no avail.Any one any suggestions ...
Error : { `` message '' : `` Channel not in Stasis application '' } $ ( document ) .on ( 'click ' , '.mute ' , function ( ) { var mute = $ ( this ) .closest ( 'td ' ) .siblings ( ' : first-child ' ) .text ( ) ; socket.emit ( 'muting ' , mute ) ; if ( $ ( this ) .hasClass ( 'mute ' ) ) { $ ( this ) .removeClass ( 'mute ...
ARI JS client mute error
JS
Learning d3 and when I create a simple array of numbers , then attempt to bind the data to a simple set of elements , but use the key function , it runs through the loop twice . The first time through , it tells me that the values of the array are undefined . The second time through they are available . Here is the htm...
< div class= '' testBind '' > < /div > < div class= '' testBind '' > < /div > < div class= '' testBind '' > < /div > var numbers = [ 1 , 2 , 3 ] ; function whichNumber ( n ) { console.log ( ' n -- -- : ' + n ) ; return n ; } var testKeyFunction = d3.selectAll ( `` div.testBind '' ) .data ( numbers , whichNumber ) ; n -...
D3.js key function running twice on simple selector/array combo
JS
So I have a list of siblings like so ; ( Note : The b 's are not children of the a 's , they 're all siblings . Indentation is for emphasis . ) In jQuery , I need to select each b , forgoing the first n elements in a streak . There is no specific type/class of element that breaks the streak , nor any dependable number ...
< div class= '' b '' > < /div > < div class= '' a '' > < /div > < div class= '' b '' > < /div > < div class= '' b '' > < /div > < div class= '' b '' > < /div > < div class= '' b '' > < /div > < div class= '' a '' > < /div > < div class= '' b '' > < /div > < div class= '' b '' > < /div > < div class= '' a '' > < /div > ...
jQuery selector : all but n first in a row
JS
I am using Bluebird for promises and trying to allow chain calling however using .bind ( ) doesnt seem to work . I am getting : TypeError : sample.testFirst ( ... ) .testSecond is not a functionThe first method is called correctly and starts the promise chain but I havent been able to get the instance binding working a...
var Promise = require ( 'bluebird ' ) ; SampleObject = function ( ) { this._ready = this.ready ( ) ; } ; SampleObject.prototype.ready = function ( ) { return new Promise ( function ( resolve ) { resolve ( ) ; } ) .bind ( this ) ; } SampleObject.prototype.testFirst = function ( ) { return this._ready.then ( function ( )...
Bluebird Promise Bind Chain
JS
I 'm building an app in which I present some planes with textures . However , I would like to calculate the radius of the helix ( which I use in my calculations to create a helix ) , dynamically based on the frustum width and the camera position.The helix is positioned at the center of the screen x=0 , y=0 , z=0.I woul...
App.prototype.calculateHelixRadius = function ( ) { // plane width = height = 512 ; var friend = this.getFriend ( ) ; var vFOV = friend.camera.fov * Math.PI / 180 ; var dist = utils.getAbsPointsDistance3D ( friend.camera.position , friend.scene.position ) ; var aspect = friend.settings.container.clientWidth / friend.se...
Calculate radius of helix so that models in helix are inside the frustum
JS
Why these nearly similar date objects give different results in Chrome 37 ? In IE11 I get `` 2014 '' and `` 2015 '' as expected . Browser works in Russian locale . Conversion to strings gives the following results :
var d2014 = new Date ( 2014 , 0 , 1 ) ; alert ( d2014.getFullYear ( ) ) ; // 2013var d2015 = new Date ( 2015 , 0 , 1 ) ; alert ( d2015.getFullYear ( ) ) ; // 2015 d2014.toString ( ) ; // Tue Dec 31 2013 23:00:00 GMT+0300 ( RTZ 2 ( зима ) ) d2015.toString ( ) ; // Thu Jan 01 2015 00:00:00 GMT+0300 ( RTZ 2 ( зима ) ) d20...
Strange Date behavior in Chrome
JS
I tried the typical sort function and checked if item is string . But I get a very strange output . Tried multiple different approaches.Should I use localeCompare or is it possible to without ? Would like the output to be : Would much appreciate any suggestions
var arr = [ { section : '12.2.a ' } , { section : '12.2.b.iii ' } , { section : '12.2.c ' } , { section : '12 ' } , { section : '12A ' } , { section : '12.3.b ' } , { section : '12.3.c ' } , { section : 'Q2 ' } , { section : 'Q32 ' } , { section : 'Q6 ' } , { section : 'Q5 ' } ] var arr2 = arr.sort ( function ( a , b )...
Sort array of objects with dots , letters , numbers . I was able to sort by numbers , but mixed values are difficult . Not sure if possible to do it right
JS
I have perfomance issues when inserting data into the dom . Insertions + jQuery mobile enhancement done on pagecontainerbeforeshow ( ) event , jQuery mobile version 1.4.2.I have tried to see which would be the fastest approach by comparing three simplified versions of what I want to do : jQuery approach : Pure js , cre...
for ( var i=0 ; i < 2000 ; ++i ) { $ ( ' < div > ' ) .attr ( { 'data-role ' : 'collapsible ' , 'id ' : 'asdf'+i+ '' } ) .html ( ' < h2 > asdf < /h2 > ' ) .appendTo ( `` # manage_content '' ) ; $ ( ' < ul > ' ) .attr ( { 'data-role ' : 'listview ' } ) .html ( ' < li > bit < /li > ' ) .appendTo ( ' # asdf'+i+ '' ) ; } $ ...
Comparing three ways of inserting dom elements + enhancing them with jQuery mobile
JS
I made a few charts with dimple and they look OK in chromium ( v 43 ) , but in Firefox ( v 40 ) they are rendered incorrectly.I inspected the page in the debugger and I can see that under the < svg > tag there is a < g > tag . The inspector shows the g tag in chrome as 720x556 and in firefox as 730x97 , which obviously...
link : function ( scope , element , attrs ) { var svg = dimple.newSvg ( element [ 0 ] , 800 , 600 ) ; svg.text ( `` Charttitle '' ) ; var myChart = new dimple.chart ( svg , data ) ; myChart.addCategoryAxis ( `` x '' , `` column1 '' ) ; myChart.addCategoryAxis ( `` y '' , `` column2 '' ) ; myChart.addCategoryAxis ( `` z...
Dimple js plot not scaling correctly in Firefox
JS
I 'm trying to create a function that will generate a tree like structure such that each item contains a reference to it 's parent item . I have a function that calls itself when creating the children but am having a tough time with it , it seems that once it is called from within itself this still refers to the top le...
var Item = function ( item , parent ) { console.log ( 'item is : ' + item.name ) ; this.parent = parent ; console.log ( 'parent is : ' + parent ) ; var fields = _.union ( _.keys ( item ) , _.keys ( this.parent ) ) ; _.each ( _.without ( fields , [ 'parent ' , 'children ' ] ) , function ( prop ) { this [ prop ] = angula...
Javascript recursive function reference this
JS
I am working on a site which uses Mootools and a carousel has been added to the site which is taken from here - http : //developer.yahoo.com/yui/examples/carousel/carousel-ariaplugin_source.htmlThe problem is that the carousel somehow does n't play nice with Mootools . With Mootools , it does n't work and when I remove...
< div class= '' yui-skin-sam '' > < h1 id= '' my-carousel-label '' > Expert Health Advice < /h1 > < div id= '' container '' > < ol id= '' carousel '' > < li class= '' item '' > < a title= '' View Author 's Biography '' class= '' authimg '' href= '' http : //health.yahoo.com/experts/skintype/bio/leslie-baumann/ '' > < i...
Mootools and YUI Carousel Issue
JS
I am using a JavaScript to track the activities of users on my page upon unloading that very page . Consider the following simplified dummie-script to simulate what I am doing on unload : The image URL in that case serves as a holder for tracking data.The image is requested in some browsers ( e.g . Firefox 3 ) and is n...
$ ( window ) .unload ( function ( ) { $ .get ( `` http : //www.google.de/images/srpr/logo3w.png '' ) ; } ) ;
How much activity do browsers allow on unload ?
JS
I am using AngularJS and ui-router and have the following code which catches 404 's and loads in a 404 template : It keeps the URL intact instead of redirecting , but shows the 404 template : Normally it would redirect to the root state with : $ urlRouterProvider.otherwise ( '/ ' ) ; However when HTML5 mode is turned o...
$ urlRouterProvider.otherwise ( function ( $ injector , $ location ) { $ injector.invoke ( [ ' $ state ' , function ( $ state ) { $ state.go ( '404 ' ) ; } ] ) ; } ) ; .state ( '404 ' , { views : { 'body ' : { templateUrl : 'partials/404.html ' , } } } ) ;
Load 404 state with AngularJS Router
JS
I know that TypeScript can detect compile errors for *.ts files.However , what about getting these benefits in AngularJS views/templates ? For example , if I have a code like : And I have a HomeController class defined , then I 'd like to receive a compile error if `` property1 '' is n't defined for HomeController clas...
< div ng-controller= '' HomeController as home '' > { { home.property1 } } < /div >
Use typescript in AngularJS to check the interpolation/binding in HTML
JS
I 'm kinda a newbie at regular expressions , so would appreciate a bit of peer feedback on this one . It will be heavily used on my site , so any weird edge cases can totally wreak havoc . The idea is to type in an amount of an ingredient in a recipe in whole units or fractions . Due to my autocomplete mechanism , just...
11/21 1/24 cups4 1/2 cups10 3/4 cups sliced ^\s* ( \d+|\d+\/\d+|\d+\s*\d+\/\d+ ) \s* ( . * ) $ ^\s* ( \d+\/\d+|\d+\s*\d+\/\d+|\d+ ) \s* ( [ a-z ] . * ) $ ^\s* ( \d+\/\d+|\d+\s*\d+\/\d+|\d+ ) \s* ( $ | [ a-z ] . * ) $
Any way to improve this regular expression ?
JS
there are two ways for for handling events on click in JSin jquery so i want to ask attaching click event as done above in jQuery is bad practice is it called hijacking
< span onclick= '' handle ( ) '' > < /span > function handle ( ) { ... ... } < span class= '' handle '' > < /span > jQuery ( '.handle ' ) .click ( function ( ) { ... .. ... . } ) ;
is jquery hijacking possible
JS
I 'm am trying to .push some data to my Firebase but I 'm getting this error in my Chrome console : Uncaught Error : Firebase.push failed : first argument contains an invalid key ( cljs $ lang $ protocol_mask $ partition0 $ ) in property 'arr.0 ' . Keys must be non-empty strings and ca n't contain `` . `` , `` # '' , `...
fb ( js/Firebase . `` https : //example.firebaseio.com/example-listings '' ) ( def app-state ( atom { `` post '' { : first_name `` Billy '' : last_name `` Bob '' : location `` CA '' : email `` bob @ aol.com '' : website `` www.pwt.com '' } } ) ) ( def postData ( get-in @ app-state [ `` post '' ] ) ) ( .push fb postData...
How to firebase.push in Clojurescript ? Is my data correct ?
JS
I want to write a custom assert function for QUnit to check if an actual string matches an expected regex . With help of this question I wrote a first basic version that works as expected : This outputs : Message : Expected : `` string matching /gibberish/ '' , Actual : `` flower '' Great ! However , while writing this...
QUnit.extend ( QUnit.assert , { matches : function ( actual , regex , message ) { var success = ! ! regex & & ! ! actual & & ( new RegExp ( regex ) ) .test ( actual ) ; var expected = `` String matching / '' + regex.toString ( ) + `` / '' ; QUnit.push ( success , actual , expected , message ) ; } } ) ; QUnit.test ( `` ...
How to write new assertion functions for QUnit without using QUnit.push ?
JS
Can anyone explain the difference in behaviour between Internet Explorer and Firefox in regards to the below : In internet explorer this method allows me to call my function from inside my namespace function by using either myFunction ( ) or exposed.myFunction ( ) .Outside my namepsace function I can use myNamespace.my...
var myNamespace = ( function ( ) { var exposed = { } ; exposed.myFunction = function myFunction ( ) { return `` Works ! `` ; } console.log ( myFunction ( ) ) ; // IE : `` Works ! '' // Firefox : ReferenceError : myFunction is not defined console.log ( exposed.myFunction ( ) ) ; // IE : `` Works ! '' // FF : `` Works ! ...
Javascript : Inconsistency when assigning a named function to a variable ( named function expression )
JS
Consider the following code : I expected f to be defined at all times during execution . However , in Chrome and IE , it is undefined when the first console.log is invoked , and in Firefox , it is undefined when the second console.log is invoked.Why is f not always defined ? Why do Chrome/IE and Firefox behave differen...
function f ( ) { f = eval ( `` '' + f ) ; console.log ( `` Inside a call to f ( ) , f is : \n % s '' , f ) ; } f ( ) ; console.log ( `` After a call to f ( ) , f is : \n % s '' , f ) ; function f ( ) { f = eval ( `` '' + f ) ; console.log ( `` Inside a call to f ( ) , f is : \n % s '' , f ) ; } undefined undefined func...
Why does a function redefining itself behave differently in Chrome/IE and Firefox ?
JS
In the Chrome Developer Tools window , I typed in : However , name became a string : This obviously is n't true for other variable names ! And name is defined as the empty string on page load ( and , as far as I can tell , can not become anything other than a string ) . So , what 's up with name ?
> name = [ `` a '' , `` b '' , `` c '' ] [ `` a '' , `` b '' , `` c '' ] > typeof name '' string '' > name '' a , b , c '' > name [ 1 ] '' , '' > foo = [ `` a '' , `` b '' , `` c '' ] [ `` a '' , `` b '' , `` c '' ] > typeof foo '' object '' > foo [ 1 ] '' b ''
What 's special about the `` name '' variable in JavaScript ?
JS
So I am trying to do a Webpage with a Parallax landing picture . For the Parallax effect to work , it has a higher height , so the user will have to scroll down . This creates a second scrollbar on the side only for this Parallax . So far so good . The problem is when I scroll down to the end of the Parallax , the seco...
* { box-sizing : border-box ; } html , body { background-color : # fedcc8 ; } .parallax { -webkit-perspective : 100px ; perspective : 100px ; height : 100vh ; overflow-x : hidden ; overflow-y : auto ; position : absolute ; top : 0 ; left : 50 % ; right : 0 ; bottom : 0 ; margin-left : -1500px ; } .parallax__layer { pos...
Why can I not scroll past my parallax without moving the mouse first ?
JS
Let 's say we have a domain for exampleAnd we have some subdomains for different countriesWhat are the disadvantages to this . I 'm speaking from an SEO Google perspective and anything else you may think of ? The problemWe have a client side JS redirect that redirect users based on their country code . This is unavoida...
www.example.com au.example.comus.example.comuk.example.comeu.example.com
Repercussions of redirecting root domain to subdomains
JS
I 'm creating an drag and drop plugin and I thought to make it a little unique i would add a cookies feature to save the position of the dragged elements.I 'm currently using the following code for the get and set cookies : These work fine . But What I ca n't get to work is this : Code Description : o.cookies === true ...
$ .setCookie = function ( c_name , value , exdays ) { var exdate = new Date ( ) ; exdate.setDate ( exdate.getDate ( ) + exdays ) ; var c_value = escape ( value ) + ( ( exdays == null ) ? `` '' : `` ; expires= '' + exdate.toUTCString ( ) ) ; document.cookie = c_name + `` = '' + c_value ; } $ .getCookie = function ( c_na...
Adding cookies to drag and drop
JS
What is a better way to pre-load images : or : What makes one better than the other ?
$ .each ( [ ' { { MEDIA_URL } } jwplayer/jwplayer.js ' , ' { { MEDIA_URL } } jwplayer/jwplayer.js.jgz ' , ' { { MEDIA_URL } } jwplayer/player.swf ' ] , function ( ) { $ ( ' < img/ > ' ) [ 0 ] .src = this ; var preloadImages = [ ' { { MEDIA_URL } } jwplayer/jwplayer.js ' , ' { { MEDIA_URL } } jwplayer/jwplayer.js.jgz ' ...
More efficient way to pre-load images
JS
Why a rotation is applied to my picture ? bellow the dimensions : Result of taken picture by the camera : https : //imgur.com/a/I152DXUDisplayed with GLImage : https : //imgur.com/a/PL7EumHRelated github issue : https : //github.com/gre/gl-react-image/issues/22EDIT1 : I found the related tutorial to make intagram filte...
Object { 13:06:33 [ exp ] `` height '' : 3264,13:06:33 [ exp ] `` uri '' : `` file : ///var/mobile/Containers/Data/Application/8196F3EA-3555-476F-B70F-E76CBBFBB3F8/Library/Caches/ExponentExperienceData/ % 2540devlyl % 252Flyl/Camera/5FA1D6E2-D99E-4675-AF6E-CB96A2367015.jpg '' ,13:06:33 [ exp ] `` width '' : 1836,13:06:...
Rotation of image with gl-react-image
JS
I was implementing a simple GCD algorithm in ES6 ( through node-esml ) and came upon ( to me ) strange behaviour with updating values of variables inside a while loop . This code works fantastically : Returning the expected answer of 1 . However , if I remove the temporary variable and instead use destructuring assignm...
function gcdWithTemp ( x , y ) { let [ r , rdash ] = [ x , y ] while ( r ! = 0 ) { q = Math.floor ( rdash / r ) temp = r r = rdash - q * r rdash = temp } return ( rdash ) } console.log ( gcdWithTemp ( 97 , 34 ) ) function gcdWithDestructuredAssignment ( x , y ) { let [ r , rdash ] = [ x , y ] while ( r ! = 0 ) { q = Ma...
Destructuring assignment in while loop in ES6 function does n't propogate out of loop ?
JS
I 've got a javascript snippet that displays a widget on my page . There 's some links that get output by the script that look like this : These links cause some JS to fire . That 's great . The problem is the href= '' # '' and the absence of a `` return false ; '' at the end of the onclick attribute . When I click one...
< a href= '' # '' onclick= '' somefunction ( ) '' > Link < /a > $ ( document ) .ready ( function ( ) { $ ( `` # wxheader ul li a '' ) .each ( function ( ) { var onclick = $ ( this ) .attr ( `` onclick '' ) + `` ; return false ; '' ; $ ( this ) .attr ( `` onclick '' , onclick ) ; } ) ; } ) ;
Modifying the onclick event with jQuery
JS
How can i achieve that I get jQuery-Intellisense in the following code example ? The problem is that Intellisense does n't know that the parameter for the function is a jQuery-Object . How could I tell the function the parameter type ? I know I could write in the function something liketo create a new jQuery-Objekt , b...
function doSomething ( $ jQueryObject ) { $ jQueryObject . // I want to have Intellisense here } ; var $ parameter = jQuery ( 'body ' ) ; doSomething ( $ parameter ) ; $ obj = $ j ( $ jQueryObject ) ;
jQuery-Intellisense for passed Arguments
JS
How is the blinking caret emulated in Etherpad ? ( See a live version at ietherpad.com ) The way I would do it , is to create a div and position it absolutely where the caret should be . Then , display and remove it in regular intervals . However they seem to do it differently.The text of a row is inI ca n't see anythi...
< div id= '' magicdomid2 '' class= '' '' > ... < /div >
How is the caret emulated in Etherpad ?
JS
I have a pagination component built with Vue 1 , for which I am receiving data from Laravel pagination : For some reason , after I have updated my chrome , pagination stopped working and I am getting undefined for response.data.meta , but on checking the network tab in the console , I am sending the data from the backe...
< template > < div class= '' row '' > < div class= '' col-md-8 '' > < div v-if= '' zeroVideos '' > No videos found for `` { { query } } '' '' < /div > < /div > < div class= '' col-md-8 '' > < single-video v-for= '' video in videos '' : video= '' video '' > < /single-video > < /div > < /div > < div class= '' row justify...
Vue resources - plugin.apply is not a function
JS
I have a npm package that I maintain . Something - perhaps npm itself - is adding entries to package.json . They start with an underscore character : What is adding these entries ? Should I leave these entries on packages I publish to the public npm registry , or delete them ?
`` _args '' : [ [ { `` raw '' : `` some-cool-package @ https : //registry.npmjs.org/some-cool-package/-/some-cool-package-2.2.0.tgz '' , `` scope '' : null , `` escapedName '' : `` some-cool-package '' , `` name '' : `` some-cool-package '' , `` rawSpec '' : `` https : //registry.npmjs.org/some-cool-package/-/some-cool...
What is adding entry lines to my package.json , and why ?
JS
I wrote this code which is supposed to say `` hi '' when I click the `` hello '' button : It does say hi , but only after the for loop is finished . Why does this happen and how do I fix this ? Thanks
< ! DOCTYPE html > < html > < head > < script > var someLargeNumber = 5000000000 ; function hello ( ) { document.getElementById ( 'hi ' ) .innerHTML = `` hi '' ; for ( var i = 0 ; i < someLargeNumber ; i++ ) { } } < /script > < /head > < body > < p id= '' hi '' > < /p > < input type= '' button '' value= '' hello '' onc...
Javascript does not print text immediately
JS
I have a form to change the personal details of the user . In this form I allow the user to change their email and/or password . With jQuery I want to show a 'Current Password ' field when it detects that one of these fields is changed.For the email field this means that when it is changed the password field appears , ...
let requiredSet ; $ ( '.js-show-target-on-change ' ) .on ( 'input ' , function ( ) { const target = $ ( '.js-show-target-on-change__target ' ) ; let currentValue = $ ( this ) .val ( ) ; if ( $ ( this ) .data ( 'type ' ) === 'email ' ) { const emailValue = $ ( this ) .data ( 'value ' ) ; if ( currentValue ! == emailValu...
jQuery to show/hide required password field
JS
One of our page is very heavy . To decrease our watcher count and to accelerate the angular digest cycle we are using a lot the On-Time-Binding syntax : : . We are also using angular-bind-notifier to avoid unnecessary watchs over our expressions on this page . This strategy allowed us to reduce the angular digest cycle...
while ( postDigestQueue.length ) { try { postDigestQueue.shift ( ) ( ) ; } catch ( e ) { $ exceptionHandler ( e ) ; } } for ( var i = 0 ; i < postDigestQueue.length ; i++ ) { try { postDigestQueue [ i ] ( ) ; } catch ( e ) { $ exceptionHandler ( e ) ; } } postDigestQueue.length = 0 ;
AngularJS digest postDigestQueue
JS
Is there an easier way to call filter on a prototype method without an anonymous function ? I wonder if there is an equivalent to myArray.filter ( function ( it ) { it.method ( ) } ) .This looks close to what might work ( it does n't ) : Instead I get a TypeError in both latest Firefox and Chrome , it 's because it doe...
function X ( ) { } X.prototype.method = function ( ) { console.log ( this ) ; } [ new X ( ) , new X ( ) ] .filter ( X.prototype.method.call ) ; x = function ( ) { console.log ( this ) } x.call ( 123 ) //logs 123y = x.call //reports that y is of type function in consoley ( 123 ) //TypeError : Function.prototype.call cal...
JS Array.prototype.filter on prototype method
JS
So I 've been working with making an Android WebView with some text in it be more accessible to blind users and I wondered if it was possible to trigger Android TalkBack to speak some text automatically ? I 'm thinking a link like this : And another element like this : Then using a focus event to auto read the text in ...
< a href= '' # '' id= '' flubble '' > Flubble < /a > < a href= '' # '' id= '' bibble '' > Bibble < /a > document.getElementById ( `` flubble '' ) .addEventListener ( `` click '' , function ( event ) { event.preventDefault ( ) ; document.getElementById ( `` bibble '' ) .focus ( ) ; //I want it to say `` bibble '' here }...
Triggering Android TalkBack Text Programmatically Via A WebView
JS
I 'm having trouble with my Cypress tests for my ( Typescript ) application recognizing types for package I 've installed . Here is my top-level directory structure : My cypress/tsconfig.json file looks like this : In one of my spec files , I have the following imports : The types for faker are defined in DefinitelyTyp...
cypressnode_modulessrc { `` compilerOptions '' : { `` strict '' : true , `` baseUrl '' : `` ../node_modules '' , `` paths '' : { `` ~/* '' : [ `` ../src/* '' ] } , `` jsx '' : `` react '' , `` target '' : `` es6 '' , `` lib '' : [ `` es6 '' , `` dom '' , `` es2017.string '' ] , `` types '' : [ `` cypress '' ] } , `` in...
Cypress tests not recognizing node_modules package types
JS
I got an amazing ripple effect implementation from this website that uses the SVG/Circle element and a jQuery animation function to create the ripple effect on user-click . Although I have a knowledge of basic programming , I know less about JavaScript and jQuery methods/functions so I did read a lot from my research a...
complete : function ( ) { c.removeAttr ( 'style ' ) ; }
Reset jQuery animation when it stops animating
JS
When I 'm using promises to express dependencies between jobs , where the resolved value becomes unimportant , there is some danger that I might be forgetting a return somewhere . Example : Here the Q.all returns a promise , and I should have returned that . Not doing so means that by the time collectOutput gets called...
startSomething ( ) .then ( function ( ) { Q.all ( tasks.map ( function ( task ) { return task.startIt ( ) ; } ) ) } ) .then ( collectOutput ) .done ( ) ;
Avoid forgotten promise returns