Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I know how to set colour of placeholder, but what if I need to find out what's colour of placeholder on some page? I cannot find this property with Chrome Devtools. ColorZilla doesn't help either.
It seems you can't access the pseudo placeholder attribute's CSS in DevTools. You can only get the text value using getAttribute('placeholder') in JavaScript.
However, it is possible to view the style properties using JavaScript instead of manually finding them in the CSS files. This is not ideal, but I created a general purpose function that allows you to specify the selector (or part of the selector), and the attribute you are looking for, and it will loop through all the stylesheets and log a table to the console.
function getSelectorStyle(selector, attribute) {
var rules = [];
function CSSRule(sheet, selector, value) {
this.sheet = sheet;
this.selector = selector;
this.value = value;
}
var styleSheets = document.styleSheets;
for (var i = 0; i < styleSheets.length; i++) {
var currentSheet = document.styleSheets[i];
if (currentSheet != null) {
var ruleList = currentSheet.cssRules;
if (ruleList != null) {
for (var j = 0; j < ruleList.length; j++) {
var currentRule = ruleList[j];
if (currentRule.selectorText != null) {
if (currentRule.selectorText.indexOf(selector) != -1) {
var sheetLocation = currentSheet.href ? currentSheet.href : "inline-css";
var item = new CSSRule(sheetLocation, currentRule.selectorText, currentRule.style[attribute]);
rules.push(item);
}
}
}
}
}
}
console.table(rules)
}
getSelectorStyle("placeholder", "color");
Update:
In terms of your problem with the colour not matching with the Amazon site, as per the comments below, it appears that the selector .form-control::-webkit-input-placeholder is not applied. The input field isn't contained in form-control. The default placeholder colour is applied instead, which is #A9A9A9 (in Chrome at least), which is what you are seeing.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
What I'm trying to do is conditionally display a div based on user input. I'd like to parse through the input and if it contains somewhere within it (The input could be a whole paragraph) one of several keywords that are in an array, then it will return true and display the div. This is what I have so far:
jQuery(function($) {
$(".conditional-content-container").hide());
var user_input = $(":input[name=input_4]");
user_input.change(function() {
if (user_input.val().indexOf(["hello", "world", "foo"]) !== -1) {
$(".conditional-content-container").show();
} else {
$(".conditional-content-container").hide();
}
});
});
<div class="conditional-content-container">
Content to be displayed if user input contains the words "hello" or "world" or "foo" somewhere within it
</div>
You need to loop over the array and check if they exist in the string
var words = ['apple', 'foo', 'bar']
function hasAnyWords(str) {
return words.some(word => str.indexOf(word) > -1);
// return words.some(function(word){
// return str.indexOf(word) > -1;
//});
}
function hasAllWords(str) {
return words.every(word => str.indexOf(word) > -1);
// return words.every(function(word){
// return str.indexOf(word) > -1;
//});
}
console.log(hasAnyWords('I like an apple'));
console.log(hasAnyWords('I like a pear'));
console.log(hasAllWords('I like an apple'));
console.log(hasAllWords('I like a bar foo apple'));
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am trying to make a Calendar of my own
https://stackblitz.com/edit/angular-1kfbod?file=src/app/app.component.css
This is a full example of my component.
How can I merge the week divs that have the same value {{day.weekNumber}} (one div instead of 4 for the example below)?
In your case, you should have separate array for your week numbers.
Typescript
public weekNumbers: number[] = [];
public rowWidth: any = 100 + '%';
ngOnInit() {
...
... // your existing code
...
let weeks = [];
for (let i = 1; i <= this.numberOfDaysCurrentMonth; i++) {
this.daysToDisplayInCurrentMonth[i - 1] = new Date(this.currentYear, this.currentMonth - 1, i).getDay();
const day = {
number: i,
weekDay: new Date(this.currentYear, this.currentMonth - 1, i).getDay(),
name: this.dayNames[this.daysToDisplayInCurrentMonth[i - 1]],
weekNumber: this.getWeekNumber(new Date(this.currentYear, this.currentMonth - 1, i))
};
weeks.push(day.weekNumber);
this.days.push(day);
}
this.weekNumbers = [];
weeks.forEach((ele) => {
if(this.weekNumbers.indexOf(ele) < 0) {
this.weekNumbers.push(ele);
}
});
this.rowWidth = (100/this.weekNumbers.length) + '%';
}
HTML
<div class="row-calendar">
<div class="week-number" [style.width]="rowWidth" *ngFor="let week of weekNumbers">
<label class="number-label"><span>{{week}} </span></label>
</div>
</div>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
Is there any Javascript plugin to populate country codes on change of country dropdown?
Plug-ins, not that I know of... I know answers shouldn't only include external links, but I guess this might be exception, I will include a few links in case 1 breaks one day...
Since Country names and codes don't change too often nowadays might be safe with this text extract:
http://www.textfixer.com/resources/dropdowns/country-list-iso-codes.txt
then using split(':') function, easy populate text & value of select lists
options elements like this:
function populateCountriesDropDown() {
var file = "countries.txt";
var selectList = document.getElementById('selectID');
var rawlist;
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function () {
if (rawFile.readyState === 4) {
if (rawFile.status === 200 || rawFile.status == 0) {
rawlist = rawFile.responseText.split('\n');
}
}
}
rawFile.send(null);
for (var i = 0; i < rawlist.length; i++) {
var country = rawlist[i].split(':');
selectList.options[selectList.options.length] = new Option(country[1], country[0]);
}
}
OR other links with what you might be looking for:
http://www.freeformatter.com/iso-country-list-html-select.html
https://github.com/umpirsky/country-list
When using .setChoices() It looks for an array of created choices. If it is a multiple choice question it can be formatted either createChoice(value) or createChoice(value, navigationType).
When looking at a choice you put in something like: var cPage = chkItem.getChoices()[j].getGotoPage();
This will produce either the page object or a Null value.
The problem is when a question is set to "go to page based on answer" and they have not set a page for every entry, and left the default to continue it also reads it (in my case cPage), as null. This means if I want to go through each choice to capture it, modify it, then push it back out to the question, it my ending Array that I push out consists of both Null and Objects, which produces an error.
My workaround for questions without pages is for the script to forcibly change the question to handle page navigation but set everyone to CONTINUE.
I would like to find a way to check if the question has "go to page based on answer" checked and if not then be able to create choices using just the value.
Figured it out: I need to check the first choice if it has a PageNavigationType(). If it does then the box is checked. If null then it is not checked. I have not written the code to fully test this but the theory should work. (I was checking against just the goToPage type which is why it didn't work before. )
var choicecount = chkItem.getChoices().length-1;
var hasNavType = chkItem.getChoices()[0].getPageNavigationType(); //if null
for (var j = 0; j <= choicecount; ++j) {
var cValue = chkItem.getChoices()[j].getValue();
var cPage = chkItem.getChoices()[j].getGotoPage();
var cNav = chkItem.getChoices()[j].getPageNavigationType();
// Logger.log(j+" "+cPage);
if (cValue != reValues[0]){
if (hasNavType == null){
newChoices.push(chkItem.createChoice(cValue));
} else {
if (cPage == null){
newChoices.push(chkItem.createChoice(cValue,cNav));
} else {
newChoices.push(chkItem.createChoice(cValue,cPage));
}
}
}
}
I'm working on a script that applies custom headings to a plain text document imported in Google Docs. The scripts works pretty much as it should. However the resulting document has a weird layout, as if random page breaks were inserted here and there. But there are no page breaks and I can't understand the reason of this layout. Checking the paragraph attributes give me no hints on what is wrong.
Here is the text BEFORE the script is applied:
https://docs.google.com/document/d/1MzFvlkG13i3rrUcz5jmmSppG4sBH6zTXr7RViwdqaIo/edit?usp=sharing
You can make a copy of the document and execute the script (from the Scripts menu, choose Apply Headings). The script applies the appropriate heading to the scene heading, name of the character, dialogue, etc.
As you can see, at the bottom of page 2 and 3 of the resulting document there is a big gap and I can't figure out why. The paragraph attributes seem ok to me...
Here is a copy of the script:
// Apply headings to sceneheadings, actions, characters, dialogues, parentheticals
// to an imported plain text film script;
function ApplyHeadings() {
var pars = DocumentApp.getActiveDocument().getBody().getParagraphs();
for(var i=0; i<pars.length; i++) {
var par = pars[i];
var partext = par.getText();
var indt = par.getIndentStart();
Logger.log(indt);
if (indt > 100 && indt < 120) {
var INT = par.findText("INT.");
var EXT = par.findText("EXT.");
if (INT != null || EXT != null) {
par.setHeading(DocumentApp.ParagraphHeading.HEADING1);
par.setAttributes(ResetAttributes());
}
else {
par.setHeading(DocumentApp.ParagraphHeading.NORMAL);
par.setAttributes(ResetAttributes());
}
}
else if (indt > 245 && indt < 260) {
par.setHeading(DocumentApp.ParagraphHeading.HEADING2);
par.setAttributes(ResetAttributes());
}
else if (indt > 170 && indt < 190) {
par.setHeading(DocumentApp.ParagraphHeading.HEADING3);
par.setAttributes(ResetAttributes());
}
else if (indt > 200 && indt < 240) {
par.setHeading(DocumentApp.ParagraphHeading.HEADING4);
par.setAttributes(ResetAttributes());
}
}
}
// Reset all the attributes to "null" apart from HEADING;
function ResetAttributes() {
var style = {};
style[DocumentApp.Attribute.STRIKETHROUGH] = null;
style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = null;
style[DocumentApp.Attribute.INDENT_START] = null;
style[DocumentApp.Attribute.INDENT_END] = null;
style[DocumentApp.Attribute.INDENT_FIRST_LINE] = null;
style[DocumentApp.Attribute.LINE_SPACING] = null;
style[DocumentApp.Attribute.ITALIC] = null;
style[DocumentApp.Attribute.FONT_SIZE] = null;
style[DocumentApp.Attribute.FONT_FAMILY] = null;
style[DocumentApp.Attribute.BOLD] = null;
style[DocumentApp.Attribute.SPACING_BEFORE] = null;
style[DocumentApp.Attribute.SPACING_AFTER] = null;
return style;
}
A couple of screenshots to make the problem more clear.
This is page 2 of the document BEFORE the script is applied.
This is page two AFTER the script is applied. Headings are applied correctly but... Why the white space at the bottom?
Note: if you manually re-apply HEADING2 to the first paragraph of page 3 (AUDIO TV), the paragraph will jump back to fill the space at the bottom of page 2. This action, however, doesn't change any attribute in the paragraph. So why the magic happens?
Thanks a lot for your patience.
That was an interesting problem ;-)
I copied your doc, ran the script and had a surprise : nothing happened !
It took me a few minutes to realize that the copy I just made had no style defined for headings, everything was for some reason in courrier new 12pt, including the headings.
I examined the log and saw the indent values, played with that a lot to finally see that the headings were there but not changing the style.
So I went in the doc menu and set 'Use my default style and... everything looks fine, see screen capture below.
So now your question : it appears that there must be something wrong in your style definition, by "wrong" I mean something that changes more than just the font Style and size but honestly I can't see any way to guess what since I'm unable to reproduce it... Please try resetting your heading styles and re-define your default.... and tell us what happens then.
PS : here are my default heading styles : (and the url of my copy in view only :https://docs.google.com/document/d/1yP0RRCrRSsQc9zCk-sdfu5olNGDkoIrabXanII4qUG0/edit?usp=sharing )