Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

restintag

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restintag - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

6

package.json
{
"name": "restintag",
"version": "0.2.0",
"version": "0.2.1",
"description": "HTTP requests made easy through HTML tags",

@@ -31,3 +31,5 @@ "main": "./src/index.js",

"frontend",
"front end"
"front end",
"jquery-plugin",
"ecosystem:jquery"
],

@@ -34,0 +36,0 @@ "author": "Khaled Al-Ansari <khaledelansari@gmail.com> (http://khaledelansari.com/)",

@@ -50,2 +50,3 @@ # RESTInTag

3. `data-disabled`: `true` to disable the tag until the request is done else just put `false`
4. `data-once`: `true` to disable the tag entirely after the first request

@@ -74,3 +75,4 @@ example:

data: {}, // request body specially for POST and PUT requests
disable: true // to disable the clicking event until the request is finished
disable: true, // to disable the clicking event until the request is finished
once: true // to disable the click event after the first request is processed
}

@@ -77,0 +79,0 @@ ```

@@ -22,3 +22,4 @@ /**!

data: {},
disable: true
disable: true,
once: false
}, options);

@@ -29,8 +30,7 @@

var thisOptions = $.extend({}, defaultOptions);
var isOnce = $this.data("once") || thisOptions.once;
var isDisabled = $this.data("disabled") || thisOptions.disable;
var methodAttr = $this.attr("data-method");
var targetAttr = $this.attr("data-target");
thisOptions.method = $this.data("method") || thisOptions.method;
thisOptions.target = $this.data("target") || thisOptions.target;
if(typeof methodAttr !== 'undefined' && methodAttr !== false) thisOptions.method = $this.data("method");
if(typeof targetAttr !== 'undefined' && targetAttr !== false) thisOptions.target = $this.data("target");
$this.removeAttr('href');

@@ -58,4 +58,4 @@

event.stopPropagation();
if(isDisabled) {
$this.attr("disabled", isDisabled);
if(isOnce || isDisabled) {
$this.attr("disabled", isOnce || isDisabled);
$this.css({

@@ -83,3 +83,3 @@ "pointer-events": "none",

}).done(function() {
if(isDisabled) {
if(!isOnce && isDisabled) {
$this.attr("disabled", isDisabled);

@@ -91,2 +91,3 @@ $this.css({

}
// else if(isOnce) $this.off("click");
});

@@ -107,2 +108,2 @@ });

})(jQuery);
}
}

@@ -1,1 +0,1 @@

var rest=function(options,successCB,errorCB){var defaultOptions=$.extend({async:true,parse:false,target:null,method:"GET",headers:{},timeout:0,data:{},disable:true},options);return $(this).each(function(){var $this=$(this);var thisOptions=$.extend({},defaultOptions);var isDisabled=$this.data("disabled")||thisOptions.disable;var methodAttr=$this.attr("data-method");var targetAttr=$this.attr("data-target");if(typeof methodAttr!=="undefined"&&methodAttr!==false)thisOptions.method=$this.data("method");if(typeof targetAttr!=="undefined"&&targetAttr!==false)thisOptions.target=$this.data("target");$this.removeAttr("href");if(thisOptions.parse){var paramsIndex=thisOptions.target.indexOf("?");var hasParams=paramsIndex>-1;if(hasParams){var params=thisOptions.target.substr(paramsIndex+1).split("#")[0].split("&");thisOptions.target=thisOptions.target.substr(0,paramsIndex);$.map(params,function(val,i){var pair=params[i].split("=");thisOptions.data[decodeURIComponent(pair[0])]=decodeURIComponent(pair[1])})}}if(typeof thisOptions.data!=="string"&&thisOptions.method!=="GET")thisOptions.data=JSON.stringify(thisOptions.data);$this.on("click",function(event){event.preventDefault();event.stopPropagation();if(isDisabled){$this.attr("disabled",isDisabled);$this.css({"pointer-events":"none",cursor:"default"})}$.ajax({async:thisOptions.async,url:thisOptions.target,method:thisOptions.method,headers:thisOptions.headers,data:thisOptions.data,timeout:thisOptions.timeout,success:function(data,textStatus,jqXHR){if(successCB)successCB(data,textStatus,jqXHR)},error:function(jqXHR,textStatus,errorThrown){if(errorCB){errorCB(jqXHR,textStatus,errorThrown)}else{console.log(jqXHR)}}}).done(function(){if(isDisabled){$this.attr("disabled",isDisabled);$this.css({"pointer-events":"",cursor:""})}})})})};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports){exports=module.exports=rest}exports.rest=rest}else{(function($){$.fn.restintag=rest})(jQuery)}
var rest=function(options,successCB,errorCB){var defaultOptions=$.extend({async:true,parse:false,target:null,method:"GET",headers:{},timeout:0,data:{},disable:true,once:false},options);return $(this).each(function(){var $this=$(this);var thisOptions=$.extend({},defaultOptions);var isOnce=$this.data("once")||thisOptions.once;var isDisabled=$this.data("disabled")||thisOptions.disable;thisOptions.method=$this.data("method")||thisOptions.method;thisOptions.target=$this.data("target")||thisOptions.target;$this.removeAttr("href");if(thisOptions.parse){var paramsIndex=thisOptions.target.indexOf("?");var hasParams=paramsIndex>-1;if(hasParams){var params=thisOptions.target.substr(paramsIndex+1).split("#")[0].split("&");thisOptions.target=thisOptions.target.substr(0,paramsIndex);$.map(params,function(val,i){var pair=params[i].split("=");thisOptions.data[decodeURIComponent(pair[0])]=decodeURIComponent(pair[1])})}}if(typeof thisOptions.data!=="string"&&thisOptions.method!=="GET")thisOptions.data=JSON.stringify(thisOptions.data);$this.on("click",function(event){event.preventDefault();event.stopPropagation();if(isOnce||isDisabled){$this.attr("disabled",isOnce||isDisabled);$this.css({"pointer-events":"none",cursor:"default"})}$.ajax({async:thisOptions.async,url:thisOptions.target,method:thisOptions.method,headers:thisOptions.headers,data:thisOptions.data,timeout:thisOptions.timeout,success:function(data,textStatus,jqXHR){if(successCB)successCB(data,textStatus,jqXHR)},error:function(jqXHR,textStatus,errorThrown){if(errorCB){errorCB(jqXHR,textStatus,errorThrown)}else{console.log(jqXHR)}}}).done(function(){if(!isOnce&&isDisabled){$this.attr("disabled",isDisabled);$this.css({"pointer-events":"",cursor:""})}})})})};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports){exports=module.exports=rest}exports.rest=rest}else{(function($){$.fn.restintag=rest})(jQuery)}

@@ -37,3 +37,4 @@ /**!

data: {},
disable: true
disable: true,
once: false
};

@@ -46,2 +47,3 @@ for(var property in options) defaultOptions[property] = options[property];

var isOnce = element.dataset ? element.dataset.once : element.getAttribute("data-once");
var isDisabled = element.dataset ? element.dataset.disabled : element.getAttribute("data-disabled");

@@ -51,4 +53,6 @@ var methodAttr = element.dataset ? element.dataset.method : element.getAttribute("data-method");

if(typeof methodAttr !== 'undefined' && methodAttr !== false) thisOptions.method = methodAttr;
if(typeof targetAttr !== 'undefined' && targetAttr !== false) thisOptions.target = targetAttr;
if(isOnce !== null && isOnce.length > 0) thisOptions.once = isOnce;
if(isDisabled !== null && isDisabled.length > 0) thisOptions.disable = isDisabled;
if(methodAttr !== null && methodAttr.length > 0) thisOptions.method = methodAttr;
if(targetAttr !== null && targetAttr.length > 0) thisOptions.target = targetAttr;
element.removeAttribute("href");

@@ -76,4 +80,4 @@

event.stopPropagation();
if(isDisabled) {
element.setAttribute("disabled", isDisabled);
if(isOnce || isDisabled) {
element.setAttribute("disabled", isOnce || isDisabled);
element.style.cursor = "default";

@@ -93,3 +97,3 @@ element.style.pointerEvents = "none";

if(isDisabled) {
if(!isOnce && isDisabled) {
element.removeAttribute("disabled");

@@ -116,2 +120,2 @@ element.style.cursor = "";

exports.restintag = restintag;
}
}

@@ -1,1 +0,1 @@

var restintag=function(selector,options,successCB,errorCB){if(selector==="undefined"||selector===null){throw new Error("selector must be provided")}else if(typeof selector!=="string"){throw new TypeError("selector must be a string")}if(!options){options={}}else if(!(options instanceof Object)||Object.prototype.toString.call(options)!=="[object Object]"){throw new TypeError("the options is not an object")}var elements=[].slice.call(document.querySelectorAll(selector));var defaultOptions={async:true,parse:false,target:null,method:"GET",headers:{},timeout:0,data:{},disable:true};for(var property in options)defaultOptions[property]=options[property];elements.forEach(function(element,index){var thisOptions={};for(var property in defaultOptions)thisOptions[property]=defaultOptions[property];var isDisabled=element.dataset?element.dataset.disabled:element.getAttribute("data-disabled");var methodAttr=element.dataset?element.dataset.method:element.getAttribute("data-method");var targetAttr=element.dataset?element.dataset.target:element.getAttribute("data-target");if(typeof methodAttr!=="undefined"&&methodAttr!==false)thisOptions.method=methodAttr;if(typeof targetAttr!=="undefined"&&targetAttr!==false)thisOptions.target=targetAttr;element.removeAttribute("href");if(thisOptions.parse&&thisOptions.method!=="GET"){var paramsIndex=thisOptions.target.indexOf("?");var hasParams=paramsIndex>-1;if(hasParams){var params=thisOptions.target.substr(paramsIndex+1).split("#")[0].split("&");thisOptions.target=thisOptions.target.substr(0,paramsIndex);params.map(function(param,index){var pair=params[index].split("=");thisOptions.data[decodeURIComponent(pair[0])]=decodeURIComponent(pair[1])})}}if(typeof thisOptions.data!=="string")thisOptions.data=JSON.stringify(thisOptions.data);element.addEventListener("click",function(event){event.preventDefault();event.stopPropagation();if(isDisabled){element.setAttribute("disabled",isDisabled);element.style.cursor="default";element.style.pointerEvents="none"}var xhr=new XMLHttpRequest;xhr.onreadystatechange=function(){if(this.readyState==4){if(xhr.status>=200&&xhr.status<400){if(successCB&&typeof successCB==="function")successCB(JSON.parse(xhr.responseText))}else{if(errorCB&&typeof errorCB==="function")errorCB(xhr.responseText);else console.log("Server response for "+thisOptions.target+" is "+this.status)}if(isDisabled){element.removeAttribute("disabled");element.style.cursor="";element.style.pointerEvents=""}}};xhr.open(thisOptions.method,thisOptions.target,thisOptions.async);for(var header in thisOptions.headers)xhr.setRequestHeader(header,thisOptions.headers[header]);xhr.timeout=thisOptions.timeout;xhr.send(thisOptions.data)},false)})};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports){exports=module.exports=restintag}exports.restintag=restintag}
var restintag=function(selector,options,successCB,errorCB){if(selector==="undefined"||selector===null){throw new Error("selector must be provided")}else if(typeof selector!=="string"){throw new TypeError("selector must be a string")}if(!options){options={}}else if(!(options instanceof Object)||Object.prototype.toString.call(options)!=="[object Object]"){throw new TypeError("the options is not an object")}var elements=[].slice.call(document.querySelectorAll(selector));var defaultOptions={async:true,parse:false,target:null,method:"GET",headers:{},timeout:0,data:{},disable:true,once:false};for(var property in options)defaultOptions[property]=options[property];elements.forEach(function(element,index){var thisOptions={};for(var property in defaultOptions)thisOptions[property]=defaultOptions[property];var isOnce=element.dataset?element.dataset.once:element.getAttribute("data-once");var isDisabled=element.dataset?element.dataset.disabled:element.getAttribute("data-disabled");var methodAttr=element.dataset?element.dataset.method:element.getAttribute("data-method");var targetAttr=element.dataset?element.dataset.target:element.getAttribute("data-target");if(isOnce!==null&&isOnce.length>0)thisOptions.once=isOnce;if(isDisabled!==null&&isDisabled.length>0)thisOptions.disable=isDisabled;if(methodAttr!==null&&methodAttr.length>0)thisOptions.method=methodAttr;if(targetAttr!==null&&targetAttr.length>0)thisOptions.target=targetAttr;element.removeAttribute("href");if(thisOptions.parse&&thisOptions.method!=="GET"){var paramsIndex=thisOptions.target.indexOf("?");var hasParams=paramsIndex>-1;if(hasParams){var params=thisOptions.target.substr(paramsIndex+1).split("#")[0].split("&");thisOptions.target=thisOptions.target.substr(0,paramsIndex);params.map(function(param,index){var pair=params[index].split("=");thisOptions.data[decodeURIComponent(pair[0])]=decodeURIComponent(pair[1])})}}if(typeof thisOptions.data!=="string")thisOptions.data=JSON.stringify(thisOptions.data);element.addEventListener("click",function(event){event.preventDefault();event.stopPropagation();if(isOnce||isDisabled){element.setAttribute("disabled",isOnce||isDisabled);element.style.cursor="default";element.style.pointerEvents="none"}var xhr=new XMLHttpRequest;xhr.onreadystatechange=function(){if(this.readyState==4){if(xhr.status>=200&&xhr.status<400){if(successCB&&typeof successCB==="function")successCB(JSON.parse(xhr.responseText))}else{if(errorCB&&typeof errorCB==="function")errorCB(xhr.responseText);else console.log("Server response for "+thisOptions.target+" is "+this.status)}if(!isOnce&&isDisabled){element.removeAttribute("disabled");element.style.cursor="";element.style.pointerEvents=""}}};xhr.open(thisOptions.method,thisOptions.target,thisOptions.async);for(var header in thisOptions.headers)xhr.setRequestHeader(header,thisOptions.headers[header]);xhr.timeout=thisOptions.timeout;xhr.send(thisOptions.data)},false)})};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports){exports=module.exports=restintag}exports.restintag=restintag}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc