jsTree xml_data plugin not working in IE11 - jstree

The jsTree xml_data plugin is not working in ie 11. It Works great in every browser (including ie10), but not in ie11. No error messages, only the "loading" forever.
$("#hierarquia").jstree({
"xml_data" : {"ajax" : {"url" : "XML.asp"}},
"plugins" : ["xml_data"]
});
Anyone have experienced this? I could not find any references for jsTree and ie11 on the web until now.
Thanks for any help!

In the the jstree.js file there is this function:
(function ($) {
$.vakata.xslt = function (xml, xsl, callback) {
var rs = "", xm, xs, processor, support;
// TODO: IE9 no XSLTProcessor, no document.recalc
if (window.ActiveXObject) {
var xslt = new ActiveXObject("Msxml2.XSLTemplate");
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
xmlDoc.loadXML(xml);
xslDoc.loadXML(xsl);
xslt.stylesheet = xslDoc;
var xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
xslProc.transform();
callback.call(null, xslProc.output);
return true;
}
if(typeof window.DOMParser !== "undefined" && typeof window.XMLHttpRequest !== "undefined" && typeof window.XSLTProcessor === "undefined") {
xml = new DOMParser().parseFromString(xml, "text/xml");
xsl = new DOMParser().parseFromString(xsl, "text/xml");
// alert(xml.transformNode());
// callback.call(null, new XMLSerializer().serializeToString(rs));
}
if(typeof window.DOMParser !== "undefined" && typeof window.XMLHttpRequest !== "undefined" && typeof window.XSLTProcessor !== "undefined") {
processor = new XSLTProcessor();
support = $.isFunction(processor.transformDocument) ? (typeof window.XMLSerializer !== "undefined") : true;
if(!support) { return false; }
xml = new DOMParser().parseFromString(xml, "text/xml");
xsl = new DOMParser().parseFromString(xsl, "text/xml");
if($.isFunction(processor.transformDocument)) {
rs = document.implementation.createDocument("", "", null);
processor.transformDocument(xml, xsl, rs, null);
callback.call(null, new XMLSerializer().serializeToString(rs));
return true;
}
else {
processor.importStylesheet(xsl);
rs = processor.transformToFragment(xml, document);
callback.call(null, $("<div />").append(rs).html());
return true;
}
}
return false;
};
The if
if (window.ActiveXObject)
You need to add the following to it:
if (window.ActiveXObject || "ActiveXObject")
Hope that makes sense
EDIT:
Changed the if statement to the below, as earlier fix was causing problems on Chrome:
if (window.ActiveXObject !== undefined || "ActiveXObject" in window)

Related

Getting error as E/launcher - Error: TypeError: Cannot read property '0' of undefined

I'm getting below error while executing this code -
E/launcher - Error: TypeError: Cannot read property '0' of undefined
Need your help to resolve this issue in Protractor version 5.4.3
let objectLocator = function(){
var webElement = null;
//find locator using provided locator type and locator value
this.findLocator = function (locator, value) {
var locatorType = locator[0];
var locatorValue = locator[1];
if (typeof locatorType !== 'undefined') {
if (locatorValue.includes('#REPLACE#')) {
locatorValue = locatorValue.replace('#REPLACE#', value);
}
if (locatorType == 'id') {
if (locatorValue !== 'undefined') {
this.webElement = element(by.id(locatorValue));
}
} else if (locatorType == 'name') {
if (locatorValue !== 'undefined') {
this.webElement = element(by.name(locatorValue));
}
} else if (locatorType == 'xpath') {
if (locatorValue !== 'undefined') {
this.webElement = element(by.xpath(locatorValue));
}
} else if (locatorType == 'css') {
if (locatorValue !== 'undefined') {
this.webElement = element(by.css(locatorValue));
}
}
}
return this.webElement;
};
};
module.exports = new objectLocator();

Most suitable ionic component for linked inputs or a plugin

I'm building an app on ionic 3, and the UI proposal have this view to verify SMS.
Is any way to do this without using 4 different inputs and linking them with JS? a plugin or something?
Thanks in advance
Found a codepen that is similar
https://codepen.io/nirarazi/pen/ZGovQo
but the magic is in the js
$(function() {
'use strict';
var body = $('body');
function goToNextInput(e) {
var key = e.which,
t = $(e.target),
sib = t.next('input');
if (key != 9 && (key < 48 || key > 57)) {
e.preventDefault();
return false;
}
if (key === 9) {
return true;
}
if (!sib || !sib.length) {
sib = body.find('input').eq(0);
}
sib.select().focus();
}
function onKeyDown(e) {
var key = e.which;
if (key === 9 || (key >= 48 && key <= 57)) {
return true;
}
e.preventDefault();
return false;
}
function onFocus(e) {
$(e.target).select();
}
body.on('keyup', 'input', goToNextInput);
body.on('keydown', 'input', onKeyDown);
body.on('click', 'input', onFocus);
})

Mootools Extends mutator, calling this.parent from functions in nested objects

Here's a simple example of how the Extends mutator can be used:
var firstClass = new Class({
aMethod: function(){
console.log('firstClass method');
}
});
var secondClass = new Class({
Extends:firstClass,
aMethod: function(){
this.parent();
console.log('secondClass method');
},
initialize: function(){
this.aMethod();
}
});
var instance = new secondClass();
//Output:
// firstClass method
// secondClass method
I would like to achieve the same behavior, but with class constructors like this:
var firstClass = new Class({
methods: {
aMethod: function(){
console.log('firstClass method');
}
}
});
var secondClass = new Class({
Extends:firstClass,
methods: {
aMethod: function(){
this.parent();
console.log('secondClass method');
}
},
initialize: function(){
this.methods.aMethod.call(this);
}
});
var instance = new secondClass();
//Output:
// Error: The method "initialize" has no parent.
instance.methods.aMethod.call(this);
//Output:
// TypeError: this.parent is not a function
My Mootools Fu is unfortunately not very strong, so I'm kind of at a loss. Is this possible with the way Extends currently works? If it's not then I'd like to work on implementing a solution to do this, however I'd need some pointers to get me started in the right direction (make a custom Mutator? modify the Core source? something else?). Any suggestions or ideas on how to proceed would be appreciated.
Update
I came up with a way to do this using pattern based mutators (Github). Mark's code needs to be included for the following to work:
(function(){
/* Utility functions */
Object.extend({
containsMethods:function(obj){
if(typeOf(obj) != 'object') return false;
return Object.getLength(Object.filter(obj, function(item){return typeOf(item) == 'function';})) > 0;
},
containsObjects:function(obj){
if(typeOf(obj) != 'object') return false;
return Object.getLength(Object.filter(obj, function(item){return typeOf(item) == 'object';})) > 0;
}
});
var getInheritance = function(obj, key){
var temp = {};
if(obj){
if(obj.inheritance !== undefined){
temp[key] = obj.inheritance;
}
delete obj.inheritance;
}
return temp;
}
/* Recursive function to turn specially keyed object literals in the constructor into class instances with inheritance */
var classify = function(obj, inherit, key, imap){
if(typeOf(obj) != 'object'){return obj;}
if(key == undefined){
key = '';
}
var inheritance = 'extends';
if(imap != null){
imap = Object.append(imap, getInheritance(obj, key));
imap = Object.append(imap, getInheritance(inherit, key));
if(imap[key] != undefined){
inheritance = imap[key];
}
}
var i = 'extends';
for(var k in inherit){
if(!inherit.hasOwnProperty(k)) {continue;}
i = 'extends';
if(imap != null){
if(typeOf(inherit[k]) == 'object'){
imap = Object.append(imap, getInheritance(inherit[k], k));
}
if(typeOf(obj[k]) == 'object'){
imap = Object.append(imap, getInheritance(obj[k], k));
}
if(imap[k] != undefined){
i = imap[k];
}
}
/* Needed to clean up properties when inheritance == false */
if(inherit[k] === undefined){
delete inherit[k];
}
if(typeOf(inherit[k]) == 'object' && i === false && !Object.keys(obj).contains(k)){
obj[k] = undefined;
continue;
}
if(obj[k] && typeOf(obj[k]) == 'object' && i !== false){
obj[k] = classify(obj[k], inherit[k], k, imap);
}
}
if(Object.containsMethods(obj)){
var constructor = {};
if(inherit != undefined && inheritance !== false){
if(inheritance == 'implements'){
constructor.Implements = (inherit.$constructor ? inherit.$constructor : new Class(inherit));
}else {
constructor.Extends = (inherit.$constructor ? inherit.$constructor : new Class(inherit));
}
}
obj = new (new Class(Object.append(constructor, obj)));
}else {
if(!Object.containsMethods(inherit)){
obj = Object.append({}, inherit, obj);
}
}
return obj;
};
/* Mutator */
Class.defineMutator(/^_(\w+)_/, function(params, key){
var old_key = key;
var key = key.replace(/_/g, "");
var c = null;
var imap = null;
if(this.$constructor){
imap = this.$constructor.imap = (this.$constructor.imap || {});
}
if(this.prototype[key] != undefined){
c = classify.call(this, params, this.prototype[key], '', imap);
}else {
c = classify.call(this, params, undefined, '', imap);
}
this.prototype[key] = c;
delete this[old_key];
});
})();
The mutator pattern is simply a key name surrounded with single underscores (ex: _methods_). The nested objects in the class constructor can contain any combination of properties and methods or other nested objects. Each individual object can have a property with the key 'inheritance' that takes the following values: 'implements', 'extends' or false. Implements and extends correspond to the behavior of the Implements and Extends Mootools class mutators. Extends is the default, and is the method used when nothing is supplied for the inheritance property. A value of false will keep the given object (and any objects nested within it) from being inherited altogether.
The entire code including examples can be found here

Do not submit empty form fields in ExtJS

I have an extjs form with fields. The user isn't required to enter data into each field so I do not want to submit the fields with no data. I want it to post only fields that actually have data. Is this possible?
I recommend using form's beforeaction event. While handling this event you can check all fields. If all values are empty just return false;. The following example works in ExtJS4 and has to work in ExtJS3:
myform.on('beforeaction', function(form, action) {
if (action.type == 'submit') {
var doSubmit = false, vals = form.getValues();
for (var i in vals)
if (vals[i] !== '') {
doSubmit = true;
break;
}
return doSubmit;
}
});
Actualy, the right way to not submit empty fields is to use action's submitEmptyText config. But it's not working in current version (ExtJS4.0.2a).
Another options is to override component's getSubmitValue() method and return null if this field is empty, this way it won't be included into submit fields.
{
xtype: 'combo',
getSubmitValue: function(){
var value = this.getValue();
if(Ext.isEmpty(value)) {
return null;
}
return value;
}
}
Instead of using form's submit, directly call Ext.Ajax.request(...) with the url, method type (GET/POST) and params (and any other options as explained in the call documentation).
To generate params, iterate over the form fields and check for null value before adding to params.
This bug is present in ExtJS 4.0.7 too.
As Molecule Man pointed:
Actualy, the right way to not submit empty fields is to use action's submitEmptyText config. But it's not working in current version (ExtJS4.0.2a).
A possible solution to fix this bug is by overriding 2 functions, getValues in "Ext.form.Basic" (where the bug is) and createForm (to create our basic form) in "Ext.form.Panel" by extension in the following way:
Ext.define("My.form.Basic", {
alias: "form.mybasic",
extend: "Ext.form.Basic",
getValues: function(asString, dirtyOnly, includeEmptyText, useDataValues) {
var values = {};
this.getFields().each(function(field) {
if (!dirtyOnly || field.isDirty()) {
var data = field[useDataValues ? "getModelData" : "getSubmitData"](includeEmptyText);
if (Ext.isObject(data)) {
var isArray = Ext.isArray;
Ext.iterate(data, function(name, val) {
if (includeEmptyText && val === "") {
val = field.emptyText || "";
}
if (includeEmptyText || ((!isArray(val) && val !== "") || (isArray(val) && val.length !== 0))) {
if (name in values) {
var bucket = values[name];
if (!isArray(bucket)) {
bucket = values[name] = [bucket];
}
if (isArray(val)) {
values[name] = bucket.concat(val);
}
else {
bucket.push(val);
}
}
else {
values[name] = val;
}
}
});
}
}
});
if (asString) {
values = Ext.Object.toQueryString(values);
}
return values;
}
});
Ext.define("My.form.Panel", {
alias: "form.mypanel",
extend: "Ext.form.Panel",
createForm: function() {
return Ext.create("My.form.Basic", this, Ext.applyIf({listeners: {}}, this.initialConfig));
}
});
The code is copied from the ext source code. The only change is inside the iteration of each field: introduced the following wrapping "if":
if (includeEmptyText || ((!isArray(val) && val !== "") || (isArray(val) && val.length !== 0)))
I am a bit late but, better later than never...

selection range issue in IE9

I have the following JavaScript code works in IE6, IE7 and IE8. However, the parentElement() and commonParentElement() are not defined in IE9. Would anyone know how to workaround it?
if (document.selection)
{
var sel = document.selection;
var rng = sel.createRange();
if (rng)
{
if ("Control" == sel.type && typeof rng.commonParentElement != "undefined")
{
targetElement = rng.commonParentElement(); // undefined in IE9
}
else if (typeof rng.parentElement != "undefined")
{
targetElement = rng.parentElement(); // undefined in IE9
}
}
}