JQuery :: Extend() When Source Object Contains Functions?
Oct 8, 2009Run this code :
var empty = {};
var defaults = { validate: false, limit: 5, name: "foo", buttons :
{}};
[code]....
Run this code :
var empty = {};
var defaults = { validate: false, limit: 5, name: "foo", buttons :
{}};
[code]....
What happens if you do the following? - That is deep copy a jQuery selector.
[Code]...
I'm concerned whether the myObj.selector object will deep copy the whole of jQuery as part of the process. My initial tests did not show any obvious speed hit, but it is rather a basic test right now.
As I know,it's not well to extend Object.prototype derictly.
In the Prototype(JS Framewoke),there is no extend Object.prototype.
It only add some static method for Object class.I want to konw the reason.
How to extend the constructor for the date object of the javasccript so that whenever a call is made to the constructor, I want to perform a particular action? Basically how to define wrappers for default javascript methods or objects like Date() so that I can perform some action and then invoke the original method? So basically if I have something like var a = new Date(); I want it to (say) alert the value of the date everything Date() is called and then execute the default date constructor.
View 3 Replies View RelatedI have a few String prototypes such as String.prototype.EscapeReg = function () { return this.replace(/[-[]{}()*+?.,\^$|#s]/g, "\$&"); }; // Escapes characters for use with a regular expressionI also have my own class/ library which is used like this var adg = new AndyG_ns.ADG_Utils(); adg.StartClock('AndyClock','dd mmm yy hh:nn'); // etc.What I would like to do is to only add the prototype to my library (not to the global namespace). The end result I'm looking for is to use code such as:
var adg = new AndyG_ns.ADG_Utils();
var myString = new adg.AString();
var parsed = myString.EscapeReg();
In addition, I want to be able to also use/create my special string sub-class within my library. I suppose I'm saying that I would like to extend or super-class the native String object.
How would I go about copying all the prototype functions AND the constructor from one object into another object, and then call them?
I know I can use this.example.call(this), but that's not an acceptable solution. I want to deploy this style over dozens, potentially hundreds of objects.
I've been going through the documentation for the deferred objects API, and one thing that's still not clear to me is : what jQuery functions are returning a deferred object?
The documentation seems to say that jQuery.ajax() and the animation functions like jQuery.fadeIn() does (what about jQuery UI effects?), but the pages for those functions say they return a jqXHR object and a plain jQuery object.
[Code]...
I am using objects in JS and I am trying to add draggable() into a DIV that works when I move the function out of the object context.
Example:
Code:
That does not work. However, if I do this:
Code:
Then it will work... because the draggable() function is not within the object.
I need this to work within the object, because I will have several DIVs associated with objects and I need them to have draggable() in specific cases.
Does anybody encountered this problem ? My purpose is to change the source of a flash object from param_src = window.location.search.substring(1)
so the essential code is something like this:
command = '<object ... src="' + param_src + '" ... TYPE="application/x-shockwave-flash" ...</object>'
document.write(command);
This works on FIREFOX but IE keeps playing the same file instead of playing a new one !
I have tried to add the no-cache meta-tags in the header but it still doesn't work.
I got some code that loads divs from other web pages into a particular div in my main page. In other words, I click on a button, and this tells jquery to load afragment of a particular page into my main page. For instance if I have 5 web pages onrock stars, I could have 5 buttons, and each button could load one rockstar's biography into a div on the main page (and replace whatever was there before). This works, and I do see the content that it loaded. But when I do 'view source' in IE, I do not see that content (the bio of the rock star). Another clue that this content is not really there, is when I try and run some code on that content. The content (from those external pages) have divs with specific names, and I try and make them into collapsible panels by running the following short function:
var IdentifyPanels = function() {
$("DIV.ContainerPanel > DIV.collapsePanelHeader > DIV.ArrowExpand").toggle(
function() {
[code]....
i don't know so much about jquery so just i use them with indication from their web site. so my problem is how can i use multiple source of jquery without one source stop the other,and that what i need:
[Code]....
I am having a hard time getting the javascript file to run any of the functions after I've changed my original script to object literal format. Please tell me why it isn't working! I have attached a zip format of my code.
View 4 Replies View RelatedUsually I have various JavaScript functions for common functionality on my pages (i.e. select all, export, etc.). Typically I will create a common.js file and place these functions within it. Is there any advantage to create a client side object which encapsulates this functionality such that I'd use something lik common.SelectAll() or something similar?
Not sure if there is a best practice peeps follow for this or not.
I am using the datepicker plug in, and am trying to extend it to not allow sundays to be selected. Now the problem I have is I am no javascript savy... so not sure the correct way to format this.
Here is my code for the plug in:
<script type="text/javascript">
$(function() {
// Tabs
$('#datepicker1').datepicker({
beforeShowDay: function(date) {
return [(date.getDay() > 1), ""];
} minDate: 0,
maxDate: "+12M +0D",
dateFormat: 'dd-mm-yy'
});});
</script>
The above is not working, It is not showing the calendar, so I know something is up somewhere here? The reason it has datepicker1 is on the page it is dynamic and can have multiple occurences of the calendar but with numbers after each.
When you need for a certain element (say a text input box) to remember some data, what is the best way to do this? Can you extend the input box object with jquery? Right now i've been storing it in the rel tag $('#testInput').attr('rel','extrainfo') it just seems like there should be a better way to do this.
View 2 Replies View RelatedCurrently I'm trying to do the following:
{
config : {
user : "name",
mod : true
}}
That is JSON nr 1, now I got the following
{
config : {
mod : false
}}
What I need as a result is:
{
config : {
user : "name",
mod : false
}}
If I do a $.extend(json1, json2) then I will lose my user name.
If I do a $.merge(json1, json2) I will keep my username, but my mod will not be overwritten.
How can I overload or extend (or intercept) jQuery's .html() method so that it works its default way unless the object has a certain class?
View 2 Replies View RelatedHow to extend the _alsoResize function of the resizable plugin?
View 1 Replies View RelatedI've cranked up the numbers for sensitivity, interval, and timeout, and the site seems totally unresponsive to my changes. I've double-checked that hoverintent.js is being called, and it definitely is.
var cfg = {
sensitivity: 7,
interval: 5500,
[code]....
recently i noticed that all of my embedded JavaScript code and external style sheets are being shown IN "view source."
this happens in all browsers ( IE, FF, Chrome, and Safari [windows]) ... oddly enough it only happens when viewing on my vista or win2k3 machines. is this something added to these OS's or the result of an installed program? has anyone seen this before?
I switched to using this function to create element:
----------------------------------------------------
function elem(name, attrs, style, text) {
var e = document.createElement(name);
if (attrs) {
for (key in attrs) {
if (key == 'class') {
e.className = attrs[key];
} else if (key == 'id') {
e.id = attrs[key];
} else {
e.setAttribute(key, attrs[key]);
}
}
}
if (style) {
for (key in style) {
e.style[key] = style[key];
}
}
if (text) {
e.appendChild(document.createTextNode(text));
}
return e;
}
---------------------------------------------------------
so instead of the "old" way:
var oMyDiv = document.createElement("DIV");
oMyDiv.setAttribute("id","testid");
oMyDiv.className = "testclass";
I use that function :
var oMyDiv = elem('DIV', {'id':'testid', 'class':'testclass'});
The rendered source shows this:
<div extend=" function (object) {return Object.extend.apply(this, [this,
object]); } "
class="testclass" id="testid">
Question: I don't understand the "EXTEND" part......anyways does it look
legit/right?
I have a website that I frequently visit (FWIW, Firefox 3.x is my browser of choice) with many image sources referring to URLs that end with "-thumbnail.jpg". However, for better image quality, I am trying to use Greasemonkey to replace all instances of "-thumbnail.jpg" in the source of images on this site with "-bigthumbnail.jpg". The closest I could think of was to somehow use getElementsByTagName and innerHTML.replace, but realized that innerHTML does not do HTML, only content.
Below is as far as I tried to get on my own,
var as,ae;
as = document.getElementsByTagName("img");
for (var i = 0; i < as.length; i++) {
ae = as[i];
ae.innerHTML = ae.innerHTML.replace(/-thumbnail/gi, "-bigthumbnail");
}
})();
I would like to extend any HTMLObject with additional functions, such as the following:
HTMLCollection.prototype.getElementByID = function(s_name)
{
alert(s_name);
return null;
}
Unfortunately this doesn't work. However, this one does:
Code:
Array.prototype.getElementsByName = function(s_name)
{
alert(s_name);
return null;
}
Is there a way to do what I'm looking for, perhaps using other techniques?
I've got a div, and it has an onMouseOver handler attached to it which makes a second div visible. The second div shares part of one side with the first, but not all.
The first div also has an onMouseOut handler which, you guessed it, makes the second div invisible.
However, if the user rolls out of the first div and into the second, I'd like to keep the second div visible. Any ideas how to accomplish this?
basically the way I have it now, it's like most other sites, in terms of paginating. You click 2, 3, 4, for the next pages.
However, I don't really like that. I like the way how twitter has it, so you can click more, and the page then extends, showing more tweets.
How can I apply this to my site (which for the most part, is like a photo gallery, by the way)?
This is a code for checking numbers A1 -> B1, when there is a match, the code will be green, otherwise black. how I can extend this script, that more then one array is checked?
<script type = "text/javascript">
var a1 = ["2","5", "11","16","23","45", "46"];
var b1 = ["2","3","8","12","23", "37", "41", "45", "48"]
[code]....