How to disable jquery-ui (widget) for a specific element? - javascript

I use Jquery-UI and accordingly the selectmenu-widget in my project. Can I disable the widget for a specific element, so that the select look and functionality returns to native?
I tried solutions mentioned in Jquery disable theming for a specific element but without success. data-role: none is not doing any change, and I can't simply remove ui-classes because the widget creates a whole new element which acts like a proxy for the select and so the select itself does not have any classes.
Any help would be appreciated.

I solved it by manually destroying the selectmenu-element and displaying the initial element again at documentReady().
I would be glad to hear about a better solution since this one is hacky and involves problems, e.g. at responsiveness if the element should be displayed just at a specific screen size, you have to handle it again manually in your function where you render the initial element back.

Related

Two dynamic DOM elements and positioning after animations?

So I have table and menus, which I want to place near selected element.
For example, table slides down from one line and there is transition, so I can't instantly take relative offset and set it to menu. I should do it after transition is complete.
So, talking in abstract way, I should emit event about selection of element when table is fully displayed. Or I should display all table and then select element, so menu will know where to go.
The problem is: I dunno how to subscribe on transition end.
Yea, I can recalculate position of menu in $watch, but I don't feel like I need a new watcher here.
How it could be implemented on ReactJS, for example? I use angularjs, but the point is - I don't need to use two-way-binding here.
Any thoughts?
Btw: I can't rely on angular-animate since it requires classes to be used, but I have to play with css dynamic attributes instead. And no, it is not possible to rewrite it to use classes, yes I tried. It will not work by the possibilities of css.

Write a sortable list using jQuery (just basic functionality, jQueryUI is too heavy for me)

I want to write a sortable list using jQuery.
My thought is as follows: As the li element moves with mouse, a placeholder will be placed dymatically where the li element will be placed when mouseup event happens.
But I don't get one thing: How to make the other li elements move up and down appropriately as the placeholder moves. I don't think I should use CSS 'top' property to move these elements as this method actually doesn't change the index of each element in the list automatically. Could someone give me some idea on this? Thanks.
Actually jQuery UI allows you to choose which parts of it you want in your script. So you can choose only sortable (it will have three other dependencies, but nothing particulary large). Just go to jQuery UI homepage and click build custom download. You can get a very lightweight script this way (which you can further strip down if you choose readable code in your download).
It helps your code cross-browser compatibility and jQuery UI code is actually readable and easy to strip down of any unnecessary functionality (you can probably remove for example scrollSensitivity setter).

jQuery tooltip plugin to use a dynamic title attribute

Background: I would like a better replacement for the default title tag tooltip, one that would at least allow me multiple lines across all browsers. The problem is that the title tag gets updated once per second.
Is there a JavaScript/jQuery plugin that can be attached to an element, and update itself as the title attribute changes? I guess it shouldn't be that hard to implement from scratch, but there is no need to reinvent things.
I'm not sure if this would be overkill for you cause, but I use this jQuery plugin: http://craigsworks.com/projects/qtip2/
In my opinion it's the best tooltip plugin out there.
Every time our title changes you could use one of its events (render() maybe).

Add element after a set of elements only if it hasn't been added previously using jQuery

I have some jQuery code that finds elements with the shaded CSS class and adds a div element after it. It is run in the document ready event handler.
$(".shaded").after("<div class='shader'></div>");
The shader class provides styling to make the above element look raised.
My problem is that we started using Ajax to populate content, so now I need to run the code above each time new content is retrieved using Ajax.
What I want to know is how I can detect if this dynamically added "shader" div has previously been added. I know I can find those next elements using this:
$(".shaded").next("div").hasClass("shader")
But how do I elegantly add the "shader" only to the elements that have not been shaded yet?
Thanks in advance.
$(".shaded + :not(.shader)").prev().after("<div class='shader'></div>");
works and tested
First of all, you should really solve this with CSS. But I can imagine situations where that is hard to do (*cough*IE6*cough*).
You could do it the nasty jQuery way and derive which elements already have a shader, like Mrchief's solution.
Or you take the responsible solution and keep a list of elements that have been shaded, and even better, a list of elements that still need to be shaded.
jQuery encourages you to 'abuse' your DOM for storing information about your model, while you really should just make a model and use jQuery based on the information in the model. This is exactly the reason why I'm no longer using jQuery for anything that doesn't involve very complex tasks (I still use it for animations and fancy plugins like lightboxes).
You can try something like this (untested though):
$(".shaded + :not('div.shader')").prev().after("<div class='shader'></div>");
It finds all divs with class shaded and filters out the ones that do not have a div with class .shader after them.
Thanks to #Joseph for pointing out the .prev()

How to make entire DOM draggable & resizable via jQuery UI?

Is there a way to "activate" an entire DOM to be draggable and resizable using jQuery UI? I then want to save the user's new positions in HTML5's data attribute to recreate the page later.
Imagine this same page you're looking at to be "activated" when you just hover, click, drag, and resize all the visible elements around (snapping would be super nice!). Any advice or idea on this?
Making literally every div/span as drag and droppable is non-sensable. What we has humans easily observe as a atomic "unit" (like the 'javascript' tag box) is not so obvious internally in the HTML structure. So you may have to do some thinking and decide what you want included in "everything" that becomes Drag and droppable. And at that point, you can just name all those elements with a "dd" class and use that.
Like Thr4wn said, if you give each element that should move a class, then you can give each member of that class a function that updates its location when it changes. I suggest using 960.gs as a grid to remember locations.
This way you can each objects classes as html5 data.
It's pretty simple, just do this :
$('*').draggable();
Not really sure why you would want to do this.
if you really want to you could use the $("*") selector. but I would not suggest it...

Categories

Resources