#StackBounty: #javascript #php #jquery How to delete the specific value of an “input type=file” multiple

Bounty: 50

I am using input type=’file’ with multiple file and one with single file. like,

//single image
//IMAGE_TYPES is constant and defined with:define('IMAGE_TYPES',array('main','floor','bedroom1','bedroom2','bedroom3','kitchen','reception','garages','epc','other'));
@foreach(IMAGE_TYPES as $images)
    @if($images!='other')
    
Click here or drop files to upload"/>
@else //multiple
Click here or drop files to upload" multiple />
@endif @endforeach

Now, I validating it with jquery like,

var image_type ='<?=json_encode(IMAGE_TYPES);?>';
image_type = JSON.parse(image_type);
var max_image_size = 2;
$.each(image_type, function( index, value ) {
  if (value!='other') {
    $('#'+value+'_image').bind('change', function() {
      var a=(this.files[0].size);
      var ValidImageTypes = ["image/jpeg", "image/png"];
      if ($.inArray(this.files[0].type, ValidImageTypes) < 0) {
        show_notification('error','Only .jpg/.jpeg and .png file allowed. Please select other image.');
        var file = document.getElementById(value+'_image');
        file.value = file.defaultValue;
        return false;
      }
      else{
        if (Math.round(a / (1024 * 1024)) > max_image_size) {
          show_notification('error','Image is Greater than '+max_image_size+'MB. Please select smaller image.');
          var file = document.getElementById(value+'_image');
          file.value = file.defaultValue;
          return false;
        }
        else
        {
          preview_main_image(value);//won't matter
        }
     }
    });
  }
  else{
    $('#other_images').bind('change', function() {
      $('div.add_preview').remove();//won't matter
      for (var i = 0; i < $("#other_images").get(0).files.length; i++) { 
        var a=(this.files[i].size);
        var name = this.files[i].name;
        var ValidImageTypes = ["image/jpeg", "image/png"];
        if ($.inArray(this.files[i].type, ValidImageTypes) < 0) {
          show_notification('error','Image '+name+' is Not allowed. Only .jpg/.jpeg and .png file allowed. Please select other image.');
        }
        else{
          if (Math.round(a / (1024 * 1024)) > max_image_size) {
            show_notification('error','Image '+name+' is Greater than '+max_image_size+'MB. Please select smaller image.');
          }
          else
          {
            $('#other_image_preview').append("
");//won't matter //preview_detail_images(value); } } } }); } });

Now, my question is when i am using single image if image is not fitting in validation then i delete it’s value from input type=’file’ using, this code

var file = document.getElementById(value+'_image');
file.value = file.defaultValue;
return false;

But when i select multiple image and if any image is not fitting in validation then how can i remove that particular image from input type=’file’.

Please help me


Get this bounty!!!

#StackBounty: #javascript #iframe Javascript, track iframes redirecting top window

Bounty: 200

Since there is no way to prevent an iframe from redirecting the top frame besides sandboxing which prevents other features required for viewability tracking I would like to track redirects. Since one site can have more than one iframe, it could be any of these.

Is there any way to track/find out which one (specific iframe) caused the top frame redirect?

Here is a sandbox (use browser console and enable preserve log):

Edit 3v50wqxz66

Note the iframe content is usually cross domain. For ease of use its within the sandox.


Get this bounty!!!

#StackBounty: #javascript #html #css #html5 #dom Simple HTML website with a JavaScript navigation bar (version 3)

Bounty: 50

This is a followup post to version 1, and version 2.


The following code is a website with a nav-bar on it. It uses some simple JavaScript and CSS (with media-queries) to make it work:


index.html:

<!DOCTYPE html>
<html lang="en-US">
<head>
  <meta charset="UTF-8" />
  <title>SigmaCubes</title>
  <meta name="author" content="Julian Lachniet,Simon Kwilinski,Jacob Wysko" />
  <meta name="description" content="SigmaCubes is the best website on the internet." />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
  <link href="https://fonts.googleapis.com/css?family=Lato|Noto+Sans|Nunito:600|Material+Icons" rel="stylesheet" type="text/css" />
  <link href="/lib/css/reset.css" rel="stylesheet" type="text/css" />
  <link href="/lib/css/sigmacubes.css" rel="stylesheet" type="text/css" />
  <link href="/favicon.ico" rel="shortcut icon" />
  /lib/js/main.js
</head>
<body>
  

Error:

JavaScript

</noscript> <!--[if IE]>

Error:

Old Internet Explorer

<![endif]--> </div>

reset.css

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p,
blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img,
ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i,
center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption,
tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section,
summary, time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}

article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav,
section {
  display: block;
}

body {
  line-height: 1;
}

ol, ul {
  list-style: none;
}

blockquote, q {
  quotes: none;
}

blockquote:before, blockquote:after, q:before, q:after {
  content: "";
  content: none;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

sigmacubes.css

html, body {
  background-color: #ddd;
  font-family: "Noto Sans", sans-serif;
  height: 100%;
}

h1 {
  font-size: 24px;
  margin: 4px 16px;
}

@media screen and (max-width: 250px) {
  #nav-stupid {
    display: block;
  }

  #content, #dropdown, #nav-large, #nav-small {
    display: none;
  }
}

@media screen and (min-width: 251px) and (max-width: 500px) {
  #nav-small {
    display: block;
  }

  #nav-large, #nav-stupid {
    display: none;
  }
}

@media screen and (min-width: 501px) {
  #nav-large {
    display: block;
  }

  #dropdown, #nav-small, #nav-stupid {
    display: none;
  }
}

.block {
  display: block;
}

.error {
  padding: 8px;
}

.error-type {
  font-weight: bold;
  margin: 4px 16px;
}

.hidden {
  display: none;
}

.link-large {
  color: #000;
  padding: 0 8px;
  text-decoration: none;
}

.link-large:hover {
  color: #00f;
}

.logo_h {
  left: 16px;
  position: absolute;
  top: 10px;
}

.link-small {
  color: #fff;
  display: block;
  padding: 8px;
  text-decoration: none;
}

.link-small:hover {
  color: #88f;
}

.nav-toggle {
  position: absolute;
  right: 16px;
  top: 10px;
}

#content {
  background-image: url("/img/hq.jpg");
  color: #fff;
  padding: 16px;
}

#dropdown {
  background-color: #393f47;
  text-align: left;
}

#nav-large, #nav-small {
  background-color: #63a4ff;
  font-family: "Nunito", sans-serif;
  font-size: 16px;
  height: 16px;
  padding: 16px 0;
  text-align: right;
}

#nav-large-links {
  display: inline;
  margin: 0 16px;
}

#wrapper {
  text-align: center;
}

main.js

var navEnabled = false;

document.addEventListener('DOMContentLoaded', main);

function main() {
  setDisplay("wrapper", "block");
}

function toggleNav() {
  if (navEnabled) {
    setDisplay("dropdown", "hidden");
  } else {
    setDisplay("dropdown", "block");
  }
  navEnabled = !navEnabled;
}

function setDisplay(id, className) {
  document.getElementById(id).className = className;
}

Live demo!


Get this bounty!!!

#StackBounty: #javascript #html #css #html5 Simple HTML website with a JavaScript navigation bar (version 3)

Bounty: 50

Followup to version 1, and version 2


The following code is a website with a nav-bar on it. It uses some simple JavaScript to make it work:


index.html:

<!DOCTYPE html>
<html lang="en-US">
<head>
  <meta charset="UTF-8" />
  <title>SigmaCubes</title>
  <meta name="author" content="Julian Lachniet,Simon Kwilinski,Jacob Wysko" />
  <meta name="description" content="SigmaCubes is the best website on the internet." />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
  <link href="https://fonts.googleapis.com/css?family=Lato|Noto+Sans|Nunito:600|Material+Icons" rel="stylesheet" type="text/css" />
  <link href="/lib/css/reset.css" rel="stylesheet" type="text/css" />
  <link href="/lib/css/sigmacubes.css" rel="stylesheet" type="text/css" />
  <link href="/favicon.ico" rel="shortcut icon" />
  /lib/js/main.js
</head>
<body>
  

Error:

JavaScript

</noscript> <!--[if IE]>

Error:

Old Internet Explorer

<![endif]--> </div>

reset.css

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p,
blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img,
ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i,
center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption,
tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section,
summary, time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}

article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav,
section {
  display: block;
}

body {
  line-height: 1;
}

ol, ul {
  list-style: none;
}

blockquote, q {
  quotes: none;
}

blockquote:before, blockquote:after, q:before, q:after {
  content: "";
  content: none;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

sigmacubes.css

html, body {
  background-color: #ddd;
  font-family: "Noto Sans", sans-serif;
  height: 100%;
}

h1 {
  font-size: 24px;
  margin: 4px 16px;
}

@media screen and (max-width: 250px) {
  #nav-stupid {
    display: block;
  }

  #content, #dropdown, #nav-large, #nav-small {
    display: none;
  }
}

@media screen and (min-width: 251px) and (max-width: 500px) {
  #nav-small {
    display: block;
  }

  #nav-large, #nav-stupid {
    display: none;
  }
}

@media screen and (min-width: 501px) {
  #nav-large {
    display: block;
  }

  #dropdown, #nav-small, #nav-stupid {
    display: none;
  }
}

.block {
  display: block;
}

.error {
  padding: 8px;
}

.error-type {
  font-weight: bold;
  margin: 4px 16px;
}

.hidden {
  display: none;
}

.link-large {
  color: #000;
  padding: 0 8px;
  text-decoration: none;
}

.link-large:hover {
  color: #00f;
}

.logo_h {
  left: 16px;
  position: absolute;
  top: 10px;
}

.link-small {
  color: #fff;
  display: block;
  padding: 8px;
  text-decoration: none;
}

.link-small:hover {
  color: #88f;
}

.nav-toggle {
  position: absolute;
  right: 16px;
  top: 10px;
}

#content {
  background-image: url("/img/hq.jpg");
  color: #fff;
  padding: 16px;
}

#dropdown {
  background-color: #393f47;
  text-align: left;
}

#nav-large, #nav-small {
  background-color: #63a4ff;
  font-family: "Nunito", sans-serif;
  font-size: 16px;
  height: 16px;
  padding: 16px 0;
  text-align: right;
}

#nav-large-links {
  display: inline;
  margin: 0 16px;
}

#wrapper {
  text-align: center;
}

main.js

var navEnabled = false;

document.addEventListener('DOMContentLoaded', main);

function main() {
  setDisplay("wrapper", "block");
}

function toggleNav() {
  if (navEnabled) {
    setDisplay("dropdown", "hidden");
  } else {
    setDisplay("dropdown", "block");
  }
  navEnabled = !navEnabled;
}

function setDisplay(id, className) {
  document.getElementById(id).className = className;
}

Live demo!


Get this bounty!!!

#StackBounty: #javascript #browser Value of DOM without manipulation of browser extensions

Bounty: 50

I would like to save the DOM of <body> into a variable with:

var body = document.querySelector('body');

The Problem

If there is a browser extension that will manipulate the DOM, users could have different values.

Maybe a solution

I could save the <body> from source code instead of DOM in a variable. So all values would be the same. And if my JavaScript edits the DOM, I need a function that remembers what exactly has been added, removed or edited from the value of the source code and rewrite that variable. That would work but I think there must be a better and easier solution.

Is there a way to exclude all extensions (no matter what browser) when saving the DOM into a variable?


Get this bounty!!!

#StackBounty: #2013 #javascript #sharepoint-on-prem Is it possible to progrmamatically edit a Script Editor Web Part's code from th…

Bounty: 100

Is it possible for JavaScript in a script editor web part or a similar web part to permanently edit the web part it resides in?

What I’d like to do is make a web part that when the page is opened in edit mode displays an interface for editing options for that web part.

Then when the user clicks save or in a similar action the web part would save the config choices they made to the containing web part.

Is something like this possible to make client side per web part config possible?


Get this bounty!!!

#StackBounty: #2013 #javascript #sharepoint-on-prem Is it possible to progrmamatically edit a Script Editor Web Part's code from th…

Bounty: 100

Is it possible for JavaScript in a script editor web part or a similar web part to permanently edit the web part it resides in?

What I’d like to do is make a web part that when the page is opened in edit mode displays an interface for editing options for that web part.

Then when the user clicks save or in a similar action the web part would save the config choices they made to the containing web part.

Is something like this possible to make client side per web part config possible?


Get this bounty!!!

#StackBounty: #2013 #javascript #sharepoint-on-prem Is it possible to progrmamatically edit a Script Editor Web Part's code from th…

Bounty: 100

Is it possible for JavaScript in a script editor web part or a similar web part to permanently edit the web part it resides in?

What I’d like to do is make a web part that when the page is opened in edit mode displays an interface for editing options for that web part.

Then when the user clicks save or in a similar action the web part would save the config choices they made to the containing web part.

Is something like this possible to make client side per web part config possible?


Get this bounty!!!

#StackBounty: #2013 #javascript #sharepoint-on-prem Is it possible to progrmamatically edit a Script Editor Web Part's code from th…

Bounty: 100

Is it possible for JavaScript in a script editor web part or a similar web part to permanently edit the web part it resides in?

What I’d like to do is make a web part that when the page is opened in edit mode displays an interface for editing options for that web part.

Then when the user clicks save or in a similar action the web part would save the config choices they made to the containing web part.

Is something like this possible to make client side per web part config possible?


Get this bounty!!!