Posts

Showing posts with the label javascript

Creating React component vs using CSS styling

Creating React component vs using CSS styling I have created a tab menu using CSS styling that I use in several different spots in my ReactJS app. .tab { overflow: hidden; border: 1px solid #ccc; background-color: #f1f1f1; margin: 0; padding: 0; } .tab button { background-color: inherit; float: left; border: none; outline: none; cursor: pointer; padding: 14px 16px; transition: 0.3s; } .tab button:hover { background-color: #ddd; } .tab button:disabled { background-color: #ccc; cursor: default; } .tabcontent { display: none; padding: 6px 12px; border: 1px solid #ccc; border-top:none; } This is in a index.css file that sits with all my .js files. Within my React code I use it like this, as an example: index.css .js <table><tbody> <tr className="tab"><td> <button onClick={() => this.openTab(0)}>Tab 1</button> <button onClick={() => this.op...

ECharts: Disable default click action on legends

ECharts: Disable default click action on legends I'm trying to use ECharts to render a simple doughnut chart which I've been able to do. I've noticed by default that the legend will hide the data item on the chart if it is clicked. I want the user to be able to select the legend to do something (fire an event) which I can do using the events available (https://ecomfe.github.io/echarts-doc/public/en/api.html#events.legendselected) however I want to prevent the default behaviour of hiding/showing the data item on the chart. In the documentation there is mention of a property on the legend called selectedMode (https://ecomfe.github.io/echarts-doc/public/en/option.html#legend.selectedMode), which prevents the toggling of the series, but it also stops the legend from being selectable entirely. I've also tried returning false on the events fired for legendselected and legendunselected but to no success. Has anyone found a way of stopping this behaviour? I'd appreciate any...

Prevent Page navigation - SweetAlert

Prevent Page navigation - SweetAlert I'm trying to replace the JS box dialog with sweet alert dialog box. At normal cases, it works perfectly. But, at the time of navigating the page on confirmation. It didn't work. JS box : var confirm = window.confirm("Warning! You may have unsaved data,it will be lost..!" + "n" + "Are you sure want to leave this page ?"); if (confirm) { $scope.$eval(event); //It prevents the page to nav ,until i confirm it. } else { event.preventDefault(); } It works. In case of sweetalert , I'm using the same scenario sweetalert $scope.validation = function(event) { //.... sweetAlert({ title: "Are you sure?", //Bold text text: "Your will not be able to recover this imaginary file!", //light text type: "warning", //type -- adds appropiriate icon showCancelButton: true, // displays cancel btton confirmButtonColor: "#DD6B55", ...

global is not defined while using socket.io-client with webpack

global is not defined while using socket.io-client with webpack I am getting following error when i have added socket.io-client plugin in my React web app. socket.io-client Uncaught ReferenceError: global is not defined at Object../node_modules/socket.io-parser/is-buffer.js (is-buffer.js:4) at webpack_require (bootstrap:22) at Object../node_modules/socket.io-parser/binary.js (binary.js:8) at webpack_require (bootstrap:22) at Object../node_modules/socket.io-parser/index.js (index.js:8) at webpack_require (bootstrap:22) at Object../node_modules/socket.io-client/lib/index.js (index.js:7) at webpack_require (bootstrap:22) at Object../src/client/components/gettingStarted/socketest.js (socketest.js:1) at webpack_require (bootstrap:22) The following is my webpack config file. /*eslint-disable*/ var Path = require('path'); var HtmlWebpackPlugin = require('html-webpack-plugin'); var FileChanger = require('webp...

CORS issue in Twitter OAuth API [duplicate]

CORS issue in Twitter OAuth API [duplicate] This question already has an answer here: I am implementing twitter signin in angular5. To get access token from client side i am following https://developer.twitter.com/en/docs/twitter-for-websites/log-in-with-twitter/guides/implementing-sign-in-with-twitter I am getting Cross Origin error on accessing twitter apis. Failed to load https://api.twitter.com/oauth/request_token: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:4200’ is therefore not allowed access. The response had HTTP status code 400. This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. 1 Answer 1 The guide you are following is designed for use with server-side code. It will not work f...

Observable fires only once

Observable fires only once I decided to pick up this RxJS tutorial over the weekend to learn about reactive programming. The goal is to set up a simple page that generates an interactive list of users from the Github users API using Observables. The list displayed is a subset of the total number of users retrieved (in my case 3 out of 30). The list needs to be refreshable (show a new set of users), and you need to be able to remove entries from it by clicking the 'remove' button on each respective entry. I've set up a chain of Observables to define the behavior of the page. Some act as events to trigger processing, and some publish processed results for use in the app. This chain should dynamically cause my list to be updated. Currently, the default flow is like this: A list update is triggered on startup, by refreshing the list and by removing something from the list. However, when I refresh the list, this happens: As you can see, the trigger to update the list of users is...

Animation is not working for multiline chart D3 v4

Animation is not working for multiline chart D3 v4 I have created a line chart. Now i am trying to add animations in it. Line chart is multi line chart. When i try to put animation in both lines , code is not working and when i comment animation code of second line , then it works for first line. Animation in both lines together is not working. Here is the link of codepen - link In codepen link "code of second line(animation) is commented" code: <html> <head> <meta charset="utf-8" /> </head> <body> <div id="lineChartGph" class="lineChartGph"></div> <script src="https://d3js.org/d3.v4.min.js"></script> <script> initLineChart(); function initLineChart(){ // set the dimensions and margins of the graph var margin = {top: 20, right: 40, bottom: 30, left: 50}, width = 450 - margin.left - margin.right, hei...

Compare user response with string using javascript for quizz

Compare user response with string using javascript for quizz I have a input field for the user who's listening a music and try to find the correct artist or track name. <input type="search" id="search" class="form-control form-control-lg" name="search" autocomplete="off" autofocus> i would like to it compare with two javascript variables : The problem is to handle human typing errors. ex : "alicia key falin" should return true for the artist and the track name. I have already tried scripts about Hamming Distance and also the fusejs library but i'm not convainced by the result. Actual tests : function hammingDistance(str1, str2) { var dist = 0; str1 = str1.toLowerCase(); str2 = str2.toLowerCase(); for (var i = 0, j = Math.max(str1.length, str2.length); i < j; i++) { if (!str1[i] || !str2[i] || str1[i] !== str2[i]) { dist++; } } return dist; } The objective being to prevent capital, low...

Why wont my calculator function complete the math?

Why wont my calculator function complete the math? Hi so I'm having trouble figuring out why my function will do the division but leave the multiplication as an array without completing the math. Here's the code: const mathObj = { "*": function(a , b) {return a * b}, "/": function(a , b) {return a / b}, "+": function(a , b) {return a + b}, "-": function(a , b) {return a - b} } const arr = [ 10, "/" , 2 , "*" , 10 , "/" , 2 ]; function solveTheMath(arr) { const len = arr.length; for(let i = 0 ; i < len ; i++){ if(arr[i] === "/" || arr[i] === "*"){ const sliced = arr.slice(i - 1 , i + 2); var mathResult = mathObj[arr[i]](sliced[0], sliced[2]); arr.splice(i - 1 , 3, mathResult); console.log(arr); //[5*5] } } } solveTheMath(arr); Why does...

Validate date field on focusout with jquery-validation

Validate date field on focusout with jquery-validation Date Input Field not valid, When first time selecting the date. Its showing required error message, because of field have an empty value( check console log ). But field will be valid on second change. Notes: A cause is that date input field loses focus when picking the date (click event). But the date populates only later changed when the click event happens. But validator will validate field on focus out event. I'm validating a form using Jquery Validation, using bootstrap-datepicker for Widget. ^^for Better UX Run code snippet on full-page ;) or jsfiddle from @Sparky / @Vignesh ans: Yes, its a workaround for this, We can use change/hide/changeDate(module attribute) event handler. It gets triggered once the input values have been set. But the problem is whenever we pick from year->month->date each clicks in the picker, removes focus from input and focusout event fired and showing the error message until choosing ...

Slick slider different autoplay for each slide

Slick slider different autoplay for each slide I have a slick carousel with both an image and a video, I have it so when it reaches the video it autoplays and when it finishes it goes to the image. What I would like is to have autoplay and autoplay speed only for the image and not for the slide with the video as when the video finishes it's waiting for the autoplay speed to finish and then move to the image which doesn't look right. Is there a way to set the autoplay speed to 0 for the video slide...You can see the carousel in action here: http://foley13.webfactional.com/grid-website/carousel-test/ Here is my javascript for the slider: jQuery(function($){ var slider = $('.homeslider').slick({ slidesToShow: 1, slidesToScroll: 1, arrows: false, fade: true, autoplay: true, autoplaySpeed: 1000, initialSlide: 1, }); slider.on('afterChange', function(event, slick, currentSlide) { var vid...

EventListener is not work [duplicate]

EventListener is not work [duplicate] This question already has an answer here: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>I need Help</title> <style media="screen"> .try { padding: 3em; background: #B51C35; text-align: center;} .try a { display: inline-block; padding: 0 .5em; font-size: 2em; font-weight: 900; color: #FFFCED; text-decoration: none; border: 5px solid #FFFCED;} </style> </head> <body> <div class=""> <h3 style="text-align:center;">The event in the console was worked but remove Attribute is not work!! <br />I just need the advice or if you can told me why is not working? </h3> </div> <div class="try movemaus"> <a href="#">Book Now!</a> </div><!-- ...

Keeping newline n as is in JavaScript object

Keeping newline n as is in JavaScript object I want to keep string values in my insert object as is This works fine, the n is kept {insert: "erferferfnerferferf"} This {insert: "nnn"} And this becomes a problem {insert: "n"} it makes the string like this {insert: " "} I want the string to keep the "nnn" rather than becoming a bunch of new lines try using .trim() , it may solve your problem. – Raghav Garg Jul 2 at 9:49 .trim() Possible duplicate of How to escape special characters in building a JSON string? – Islam Elshobokshy Jul 2 at 9:51 JSON.stringify("nnn").slice(1, -1) – Keith ...

How to count occurrences of a path in an array of objects with ramda.js?

How to count occurrences of a path in an array of objects with ramda.js? I'm trying to use ramda.js to count occurrences of a key-value pair inside an array of objects, such as: ramda.js var array = [ {a: {b: 'a'}}, {a: {b: 'a'}}, {a: {b: 'X'}}, {a: 'a'} ] If I wanted to count the number of times {a: {b: 'a'}} occurs inside of array in ramda.js , what would I do? {a: {b: 'a'}} array ramda.js Think in terms of these steps: [1] R.pathEq to check whether an array element matches [2] R.map to check every element of the array, converting it to true or false [3] Number can be used as a function to convert from true to 1 and false to 0 [4] R.sum to tally up all the 1 s in the array Let me know if you need more assistance than the above and I can provide a complete solution. – Scott Christopher Jul 2 at 9:24 ...

No rounded corners on React-Bootstrap-NavItem

No rounded corners on React-Bootstrap-NavItem I want to have the same look as the pills style but without the rounded corners pills this is what i have so far <style type="text/css">{` .nav-pills > li + li { border-radius: 0 !important; } `}</style> <Nav bsStyle="pills" justified activeKey={this.props.currentStep} onSelect={this.updateCurrentStep.bind(this)} > <NavItem eventKey={1} title="Template">Template</NavItem> <NavItem eventKey={2} title="Edit">Edit</NavItem> <NavItem eventKey={3} title="Preview">Preview</NavItem> </Nav> How do I set the border-radius of my NavItem to 0? It does appear in the rules of the li item but it does not change anything. border-radius NavItem li 2 Answers 2 There are many different (and arguably better) ways to handle...