Raphael.js : how to unset Element's attr? - raphael

I have a link set to Element:
element.attr({href: 'http://google.com'});
Now I want to delete a link. I'm trying:
element.attr({href: false});
element.attr({href: null});
element.attr({href: ''});
But none of them works.
Even
delete element.attrs.href;
doesn't help.
How can I unset element's attribute?

you should be aware that (using Raphaël API,) .attr() does not affect the underlying DOM element, but merely attaches a property to the Raphaël object.
if you wish to address the actual node's href attribute you should either use:
element.node.href = 'http://google.com';
or:
element.node.setAttribute('href', 'http://google.com');
Check out 'Element.node' on the Raphaël's documentation.

Related

Emberjs: Use args as tracked property

I am doing a store query in the controller and then passing the result down to a child component.
// Controller
#tracked comment;
#action
async fetchComment() {
const comment = await this.store.query('note', {
filter: {
listing: this.listing.id,
},
});
if (comment && comment.length > 0) {
this.comment = comment.firstObject;
}
}
// Template
<MyComponent #comment={{this.comment}} />
I want to use the arg to populate a tracked property in the child component.
// Component
#tracked comment = this.args.comment;
I found this does not work but works well as a getter. However with a getter I am unable to set this to null when deleting that record.
I have also tried to set the tracked property in the Constructor but that didnt work either.
I suspect this has something to do with passing in a promise or store object in the args because this works fine with static data.
why your code does not work
this code can not work:
#tracked comment = this.args.comment;
this is because comment on the controller is initially undefined but will later bet set to comment.firstObject when the network request is done and the await in your fetchComment function returns.
Generally everythings on args basically always behaves like its #tracked (while more accurate you would describe it as getters). So this usually will just update fine. But the assignment #tracked comment = this.args.comment; only happens once when you create the component, so you no longer depend on updates on args.
why you can not set this.args.comment to null
If you use a getter or directly always use this.args.comment you can not change this reference. This is because this.args is always readonly. you can change objects on this.args.something, but you never can change the reference or primitive value on this.args.
Sidenote: this is only true if the component was called with <AngleBracket /> syntax. For the older {{curly-component}} syntax this is not true. So this does not depend on the component itself but how the component gets called.
you could notify the controller to remove the reference
one good thing to do is to pass down a deleteComment action to the component that basically does something like this.comment = null on the controller. then you use this.args.comment directly or by a getter and you can call this.args.deleteComment() to set comment on the controller to null, which will update anything that uses this.args.comment or a getter that returns this.args.comment.
this is essentially because in your architecture the controller owns the data (because it loads it). so the controller is also responsible to delete it.
if you use ember-data you can check isDeleted
if its a ember-data model (which it probably is if you call this.store) then it has a isDeleted property. you can use this to check if the record is deleted, since ember-data records dont disappear if they get deleted. which is exactly because of problems like this.
how you use another property to shadow a argument
you could do something like this to shadow an argument in your component:
#tracked commentIsDeleted = false;
get comment() {
return this.commentIsDeleted
? null
: this.args.comment;
}
this way at first this.comment will work like a normal getter, but you can shadow delete it by setting this.commentIsDeleted = true;. From that on this.comment will be null.

Qml: pass argument as part of URL when loading components from files

Is there a mechanism to pass URL arguments in Qml and extract them later?:
StackView.push("Page.qml?#label2);
Regards,
You can "pass arguments" when creating an object from a component.
StackView.push(component.createObject(null, {"someProperty" : someValue}))
So you can use an auxilary component to facilitate that:
Component { id: component; url: "Page.qml" } // or
property Component component: Qt.createComponent("Page.qml") // or
Component { id: component; Page {} }
Or if you don't want to pollute with extra stuff, you can directly:
StackView.push(Qt.createComponent("Page.qml").createObject(null, {"someProperty" : someValue}))
Lastly, not a good idea to have your StackView named StackView, I mean in QML neither properties nor ids can begin with uppercase character.
No need to create an object manually. Just do this
stackView.push(Qt.resolvedUrl("qrc:/U/R/L/item.qml"), {someCustomProperty: 0})
This is NOT worked:
navigationBar.push(Qt.resolvedUrl('qrc:/Pages/BookListPage.qml'), {argument:'test'})
But this is worked (to create an object):
navigationBar.push(Qt.createComponent("qrc:/Pages/BookListPage.qml").createObject(null, {argument:'test'}))
Actually according to the QT docs ([http://doc.qt.io/qt-5/qml-qtquick-controls-stackview.html][1]) the recommended way is to pass a property list containing at least the the following minimum entries to the push function ():
item: this property is required, and holds the item to be pushed.
properties: a list of QML properties to be assigned to the item upon push. These properties will be copied into the item at load
time, or when the item will become the current item (normally upon
push).
so we get
navigationBar.push({item: Qt.resolvedUrl("MyRectangle.qml"), properties: {"color" : "red"}});

phpQuery finding the type of tag

I need to be able to determine the type of tag i have selected with phpQuery.
So, if i have the reference of an element, how can i easily figure out its tag type?
In jquery/js tagName will suffice or prop('tagName')
But in phpQuery i cannot seem to find a straight forward function to do this..
$doc = phpQuery::newDocumentFilePHP($ftp_file['local_path']);
if(!pq('.clasToFind')->length) {
$tagType = pq('.clasToFind')->tagName;
}
Is the best answer regex the answer here?
tagName is a DomNode property. So when you iterate:
foreach(pq('.clasToFind') as $el){
echo $el->tagName;
}
See my answer here: How to find tag name using phpquery?
You need to call get to point to the first element of the collection, even if it has only one element. So, your code would be something like this:
$doc = phpQuery::newDocumentFilePHP($ftp_file['local_path']);
if($doc->find('.clasToFind')->length) {
$tagType = $doc->find('.clasToFind')->get(0)->tagName;
}

Format a property before displaying it

Hello StackOverflow experts,
I would like to know if it would be possible to use Ember.js' computed properties to modify the value of the property before returning to whatever object requests it.
Imagine this simple example:
I have a User object with mail property
When I set the property, I want the email address to change from first.last#example.com to first.last#anotherexample.com, then return it
When I request the property ( via User.get ) I want to get the modified property back.
I think it should be pretty simple by utilising another 'helper' property, like formatted_mail, where I would store and retrieve the formatted value, but I wonder if something like this can be done without additional model properties.
So far, I have this coffescript code, but I always get 'undefined' when reading the property, even though I set it before, so I suspect the value does not get saved by Ember anywhere:
mail: ( ( key, value ) ->
if arguments.length == 1
return this.get 'mail'
else
return value.split( '#' )[0] + '#anotherexample.com'
).property 'mail'
Thank you for your assistance!
You are close to solution.
As computed properties are always cached by default in Ember (you could disable this behaviour using .volatile()), you do not have to specify what to do when arguments.length is 1, except if you want to specify a default value.
So here it should looks like:
App.User = Ember.Object.extend({
mail: function(key, value) {
if (arguments.length === 2) {
return value.split('#')[0] + "#tieto.com";
}
return null;
}.property()
});
The return null just specify the default value.
When you set the mail property, it will cache the returned value and always returns it without recomputing this property.
Note that you can do that only because the mail property does not depend on other properties. If you were declaring it with .property('anotherProperty'), the mail property will be recomputed any time anoterProperty changes. So in the example above it will reset it to null.
You can try it in this JSFiddle.

How to access back-forward list of UIWebView

How can we get the no of list items in bad-forward list of UIWebView? What I wanted to do is when back list is empty (ie. when there is no link to go back) navigate to previous controller. So wanted to know the count in the list.
Thanks in advance
Sayali
you dont want to access backforward list just for that, simply use .canGoBack property.
Here is the way to do it anyways (be carefull, private API here) :
id webview111 = [self _documentView]; /// self - uiwebview subclass
coreWebV = [webview111 webView];
backForwardList = [coreWebV backForwardList];