lang
stringclasses
4 values
desc
stringlengths
2
8.98k
code
stringlengths
7
36.2k
title
stringlengths
12
162
JS
I am trying to map vertices from the AudioContext api in Three.js.Now , I have successfully done this with planes ( non shader ) but am running into problems trying to apply it to a cylinder . Since the cylinder vertices are full vectors , instead of 0 's for a plane , I do n't know how I would map them to the frequenc...
function audioLink ( ) { player = document.getElementById ( 'musicPlayer ' ) , context = new ( window.AudioContext || window.webkitAudioContext ) , analyser = context.createAnalyser ( ) , source = context.createMediaElementSource ( player ) ; source.connect ( analyser ) ; analyser.connect ( context.destination ) ; anal...
Vertex Displacment with Audio Context ( THREE.JS R76 )
JS
I saw this pattern in the underscore source code and many other open source JavaScript projects : Anyone can explain what this pattern do ? and what is the benefits of using it ? Why not just :
( function ( ) { // the library code } ) .call ( this ) ; ( function ( ) { // the library code } ( ) ) ;
Understanding the structure of underscore.js code
JS
I am using following code to delete a cookie : There are two cookies , one in on domain www.websiteaddress.com and other is on .websiteaddress.com.When I am on page www.websiteaddress.com the cookie having domain address www.websiteaddress.com gets deleted but other one is not deleted . How can I delete both cookies wh...
document.cookie = `` CookieName= ; expires=Thu , 01 Jan 1970 00:00:00 UTC '' ;
Javascript Not deleting all cookies
JS
On this part the user gets to comment on posts . After it gets checked on server side and the data is recieved , I try to change the this.state.comments value . and so it 's done . But the problem is , it is not changing the comment section on component.I have read the previous questions about rerendering so please do ...
$ .post ( `` requests.php '' , { requestKey : 'newComment ' , commenterUser : commenterUser , commenterEmail : commenterEmail , theComment : theComment , pnum : pnum } , function ( data , status , xhr ) { if ( status == 'success ' ) { if ( data == 'commented ' ) { this.setState ( { comments : data } ) } else { } } } ) ...
react component state change after ajax call but does not rerender component
JS
I am writing my project in ES6 , and currently facing an issue with i18next module . https : //www.i18next.com/On my local system , when I import i18next import i18next from 'i18next ' ; and use it in my source files everything works . However after I run npm run gulp ( it combines all source files into one javascript ...
function _interopRequireDefault ( obj ) { return obj & & obj.__esModule ? obj : { default : obj } ; } import gulp from 'gulp ' ; import browserify from 'browserify ' ; import source from 'vinyl-source-stream ' ; import mocha from 'gulp-mocha ' ; const compileFile = 'main.js ' ; gulp.task ( 'dest ' , ( ) = > { browserif...
Google Apps Script error with i18next module
JS
Right now , I 'm trying to create a script that automatically creates links to other pages in a wiki document.The most obvious solution would be to simply replace every match of the string text with [ [ text ] ] , but then I would run into some problems - for example , if I tried to wikify the string `` some problems '...
function createLinks ( startingSymbol , endingSymbol , text , links ) { //this needs to be implemented somehow - replace every match of the list of links with a link } createLinks ( `` [ [ `` , `` ] ] '' , `` This is the text to wikify '' , [ `` wikify '' , `` text '' ] ) ; //this function would return `` This is the [...
Automatically add wikilinks in a MediaWiki page , given a list of page titles
JS
I 'm trying to improve my jQuery performance and I 've noticed it runs faster in Chrome than in other browsers . Does it make sense when it is just an AJAX call to a PHP file ? In order to test it , I am doing this on a click event : Result in seconds are : Chrome 25 : 0.148Firefox 19.0.2 : 0.212Internet Explorer 9 : 0...
var startTime = new Date ( ) ; $ .post ( `` http : // '' + document.domain + `` action.json '' , { data : data } , function ( dat ) { console.log ( 'ending : ' , ( new Date ( ) - startTime ) / 1000 ) ; } } ) ;
$ .post jQuery faster or slower depending on the browser ?
JS
This is a follow up from this answer.I have some 3rd party code ( react components ) that I bundle as ES modules ( using the pkg.module entry point ) . This works great ( you get module concatenation and tree shaking ) , but the included code is n't transpiled with babel because , following most config examples , I exc...
{ ... module : { rules : [ { exclude : / ( node_modules ) / , use : { loader : 'babel-loader ' , ... } } ] } , ... } { ... module : { rules : [ { include : [ /node_modules\/ @ my-scope/ , /src/ ] , use : { loader : 'babel-loader ' , ... } } ] } , ... }
How to optionally process code in node_modules with babel-loader in webpack ?
JS
I am making a nested menu and submenus and everything has been done as of now.. I am now in the need to make this collapsible menu to get opened by default based on the id given..You could also take a look at the complete working code snippet below , Requirement : I am having an id value stored in const openMenuId = ``...
const loadMenu = ( ) = > Promise.resolve ( [ { id : '' 1 '' , name : '' One '' , children : [ { id : '' 1.1 '' , name : '' One - one '' , children : [ { id : '' 1.1.1 '' , name : '' One - one - one '' } , { id : '' 1.1.2 '' , name : '' One - one - two '' } , { id : '' 1.1.3 '' , name : '' One - one - three '' } ] } ] }...
Open the collapsible menu by default based on the id
JS
I tried Dart SDK after the 1.0 release , and wrote a simple hello-world program in Dart.Then , with the SDK tool , I generated the JavaScript file : helloworld.dart.jsI went through the output js code , I saw there is a function named convertToFastObject.The definition is : The usage code is like : I know this code is ...
function convertToFastObject ( properties ) { function MyClass ( ) { } ; MyClass.prototype = properties ; new MyClass ( ) ; return properties ; } A = convertToFastObject ( A ) ; B = convertToFastObject ( B ) ;
Why the convertToFastObject function make it fast ?
JS
Why do nested parentheses cause empty strings in this regex ? what I want to achieve is this
var str = `` ab ( ( cd ) ) ef '' ; var arr = str.split ( / ( [ \ ) \ ( ] ) / ) ; console.log ( arr ) ; // [ `` ab '' , `` ( `` , `` '' , `` ( `` , `` cd '' , `` ) '' , `` '' , `` ) '' , `` ef '' ] [ `` ab '' , `` ( `` , `` ( `` , `` cd '' , `` ) '' , `` ) '' , `` ef '' ]
why do nested parentheses cause empty strings in this regex ?
JS
This should be real easy . Given below is the HTML.I want to get just the # Attachment # and not the other text . When I tried it gives out all # Attachment # , # AttachmentName # as well as # AttachmentPath # . I know I could just put # Attachment # into another span and access it directly but I was just intrigued on ...
< div id='attachmentContainer ' > # Attachment # < span id='spnAttachmentName ' class='hidden ' > # AttachmentName # < /span > < span id='spnAttachmentPath ' class='hidden ' > # AttachmentPath # < /span > < /div > $ ( `` # attachmentContainer '' ) .text ( )
How to get the text of a div which is not a part of any other container in JQuery ?
JS
I have an html file and it accepts few query stringsHtml file also contains css and script included using script tagie we can call this html file as belowexternal.html ? param='something ' i have to use this html in a react component and return as JSX.currently i have done returning as an Iframe as belowbut how can i d...
const Component = ( ) = > { const iframeUrl = ` external.html ? param='something ' ` ; return ( < iframe { ... props } src= { iframeUrl } / > ) }
Add an external html file with query strings in reactjs
JS
The documentation says : showThis event is emitted when the panel is shown.So in main.js I did this ( where thePanel is using the require ( `` panel '' ) .Panel method ) : But the event does n't seem to be called . I 've also tried doing a function in the content script for window.onfocus but that does n't appear to be...
thePanel.port.on ( `` show '' , function ( d ) { console.log ( 'The panel has just been shown ' ) ; } ) ;
How do you detect when an Add-on SDK panel has been shown ?
JS
In JavaScript/Typescript , What is the short version to destructure and then assign in a new object like so :
const payload : MyPayload = { a : 1 , b : 2 , c : 3 , d : 4 , e : 5 } // Destructconst { a , c , e } = payload ; // New Objconst newPayload = { a , c , e } ;
JavaScript Destructure and assign to new object
JS
I am trying to integrate Google Pay into our online store using the Google Pay API , and in the tutorial , there is this snippet which set the amount to pay , and currency code in a JavaScript object like this : This looks awfully insecure , in that anyone can tamper with the values on the client-side before eventually...
paymentDataRequest.transactionInfo = { totalPriceStatus : 'FINAL ' , totalPrice : '123.45 ' , currencyCode : 'USD ' } ;
Prevent client-side tampering when using Google Pay JavaScript API
JS
This is the function I wrote to retrieve all the values in an given object.Is there any builtin way to retrieve all the values in an object ? Something like this exists in java for HashMaps . I know JS has a method for retrieving all the keys by doing Object.keys ( obj ) .
function getValues ( data ) { var keys = Object.keys ( data ) ; var values = [ ] ; for ( var i = 0 , l = keys.length , key ; i < l ; i++ ) { key = keys [ i ] ; values.push ( data [ key ] ) ; } return values ; }
Retrieving all values from a JavaScript object
JS
DescriptionFor the purpose of a unit test , I would like to check if a particular function has been bound.ExampleQuestionIs there someway to check that bar has been bound that does n't require mocking the bind function ? NotesWhile How to get [ [ boundthis ] ] from function is asking about getting the [ [ boundthis ] ]...
function foo ( ) { } var bar = foo.bind ( context ) ; assertBound ( bar ) ; // -- > trueassertBound ( foo ) ; // -- > false
Assert that a function has been bound early
JS
I 'm making a web scraper , most of the data on the web page is in JavaScript object literal form , e.g . : So when I search for the contents in my JavaScript app the Object above would be : Is it possible to parse those to regular JavaScript Objects without using 'eval ' or making my own parser ? I saw other similar q...
// Silly examplevar user = { name : 'John ' , surname : 'Doe ' , age : 21 , family : [ { name : 'Jane ' , surname : 'Doe ' , age : 37 } , // ... ] } ; `` { name : 'John ' , surname : 'Doe ' , age : 21 , family : [ { name : 'Jane ' , surname : 'Doe ' , age : 37 } ] } '' const literal = script.innerText.slice ( script.in...
Converting JavaScript object literal to JavaScript object WITHOUT 'eval '
JS
any simply way ? this is my code : and it print [ 1,2,3,4 ] thanks
var a= [ 1,2,3,4 ] a.slice ( 0,1 ) alert ( a )
how to change the array [ 1,2,3,4 ] to [ 1,3,4 ]
JS
I 've searched so much but I ca n't figure it out how to configure my bars.I plan to put 3 loading bars that execute automatically according time : My Code is this ( be aware that I do n't know how to change this values , I tried but do n't work properly ... This is the help I need , the frame stuff ) Thank you all
1st will start from 30 to 60 seconds2nd from 300 to 1800 seconds3rd from 1801 to 1860 seconds var my1Bar = setTimeout ( start1Bar , 30000 ) ; var my2Bar = setTimeout ( start2Bar , 300000 ) ; var my3Bar = setTimeout ( start3Bar , 1800000 ) ; function start1Bar ( ) { var elem = document.getElementById ( `` my1Bar '' ) ; ...
Javascript Loading Bars according time
JS
I 'm trying to use refs in order to take data from my laravel blade , in each row of a foreach loop , and pre-check checkboxes is the values match a checkbox . In this example , if a row in the loop has $ result- > site of intra and $ result- > category of catalog , I would want the intra and catalog checkboxes on that...
@ foreach ( $ getResults as $ k = > $ result ) // $ result- > site and $ result- > category hold the value I need to match in order to pre-select a checkbox < div slot= '' site '' > < input category= '' checkbox '' id='direct ' value='direct ' ref= '' existingsiteNames '' data-md-icheck / > < label > Direct < /label > ...
Using refs in laravel blade to pre-check checkboxes
JS
My node project currently contains a sideway christmas tree of nested callbacks in order to fetch data and process them in the right order . Now I 'm trying refactor that using Promises , but I 'm unsure how to do it properly.Let 's say I 'm fetching a list of offices , then for each office all their employees and then...
fetch ( officesEndpoint , function ( data , response ) { parse ( data , function ( err , offices ) { offices.forEach ( function ( office ) { save ( office ) ; fetch ( employeesEndPoint , function ( data , response ) { parse ( data , function ( err , employees ) { // link each employee to office save ( office ) ; save (...
How to properly chain Promises with nesting
JS
Much ink has been spilled on the subject of testing two objects for deep equality in JavaScript . None , however , seem to care about distinguishing the following two objects : Most deep equality algorithms would say that o1 , o2 and o3 are equal . I want an algorithm that says that o1 and o2 are not equal , but o1 and...
var o1 = [ { } , { } ] ; var subitem = { } ; var o2 = [ subitem , subitem ] ; var o3 = [ { } , { } ] ; var o1 = [ ] ; o1.push ( o1 ) ; var o2 = [ ] ; o2.push ( o2 ) ; // deepGraphEqual ( o1 , o2 ) == truevar o3 = [ [ ] ] ; o3 [ 0 ] .push ( o3 ) ; // deepGraphEqual ( o1 , o3 ) == false
Test deep equality *with sharing* of JavaScript objects
JS
Resetting outerHTML property of document.body has a strange side effect : it adds extra empty < head > < /head > into the DOM , just before body : All browsers seem to be consistent in this . I 've been told it is specified to be this way , but was not able to dig up authoritative standards stance about this , not even...
head { display : inline ; counter-increment : h ; border : 1px solid ; } head : last-of-type : :after { content : 'Head elements count : ' counter ( h ) ; } [ onclick ] : :after { content : attr ( onclick ) ; } < button onclick= '' document.body.outerHTML=document.body.outerHTML '' > < /button >
Setting document.body.outerHTML creates empty heads . Why ?
JS
I have looked through all the other ( excellent ) answers on SO ( especially this : How do JavaScript closures work ? ) but I wanted your feedback on my understanding of the concept.I understand that one use case is to hide the implementation of private methods from public access.The other one that I think of is having...
< script > function carFactory ( make ) { var m = make ; return { manufacture : function ( model ) { console.log ( `` A `` + m + `` `` + model + `` has been created '' ) ; } } } toyotaFactory = carFactory ( `` toyota '' ) ; hondaFactory = carFactory ( `` honda '' ) ; toyotaFactory.manufacture ( `` corolla '' ) ; toyota...
Is this a valid use case for javascript closure ?
JS
I have the following string : I want to replace all the [ with `` . I tried the following but it did n't work : what am I doing wrong here ? Many thanks in advance .
[ 27564 ] [ 85938 ] [ 457438 ] [ 273 ] [ 48232 ] var str = ' [ 27564 ] [ 85938 ] [ 457438 ] [ 273 ] [ 48232 ] ' var nChar = ' [ ' ; var re = new RegExp ( nChar , ' g ' ) var visList = str.replace ( re , '' ) ;
Global Replace with js
JS
I have a DataTable that I am trying to load the data via and ajax call but the first line of data always says : `` No data available in table '' But under it the loaded ajax data is included . How do I remove the No data line and have the ajax data load into that spot ? Code Below : Implementation of DataTable : Javasc...
< div class= '' box-body '' > < table id= '' changeTicketsTable '' class= '' table table-bordered table-striped '' > < thead > < tr > < th > Ticket Number < /th > < th > Description < /th > < th > Risk < /th > < th > Primary CI < /th > < th > State < /th > < th > Planned Start Date < /th > < th > Actual Start Date < /t...
Unable to Update Body of DataTable using an Ajax call
JS
I find the code below , but I ca n't understand this.What does if ( ! - [ 1 , ] ) mean ? Thanks
if ( ! - [ 1 , ] & & ! window.XMLHttpRequest ) { document.execCommand ( `` BackgroundImageCache '' , false , true ) ; }
what does `` - [ 1 , ] '' mean in `` if ( ! - [ 1 , ] & & ! window.XMLHttpRequest ) '' ?
JS
I wanted to create a function which take a string of any numbers and characters as a one parameter . the task is to find all the even numbers ( digits ) and sum them up then display the total value in console.for example , if the following string is passed to this function as a one parameter ( `` 112 , sf34,4 ) -k ) ''...
function functionFive ( str ) { const string = [ ... str ] .map ( char = > { const numberString = char.match ( /^\d+ $ / ) if ( numberString ! == null ) { const number = parseInt ( numberString ) return number } const num = string.map ( number= > { if ( number ! == undefined & & number % 2 === 0 ) { console.log ( numbe...
function for the sum of all even numbers
JS
So , I 'm using d3 and d3-hexbin as global libraries : ... and referencing them in .ts as : ... using DefinitelyTyped definitions . However , although this works : ... this : ... fails with a : Thoughts ?
< script src= '' https : //d3js.org/d3.v4.min.js '' > < /script > < script src= '' https : //d3js.org/d3-hexbin.v0.2.min.js '' > < /script > /// < reference types= '' d3 '' / > /// < reference types= '' d3-hexbin '' / > const svg = d3.select ( ' # hitmap ' ) .append ( 'svg ' ) const hexbin = d3.hexbin ( ) .radius ( bin...
'd3 and 'd3-hexbin ' in typescript as global libraries
JS
Consider Sec . 11.2 of ECMA-262.The PrimaryExpression is the followingThe first question is : What ( Expression ) does mean in the PrimaryExpression defenition ? The { prop : 'prop ' } is ObjectLiteral . Thus { prop : 'prop ' } ( ) is CallExpression . I 'm trying to check this with JSFIDDLE but I have The second questi...
SyntaxMemberExpression : PrimaryExpression FunctionExpression MemberExpression [ Expression ] MemberExpression . IdentifierName new MemberExpression ArgumentsNewExpression : MemberExpression new NewExpressionCallExpression : MemberExpression Arguments CallExpression Arguments CallExpression [ Expression ] CallExpressio...
Understanding terminology and notation JavaScript
JS
In my Angular service i have the following methods : In my template i 'm showing the items in a list.I would like to be able to create a new item and then re-load the list ( to include the newly created item ) , so i 've implemented the following : This seemingly works fine , but in the end i would like to do some proc...
// creates an Item and returns the ID of the created ItemcreateItem ( item : Item ) : Observable < ItemId > { return this.http.post < ItemId > ( 'some_api_url ' , item ) ; } // returns all ItemsgetAllItems ( ) : Observable < Item [ ] > { return this.http.get < Item [ ] > ( 'some_api_url ' ) ; } this.itemService.createI...
Passing down values from multiple Observables
JS
I want to use a single mutation for the application to send user info to server and then get the top level query in the output . ( I know this is not a good convention but I want to do this to test if I can improve performance ) .So as a result , there will only be one mutation that takes user 's info and returns the f...
const UserType = new GraphQLObjectType ( { name : 'User ' , fields : ( ) = > ( { someData : { type : GraphQLList ( Post ) , resolve : ( user , args , context ) = > getFeed ( context ) // context in here is the old context . } , } ) } ) const someMutation = mutationWithClientMutationId ( { name : 'someMutation ' , input...
Update graphql context in a mutation for the output object of the same mutation
JS
I am looking for a pattern to get the totals for each n-th item of arrays . Conceptually this would be like getting column totals of a data table.I had some equivalent Python code on the server side , but decided it should be handled client side , thus in javascript . Here is the equivalent Python code : How would you ...
var dataRows = [ [ 10 , 11 , 12 , 13 ] , [ 20 , 21 , 22 , 23 ] , [ 30 , 31 , 32 , 33 ] ] // The outcome should be : // [ 60 , 63 , 66 , 69 ] [ sum ( i ) for i in zip ( *data_rows ) ]
Pattern for `` column total '' of an array of arrays
JS
New to lodash and playing around with it to gain more understanding . I do n't understand the behavior of the following code.After learning about the arity argument to _.curry , I have a code snippet that produces results that seems strange to me . I do n't understand the output of the last console.log . Looks to me li...
const words = [ 'jim ' , 'john ' ] ; const pad10 = words = > _.map ( words , word = > _.pad ( word , 10 ) ) ; console.log ( pad10 ( words ) ) ; // [ ' jim ' , ' john ' ] const flipMap = _.flip ( _.map ) ; const flipPad = _.flip ( _.pad ) ; const curriedFlipMap = _.curry ( flipMap , 2 ) ; const pad10v2 = curriedFlipMap ...
When is a = > f ( a ) not equivalent to f ?
JS
When I call context.drawImage in Chrome 81+ it will auto-rotate the image . I want to disable this . I can disable it in an img tag using image-orientation : none , but that does n't work on a canvas.It seems to ignore the image-orientation style . In this example below , img tag does not get auto-rotated ( as expected...
< html > < head > < script > window.onload = function ( ) { var c = document.getElementById ( `` myCanvas '' ) ; var ctx = c.getContext ( `` 2d '' ) ; var img = document.getElementById ( `` imgtest '' ) ; // This style is ignored img.style.imageOrientation = 'none ' ; ctx.drawImage ( img , 0 , 0 ) ; } ; < /script > < /...
How to ignore Image exif data on a Canvas in Chrome 81+
JS
I am trying to open 2 angular app pages in sequence to get their screenshots using phantomjs . Page 1 needs to open before page 2 as it prepares some data for page 2 . I am using two nested setTimeout ( ) functions in the following way : The first console statement : console.log ( 'page 1 status : ' , status ) ; gets p...
var page = require ( 'webpage ' ) .create ( ) , t , url ; phantom.addCookie ( { 'name ' : 'token ' , 'value ' : ' < authentication-token-goes-here > ' , 'domain ' : 'localhost ' } ) ; t = Date.now ( ) ; url = `` http : //localhost:8000/ # /page1 '' ; page.onConsoleMessage = function ( msg , lineNum , sourceId ) { conso...
opening angular app pages in sequence - second page.open callback does n't get called
JS
My requirement is to make a css3d rendering plane to be act as a floor . And a 3d cube should be on top of the plane . Following I have attached the code which I tried.Both plane and the cube shares the same scene and camera.But renders are different . But I could n't place the 3d cube on top of the plane and rotation ...
< ! DOCTYPE html > < html lang= '' en '' > < head > < title > 3JS CODE < /title > < meta charset= '' utf-8 '' > < meta name= '' viewport '' content= '' width=device-width , user-scalable=no , minimum-scale=1.0 , maximum-scale=1.0 '' > < style > body { font-family : Monospace ; background-color : # f0f0f0 ; margin : 0px...
Make css3d rendering plane to be act as a floor in 3JS ?
JS
I have an app that via Dropbox Javascript SDK trying to download the file . I do n't have any idea what is wrong . Accessing Dropbox API via fetch calls directly bringing the same error.Dropbox API documentation saying that error 400 is for bad input parameters while it looks like what I 'm sending is ok - `` Dropbox-A...
const Dropbox = require ( `` dropbox '' ) .Dropbox ; import axios from `` axios '' ; import fs = require ( `` fs '' ) ; import { logger } from `` ./logger '' ; export class FileHandler { public async handle ( path : string , token : string ) : Promise < void > { try { const dbx = new Dropbox ( { fetch : axios , accessT...
Error 400 when trying to access Dropbox API via Dropbox Javascript SDK
JS
I 'm working with an ecommerce platform that lacks the ability to reorder the options of our product attribute fields . It really sucks because to insert a new option you pretty much have to delete all of the existing ones and start over . I 'm trying to do it client-side instead . Here 's what I 'm working with ( this...
< select > < option > 9 EE < /option > < option > 9 1/2 EE < /option > < option > 10 EE < /option > < option > 10 1/2 EE < /option > < option > 11 EE < /option > < option > 11 1/2 EE < /option > < option > 9 EEEE < /option > < option > 9 1/2 D < /option > < option > 9 1/2 EEEE < /option > < option > 10 EEEE < /option >...
Understanding sort ( ) compareFunction
JS
This is a bit of a conundrum , I have an idea of how I might be able to fix it but I 'm wondering if there 's a ( much ) easier way.In short , whenever a regular expression is executed in JavaScript , certain properties are assigned values on the RegExp constructor . For instance : I 'd like to execute a regular expres...
/foo/.test ( 'football ' ) //- > trueRegExp.input//- > `` football '' RegExp.rightContext//- > `` tball ''
Prevent tainting properties of the RegExp constructor in JavaScript
JS
In jQuery you can chain actions for the same selector very easily but if you want to use different selector for each action it requires nested $ .when with more then two actions which is quite hard to read and maintain.HTML : CSS : JS : based on this : how to hide multiple items but only call the handler once ? jsfiddl...
< span id= ' a ' > Hello < /span > < span id= ' b ' > world < /span > < span id= ' c ' > ! ! ! < /span > span { display : none ; } var d = 500 ; // duration// Execute in parallel.// $ ( ' # a ' ) .show ( d ) .hide ( d ) ; // $ ( ' # b ' ) .show ( d ) .hide ( d ) ; // $ ( ' # c ' ) .show ( d ) .hide ( d ) ; $ .when ( $ ...
Is there an easier way of chaining different jQuery actions for different selectors then nested $ .when ?
JS
Alright so here 's the deal . i 'm using strapdown to render markdown posts . strapdown uses marked to parse these markdown posts , which in turn uses regular expression literals.I 've tried to extend marked to include the following markdown `` extensions '' as described here ( shoutout to soffes ) .Background Infolite...
var src = `` two new features to the marked.js inline lexer . ==highlighted text== , and _underlined text_ '' ; var underline = /_ ( .* ? ) _/ ; var cap = underline.exec ( src ) ; document.write ( `` < em class='underline ' > '' +cap [ 1 ] + '' < /em > '' ) ; var src = `` two new features to the marked.js inline lexer ...
regex.exec ( ) - failing to match string
JS
I 'm building a photography portfolio . Some of my images have nudity , so I want to hide those by default until the user clicks a `` Toggle Worksafe Mode '' button.I can do it with a standard form post ( and sessions ) , but that causes `` confirm form resubmission '' errors when the user backs or reloads . I 'm tryin...
< ? php session_start ( ) ; if ( ! isset ( $ _SESSION [ 'Worksafe_Mode ' ] { $ _SESSION [ 'Worksafe_Mode ' ] = 1 ; } ? > < ! -- other page content -- > < script src= '' scripts/jquery-3.2.1.min.js '' > < /script > < ! -- other page content -- > < button type= '' button '' id= '' Worksafe_Button '' name= '' Worksafe_But...
Ajax & Session Variables ? Worksafe Filter ( selective image hiding )
JS
Regex Dialect : JavaScriptI have the following capture group ( ( '| '' ) .* ? [ ^\\\2 ] \2 ) that selects a quoted string excluding escaped quotes.Matches these for example ... However I would now like to remove all whitespace from a string except anything matching this pattern . Is there perhaps a way to back referenc...
`` Felix 's pet '' 'Felix\ 's pet '
Remove all whitespace EXCEPT what is contained in the capture group
JS
See this plunker code ( Notice console.log messages ) to understand what I am trying to say/ask.I have defined 3 modules , namely , myApp , myApp.view1 , myApp.view2 . Only myApp module has dependency declared on the other 2.myApp Module myApp.view1 ModulemyApp.view2 ModuleMy Doubts / Questions : Why can `` myApp.view1...
angular.module ( 'myApp ' , [ 'ngRoute ' , 'myApp.view1 ' , 'myApp.view2 ' ] ) .config ( [ ' $ routeProvider ' , function ( $ routeProvider ) { $ routeProvider.otherwise ( { redirectTo : '/view1 ' } ) ; } ] ) .value ( 'author ' , 'Suman Barick ' ) angular.module ( 'myApp.view1 ' , [ 'ngRoute ' ] ) .config ( [ ' $ route...
What is the point of declaring angular module dependency if one module can access the values and services from another module anyway
JS
I am making a project with three.js where the user can dynamically change the dimensions of the model . The question is very similar to this one that I posted , but I am afraid it is not working since this time I am working with an extrusion of a planar shape . The snippet of the code where I am having problems is the ...
cubeY.onChange ( function ( value ) { cube.scale.y = value ; cube.position.y = ( cubeHeight * value ) / 2 ; roof.position.y = ( roofHeight * roof.scale.y ) / 2 + cube.position.y * 2 - roofHeight ; } ) ; ; roofY.onChange ( function ( value ) { roof.scale.y = value ; roof.position.y = ( ( roofHeight * value ) + cube.posi...
Dynamically scale object stacked over another one
JS
I 'm working on an app in which I 'm able to run my own Javascript inside browser context after opening a 3rd party website . As a sample website which is build on reactjs and has a login form , you can refer to this link.I 'm trying to fill the username and password in the form which is generated by reactjs . However ...
function setNativeValue ( element , value ) { element.focus ( ) ; element.click ( ) ; element.value = value ; element.defaultValue = value ; let tracker = element._valueTracker ; if ( tracker ) { tracker.setValue ( lastValue ) ; } let inputEvent = new Event ( `` input '' , { target : element , bubbles : true } ) ; inpu...
Populating ReactJS HTML Form via Javascript
JS
We have an AngularJS application running locally on a machine ( all assets are on the hard drive ) and we have a seemingly difficult to solve screen flicker when we switch pages.Here 's what happens , our issue is on # 3:1 ) User start on main page ( http : //localhost:9000/ # / ) 2 ) User clicks on button to go to nex...
body { background-image : url ( `` /assets/page2_background.png '' ) ; background-size : 100 % ; } < img src= '' assets/page2_background.png '' style= '' display : none '' > .config ( function ( $ routeProvider ) { $ routeProvider .when ( '/page2 ' , { templateUrl : 'views/page2.html ' , controller : 'Page2Ctrl ' , con...
White Screen Flicker When Switching Pages
JS
On a regular click of the child div , the following code will print the ID of that specific child div that was clicked.However , if you click on one child div and drag/release in the other child div then it will print the ID of the parent element.This does not occur when the click handler is assigned to the children.Wh...
< div id= '' parent '' > < div id= '' A '' class= '' child '' > < /div > < div id= '' B '' class= '' child '' > < /div > < /div > < script > $ ( `` # parent '' ) .on ( 'click ' , event = > { $ ( event.target ) .text ( event.target.id ) } ) < /script > $ ( `` .child '' ) .on ( 'click ' , event = > { $ ( event.target ) ....
Why does clicking and dragging cause the parent element to be the ` event.target ` ?
JS
I ca n't get my component to show my autosuggestions.It is observed in the console that my data is available and I sent it to this component using the suggestions prop , using Material UI AutoComplete component feature here I am trying to set my options , and these are changing as I type as it 's handled in a parent co...
import React , { FunctionComponent , FormEvent , ChangeEvent } from `` react '' ; import { Grid , TextField , Typography } from `` @ material-ui/core '' ; import { CreateProjectModel , JobModel } from `` ~/Models/Projects '' ; import ErrorModel from `` ~/Models/ErrorModel '' ; import Autocomplete from `` @ material-ui/...
MaterialUI Compoent does not AutoComplete when data is available
JS
I have some jQuery codes , which is repeated again and again , i would like to reduce the code i am writing that is by converting it into functions . here is the codes i am using.I would like to know few things , a ) With reference to above code , how do i convert it to function , as the code have very few changes like...
$ ( 'form # save-user button [ name= '' save-user '' ] ' ) .click ( function ( ) { var formData = 'option=saveuser & '+ $ ( 'form # save-user ' ) .serialize ( ) ; $ .ajax ( { type : 'POST ' , url : 'process.php ' , data : formData , success : function ( msg ) { if ( msg === 'empty ' ) { alert ( 'Required Values Missing...
How do i convert this jQuery code into jQuery function ?
JS
I have a table , I ’ m trying to make it responsive.When I resize from right to left , it shrinks perfectlyWhile at the small window , I hit refresh and try to resize it back outThis is what I did for CSS for nowNote : I 've tried this on all browser types : Chrome , Firefox , Safari , same result.Try # 2When I expand ...
@ media only screen and ( max-width : 1555px ) { td : nth-child ( 9 ) , th : nth-child ( 9 ) { display : none ; } td : nth-child ( 8 ) , th : nth-child ( 8 ) { display : none ; } td : nth-child ( 7 ) , th : nth-child ( 7 ) { display : none ; } } @ media only screen and ( max-width : 1080px ) { td : nth-child ( 6 ) , th...
How can I make table responsive while window resizing ?
JS
I was reading Secrets of the JavaScript Ninja and I saw this code which produces a function overload : As far as I understand , the addMethod always keeps the old value of the function ( via closure ) .So finally , there is one function which checks a condition , and if it fails , it invokes the old function which in t...
function addMethod ( object , name , fn ) { var old = object [ name ] ; object [ name ] = function ( ) { if ( fn.length == arguments.length ) return fn.apply ( this , arguments ) else if ( typeof old == 'function ' ) return old.apply ( this , arguments ) ; } ; } function Ninjas ( ) { var ninjas = [ `` Dean Edwards '' ,...
JavaScript and function overload clarification
JS
I got to this document which says there is a closure happening here : While this code removes the closure : I ca n't see how the second one solves the closure issue . Why would not the code at el.onclick = clickHandler create a closure ? clickHandler 's this has to be fulfilled with el .
function addHandler ( ) { document.getElementById ( 'el ' ) .onclick = function ( ) { this.style.backgroundColor = 'red ' ; } ; } function addHandler ( ) { var clickHandler = function ( ) { this.style.backgroundColor = 'red ' ; } ; ( function ( ) { var el = document.getElementById ( 'el ' ) ; el.onclick = clickHandler ...
How does 'this '' work in closure ?
JS
I have two variables : tempTimeRequeststimeLastUpdateRequestsBoth are given in milliseconds since epoch.I 'm facing a bizarre behaviour from js : the result I get forisHow come I have the same value of seconds if clearly have 51 seconds for the second ( which gives the right result ) but 65 ( which would give 05 second...
alert ( tempTimeRequests+ '' \n '' + timeLastUpdateRequests+ '' \n '' + Date ( tempTimeRequests ) + '' \n '' + Date ( timeLastUpdateRequests ) ) 13690636650001369063651000Mon May 20 2013 17:27:51 GMT+0200 ( CEST ) Mon May 20 2013 17:27:51 GMT+0200 ( CEST )
Conversion from milliseconds to Unix Timestamp from different times gives same result
JS
I defined a function in JavaScript that replace all - , _ , @ , # , $ and \ ( they are possible separators ) with / ( valid separator ) .My goal is any string like `` 1394_ib_01 # 13568 '' convert to `` 1394/ib/01/13568 '' My problem is when a string with \ character send to function result is not valid.I tried use Uni...
function replaceCharacters ( input ) { pattern_string = `` -|_| @ | # | $ |\u005C '' ; // using character Unicode //pattern_string = `` -|_| @ | # | $ |\ '' ; // using original character //pattern_string = `` -|_| @ | # | $ |\\ '' ; // using `` \\ '' //pattern_string = `` \|-|_| @ | # | $ '' ; // reposition in middle o...
JavaScript - What is correct way for replace `` \ '' charcter with `` / '' in RegExp
JS
I am not able to scroll all the way until end . Following code stop working near the end of page.I have used following methods to scroll programmatically , Info : Some width related info for my case , Note : I have used webkitColumnGap css and turned vertical page into horizontal . That 's why I have bigger scrollWidth...
// 1 still see scrolling leftwindow.scrollTo ( x , y ) > window.scrollTo ( window.scrollWidth,0 ) window.scrollBy ( x , y ) > // 2scrollingElement.scrollLeft = scrollingElement.scrollWidth - document.documentElement.clientWidth ; window.scrollWidth > 6180scrollingElement.scrollWidth > 6183document.documentElement.clien...
Coud n't scroll to end of the page using window.scrollTo
JS
How can I subtract text with jQuery ? I tried to use minus to delete the text , but it does n't work.In this line , the value outputted is `` 300px '' , and I want to remove `` px '' to get just the number 300 .
var coluna = $ ( '.coluna ' ) .css ( 'width ' ) ;
How to subtract text with jQuery
JS
Using ngGrid v2.X , I 'm trying to devolop a grid that loads more data when page scroll ( not grid scroll ) goes bottom.By searching for similar questions i 've found a solution to my 1st problem : ngGrid must have dynamic height , so i 've did this Which takes me to my 2nd problem . I need data be loading by scroll , ...
.ngViewport { height : auto ! important ; } .ngCanvas , .ngViewport , .ngRow , .ngFooterPanel , .ngTopPanel { width : 100 % ! important ; } .ngRow { border-bottom : none ! important ; } $ scope. $ on ( 'ngGridEventScroll ' , function ( ) { $ scope.currentDataPosition++ ; $ scope.setPagingData ( $ scope.dataArray , $ sc...
How to use page scroll on ngGridEventScroll ?
JS
I initialize a property within the Controller 's Constructor.I have an Action Method which reset the property again on a button click event.Following javascript code is in my view which is called when the button is clicked.My problem is when I click the button , value of property changes in the Controller . But it does...
public BookController ( ) { SessionProvider.SessionLoadSceanrio = false ; } public ActionResult LoadScenario ( int bookId ) { SessionProvider.SessionLoadSceanrio = true ; // remaining code return Json ( ScenarioId , JsonRequestBehavior.AllowGet ) ; } var BookHandler = { $ ( `` # btnLoadScen '' ) .click ( function ( e )...
C # property value does n't get modified within Javascript/ jquery
JS
I have set up a JSFiddle and I am trying to show and hide some text.When you click on any of the `` staff '' elements and after the animation I have finishes , the text I have within each of the classes shows . When the user then clicks the `` staff '' element again , the text hides/fadesout.My work in progress is here...
< div class= '' slide '' style= '' height:568px ; '' > < div class= '' staff staff-matt '' data-hammer= '' [ object Object ] '' > < div id= '' text1 '' > < h1 > Lorem Ipsum < h1 > < p > lorem ipsum dolar < p > < /div > < /div > < div class= '' staff staff-shail '' data-hammer= '' [ object Object ] '' > < div id= '' tex...
show element when clicked and hide again when not active
JS
What is going on here ? This actually creates an array : Where is the documentation for this structure syntax ? It 's also smart : changing to : ( notice 0 , 1 , 3 ) will mess up the array and it will be : Also , removing the splice function : yields : ( regular object ) So I have two questions : What is this structure...
var x = { length:3 , ' 0 ' : 'foo ' , ' 1 ' : 'bar ' , ' 2 ' : ' f ' , splice : function ( ) { } } [ `` foo '' , `` bar '' , `` f '' ] var x = { length:3 , ' 0 ' : 'foo ' , ' 1 ' : 'bar ' , ' 3 ' : ' f ' , splice : function ( ) { } } [ `` foo '' , `` bar '' , undefined × 1 ] var x = { length:3 , ' 0 ' : 'foo ' , ' 1 ' ...
Creating array by Object ( and vice versa ) in JavaScript ?
JS
I have a HTML table in side which i have several td as input field , my table is dynamic , when page loads i am appending the 1st row of my table and focus on first input field , in my case i.e Item NameI have 3 input fields in my row which are Item Name , Unit Qty and Disc % When user clicks inside ItemName input fiel...
function rowappend ( ) // this one is appending row { var markup = ' < tr > < td > < input type= '' text '' class= '' form-control commantd '' name= '' itemNametd '' id= '' itemNametd '' > ' + ' < /td > < td id= '' itemCodetd '' class= '' commantd '' > < /td > ' + ' < td > < input type= '' text '' class= '' form-contro...
Appended new row is not behaving like previous one ( row )
JS
I want to create empty array with fixed length , and then use .map on it to return new array . However , it 's not working as expected.According to mdn docs : If the only argument passed to the Array constructor is an integer between 0 and 232-1 ( inclusive ) , this returns a new JavaScript array with length set to tha...
var a = new Array ( 3 ) ; a.map ( ( x , i ) = > i ) ; // [ undefined × 3 ] var a = Array.apply ( null , new Array ( 3 ) ) ; a.map ( ( x , i ) = > i ) ; // [ 0 , 1 , 2 ]
Array constructor not working as expected
JS
I 'm trying to see argument passed to a built in JavaScript function alert ( ) using following code . Once I get the argument passed to it , now I want to call the real ( built-in ) function , so that the code does n't break.This code somehow goes to infinite recursion .
built_in_alert = alert ; function alert ( text ) // Our custom alert function . { console.log ( 'Alert function called with param : '+ text ) ; built_in_alert ( `` Calling with `` +text ) // try to call the actual built in alert ( ) function.return 0 ; } alert ( `` hi '' ) ;
Is it possible to detour Built-In JavaScript Function
JS
I have a div with background 30 % resized and a img sized 100 % I would like detect onclick only on the background resized div ( purple in the picture below ) , not on all element What is the best way ? Thank you in advance.UPDATEThis is what i would like do !
< div class= '' div1 '' style= '' width:600px ; background : url ( img/litlePict.png ) no-repeat scroll center center / 30 % auto '' > < img class= '' store '' src= '' img/mypict.png '' width= '' 100 % '' / > < /div >
Detect click on div background 30 % resized
JS
I 'm programming a firefox addon and using a panel to display info on a video , everything works fine althought I ca n't make the panel transparent . I define the panel styling in the html file as follow : Except the panel is not transparent only the text area is . I tried with : opacity:1 for textareaIt does n't work ...
< html > < head > < meta charset= '' utf-8 '' / > < style type= '' text/css '' media= '' all '' > html { opacity:0.1 ; border-style : none ; resize : none ; } textarea { background-color : transparent ; resize : none ; border-style : none ; } < /style > < /head > < body > < textarea id= '' text '' readonly=true rows= '...
Panel tranparency firefox addon
JS
I have a stack of divs : I need to style the first of each class , and do n't have control over the html ... preferably pure CSS , but jQuery would also do .
< div > < div class= '' meat '' > Some stuff < /div > < div class= '' meat '' > Some stuff < /div > < div class= '' meat '' > Some stuff < /div > < div class= '' meat '' > Some stuff < /div > < div class= '' dairy '' > Some stuff < /div > < div class= '' dairy '' > Some stuff < /div > < div class= '' dairy '' > Some st...
Style the First Occurence of a Class
JS
I have a script written in PHP and the same script written in Javascript.It iterates a million times and on each time strips a string into an array and assigns the first array item into a new variable.The PHP is : And the Javascript is : I run PHP with PHP-CLI 5.3.10 and the Javascript with node v0.6.12.For PHP I use '...
class First { public function Iterate ( ) { $ count = 1000000 ; $ test_string = `` ; $ test_array = `` ; $ first_word = `` ; for ( $ i=1 ; $ i < = $ count ; $ i++ ) { $ test_string = 'This is a test string ' ; //could use explode but no explode in js $ test_array = split ( `` `` , $ test_string ) ; $ first_word = $ tes...
Memory consumption on an iteration script
JS
I 'm trying to have different css styles for a div that has same css class in a row and different for a single div for the same class . Here 's what I 'm trying to achieve if the explanation is confusing.This should be the output : Can it be done by CSS only or does it require JavaScript too ?
.row { display : flex ; margin : 20px ; } .number { width : 32px ; height : 32px ; display : flex ; justify-content : center ; align-items : center ; } .number.bg { background-color : # e24381 ; color : # ffffff ; border-radius : 24px 0 0 24px ; } .number.bg ~ .number.bg { border-radius : 0 24px 24px 0 ; } < div class=...
different style for continuous css class
JS
Playing with built-in JavaScript objects and constructors , I noticed something a little odd.Sometimes , it 's possible to get new objects by calling a constructor without new . For example : But sometimes this does n't work : Is the behavior of non-new constructor built-in functions defined anywhere in the ECMAScript ...
> new Array ( 1,2,3,4 ) [ 1 , 2 , 3 , 4 ] > Array ( 1,2,3,4 ) [ 1 , 2 , 3 , 4 ] > Date ( ) '' Thu Jun 05 2014 00:28:10 GMT-0600 ( CST ) '' > new Date ( ) Date 2014-06-05T06:28:10.876Z
When does *not* using new work on built-ins ?
JS
I 'm using react-inline-grid and as soon as I wrap my components with < Grid > , the wrapped components seem to loose their access to the store : Uncaught TypeError : Can not read property 'currentStep ' of undefinedThe code : The extra div is because threw an error when I passed it an array of React components . I tri...
class App extends Component { componentDidMount ( ) { const { dispatch } = this.props ; dispatch ( loadData ( ) ) ; } render ( ) { return ( < div > < Grid > < Row > < Cell > < Stepper / > < /Cell > < /Row > < /Grid > < /div > ) ; } } const mapStateToProps = state = > ( { app : state.app } ) ; export default connect ( m...
Components lose access to store when wrapped in < Grid > ( react-inline-grid )
JS
I made a little 3d engine.But I have some problems with the rotating functions.They make the object stretch out from time to time.Here 's the math :
this.rotateX = function ( angle ) { var cos = Math.cos ( angle ) ; var sin = Math.sin ( angle ) ; for ( var i = 0 ; i < this.points.length ; i++ ) { this.points [ i ] .y = sin * this.points [ i ] .z + cos * this.points [ i ] .y ; this.points [ i ] .z = -sin * this.points [ i ] .y + cos * this.points [ i ] .z ; } } this...
3D Engine stretches objects out while rotating
JS
I'am very new to Angularjs.I created an Angularjs Service to store some `` global '' vars . It looks like this : Now I want use ng-show/hide in different controllers . Is this even possible ? Or is it better to store this in the rootScope ? For a bit of help I would be very grateful ; - ) thx
.factory ( 'authVars ' , function ( ) { var sdo = { baseBackendUrl : 'https : //www.myurl.com ' , user : `` , password : `` , token : `` , isLogged : false } ; return sdo ; } ) < div class= '' alert '' ng-hide= '' authVars.isLogged '' > < strong > whatEver < /strong > < /div >
Angularjs service vars in all controller templates
JS
I need to replace some part of text , e.g . mustache var { { myvar } } , on already loaded page.Example html : What 's the problem ? Use $ ( html ) .html ( myrenderscript ( $ ( html ) .html ( ) ) ) ! It 's ugly , slow and brokes < script > tags.What do you want ? I want to get closest tag with { { } } and than render a...
< html > < head > < title > { { MYTITLE } } < /title > < /head > < body > < p > < strong > < ul > < li > text { { TEXT } } < /li > < /ul > < /strong > < /p > { { ANOTHER } } < /body > < /html > $ ( 'html : contains ( `` { { `` ) ' ) .filter ( function ( i ) { return $ ( this ) .find ( ' : contains ( `` { { `` ) ' ) .le...
Smart text replacing with jQuery
JS
I 've a code that sends a message to a welcome channel : It 's working , but there is a problem I ca n't solve . When I enter the server it shows : But when I enter the dyno bot or another user it shows : When I enter again or another user : It 's always sending the previous user welcome image ... I am hours and hours ...
import Discord from `` discord.js '' const client = new Discord.Client ( ) client.on ( `` guildMemberAdd '' , async member = > { let bg = await jimp.read ( `` img/img_bg.png '' ) // Bg da imagem . if ( guildId === `` 729008562747080836 '' ) { bg = await jimp.read ( `` img/img_bg-thunder.png '' ) // Bg da imagem da Thun...
My welcome message is confusing . ( Discord.js )
JS
I have a string value ( `` 11112233 '' ) . I want to split this string and separate it to 3 different value.I searched a lot , its possible with characters like ( / ) or other symbols.Something else , My number is always different , so i cant split it by enter the exact string.I want to do something like this : How i c...
Val 1 = 1111val 2 = 22 val 3 = 33 var myVal = `` 11112233 '' ; var lastVal = myVal.split ( 0 , 3 ) ; // split from index 0 till index 3
String split based on repetitions
JS
I have an iframe-based widget that uses postMessage to communicate to the parent . That means i.e . that I send a message from the iframe to request a resize of itself.The data is json , and is at the moment interfering with messages sent by other widgets / scripts on the parent page . So I need a way to distinguish my...
parent.postMessage ( JSON.stringify ( data ) , page.widgetOrigin ) ; poules.sdk.receiveMessage = function ( event ) { var data = JSON.parse ( event.data ) ; switch ( data.message ) { case 'requestResize ' : poules.sdk.requestResize ( data ) ; break ; case 'loginSuccess ' : poules.sdk.triggerLoginEvent ( data ) ; break ...
Is there a standard way for recognizing your own postMessage in the onmessage eventhandler ?
JS
The type ahead functionality works where it is supposed to . The issue though is that the type ahead functionality is making the JSON request on every request for the data when it should really only happen for one specific request.I have the following controller : I have the following in my javascript file : And just f...
# controllers/agencies_controller.rbclass AgenciesController < ApplicationController def get_unique_agency_names @ unique_agency_names = Agency.uniq.pluck ( : name ) respond_to do |format| format.json { render json : @ unique_agency_names } end end ... end # app/assets/javascripts.agencies/index.js $ ( document ) .read...
Typeahead in rails app : Append JSON request to only one specific request instead of appending JSON request to every request via prefetch
JS
What 's the value of this in an imported function , which is called from a namespace import ? ( according to the ECMA spec ) My guess would be : It 's the module object , but have n't found a clear answer to this in the spec . Does the normal behavior apply here or is there something special in ES6 modules for namespac...
// module.jsexport function fun ( ) { return this ; } // main.jsimport * as module from `` ./module.js '' ; let x = module.fun ( ) ; // What 's the value of x here ?
ES6 namespace import : behavior of `` this ''
JS
Provided you have a container div with hundreds of very simple children elements such as the following : Would including an unique id for each single element harm ( client ) performance in any ( meaningful ) way , be it rendering , javascript or memory wise ? Why I 'm asking : I may need from time to time to reference ...
< div id= '' stuffContainer '' class= '' item-container '' > < div class= '' single-item '' > < /div > < div class= '' single-item '' > < /div > < div class= '' single-item '' > < /div > < div class= '' single-item '' > < /div > < div class= '' single-item '' > < /div > < div class= '' single-item '' > < /div > [ ... ]...
HTML DOMs , ids vs no ids ?
JS
I 'm not good at regex , trying to make 2 regex.Regex1 : All specified words in any order but nothing else . ( repetition allowed ) .Regex2 : All specified words in any order but nothing else . ( repetition not allowed ) .Words : Strings : Regex1 evaluate above strings as : Regex2 evaluate above strings as : My Attempt...
aaa , bbb , ccc aaa ccc bbbaaa cccaaa bbb ddd cccbbb aaa bbb ccc true - > all word present in any orderfalse - > bbb is missingfalse - > unknown word 'ddd'false - > repetition not allowed true - > all word present in any orderfalse - > bbb is missingfalse - > unknown word 'ddd'true - > all word present in any order and...
Regex : Specified words in any order
JS
I enjoy working with Google Analytics and the ways that I am able to slice information about our visitors . We use Customer Variables to track information about who and how are users interact with our site . Staying true to the goal of Analytics , we are always looking for ways to improve and optimize our website . Cur...
_gaq.push ( '_setCustomVar ' , 5 , 'capslock ' , 'true ' , 3 ) ;
How do you track Caps Lock users with Google Analytics ?
JS
I 'm working on an opensource JS framework and I want to use JSX with typescript for it 's components . But I have an issue with type definitions for JSXTS expects : to be ( for any react-like framework ) : While in this framework the actual type is based on Observables ( RxJS ) : E.g . a simple h1 header component : S...
< Header title= '' Hello World '' / > function Header ( props : { title : string } ) : JSXElement function Header ( props : Observable < { title : string } > ) : JSXElement | Observable < JSXElement > function Header ( props $ ) { // take in a stream of updates return props $ .pipe ( // return a stream of JSX updates m...
JSX TypeScript definitions override for custom framework 's components ?
JS
I have the following codeIt stores all combinations on the data of the element . When a sequence of keys match ( it is checked by all keys pressed by the user than compared the end of this string to the sequence set to the element ) , I check an array which stores all sequences and callback functions to see if there is...
( function ( $ ) { $ .fn.kb = function ( evt , map , fn , options ) { var _this = this ; var modifiers = [ 17 , 18 , 19 ] ; function precise ( a , b ) { return b.Size - a.Size ; } if ( ! this.data ( `` Combos '' ) ) this.data ( `` Combos '' , [ ] ) ; var combos = this.data ( `` Combos '' ) ; var combo = { Size : map.Ke...
How can I optimize this code ?
JS
I 'm currently working on a project where the following inheritance structure is used : Now , I 'm trying add some object pooling to the equation . The pattern I 'm currently using works something like ( pseudocode ) : Of course , the problem with using these two patterns is that constructor calls on SubType wont draw ...
var Type = function ( a ) { this.a = a ; } ; var SubType = function ( a ) { Type.call ( this , a ) ; } ; SubType.prototype = Object.create ( Type.prototype ) ; SubType.prototype.constructor = SubType ; Type.new = function ( ) { if object available in pool reset popped pool object return pool object else return new Type...
Classical Inheritance and Object Pooling
JS
This is jquery function : Problem is how to let program goes into .fail block , I use .Net MVC , However , set break point in Controller does n't trigger a timeout exception then leads to fail callback.Do n't know how people test this.Should I start looking at some tools ?
$ .get ( `` /url '' , function ( ) { //success } ) .fail ( function ( ) { //fail < -- -- how to make code go in there . } ) ;
How to test JQuery fail callback ?
JS
According to this answer to 'Is object empty ? ' : I 've seen several implementations of something similar in small JavaScript libraries , like : I did a quick jsperf to test this sort of thing , and caching looked a bit quicker overall than not caching , but my test could be flawed . ( I am using the word 'cache ' to ...
// Speed up calls to hasOwnPropertyvar hasOwnProperty = Object.prototype.hasOwnProperty ; var slice = Array.prototype.slice ; //orfunction slice ( collection ) { return Array.prototype.slice.call ( collection ) ; }
Can I speed up calls to native methods in JavaScript ?
JS
I would like to have a function to sort an array of objects by getting a string as input that include the name of the property and sort direction . I need something like this :
var myArray = [ { name : '' A '' , age : 30 } , { name : '' B '' , age:20 } , { name : '' C '' , age:20 } ] ; var strSort = `` age asc , name desc '' ; var sortedArray = customSortFuntion ( myArray , strSort ) ; //sortedArray == [ { name : '' C '' , age:20 } , { name : '' B '' , age:20 } , { name : '' A '' , age : 30 }...
Sorting an array of objects specifying sort criteria as a string
JS
I have a code , that shows a modal with this code using jquery : but with angular.js not works . what is the equivalent of $ ( ' # myModal ' ) using angular.js ?
$ ( ' # myModal ' ) .modal ( { 'show ' : true } ) ; // not works for meangular.element ( `` # myModal '' )
what is the equivalent of $ ( ' # xxl ' ) selector of jquery in angular.js
JS
I 'm trying to move angular code into separate files before the project grows too big.I tried moving the app , controllers and services into separate files but the errors stopped referencing points in the code ( or they were too generic ) .I have decided to put the file contents in on big < script > tag so I can work t...
( function ( ) { 'use strict ' ; ... } ( ) ) ; ( function ( ) { 'use strict ' ; var app = angular.module ( 'protonApp ' , [ 'ui.router ' , 'protonAppControllers ' , 'protonAppServices ' ] ) ; app.config ( [ ' $ stateProvider ' , ' $ urlRouterProvider ' , function ( $ stateProvider , $ urlRouterProvider ) { ... } ] ) ; ...
Putting app , controllers & services in separate files
JS
I 've searched high and low for an `` elegant '' way to do this . Using Angular UI Sortable I currently have 3 columns , which essentially looks like this codepen , just with 3 columns instead of 2 . Looking over the sortOptions : } Given those sortable events , I do n't see how I can detect if a card is being dropped ...
function createOptions ( listName ) { var _listName = listName ; var options = { placeholder : `` app '' , connectWith : `` .apps-container '' , activate : function ( ) { console.log ( `` list `` + _listName + `` : activate '' ) ; } , beforeStop : function ( ) { console.log ( `` list `` + _listName + `` : beforeStop ''...
Angular UI Sortable - Grouping
JS
For some cases , I do n't want to use mixins in my Plugin.I am trying to add a custom Methods like created ( ) , mounted ( ) , methods { } , so I can access its property when the component is loaded & run my custom method.example : `` customMethod ''
// @ root/home.vue < script > export default { name : 'Home ' , props : { msg : String } , mounted ( ) { // } , methods { // } , customMethod { } } < /script >
How to add global funtions like Create , Methods , Mounted from a plugin in Vue ?
JS
I have an element that on focus via javascript changes to display absolute and covers its parent element . Then on blur back to default a table-cell.What seems to happen is that the element just sits below the first table-cell , it does n't go back to its original position ? This only appears to happen in webkit and I ...
< script src= '' https : //ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js '' > < /script > < ! doctype html > < ! -- [ if lt IE 7 ] > < html class= '' no-js ie6 oldie '' lang= '' en '' > < ! [ endif ] -- > < ! -- [ if IE 7 ] > < html class= '' no-js ie7 oldie '' lang= '' en '' > < ! [ endif ] -- > < ! -- [ i...
How do I force an element in webkit to go back to original size ?
JS
I 've had a long-standing assumption that deep prototype chains resulted in performance deterioration for property accessors . I was trying to explain that on hide the getter or add in the proto Object when a quick benchmark I threw together resulted in quite the opposite outcome from what I was expecting.What is going...
const object1 = { foo : 'Hello , World ! ' , get bar ( ) { return this.foo } } ; const object2 = Object.assign ( Object.create ( { get bar ( ) { return this.foo } } ) , { foo : 'Hello , World ! ' } ) ; let result ; result = object1.bar ; result = object2.bar ;
How does extending the prototype chain increase performance in this case ?
JS
I did n't find a post asking for a pattern similar to this one , sorry if I missed it.Anyway , I 'm repeateadly seeing this pattern in many jQuery plugins or scripts : What 's its purpose ? Does it have a name ? Thanks !
( function ( ) { ... ... ... .. } ( ) ) ;
What is this pattern 's name / purpose ?
JS
I am new to Javascript , and know how can I load html before javascript is executed.I did check the questions on stackoverflow and tried to implement the solutions given but none worked.Following is the code of various code that I tried.Wrote script tag before the body ends wrote the javascript code inside a function a...
< ! DOCTYPE html > < html > < head > < title > Age Calculator < /title > < /head > < body onload= '' cal ( ) ; '' > < h1 > Age Calculator < /h1 > < p > Enter your age and find how many days you have been alive < /p > < script type= '' text/javascript '' src= '' Age.js '' > < /script > < /body > < /html > //Javascript c...
Unable to load HTML before Javascript
JS
I am fairly new to JavaScript and coming from a different programming background I have a tough time to understand how JavaScript knows how to resolve parameters passed to a function.Let 's look at and easy example . from the documentation of jQuery .on , I see 2 different signatures : .on ( events [ , selector ] [ , d...
$ ( function ( ) { let dat = { a : 1 , b : 2 } $ ( ' # do ' ) .on ( 'click ' , dat , function ( evt ) { alert ( evt.data.b ) ; } ) ; $ ( ' # do2 ' ) .on ( 'click ' , function ( evt ) { alert ( `` click '' ) ; } ) ; } ) < script src= '' https : //cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js '' > < /script >...
How does javascript resolve parameters ?