lang stringclasses 4
values | desc stringlengths 2 8.98k | code stringlengths 7 36.2k | title stringlengths 12 162 |
|---|---|---|---|
JS | I am using ES6 class to define my controller so this is the syntax , view : So `` Hello '' from within the constructor is getting logged fine . But , `` change fired '' within the typedText ( ) function is not firing because apparently is undefined how do I make my class function textTyped ( ) to access the $ log servi... | export class SearchBarController { constructor ( $ log ) { 'ngInject ' ; $ log.debug ( `` Hello '' ) ; } textTyped ( $ log ) { $ log.debug ( `` change fired . `` ) ; } } < input type= '' text '' data-ng-model= '' vm.txt '' data-ng-change= '' vm.textTyped ( ) '' / > this.logger = $ log ; this.logger.debug ( `` Change fi... | Dependency Injections are undefined in controller functions while using Angular1+ ES6 , with controller as a class |
JS | I have a sortable where it was created with loaded from JSON files.Now I want to delete an item.I receive from a textarea the element name that I have to cancel.I save in a variable namdel.With a for loop I am going to compare this variable with the name of the sortable.The HTML code of the sortable : The problem is ho... | < div id= '' sortparam '' > < ul style= '' '' class= '' ui-sortable '' id= '' sortable '' > < li style= '' '' id= '' 1 '' class= '' ui-state-default '' > < span class= '' ui-icon ui-icon-arrowthick-2-n-s '' > < /span > Singular sensation < /li > < li style= '' '' id= '' 2 '' class= '' ui-state-default '' > < span class... | How to find value 's item in sortable with javascript |
JS | In my code I assumed the following || short-circuiting was safe : But to my surprise if we short-circuit an empty array with a true statement an empty array is still returned . I will demonstrate with some console code below and my question is why [ ] || true evaluates to [ ] .Part of me thinks that it is because an ar... | var $ holidayExpandBarOrOpeningHours = $ ( `` .expandBar + .holidayHours_c '' ) .prev ( ) || $ ( `` .openingHours '' ) ; false || `` expected '' '' expected '' false == [ ] true [ ] || `` expected '' [ ] typeof ( [ ] ) '' object '' ( { } ) || `` expected '' Object { } ( { } ) == falsefalse { } == falseSyntaxError : Une... | Short-circuiting an empty array in JS has an unexpected outcome : ` [ ] || true == [ ] ` |
JS | Is there any way to execute callback on both results of Promise object ? For example I want to make some cleanup logic after execution of xhr request . So I need to do something like this : In jquery Defered for example i can use method always ( ) : Does Promise support something like this ? | var cleanUp = function ( ) { something.here ( ) ; } myLib.makeXhr ( ) .then ( cleanUp , cleanUp ) ; myLib.makeXhr ( ) .always ( function ( ) { something.here ( ) ; } ) ; | JavaScript native Promise execute callback on both results |
JS | If I do the following : then I can show that value using CSS as : But if I do the following : then the same CSS code shows nothing.As I understanding the difference is that in the first case I am just setting an attribute on the HTML element that I happen to prefix with data , while in the second case I am setting the ... | $ ( '.js-element ' ) .attr ( `` data-count '' , 2 ) .js-element : after { content : attr ( data-count ) ; } $ ( '.js-element ' ) .data ( `` count '' , 2 ) | Show data from dataset in CSS ? |
JS | I just ran into a problem where I did : Which does n't work because JavaScript inserts the semicolon after the return making the above equivalent to : This totally baffled me as to why it does this.I found some Stack Overflow questions about the topic ( e.g . this , this , and this ) but they just explain when it does ... | return isSomething ( ) & & isSomethingElse ( ) ; return ; isSomething ( ) & & isSomethingElse ( ) ; | Why is JavaScript designed to automatically insert a semicolon after a return followed by a new line ? |
JS | I 'm trying to create a chart like the one in this image using Plotly.js : It 's a grouped boxplot ( by sites , currently only one ) with two y axes.I 've managed to create two versions , both of which do n't work : Create 5 traces ( 1 for each box ) so that you can define the correct y axis for each box . This then pu... | var data = [ { `` x '' : [ `` Site 1 '' , `` Site 1 '' , `` Site 1 '' , `` Site 1 '' , `` Site 1 '' , `` Site 1 '' ] , `` xaxis '' : '' x '' , `` yaxis '' : '' y '' , `` name '' : '' A '' , `` type '' : '' box '' , `` boxpoints '' : false , `` y '' : [ `` 3.81 '' , `` 3.74 '' , `` 3.62 '' , `` 3.50 '' , `` 3.50 '' , ``... | How to get grouped boxplots with vertical subplots |
JS | Trying to get 3 level dropdown working . In Opencart I have been using a third party repsonsive menu which works great . Demonstrated and available here http : //cssmenumaker.com/menu/responsive-flat-menuHowever , Opencart does n't support 3 level categories so an addon is needed https : //www.opencart.com/index.php ? ... | < div id= '' cssmenu '' > < div id= '' menu-button '' > Menu < /div > < ul > < li class= '' has-sub '' > < span class= '' submenu-button '' > < /span > < a href= '' extractor-fans '' > Extractor Fans < /a > < ul style= '' '' > < li > < a class= '' arrow '' href= '' /bathroom-extractor-fans '' > Bathroom Shower < /a > <... | 3rd Level JQuery Dropdown Not Displaying |
JS | I get an issue about drawing an arc with MathJax and latex2html5 ( from http : //latex2html5.com/ ) .I would like to draw this schema with these 2 libraries above : My issue is that I ca n't draw the 2 arcs on the left which link EV and DE states.On the link above , I did : The line : concerns this part but the result ... | < script type= '' tex/latex '' > \begin { center } \begin { pspicture } ( -4 , -4 ) ( 4,4 ) \pscircle ( -3.3,2.5 ) { 0.4 } \pscircle ( -3.3 , -2.5 ) { 0.4 } \pscircle ( 3.3 , -2.5 ) { 0.4 } \pscircle ( 3.3,2.5 ) { 0.4 } \psline { - > } ( -2.9,2.5 ) ( 2.9,2.5 ) \rput ( 0,2.8 ) { 00 } \psline { - > } ( 3.3,2.1 ) ( 3.3 , ... | Drawing an arc with pstricks and latex2html5 |
JS | ProblemI 'm trying to scan a drive directory ( recursively walk all the paths ) and write all the paths to a file ( as it 's finding them ) using fs.createWriteStream in order to keep the memory usage low , but it does n't work , the memory usage reaches 2GB during the scan.ExpectedI was expecting fs.createWriteStream ... | const fs = require ( 'fs ' ) const walkdir = require ( 'walkdir ' ) let dir = ' C : /'let options = { `` max_depth '' : 0 , `` track_inodes '' : true , `` return_object '' : false , `` no_return '' : true , } const wstream = fs.createWriteStream ( `` C : /Users/USERNAME/Desktop/paths.txt '' ) let walker = walkdir ( dir... | fs.createWriteStream does n't use back-pressure when writing data to a file , causing high memory usage |
JS | ES6 has generators that return iterators : There is a proposal for asynchronous functions that return Promises : So what happens if I combine the two , like this : What does it return ? Is it Promise < Iterator < Item > > ? Iterator < Promise < Item > > ? Something else ? How do I consume it ? I imagine there should be... | function* range ( n ) { for ( let i = 0 ; i < n ; ++i ) { yield i ; } } for ( let x of range ( 10 ) ) { console.log ( x ) ; } async function f ( x ) { let y = await g ( x ) ; return y * y ; } f ( 2 ) .then ( y = > { console.log ( y ) ; } ) ; async function* ag ( n ) { for ( let i = 0 ; i < n ; ++i ) { yield i ; } } for... | ES6 asynchronous generator result |
JS | I wanted to ask about the pros cons of my the following OOP style.I write my JS classes in the following manner.Is this a good approach ? Is there any drawback ? I do n't use inheritance , but would it work this way to achieve inheritance ? Thanks in advance . | var MyClass = function ( ) { // private vars var self = this , _foo = 1 , _bar = `` test '' ; // public vars this.cool = true ; // private methods var initialize = function ( a , b ) { // initialize everything } ; var doSomething = function ( ) { var test = 34 ; _foo = cool ; } ; // public methods this.startRequest = f... | Is this a good way to do JS OOP ? |
JS | While reading an article on Long Polling I got little confused between following two flavors of setInterval1 -2- As per blog it says - About second snippet , So , this pattern does n't guarantee execution on a fixed interval per se . But , it does guarantee that the previous interval has completed before the next inter... | setInterval ( function ( ) { $ .ajax ( { url : `` server '' , success : function ( data ) { //Update your dashboard gauge salesGauge.setValue ( data.value ) ; } , dataType : `` json '' } ) ; } , 30000 ) ; ( function poll ( ) { setTimeout ( function ( ) { $ .ajax ( { url : `` server '' , success : function ( data ) { sa... | recursive setTimeout pattern |
JS | Is these a way i can loop through a PHP array and have the data outputted into a JavaScript array ? For example , the JS script below will not work I Know its because the `` i '' is not a php variable so therefore invalid inside the php section , but its just an way to show what i would like to achieve . The $ rowCount... | var mon_Loop = < ? php echo $ rowCount_Mon ? > ; var mon_Events = new Array ( ) ; for ( i = 0 ; i < mon_Loop ; i++ ) { mon_Events [ i ] = < ? php $ divMon [ i ] ? > } mon_Events [ 0 ] = < ? php echo $ divMon [ 0 ] ? > | Placing PHP array values into a javascript array ? |
JS | I am trying to use custom properties based on dynamic values , such as attr ( ) .For instance , in below code , I tried to access both custom-properties based on the current element 's id attribute.But it obviously fails.Is there some way to achieve this ? | : root { -- app-foo : 'Hello ' ; -- app-bar : 'World ' ; } div : :after { /* expected : 'Hello ' for # foo 'World ' for # bar */ content : var ( ' -- app-'attr ( id ) ) ; } < div id= '' foo '' > < /div > < div id= '' bar '' > < /div > | How to set a dynamic property name in var ( ) |
JS | I 've been working on a time app for JS and I was wondering , how could I change the time zone . See , I live in the eastern time zone of North America , and i do n't like converting it to the International Timezone . So here is my Code . When I click the button , I get , But I want it to be : | < button type= '' button '' onclick= '' document.getElementById ( 'time ' ) .innerHTML = Date ( ) '' > Click me to display Date and Time. < /button > < p id= '' time '' > < /p > Wed Dec 30 2015 13:40:25 GMT+0000 ( UTC ) Wed Dec 30 2015 8:40:25 ( EST ) | How do I change the time zone in JavaScript ? |
JS | Let 's consider this code : QuestionsWhich are the differences between the three assignments ? Do the objects a , b and c exactly overlap ? If yes , why ? If no , why ? Please add references to your answers.Demo . | ( function ( ) { var a = { `` id '' : `` 1 '' , `` name '' : `` mike '' , `` lastname '' : `` ross '' } ; var b = JSON.parse ( ' { `` id '' : `` 1 '' , `` name '' : `` mike '' , `` lastname '' : `` ross '' } ' ) ; var c = Object.create ( { `` id '' : `` 1 '' , `` name '' : `` mike '' , `` lastname '' : `` ross '' } ) ;... | JSON literals and Javascript objects . I am confused |
JS | I recently used a little utility library by John Resig , called inherit.js . I usually try to understand the core parts of the libraries I am using , and after a lot of head scratching I finally understood the hard bits of the code ( namely how he could call the corresponding method of the super class ) .The 1 % bit I ... | fnTest = /xyz/.test ( function ( ) { xyz ; } ) ? /\b_super\b/ : / . */ ; // Check if we 're overwriting an existing function prototype [ name ] = typeof prop [ name ] == `` function '' & & typeof _super [ name ] == `` function '' & & fnTest.test ( prop [ name ] ) ? aFunctionThatCanCallSuper /* Lots of code */ : prop [ ... | Weird regex in inherit.js ( by John Resig ) - why , what and how ? |
JS | I 've got an HTML-template which loads data from controller 's array and keeps them in a table . Also I have a directive , which makes transclusion for table rows . The data array is being filled on API-requests . After the new requests I 've got the request results merged in my table . One set of rows is being added f... | < div class= '' row '' > < div class= '' col-md-12 '' > < div id= '' results '' ng-show= '' results.length > 0 '' > < table class= '' table result-table '' > < thead > < tr > < th > 1 < /th > < th > 2 < /th > < th > 3 < /th > < th > 4 < /th > < /tr > < /thead > < tbody > < tr ng-repeat= '' result in results '' my-resul... | Clear previous data before request |
JS | When trying to remove options from select , there is always one left , why ? This JS is not working : And this is not working also : I know that there are other solutions to achieve that , but i would like to understand why it 's not working as it supposed to | < select id= '' form-select '' > < option > 111 < /option > < option > 222 < /option > < option > 333 < /option > < /select > var t = document.querySelector ( ' # form-select ' ) ; for ( var i of t.options ) { t.remove ( i.index ) } for ( var i of document.querySelector ( ' # form-select ' ) .options ) { i.remove ( ) } | Removing options from Select tag in Vanilla JavaScript with `` for .. of '' loop |
JS | I am struggling with an issue to fit pragmatically transformed SVG element into the given rect bounds.Destination rect is given and not transformed.Input rect has any type of transformations.Input rect can be a child of any transformed groups.Transformations should be applied only to the input rect.This question is onl... | var inputElement = document.getElementById ( `` input '' ) ; var destinationElement = document.getElementById ( `` destination '' ) ; var inputBB = inputElement.getBoundingClientRect ( ) ; var outputBB = destinationElement.getBoundingClientRect ( ) ; var scaleX = outputBB.width / inputBB.width ; var scaleY = outputBB.h... | Fit SVG transformed element into the rect bounds with JavaScript |
JS | I 've developed a JavaScript plugin to be included on our customers ' websites . The plugin I 've created depends on some external libraries , which are bundled and delivered to the client as one big package : jQuery 1.8.2 and KnockoutJS v3.0.0.The plugin plays fine on most sites , but if the host site uses RequireJS ,... | Mismatched anonymous define ( ) module ( function ( factory ) { // Support three module loading scenarios if ( typeof require === 'function ' & & typeof exports === 'object ' & & typeof module === 'object ' ) { // [ 1 ] CommonJS/Node.js var target = module [ 'exports ' ] || exports ; // module.exports is for Node.js fa... | Error loading KnockoutJS as part of a third party package when host site uses RequireJS |
JS | I am following the Basic Tutorial to use TurkServer , but I get an error from the beginning.The error I get when I run : meteor -- settings settings.jsonMy settings file : It seems general problem with Meteor , not with TurkServer ( the project files https : //www.dropbox.com/s/ppgbuwv4k3imbt5/interactiveEstimation.zip... | W20160615-01:19:27.320 ( -4 ) ? ( STDERR ) W20160615-01:19:27.406 ( -4 ) ? ( STDERR ) ~/.meteor/packages/meteor-tool/.1.3.3.b5ue33++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:280W20160615-01:19:27.406 ( -4 ) ? ( STDERR ) throw ( ex ) ; W20160615-01:19:27.4... | Can not read property 'bcrypt ' of undefined with Meteor |
JS | ES6 introduced template strings delimited by backticks ` .In which cases would replacing single ' or double `` quotes around a string by backticks yield a different result , or otherwise be unsafe ? Escaping of existing backticks inside the code is performed as part of the operation.I understand that any string contain... | // beforevar message = `` Display backtick ` on screen '' ; // aftervar message = ` Display backtick \ ` on screen ` ; | changing string delimiters to backticks : possible impact ? |
JS | I am trying to grasp how the trie and such in immutability is implemented , as relates to immutability in JS . I understand how there is supposed to be significant structural sharing.My question is say you have a graph sort of structure like this : So then you add an x to the system . I 'll try it two different ways : ... | a -- b | c | d -- h | e -- i -- l | f -- j -- m | g -- k -- n a -- b | c | d -- h -- x | e -- i -- l | f -- j -- m | g -- k -- n a -- b | c | d -- h | x | e -- i -- l | f -- j -- m | g -- k -- n -- -- -- -- -- -- -- -- -- -- -- -- -- | || a -- b || | || c || | || d -- h || | || e -- i -- l || | || f -- j -- m || | || g... | How Immutability is Implemented |
JS | I have my group by ng-options looks like thisHere is my datathe problem is that this creates the optgroup on the bottoms of this select menu , not the order as same as my data list.i want to produce : Here is FiddleThanks ! | < select ng-model= '' selected '' ng-options= '' d.title group by d.group for d in data '' > < /select > $ scope.data = [ { group : '' '' , title : '' No GroupA '' } , { group : '' Group_1 '' , title : '' 1 '' } , { group : '' '' , title : '' No GroupB '' } , { group : '' Group_2 '' , title : '' 2 '' } , { group : '' '... | Angularjs : ng-options : How to order options with group and non-group |
JS | I have been struggling with this for a while and I am going to provide you with as much information as possible ( some maybe irrelevant ) because I am completely stuck . I am using Ionic and I would like to be able to take a picture with my phone and upload it to an AWS S3 bucket . I used Cordova camera to accomplish t... | `` Not a valid bitmap file . its format is not currently supported . '' | AWS S3 getting Not a valid bitmap file |
JS | I know that pure functions are in the `` functional programming '' paradigm , you create a function that does n't have any side effects and that for a input it always return the same output like : This is a pure function because for a input I always return the same output and I did n't create any side effects . Ok I go... | function ( a , b ) { return a + b ; } function changeContent ( ) { let content = document.querySelector ( `` # content '' ) ; content.textContent = 'Hello World ' ; } | What is the philosophy behind `` functional programming '' when you actually want to create a side effect ? |
JS | While following a HTML5 rocks web audio tutorial JSHint gives this warning ... For the following line ... The JSHint docs explain the warning is issued whenever new is used with an object literal and go on to say that new `` is only useful for creating instances of a constructor function and has no sensible meaning whe... | W056 - Bad constructor.at line 26 col 73 var audioContext = new ( window.AudioContext || window.webkitAudioContext ) ( ) ; | How `` bad '' is this constructor really ? |
JS | I 'm using AngularJS , ng-table and coffeescript together and would like to create a multiple template filter within coffeescript and pass it into my angularjs template.I have a name & surname combined column which I would like two filters for 'name ' and 'surname'.So far I have it working like so ; But I would like to... | < td data-title= '' 'Customer ' '' sortable= '' 'fullname ' '' filter= '' { 'name_cont ' : 'text ' , 'surname_cont ' : 'text ' } '' > $ scope.nameFilterDef = { name : { id : `` text '' , placeholder : `` Name '' } , surname : { id : `` text '' , placeholder : `` Surname '' } } < td data-title= '' 'Customer ' '' sortabl... | ng-table multiple template filters using coffeescript |
JS | Possible Duplicate : Do you ever need to specify javascript : in an onclick ? To execute JavaScript on a DOM event , you could use something like this : Something like this seems to work as well : However , I 've heard that the second example is `` bad '' and that the first example should be used over the second.Is thi... | < div onclick= '' alert ( 'Alert ' ) ; '' > Alert < /div > < div onclick= '' javascript : alert ( 'Alert ' ) ; '' > Alert < /div > < a href= '' javascript : alert ( 'Alert ' ) ; '' > Alert < /a > | Why is using `` javascript : < code > '' bad ? |
JS | Well it seems that I 'm having some sort of a problem with Firefox , I 've added a logo to my website and styled it through this CSS block : When I open the web page with Chrome or any other browser other than Firefox it displays it in the right way , unless I zoomed in it will show a thin line , while opening the web ... | # splash div.logo > a { background-image : url ( `` ../../ -- -.png '' ) ; background-size : 280px ; height : 85px ; width : 280px ; } IndexPage : { Splash : { init : function ( ) { var $ splash = $ ( ' # splash ' ) , $ logo = $ splash.find ( ' # logo ' ) , frame = 1 , frameCount = 46 framesPerSecond = 50 ; function an... | Firefox adds undesired thin line above a logo animated using JavaScript |
JS | I am having an issue when enabling deferred updates in the knockout library . I have implemented Jquery datatables as a component , when navigating to a view that has this component i can see the following methods being called in order.Getview > Activate > Attacheverything works as expectedBut if i press f5 and refresh... | define ( [ ] , function ( ) { var test = function ( ) { var self = this ; var defaultViewHtml = ' < div > < h1 > Hello World < /h1 > < /div > ' ; var currentView = null ; self.getView = function ( ) { console.log ( 'GetView ' ) ; if ( ! currentView ) { currentView = $ ( defaultViewHtml ) [ 0 ] ; } return currentView ; ... | Durandal JS knockout Deferred updates |
JS | In new React ES6 classes this needs to be binded as stated here : http : //facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html # autobindingfor eg : The explanation for this is because it 's the default behaviour , however if I make an ES6 class and then I make a new instance of it this will be bindedWhy... | class Counter extends React.Component { constructor ( ) { super ( ) ; this.tick = this.tick.bind ( this ) ; } tick ( ) { ... } ... } import React from 'React'class Test extends React.Component { constructor ( ) { super ( ) } foo ( ) { console.log ( 'bar ' ) } hello ( ) { this.foo ( ) } } var test = new Test ( ) test.he... | Why binding is needed in ES6 react classes |
JS | I 'm building out a notification system and it 's sorta working , but sorta not . I have the follow Composition functionThis is working ( It 's been simplified a little bit ) . Now , I have two entry points in Webpack . In one entry point ( auth ) , I have the following code to load up a Vue Component for showing the N... | const data = reactive ( { notifications : [ ] } ) ; let notificationKey = 0 ; export const useNotification = ( ) = > { const visibleNotifications = computed ( ( ) = > { return data.notifications.slice ( ) .reverse ( ) ; } ) ; const add = ( notification : INotification ) = > { notification.key = notificationKey++ ; noti... | Vue Composition Reactive properties are not updating in components |
JS | In Chrome and Firefox I can see in console : Could you explain me the difference ? I mean I always thought Window is top level object , and now I see it 's actually a function , whilst window is an object . Since window is top level object should Window be a method of Window ? Little confusing ... Oh , and there 's als... | typeof Window '' function '' typeof window '' object '' typeof Object '' function '' | Window object , window function and Object function |
JS | I 've got a select element bound to a model in an angular view . When filling out the form with the keyboard , I noticed that if you down arrow to the second option the value , the model still represents the first value . This only happens when using the keyboard to fill out the form . Set up is pretty simple , using a... | var app = angular.module ( 'app ' , [ ] ) ; app.controller ( 'myController ' , function ( ) { var vm = this ; vm.options = [ { Id : 1 , Value : ' A ' } , { Id : 2 , Value : ' B ' } , { Id : 3 , Value : ' C ' } ] } ) ; < script src= '' https : //code.angularjs.org/1.4.3/angular.js '' > < /script > < body ng-app= '' app ... | Select element in angular not updating modelValue on second selection |
JS | I am working with EPUB.JS , which uses the following code to get some information from an ePub file : This line of code fails in IE10 , as the querySelector returns null . I 've never seen an attribute selector in the format [ *|attr= '' val '' ] before , but what I think they were trying to say was , `` Select all nav... | var navEl = navHtml.querySelector ( 'nav [ *|type= '' toc '' ] ' ) var navEl = navHtml.querySelector ( 'nav ' ) | CSS3 Selectors [ *|type= '' toc '' ] |
JS | Possible Duplicate : how to remove css property using javascript ? I have this javascript : and so on ... Later on I am faced with the need of removing a property ( not changing its value , really removing meaning : like I had not set that before ) I coded something like this : div.style.height = undefined ; div.style.... | var div = document.getElementById ( 'myDiv ' ) ; div.style.width = '300px ' ; div.style.height = '200px ' ; ... | what 's the correct way to remove/reset a css property via javascript ? |
JS | Consider the following typical React document structure : Component.jsxWhere these components are composed as follows : OuterClickableArea.jsWith , for the sake of this argument , InnerClickableArea.js having pretty much the same code except for the class name and the console log statement.Now if you were to run this a... | < OuterClickableArea > < InnerClickableArea > content < /InnerClickableArea > < /OuterClickableArea > export default class OuterClickableArea extends React.Component { constructor ( props ) { super ( props ) this.state = { clicking : false } this.onMouseDown = this.onMouseDown.bind ( this ) this.onMouseUp = this.onMous... | How to achieve re-useable components with React and mouse event propagation ? |
JS | I 'm sure this is incredibly simple but I 'm pretty new to JS and I 'd like to know the best way of doing this rather than hacking it out with a workaround.So I have a div block and it 's visibility is toggled when pressing a text field above it.And then I have my JS : This works fine , however when the user clicks the... | < h3 onclick= '' javascript : toggle1 ( ) ; '' > < span style= '' cursor : pointer '' > < b > Text1 < /b > < /span > < /h3 > < div id= '' Text1 '' hidden= '' hidden '' > blahblah < /div > function toggle1 ( ) { $ ( ' # Text1 ' ) .toggle ( 1000 ) ; } < hr id= '' line1 '' style= '' height:2px ; border : none ; color : # ... | JS toggle visibility and change css of other items |
JS | I have a link that looks like this : Is it possible to render this into Hello World ? The link should point to https : //www.google.com/ ? q=Hello world without specifying this in the href . I am thinking javascript is probably the best way of doing this ? Any help would be good ! | < a class= '' link '' href= '' https : //www.google.com/ ? q= '' > Hello world < /a > | Make anchortext part of href ? |
JS | I am doing a web dynamic project with a Google map in a body of my html/jsp page.I made a function which create a marker thanks to ( lat , lng , map ) and use a special image.png as icon in the parameters of the marker.In my map , I made two different styles ( colors of map ... ) : `` Day '' and `` Night '' .I want to ... | if ( map.mapTypeControlOptions.mapTypeIds.equals ( Day ) ) { var image= ... png } else { var image= ... png } ... customMapTypeIdJour < div id= '' map '' > < /div > < script > function initMap ( ) { var customMapTypeNuit = new google.maps.StyledMapType ( [ { `` featureType '' : `` landscape.man_made '' , `` elementType... | GoogleMaps change icon 's marker when MapStyle change |
JS | I got a issue here with methods firing not in the correct order.I ca n't figure out how to make the this.props.history.pushState ( null , '/authors ' ) ; wait in the saveAuthor ( ) method.Help will be greatly appreciated . | import React , { Component } from 'react ' ; import AuthorForm from './authorForm ' ; import { History } from 'react-router ' ; const source = 'http : //localhost:3000/authors ' ; // History Mixin Component Hackfunction connectHistory ( Component ) { return React.createClass ( { mixins : [ History ] , render ( ) { retu... | React Router - History fires first rather waiting |
JS | I am pretty new to JS `` strict mode '' ; , when I use code like : I wonder why Chrome ( ver 49 ) give no error , but Node.js can give `` SyntaxError : In strict mode code , functions can only be declared at top level or immediately within another function . '' This table points out that my Chrome should report error . | function outer ( ) { `` use strict '' ; var ctype ; function inner ( ) { if ( ctype ! =undefined ) { function hello1 ( ) { console.log ( `` hello1 '' ) ; } hello1 ( ) } else { function hello2 ( ) { console.log ( `` hello2 '' ) ; } hello2 ( ) ; } } return inner ; } var inner = outer ( ) ; inner ( ) ; | Why Chrome still keep silent when using functions inside blocks in `` strict mode '' ? |
JS | I am implementing a turing machine ( think of it as a virtual machine ) in Javascript . I 'm working on a routine which is to perform the calculations as efficiently as possible ( this was not a focus of the project from the outset ) . Yes , I should not be thinking about optimizing unless I run into performance issues... | // states is an array of arrays of triplets and is the transition funcvar trans = states [ state ] [ alph_index [ tape [ pos ] ] ] ; tape [ cur_tape_pos ] = trans [ 0 ] ; // writecur_tape_pos += trans [ 1 ] ; // movestate = trans [ 2 ] ; // state update | What is the most efficient way to perform ( integer ) operations in Javascript ? |
JS | I need to calculate the angle between 3 points . For this , I do the following : Grab the 3 points ( previous , current and next , it 's within a loop ) Calculate the distance between the points with PythagorasCalculate the angle using Math.acosThis seems to work fine for shapes without angels of over 180 degrees , how... | // Pythagoras for calculating distance between two points ( 2D ) pointDistance = function ( p1x , p1y , p2x , p2y ) { return Math.sqrt ( ( p1x - p2x ) * ( p1x - p2x ) + ( p1y - p2y ) * ( p1y - p2y ) ) ; } ; // Get the distance between the previous , current and next points// vprev , vcur and vnext are objects that look... | Incorrect angle , wrong side calculated |
JS | Fire up your firebug console and try this out.Compare this : to this : Notice the difference ? If thisx is undefined , it will immediatly throw a reference error . If x is an undefined property of this , jQuery will return the document as it 's result set instead . Next jQuery will attempt to remove your document ( whi... | $ ( 'body ' ) .data ( ' x',1 ) ; $ ( thisx ) .remove ( ) ; console.log ( $ ( 'body ' ) .data ( ' x ' ) ) ; $ ( 'body ' ) .data ( ' x',1 ) ; $ ( this.x ) .remove ( ) ; console.log ( $ ( 'body ' ) .data ( ' x ' ) ) ; | Is this right ? A jQuery bug that erases the data store ? |
JS | Say I have the following HTML ( condensed ) : I want to remove the lowest child elements first , until ultimately removing the parent , then move on to the next parent element and its children . This can be easily accomplished by a simple loop that goes through each child element , removes it , then removes the next ch... | < div > < div > < div > < ul > < li > Text < /li > < /ul > < /div > < /div > < /div > < div > < div > < div > < ul > < li > Text 2 < /li > < /ul > < /div > < /div > < /div > < div > < div > < div > < ul > < li > Text 3 < /li > < /ul > < /div > < /div > < /div > var children = $ ( `` body '' ) .find ( `` * '' ) ; var i ... | Remove element nodes in post-order traversal |
JS | How can I get data from my Mongo database to pipe in Gulp as a data source when using Gulp Data ? Gulp Task ( simplified ) When I am using the prototype database , I can run , And get this result : | gulp.task ( 'db-test ' , function ( ) { return gulp.src ( './examples/test3.html ' ) .pipe ( data ( function ( file , cb ) { MongoClient.connect ( 'mongodb : //127.0.0.1:27017/prototype ' , function ( err , db ) { if ( err ) return cb ( err ) ; cb ( undefined , db.collection ( 'heroes ' ) .findOne ( ) ) ; // < -- This ... | Data from Mongo in Gulp using Gulp Data |
JS | I have few divs .posts which have a attr data-id which corresponds to the mysql DB id . Now if I want to scroll to a specific div which I am only known to the data-id.How will I scroll to it ? .My JSFiddle is here.Can anyone give an example along with a JSFiddle ? | < div class= '' posts '' data-id= '' 1 '' > < /div > < div class= '' posts '' data-id= '' 2 '' > < /div > | Scroll to a specific div |
JS | According to the browserify-shim docs , you can specify which globals browserify-shim needs to expose from your legacy modules by using the following syntax in your package.json : I want the legacy module to be accessible via require ( 'legacyModule ' ) and window.myVar.From my experience , if the non-commonjs module I... | { `` browserify-shim '' : { `` legacyModule '' : `` myVar '' } } | browserify-shim not exporting implicit globals when they are var scoped |
JS | In my code , I have something that boils down to this : ( In case you are wondering , I am later calling x ( ) and y may be defined as a function or it might not , so I do n't want a TypeError to be thrown if it is not . ) For some reason , this causes a SyntaxError : Unexpected token ) Why ? I found out thatworks just... | var x = y || ( ) = > { } ; var x = y || ( ( ) = > { } ) ; y || ( ) = > { } | Why does the logical or operator ( || ) with an empty arrow function ( ( ) = > { } ) cause a SyntaxError ? |
JS | I have 2 iFrames on my page . Both are draggable using jQuery UI . The iFrame that loads second is always the dominant one if both iFrames are dragged over the same space , ie . It covers up the first iFrame . Is there a way to set the iFrame in focus as the dominant iFrame so that if I am moving the first iFrame and d... | < a class = 'expandorcollapse3 ' href = ' # ' > Web Page 1 < /a > < br > < a class = 'expandorcollapse4 ' href = ' # ' > Web Page 2 < /a > < div id = 'iframetest1 ' style = 'display : none ' > < iframe id = 'iframe1 ' src = 'http : //www.wsj.com ' > < /iframe > < /a > < /div > < div id = 'iframetest2 ' style = 'display... | Multiple Draggable iFrames , Always Have iFrame in Focus Be On Top |
JS | I want to find all document 's created since midnight , regardless of the users timezone . If the users on Pacific time , it should show all their documents since midnight Pacific . Same with Eastern time . I 'm on Eastern time and this works for me : But my client is on CST and it does n't work for him . It instead sh... | var d = new Date ( ) ; var midnight = d.setHours ( 0,0,0,0 ) ; // last midnight var count = Items.find ( { username : Meteor.user ( ) .username , createdAt : { $ gt : midnight } } ) .count ( ) ; | Return documents created since midnight |
JS | I have an object like this : I want to convert to this : I have used this following method : But it only store the last key pair value as newData . That is I understand that it overwrite the previous data and store only the last data it get . But i ca n't solve this problem.Any Help ? | { `` A '' : [ `` -4927 '' , '' 8779 '' , '' -9971 '' , '' -23767 '' ] , `` B '' : [ `` -10617 '' , '' -1456 '' , '' 3131 '' , '' 259 '' ] , `` C '' : [ `` -5185 '' , '' 1168 '' , '' 21501 '' , '' 18989 '' ] , `` D '' : [ `` 2010 '' , '' 5664 '' , '' 2148 '' , '' -674 '' ] } [ { name : ' A ' , data : [ `` -4927 '' , '' ... | JavaScript : Convert object structure |
JS | So i 'm just starting to discover how awesome jquery is and how a basic function can drive me nuts to understand . I 'm trying to highlight a div with a specific `` id '' generated via backendSo if I hover over the `` id_1 '' Top , I want to highlight both the `` id_1 '' Top and Bottom . Below is a link to that so it '... | < br/ > < br/ > < br/ > < br/ > < div id= '' id_1 '' > < h2 > id_1 - < a class= '' marker_id_1 '' href= '' # top '' name= '' id_1 '' id= '' id_1 '' > Top < /a > < /h2 > < /div > < div id= '' id_1 '' > < h2 > id_1 - < a class= '' marker_id_1 '' href= '' # top '' name= '' id_1 '' id= '' id_1 '' > Bottom < /a > < /h2 > < ... | highlight specific divs ( tds ) onhover of a link |
JS | This is a continuation from my previous question.I managed to fixed the `` animation pauses every continuous keystrokes '' by adding a condition e.which === 13 , which detects and animate when the Enter key is pressed.This is how the previous one works : As you can see , after entering a newline then a continues of key... | var kAnimationSpeed = 250 ; var kPadding = 10 ; $ ( 'div [ contenteditable ] ' ) .on ( 'blur keyup paste input ' , function ( e ) { var styleElement = $ ( this ) .prev ( ) ; var editorHeight = $ ( this ) .height ( ) ; var styleElementHeight = styleElement.height ( ) ; if ( editorHeight ! == styleElementHeight - kPaddin... | Contenteditable height animation : animate only after a line is deleted |
JS | I am trying to get weinre working via Ajax by calling this on dom ready : Now , this is what is being sent : Which means that , for me to debug i have to use a randomly generated ID . I have tried this also : url : 'http : //debug.build.phonegap.com/target/target-script-min.js ? _=hutber ' , Just shooting in the dark.S... | $ .ajax ( { url : 'http : //debug.build.phonegap.com/target/target-script-min.js # hutber ' , dataType : `` script '' , crossDomain : true , error : function ( data ) { c ( data.status ) ; } , success : function ( data ) { c ( data ) ; } } ) ; http : //debug.build.phonegap.com/target/target-script-min.js ? _=1381476442... | Passing # values with ajax not working |
JS | i am using Google Dashboard 's table functionality , i want to assign value of id to tr of each row that is created , i have array as followsI am still unable to figure out if there is some way to bind values to DOM elements any help will be appreciated . | var data = google.visualization.arrayToDataTable ( [ [ 'Name ' , 'Donuts eaten ' , 'id ' ] , [ 'Michael ' , 5 , ' 1 ' ] , [ 'Elisa ' , 7 , ' 2 ' ] , [ 'Robert ' , 3 , ' 3 ' ] , [ 'John ' , 2 , ' 4 ' ] , [ 'Jessica ' , 6 , ' 5 ' ] , [ 'Aaron ' , 1 , ' 6 ' ] , [ 'Margareth ' , 8 , ' 7 ' ] ] ) ; var table = new google.vis... | how to assign values to TR in google dashboard table |
JS | Usually , when I want to check the type of an object ( whether it 's an array , a NodeList , or whatever ) , I use the following : The question is : why can I not do the following ? I do n't get where the syntax error is.I can do something approaching with [ ] though , the following works : So ... I 'm confused . | var arr = [ ] // I do n't do this , but it 's for the sake of the examplevar obj = { } obj.toString.apply ( arr ) // This works var arr = [ ] { } .toString.apply ( arr ) // Syntax error : Unexpected token . var nodeList = document.getElementsByClassName ( 'foo ' ) [ ] .forEach.call ( nodeList , function ( bar ) { conso... | Why does n't ` { } .toString.apply ( array ) ` work ? |
JS | In our team of JavaScript devs we have embraced redux/react style of writing pure functional code . However , we do seem to have trouble unit testing our code . Consider the following example : This function call depends on calls to process , extractBar and extractBaz , each of which can call other functions . Together... | function foo ( data ) { return process ( { value : extractBar ( data.prop1 ) , otherValue : extractBaz ( data.prop2.someOtherProp ) } ) ; } function foo ( data , deps = defaultDeps ) { return deps.process ( { value : deps.extractBar ( data.prop1 ) , otherValue : deps.extractBaz ( data.prop2.someOtherProp ) } ) ; } func... | How to test a tree of pure function calls in isolation ? |
JS | I have an array of objects . I want to get the max out of the number attribute from the array : I 'm using this solution but I keep getting NAN : My goal is to get the max and then store it in a variableHow would I achieve it with reduce ? It seems like it is only working with array of numbers . | [ { number : 1000 , name : `` Josh '' } , { number : 2000 , name : `` Joker '' } , { number : 3000 , name : `` Batman '' } ] const max = arr.reduce ( ( a , b ) = > Math.max ( a.number , b.number ) ) ; const x = { number : 3000 , name : `` Batman '' } | How to do reduce math.max to an array of objects |
JS | I 'm writing a binary string from the server like this : and reading it with js and jDataView lib this way : The problem is that I can only read the values that are less than 128. jDataView uses getCharCode at to read Uint and it returns 65533 for each of the bigger values.How to I get the values in js ? | header ( 'Content-type : application/octet-stream ' ) ; echo $ data = pack ( ' C* ' , 0 , 10 , 100 , 127 , 128 , 200 , 250 , 255 , 256 ) ; $ .get ( '/get ' , function ( text ) { var view = new jDataView ( text ) ; for ( var i = 0 ; i < 20 ; i++ ) { console.log ( i , view.getUint8 ( i ) ) ; } } ) ; | How to read unsigned int in Javascript ? |
JS | I need help making a jQuery plugin for one of my vanilla JS scripts , this here is the current jQuery plugin , but the next version works with more methods and I need to address them all somehow.Currently I was working on thisWhy t [ method ] ( ) does n't work and how can I make it work ? UPDATE : I am adding here some... | ( function ( $ ) { var t ; $ .fn.KUTE = function ( method , start , end , ops ) { // method can be Animate ( ) , fromTo ( ) , to ( ) , stop ( ) , start ( ) , chain ( ) , pause ( ) , stop ( ) , etc return this.each ( function ( ) { if ( method === 'to ' ) { t = new KUTE [ method ] ( this , null , end , ops ) ; } else if... | Javascript : object [ method ] ( ) not working or how to build a jQuery plugin for a plain Javascript code |
JS | I 've got an object like : I want to reduce the duplicates like : What 's a good way to do that ? A few caveats : There will only ever be a small number of pairs . ( Currently there are 7 ; I could imagine it going up to , say , 20 . ) The initial property names will only ever be a single character , like in the exampl... | { a : 'foo ' , b : 'bar ' , c : 'foo ' , d : 'baz ' , e : 'bar ' } { ac : 'foo ' , be : 'bar ' , d : 'baz ' } | reduce duplicate in a javascript object |
JS | I need to know how to check the variable if its an Array or its an ObjectIs there any way to tell the difference between the two types ? | var arr = [ 'foo ' , 'bar ' ] ; var obj = { 0 : 'foo ' , 1 : 'bar ' } document.write ( 'arr is an : ' + typeof arr + ' , obj is an : ' + typeof obj ) // The result is always : // arr is an : object , obj is an : object | In JavaScript how to detect weather the type is Array or Object ? |
JS | i want to figure out how to properly calculate vizibility zone and draw it using d3.geo projections . visibility zone in my case is optical camera frustumfor now , i have a two plots , both represent azimuth and elevation from view point , one in gnomonic ( according to wiki ) projection : Width and height below is a o... | // this magic number is experimentally found //pixels in one degree in gnomonic projection chart with scale 1500var px = 26.8 ; var w = px * viewport.width ; var h = px * viewport.height ; d3.geoGnomonic ( ) .translate ( [ w / 2 , h / 2 ] ) .scale ( 1500 ) var d3 = window.d3 ; var colorGenerator = d3.scaleOrdinal ( d3.... | d3.js visibility-zone calculations or how to draw geo rectangle |
JS | I have a sequence of divs with some similar data-attributes . I would like that when the user selects the checkbox , the divs corresponding to it appear when checked.The code works to show divs , but when the checkbox is not selected , divs keep showing up.How to make the divs hide when unchecked and keep the other sho... | .letters { display : none ; } < div > < div class= '' letters '' data-text= '' b '' > B < /div > < div class= '' letters '' data-text= '' b '' > B < /div > < div class= '' letters '' data-text= '' b '' > B < /div > < div class= '' letters '' data-text= '' a '' > A < /div > < div class= '' letters '' data-text= '' b '' ... | Show/Hide divs with data-attribute based on checkboxex checked |
JS | I am trying to position a < div > above a users text selection that will act as a toolbar similar to Mediums.While I have successfully gotten the < div > to be positioned next to the selection , I can not seem to get it to correctly center relative to the selection : I can determine the selection 's center point by sub... | $ ( function ( ) { // Setup the Event Listener $ ( '.article ' ) .on ( 'mouseup ' , function ( ) { // Selection Related Variables let selection = window.getSelection ( ) , getRange = selection.getRangeAt ( 0 ) , selectionRect = getRange.getBoundingClientRect ( ) ; // Set the Toolbar Position $ ( '.toolbar ' ) .css ( { ... | JavaScript : Position DIV Centered Above Text Selection ? |
JS | In Javascript , i can bind this to another function and invoke it with .call or .applyIn PHP , i can do that with call_user_func or call_user_func_array , but how can i bind $ this into the function ? Javascript : PHP : UPDATE : Thanks @ deceze for the Reflection idea , I 've found these solutions but I do n't think it... | function greet ( ) { alert ( 'Hello ' + this.name ) ; } function SomeClass ( ) { } SomeClass.prototype = { name : 'John ' , test : function ( ) { greet.call ( this ) ; } } var me = new SomeClass ( ) ; me.test ( ) ; // Hello John function greet ( ) { echo 'Hello ' . $ this- > name ; } class SomeClass { public $ name = '... | PHP call_user_func bind thisArg like Javascript call |
JS | I placed scrollIntoView ( ) to make my grid scroll visible . When I add new grid in gridContainer so I using this method . This is working I can check from debugger . my scrollIntoView ( ) But once it reached in defer function it not scrollIntoView ( ) functioning . Can anybody please suggest how to skip this . What de... | grid.body.dom.scrollIntoView ( ) ; defer : function ( fn , millis , scope , args , appendArgs ) { fn = Ext.Function.bind ( fn , scope , args , appendArgs ) ; if ( millis > 0 ) { return setTimeout ( function ( ) { if ( Ext.elevateFunction ) { Ext.elevateFunction ( fn ) ; } else { fn ( ) ; } } , millis ) ; } fn ( ) ; ret... | What exactly defer do ? |
JS | When coding ReactJS I have to supply keys for dynamic children . For example : I understand why they keys are there . But why do I have to give them ? Could n't react just assign a running number or UUIDv4 or something else ? Related doc : http : //facebook.github.io/react/docs/multiple-components.html # dynamic-childr... | render ( ) { const { options } = this.state const availableOptions = options.map ( opt = > { return ( < option key= { opt.id } value= { opt.id } > { opt.displayValue } < /option > } ) } return ( < select onChange= { this._onOptionSelect } > { availableOptions } < /select > ) } | Why does n't ReactJS autogenerate keys for dynamic children ? |
JS | Updated Working FiddleOriginal questionI was wondering why I cant get a message with the `` dragstart '' from the circle in this code ... I cant get the message `` circle '' when its dragged . I tried , with some working code from http : //www.html5canvastutorials.com . In this code : http : //www.html5canvastutorials.... | < ! DOCTYPE html PUBLIC `` -//W3C//DTD XHTML 1.0 Transitional//EN '' `` http : //www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd '' > < html xmlns= '' http : //www.w3.org/1999/xhtml '' > < head > < meta http-equiv= '' Content-Type '' content= '' text/html ; charset=utf-8 '' / > < title > Untitled Document < /title > <... | html5 , dragstart from object in a group |
JS | I found this in a piece of code and i 'm wondering what it does ? Assign b to x ... but what 's with the , c ? | var x = b , c ; | What does a comma do in assignment statements in JavaScript ? |
JS | How can I separate in sections a document with headings ? Convert thisinto thisI guess with jQuery this is easy , but I have n't figured how yet . | < h1 > chapter 1 < /h1 > < p > lorem ipsum < /p > < p > sit amet < /p > < h1 > chapter 2 < /h1 > < p > lorem ipsum < /p > < p > sit amet < /p > < div class= '' chapter '' > < h1 > chapter 1 < /h1 > < p > lorem ipsum < /p > < p > sit amet < /p > < /div > < div class= '' chapter '' > < h1 > chapter 2 < /h1 > < p > lorem ... | Separate an HTML document with headings into sections |
JS | Possible Duplicate : Do var fn = function ( ) { … } and var fn = function foo ( ) { … } ever differ ? From hereWhat is the difference between a function expression vs declaration in JavaScript ? I understand that there is a difference between declaring functions and declaring them as variables.But It 's not clear if th... | var func_name = function ( param , param1 ) { ... } ; var func_name = function func_name ( param , param1 ) { ... } ; | Javascript function definition |
JS | the result of the following statement should give 9 : ( using java or js or c++ ) but in php the same statements will give 12 ? ! is this a bug or can anyone explain why ? | i = 1 ; i += ++i + i++ + ++i ; //i = 9 now $ i = 1 ; $ i += ++ $ i + $ i++ + ++ $ i ; echo $ i ; | pre-increment and post-increment in PHP |
JS | I try to use swipe-pages by template repeat . In the polymer I wroteIt give me the error I cant get it work . Also use does not work . in this case it throws exception that their is 0 pages.I think that the the swipe-pages does not receive the input after the template repeat run.If I write it not by template it works o... | < swipe-pages > < template is= '' dom-repeat '' items= '' { { values } } '' > < swipe-page > < div > Text to swipe < /div > < /swipe-page > < /template > < /swipe-pages > created : function ( ) { console.log ( this ) ; this.values = [ 1,2,3 ] ; } Uncaught TypeError : Can not set property 'values ' of undefined Polymer.... | Polymer swipe-pages create by repeat |
JS | Taking the following pseudo codeIs the console.info : -A . Guaranteed to display 'bar ' B . Guaranteed to display 'undefined ' C . Indeterminatei.e . even though the write to disc is async , will a synchronous read be resolved from a buffer internal to indexeddb and/or localforage ? | localforageStore.setItem ( 'foo ' , 'bar ' ) .then ( console.log ( 'foo is persisted to disk ' ) ) ; localforageStore.getItem ( 'foo ' ) .then ( v = > console.info ( 'foo is '+v ) ) ; // A , B or C ? | are indexeddb/localforage reads resolved from a synchronous buffer ? |
JS | I have the following running code in JavaScript 's Plottable.js . As stated in the image below , how can I modify my Javascript code so that it can include the horizontal line at y=2 ? | var data = [ { x : 1 , y : 1 } , { x : 2 , y : 3 } , { x : 3 , y : 2 } , { x : 4 , y : 4 } , { x : 5 , y : 3 } , { x : 6 , y : 5 } ] ; var xScale = new Plottable.Scales.Linear ( ) ; var yScale = new Plottable.Scales.Linear ( ) ; var xAxis = new Plottable.Axes.Numeric ( xScale , `` bottom '' ) ; var yAxis = new Plottabl... | How to add horizontal line over y-axis in Plottable.js |
JS | General setupI am building a small website with webpack and pug based on this awesome boilerplate : https : //github.com/alexnoz/webpack-pug-scss-boilerplate.gitThe project is up and running and I am able to render pug files correctly.RequirementNow I need to load some data before all the webpack compiling happens . I ... | // in webpack.config.jsvar myData = [ ] loadSomeDataAsync ( ) .then ( loadedData = > myData = loadedData ) { loader : 'pug-html-loader ' , options : { data : myData // < ==== } } | Pass asynchronously loaded data to pug-html-loader in webpack |
JS | Hi I 'm trying to author a jQuery plugin and I need to have methods accessible to elements after they are initialized as that kind of object , e.g . : I tried withand several other different attempts , I just ca n't figure out how to do it.EDIT : I 'll try to explain this better.I 'm trying to turn a table into a list ... | $ ( '.list ' ) .list ( { some options } ) ; //This initializes .list as a list//now I want it to have certain methods like : $ ( '.list ' ) .find ( 'List item ' ) ; //does some logic that I need $ .fn.list = function ( options ) { return this.each ( function ( ) { // some code here this.find = function ( test ) { //fun... | Creating methods on the fly |
JS | here is my codewhen i click on the button her here is more info on request i have to add some more info to be able to post the question , so here it is | $ ( document ) .on ( 'click ' , ' # global-search-button ' , function ( ) { $ .pjax ( { url : `` http : //localhost/project/brows '' , container : ' # pjax-container ' , timeout : 9000000 , } ) } ) ; Request URL : http : //localhost/project/brows ? _pjax= % 23pjax-containerReferrer Policy : no-referrer-when-downgradePr... | pjax request change status to canceled as soon as it fires |
JS | After digging several hours we decided to come up with a question on SO , hoping that someone else could help regarding the following problem.For one of our web applications , we used the Onsen UI js framework with its React support library When we try to render the application on our dev environments everything seems ... | | -- -- -- -- -- -- -- -- | -- -- -- -- -- -- -- -| -- -- -- -- -- -- -- || HTML attribute | DEV ENV | STAGING ENV || -- -- -- -- -- -- -- -- | -- -- -- -- -- -- -- -| -- -- -- -- -- -- -- || fixed-content | fixed-content | fixedcontent || -- -- -- -- -- -- -- -- | -- -- -- -- -- -- -- -| -- -- -- -- -- -- -- || active... | Why are HTML attributes set differently into the DOM ? |
JS | I am using the youtube api to search for youtube videos . The videos will then be displayed on # searchBar with the video id ex . NJNlqeMM8Ns as data-video . I get the video id by pressing on a img : Which in my poorly understanding of javascript becomes ( this ) .When I search for videos I will get more than one resul... | < img data-video = `` { { videoid } } '' src = `` bilder/play.png '' alt = `` play '' class = `` knapp '' width = `` 40 '' height = `` 40 '' > $ ( `` .knapp '' ) .click ( function ( ) { var index = $ ( `` .knapp '' ) .index ( this ) ; alert ( index ) ; } ) ; function onPlayerStateChange ( event ) { if ( event.data == Y... | Index of object and play next with youtube api |
JS | I am working on a parser combinator library in JavaScript . For that I want to create functions that can be called like any other functions , but also have member functions that can be called in turn to produce output based on the function they are attached to ( e.g . combinators ) .I can of course add members to funct... | //the functions I want to add additional members tofunction hello ( x ) { return `` Hello `` + x ; } function goodbye ( x ) { return `` Goodbye `` + x ; } //The function I want as a member of the above functions.//it creates another function based on the function it is //attached to.function double ( ) { var that = thi... | Is it possible to create a function with another prototype than Function.prototype ? |
JS | Please forgive me if this is very simple but I am not be able to find out the work around to solve the issue.I am trying to open ESRI map in a bootstrap modal . On the first time it does n't load the map ( in console I see the error `` require is not defined '' ) but second time it works fine . If I open the map in a s... | @ { < link rel= '' stylesheet '' href= '' https : //js.arcgis.com/3.21/dijit/themes/claro/claro.css '' > < link rel= '' stylesheet '' href= '' https : //js.arcgis.com/3.21/esri/css/esri.css '' > < script src= '' https : //js.arcgis.com/3.21/ '' > < /script > < script > var map ; require ( [ `` esri/map '' , `` dojo/par... | Bootstrap modal require is not defined for ArcGIS server map |
JS | Let 's say I want to combine a bunch of Javascript and Julius file . I do it like this : But the problem with the above approach is that Yesod takes all the Julius file in the widget and converts them to a single file ( autogen-xxx.js ) and appends it at the end . Although this is a good optimization , this breaks my J... | jsWidget : : WidgetjsWidget = do addScript $ StaticR js_test1_js toWidget $ ( juliusFile `` static/js/gis/sample.julius '' ) addScript $ StaticR js_test2_js addScript $ StaticR js_test3_js | Yesod : Maintaining order of JavaScript and Julius Files |
JS | The problem in this case : I just add { key : 123 , value : 100 } to myset , why does n't it contain { key : 123 , value : 100 } ? Another case , if I use obj instead of { key : 123 , value : 100 } , it would return true.Set.prototype.has ( ) says : The has ( ) method returns a boolean indicating whether an element wit... | var myset = new Set ( ) ; myset.add ( { key : 123 , value : 100 } ) ; var has = myset.has ( { key : 123 , value : 100 } ) ; console.log ( has ) ; // false var obj = { key : 456 , value : 200 } ; myset.add ( obj ) ; has = myset.has ( obj ) ; console.log ( has ) ; // true has = myset.has ( x = > x.key === 123 ) ; console... | Set.prototype.has ( ) with predicate |
JS | I am starting a new Angular project and trying to modularize all of my code – I 'm tired of having massive app.js files and , because I 'm developing a platform for a company , it 's important my code is neat and modularized for easy testing , cleanliness , and ease of transition to Angular 2.Currently , I have three a... | angular .module ( 'app ' , [ /* Shared Modules */ 'app.config ' , 'app.states ' /* Feature Areas */ ] ) angular .module ( 'app ' , [ /* Angular Modules */ 'ngResource ' , 'ngSanitize ' , /* 3rd-party Modules */ 'ui.router ' ] ) ; angular .module ( 'app ' ) .config ( [ ' $ stateProvider ' , ' $ urlRouterProvider ' , ' $... | Modularizing Angular |
JS | i have a json data from my server : look exactly like the documentation ( https : //guides.emberjs.com/v2.5.0/models/handling-metadata/ ) i try to get the meta object with no success | { `` post '' : { `` id '' : 1 , `` title '' : `` Progressive Enhancement is Dead '' , `` comments '' : [ `` 1 '' , `` 2 '' ] , `` links '' : { `` user '' : `` /people/tomdale '' } } , `` meta '' : { `` total '' : 100 } } export default Ember.Route.extend ( { model ( ) { var data = this.store.findAll ( 'post ' ) ; data.... | ember js get meta informations from json |
JS | So , I 'm trying to parse some JSON in Javascript . This feels like it should work , but I 'm getting an error . Here 's the function call : And here 's the errorI 'm trying this on an empty web page , no JS libraries are present.The string , just executed as Javascript creates an object with the two expected attribute... | JSON.parse ( `` { player : 'green ' , direction : 'north ' } '' ) ; VM156:1 Uncaught SyntaxError : Unexpected token p in JSON at position 1 at Object.parse ( native ) at < anonymous > :1:6 | JSON.parse , what am I doing wrong ? |
JS | I have a completely static site - index.html and some CSS/JS/PNG files . I 'd like to use a service worker to cache all of them . It seems that Workbox should make this easy . Here 's my sw.js : And here 's my build script : That all seems to work fine . The build script runs , the service worker is activated , and my ... | importScripts ( 'https : //storage.googleapis.com/workbox-cdn/releases/3.5.0/workbox-sw.js ' ) ; workbox.precaching.precacheAndRoute ( [ ] ) ; workbox.routing.registerNavigationRoute ( '/index.html ' ) ; const workboxBuild = require ( `` workbox-build '' ) ; // NOTE : This should be run *AFTER* all your assets are buil... | How do I actually display my updated index.html from Workbox ? |
JS | I 've got two arrays in Javascript which currently look like this , but are updated by HTTP requests ( node ) : I 'm looking to compare these arrays , so that , if there is an array inside y that is not in x , it will be saved to a new array - z . Note that sometimes the order of arrays inside the arrays will change , ... | var x = [ [ 292 , '' 2349 '' , '' 902103 '' , '' 9 '' ] , [ 3289 , '' 93829 '' , '' 092 '' , '' 920238 '' ] ] var y = [ [ 292 , '' 2349 '' , '' 902103 '' , '' 9 '' ] , [ 322 , '' 93829 '' , '' 092 '' , '' 920238 '' ] , [ 924 , '' 9320 '' , '' 8932 '' , '' 4329 '' ] ] | Comparing two arrays in Javascript |
JS | If I have html like the following on my own site how come it is able to track the event ? Is it possible that browser starts loading the http : //google.com in the same window before the tracking request is made as it is asynchronous ? In case of using the synchronous API the browser obviously waits until the script in... | < a href= '' http : //google.com '' onclick= '' _gaq.push ( [ '_trackEvent ' , 'category ' , 'event ' ] ) ; '' > click < /a > | How google analytics ' asynchronous api is able to track clicking links |
JS | Are there any standard rules for implementing predefined events in a jQuery plugin ? For example , the special case of Zebra Accordion plugin ( a tiny accordion plugin for jQuery ) or any other plugin defines some events like below : Zebra Accordion Events : onClose : Event fired after a tab is collapsed.onOpen : Event... | $ ( '.Zebra_Accordion ' ) .on ( 'onOpen ' , function ( e ) { $ ( this ) .append ( `` < span class='fa fa-chevron-down ' > < /span > '' ) ; } ) ; $ ( '.Zebra_Accordion ' ) .off ( 'onClose ' , function ( e ) { $ ( this ) .append ( `` < span class='fa fa-chevron-up ' > < /span > '' ) ; } ) ; | How can I use jQuery for predefined events ? |
JS | I need to order an array of objects , composed by a name and a dependencies list ( made out of names ) .An example of this array could be : I 'd like this array to be sorted so that the items which require a specific set of dependencies will be positioned after its required dependencies.The array could actually contain... | [ { name : ' a ' , requires : [ ' b ' , ' c ' ] } , { name : ' b ' , requires : [ ' c ' ] } , { name : ' c ' , requires : [ ] } , ] [ { name : ' c ' , requires : [ ] } , // first , no dependencies , and required by both the others { name : ' b ' , requires : [ ' c ' ] } , // second , because it needs ` c ` first { name... | Order array of objects based on dependencies list ? |
JS | I need to split a CSS class names string into array of CSS class names in JavaScript . All the below strings should produce the same array.Currently I 'm using code to do that , But I believe regex would be a better solution that this right ? I got this regex by googling / ( [ ^ , ] + ) but the result array has spaces ... | 'lmn-button , lmn-button-primary ' = > [ 'lmn-button ' , 'lmn-button-primary ' ] 'lmn-button , lmn-button-primary ' = > [ 'lmn-button ' , 'lmn-button-primary ' ] // Note the space after comma'lmn-button , lmn-button-primary ' = > [ 'lmn-button ' , 'lmn-button-primary ' ] // Note the space before comma ' lmn-button , lm... | Regex to split a comma separated css class names string into array |
JS | The variable logincompare_user is taken from login that gives us the position where the user is in a list and their corresponding money will be in that same position in the ahorros and monetaria lists . Why this subtract is n't working ? | var ahorros = [ 5000,6000,10000 ] ; var monetaria = [ 2000,15000,1000 ] ; var registro = [ ] ; function transferencias ( ahorros , monetaria , registro , logincompare_user ) { var cta_ahorro = ahorros [ logincompare_user ] ; var cta_monetaria = monetaria [ logincompare_user ] ; registro.push ( `` Entrada a Transferenci... | Javascript - Ca n't subtract Ints after converting with ParseInt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.