set a number of click and disable link from click after hit the target number - wordpress

I need to do setting for wordpress which set a number of clicks for some link to disable it after hit the targeted number. Is there any plugin or suggest to do so?

You can do it with a simple jQuery:
$('#targetLink').click(function () {
$('#counter').html(function (i, val) {
if (val > 1) {
return val * 1 - 1;
} else {
$("#targetLink").removeAttr("href");
if (val > 0) {
return val * 1 - 1;
}
}
}); });
Demo: http://jsfiddle.net/533L9n5f/
Of course, you have to adapt it to your HTML structure.
Next time, it could help a lot if you elaborate your question a bit more. Read this site for some best practices: How do I ask a good question?

Related

Detect opening of PluginSidebar in Wordpress Gutenberg

I'm looking to reinitialise some settings and state data when my PluginSidebar is reopened, but I'm struggling to find anything useful in wp.data core/editor or similar that I could use to best create a subscription.
Does gutenberg provide any such data where I can check to see if the side panel is open or shut, so that I could fire a function of my choice every time it opens?
At present, I have a mutationObserver in place listening to see if it opens, which is quite clunky.
Some pseudo-code of my preferred approach.
subscribe(() => {
if (select('core/editor').isPluginSidebarOpen()) {
open = true
} else {
open = false
}
})
Your pseudo-code is so very close.. the function exists and is called isPluginSidebarOpened and comes from core/edit-post, eg:
import { subscribe, select } from '#wordpress/data';
subscribe(() => {
if (select('core/edit-post').isPluginSidebarOpened()) {
// Is open..
} else {
// Is closed..
}
});

Control relay with contact button on Openhab problem

Hy,
I want to control a relay with a button in openHab, and i want to create a rule to check if state is ON or OFF and after that to do a thing.
I am new in codding and i don't know what I've done wrong.
I need some help, please.
This si the code from home.items
Switch buc1_releu "Bec1" (LivingRoom) { gpio="pin:18 activelow:yes initialValue:high force:true" }
Contact buc1_intrerupator "Intrerupator [%s]" (LivingRoom) { gpio="pin:23 activelow:yes" }
And this si the home.rules
rule "buc1"
when
Item buc1_intrerupator changed
then
if (buc1_releu.state == ON){
sendCommand(OFF)
}
else if (buc1_releu.state == OFF){
sendCommand(ON)
}
end
Found the problem, this is the correct code :D
rule "buc1"
when
Item buc1_intrerupator changed
then
if (buc1_releu.state == ON) {
buc1_releu.sendCommand(OFF)
}
else if (buc1_releu.state == OFF) {
buc1_releu.sendCommand(ON)
}
end

Fullcalendar restrict view to today + x months

I am using the fullcalendar library. How can i restrict my months view to only see the next x number months?
I dont see any straight forward answers to this in the documentation. I am not sure if I am supposed to try and alter the render methods?
Thanks
This should do the trick for you
$('#calendar').fullCalendar({
viewDisplay: function(view) {
// maybe return false aborts action?
if (view.start > lastDayOfNextMonth) {
return false;
}
// or disable next button if this is last valid month
if (view.end + oneDay >= lastValidDate) {
$("#calendar #fc-button-next").attr("disabled","disabled");
}
// or gotoDate if view.start is out of range
if (view.start > lastValidDate) {
// proceed
}
}
});
This question has a bunch of samples: FullCalendar examples

JsViews Data-Link Helper Function

I have the following helper defined:
$.views.helpers({
total: function(lines) {
var total = 0;
for (var i = 0; i < lines.length; i++) {
total += lines[i].price * lines[i].quantity;
}
return total;
}
});
Then I have have the following code to data link my model to my view:
var model = {
lines: []
};
$("#lines").link(true, model);
Finally within the view I have the following:
<span data-link="~total(lines)"></span>
However whenever I observably add or remove items from the array it doesn't update the total. I read that you could pass in lines.length into the function and indeed it updated the total each time I added or removed an item. But when I observably updated the quantity property against any of the lines the total did not update.
I'd appreciate it if someone could show me how to do this.
Thanks
Yes, as you found with https://github.com/BorisMoore/jsviews/issues/280, there is not currently a declarative syntax for depending on "All". Probably after V1.0 that feature will be added - along the lines of total.depends = "lines**"; or total.depends = "lines*.*"; for a helper: function total(...)...
Meantime you can use a programmatic approach - which is still very easy. Just trigger a refresh by adding:
$.observable(model.lines).observeAll(function() {
$("#lines").link(true, model);
})
or refresh just the 'total' span by writing:
<span id="total" data-link="~total(lines)"></span>
and
$.observable(model.lines).observeAll(function() {
$("#total").link(true, model);
})
See for example: http://jsfiddle.net/BorisMoore/wch601L9/
I've found the following issue which has a couple of suggested fixes:
https://github.com/BorisMoore/jsviews/issues/280
Unfortunately both are abit of a hack but I guess it will have to do for now.

CodeMirror - AutoComplete "options" not setting right

I am using CodeMirror and attempting to do some CSS styling to the autocomplete pop up. This is a bit difficult, because I need it to not go away when I go to inspect styles and stuff.
So I hunted for a way to do this. I found this code in show-hint.js
if (options.closeOnUnfocus !== false) {
var closingOnBlur;
cm.on("blur", this.onBlur = function () { closingOnBlur = setTimeout(function () { completion.close(); }, 100); });
cm.on("focus", this.onFocus = function () { clearTimeout(closingOnBlur); });
}
If I comment this out, then the autocomplete pop up does not go away when I click on other things; That's what I wanted. But I thought I would explore this more and try to determine what to do to toggle this on and off at will.
So I wanted to be able to set this closeOnUnfocus option on my own. That seemed simple enough.
I cannot find a way to do this, though. Exploring further I found an example on code mirror's website that demonstrates a way to setup the autocomplete system using the following code;
CodeMirror.commands.autocomplete = function(cm) {
CodeMirror.showHint(cm, CodeMirror.hint.anyword);
}
Exploring further, show-hint.js starts out with a function called showHint that has this signature;
CodeMirror.showHint = function (cm, getHints, options) {
// We want a single cursor position.
if (cm.somethingSelected()) return;
if (getHints == null) {
if (options && options.async) return;
else getHints = CodeMirror.hint.auto;
}
if (cm.state.completionActive) cm.state.completionActive.close();
var completion = cm.state.completionActive = new Completion(cm, getHints, options || {});
CodeMirror.signal(cm, "startCompletion", cm);
if (completion.options.async)
getHints(cm, function (hints) { completion.showHints(hints); }, completion.options);
else
return completion.showHints(getHints(cm, completion.options));
};
Okay, so it stands to reason that I could accomplish what I want by passing my option through here; like this...
CodeMirror.commands.autocomplete = function (cm) {
CodeMirror.showHint(cm, CodeMirror.hint.anyword, {
closeOnUnfocus: false
});
}
But this doesn't work - in fact, it seems that the options just don't get passed at all. If I do a console.log in the show-hint.js, the options are outright ignored. They never get through.
So how can I pass options through? I am very confused.
If you want to change the styles of of the hint menu, just use the provided CSS hooks. There is no need to mess around with the autocomplete handlers. e.g.:
.CodeMirror-hints {
background-color: red;
}
.CodeMirror-hint {
background-color: green;
}
.CodeMirror-hint-active {
background-color: blue;
color: yellow;
}
And here's a live Demo.
I've just started to use Codemirror (v4.1) and I've found the same problem. After checking show-hint.js contents it seems that documentation is not updated.
Try to write this when you want to get the suggestions:
CodeMirror.showHint({hint: CodeMirror.hint.deluge, completeSingle: false, closeOnUnfocus: true});
If you need to use the async mode of getting suggestions (it was my case), now you have to do this before previous snippet:
CodeMirror.hint.deluge.async = true;
Hope this helps!
You can pass the options like this :
CodeMirror.showHint(cm,CodeMirror.hint.anyword,{completeSingle: false,closeOnUnfocus:false});
You can write the code as follows:
editor.on("keyup",function(cm){
CodeMirror.showHint(cm,CodeMirror.hint.deluge,{completeSingle: false});
});
It's working for me.

Resources