- Screen name: zerointeger
zerointeger's Profile
14 Posts
15 Responses
0
Followers
Show:
- Expanded view
- List view
Private Message
- 04-Jun-2011 05:35 PM
- Forum: Developing jQuery Plugins
I am stumped. I was under the impression that when using methods for plugin development the init method could be set to set and merge options for other method objects.- (function($){
$.fn.demo = function(method){
var methods = {
init: function(options){
return this.each(function(options){
var defaults = {
x: true,
};
options = $.extend({}, defaults, options);
});
},
first: function(options){ - // errors with options?
return this.each(function(){
__do(options);
});
}, - second: function(options){
- // errors with options?
return this.each(function(){
__do(options);
});
}
- };
var __do = function(options){ - // where is options.x?
- }
/* robot, do something */
if (methods[method]){
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method==='object' || ! method){
return methods.init.apply(this, arguments);
} else {
console.log('Method '+method+' does not exist');
}
};
})(jQuery);
- I am stumped on this.. any help or pointers is appreciated.
This bit of code works great by itself.- $('#formID').live('submit', function(e){
- // do something
- });
However if I try to include something similar in a plugin like so:- (function($){
- /* jQuery.handleStorage plugin */
- $.fn.tester = function(method) {
- /* defined methods */
- methods = {
- /* primary method of usage */
- init: function(options){
- /* default options */
- var defaults = {
- wtf: ''
- };
- var opts = $.extend({}, defaults, options);
- $('#'+$(this).attr('id')).live('submit', function(e){
- // do something
- });
- }
- };
- if (methods[method]){
- return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
- } else if (typeof method==='object' || ! method){
- return methods.init.apply(this, arguments);
- } else {
- $.error('Method '+method+' does not exist on '+opts.name);
- }
- };
- })(jQuery);
I have used the .live() function in other plugins so this is baffling the bejeebus out of me. I am using the latest jquery 1.6.- Not being a super proficient plugin developer has led me here...
I am having a problem with a bit of code which should bind to the forms submit event and process accordingly. Any help is appreciated. Thanks in advance.- (function($){
- $.fn.test = function(options) {
/* default options */
var defaults = {
appid: 'jQuery.test', // Plugin name (unique ID for local, session or cookie storage id)
storage: 'localStorage', // localStorage || sessionStorage || cookie (cookie storage requires jQuery cookie plugin)
dowhat: '', // set || get storage items
form: $(this).attr('id'), // form element (used for processing entire form)
k: $(this).k, // name to use for index
v: $(this).v, // value to use for indexed storage item
aes: false, // Use encrypted storage?
key: '', // key for encrypted storage
display: $(this).display // div element used to display contents of storage
};
/* return */
var ret = '';
/* merge specified options with defaults */
options = $.extend(defaults, options);
/* perform key setting/getting */
$.handleKey(options);
/* public functions
this.get = function(){
return $.getItem(options.storage, options.k);
}
this.set = function(){
return $.setItem(options.storage, options.k, options.v);
} */
/* what are we doing? */
switch(options.dowhat){
case 'get':
ret = $.getItem(options.storage, options.k);
break;
case 'set':
ret = $.setItem(options.storage, options.k, options.v);
break;
default:
$('.'+options.form).live('submit', function(e){ - ret = $.handleAll(options.form, $.getForm(options));
});
break;
}
/* set the display item */
$('#'+options.display).html(ret);
return true;
};
})(jQuery);
- <!-- localStorage default unencrypted examples -->
<script>
var $j = jQuery.noConflict();
$j(document).ready(function(){
$j('#defaultset').test();
});
</script>
<fieldset>
<legend><strong>Default setAll to localStorage</strong></legend>
<form id="defaultset" class="defaultset" method="post" action="tests.html">
<div>
<label for="name">Name</label>
<input type="text" name="name" id="name" value="joe whatzitzname" />
</div>
<div>
<label for="name">Address</label>
<input type="text" name="address" id="address" value="over the hill" />
</div>
<div>
<label for="name">Phone</label>
<input type="text" name="phone" id="phone" value="123-456-7890" />
</div>
<div>
<label for="name">Email</label>
<input type="text" name="email" id="email" value="joe@rocks.com" />
</div>
<input type="button" value="submit" />
</form>
<div id="defaultsetdiv"></div>
</fieldset>
- I have been googling around about this for quite awhile without any definite answer.
Here is the code I am having a problem with:- var $m = {'id1':'page1.html','id2':'page2.html'};
/* load modules */
$j.each($m, function($key, $value){
$j('#'+$key).html($loading);
$j.ajax({
url:'proxy.php',
type:'post',
data:'module='+$value,
context:$j('#'+$key),
dataType:'html',
success: function($response){
$j('#'+$key).html($response);
}
});
});
Some of the things I have read when searching for similar problems indicate a problem with the div id changing prior to the success callback.
Can anyone shed some light on this?- I realize this has been posted and I should read the documentation but I have done these things.
I am trying to disabled ajax form processing with jquery mobile so I can use another plugin to handle form processing but now everything is double posted and I am receiving errors when jquery mobile tries redirections
Here is the code I am working with.- var $j = jQuery.noConflict();
$j(document).ready(function() {
$j(document).live('mobileinit',function() {
$j.extend($j.mobile, {ajaxFormsEnabled:false, ajaxLinksEnabled:false});
});
$j(document).bind('mobileinit',function() {
$j.extend($j.mobile, {ajaxFormsEnabled:false, ajaxLinksEnabled:false});
});
$j('#theAsymmetricalForm').pidCrypt();
});
<script src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.js"></script>
to.data("page")._trigger("beforeshow", {prevPage: from});
I have been scouring around looking for more information, as well as attempting to debug some of the methods and objects internal to both libraries but am not having any luck.
Here is a description of the problem I am experiencing since upgrading.
Output from the firebug plugin shows GET requests take place but the content is always referring to the last tab element in the UL list and does not load into the ui.panel or ui.tab page element(s).
Here is an example:- <script src="libs/js/jquery-1.4.3.min.js"></script>
- <script src="libs/js/jquery-ui-1.8.5.custom.min.js"></script>
- <script src="libs/js/jquery.cookie.js"></script>
- <script type="text/javascript">
- var $j = jQuery.noConflict();
- $j(document).ready(function() {
- var tabID = $j.cookie('tabID')||0;
- $j('#tabs').tabs({
- ajaxOptions: {async: true,cache: true},
- selected: tabID,
- show: function(junk, ui) {
- $j.cookie('tabID', ui.index, {expires:3600});
- },
- });
- });
- </script>
- <div id="tabs" class="tabs">
- <ul id="tabID">
- <li><a href="content.php?do=0x00a0" />One</a></li>
- <li><a href="content.php?do=0x00b0" />Two</a></li>
- <li><a href="content.php?do=0x00c0" />Three</a></li>
- </ul>
- </div>
Output from firebug shows that upon initial page load the 'selected' option (which should load the last tab element integer stored in the cookie), is sending a GET request for the last element in the UL list. In this case do=0x00c0. On top of that the response from the ajax GET request does not load in the ui.panel or ui.tab element(s).
I am using Linux (Kubuntu), Firefox 3.6.10 canonical - 1.0 if that makes a difference.
- Is there a review process for new plugins?
This is my first plugin for jQuery but feel its pretty solid and should be beneficial to others.
http://plugins.jquery.com/project/jQuery-Gibberish-AES
Thanks- 05-Oct-2010 08:10 PM
- Forum: Developing jQuery Plugins
I am stumped. First plug-in project and have hit a snag.
Declaring a function which utilizes the .ajax() call will not return the data retrieved during the 'success' function.
Here is the code if anyone could tell me what I am doing wrong... thanks in advance.- (function($){
$.rsaKey = function(proxy) {
$.ajax({
data: 'ssl-key=true',
type: 'post',
url: proxy,
success: function(response) {
return response;
}
});
}
$.fn.gibberish = function(options) { - var options = $.extend(defaults, options);
- return this.each(function() {
- var data = $.rsaKey(options.proxy);
- alert(data);
- });
- });
- })(jQuery);
- 04-Aug-2010 01:52 PM
- Forum: Using jQuery
I am stumped here, when using a selector's name attribute, perform a x.replace() on the variable, then attempting to get the new name of the attribute I am getting the original selector's name.- $j('input[name*=\\[txtProductQuantity\\]]').bind('blur', function() {
- if ($j(this).val()) {
- var x = $j(this).attr('id').replace('txtProductQuantity','txtProductPrice');
- alert(x+' => '+$j('input[name^='+x+']').attr('name'));
- }
- });
- I am experiencing a problem that I have not been able to resolve with research.
Using a group of nested form elements (IE. <input id="txt[0][amount]">, <input id="txt[1][amount]">).
I am not able to come up with a method of selecting and assigning a bind event to anything matching the specified group of input elements- $j('input[name*=txt\\[*\\]\\[amount\\]]').bind('blur', function() {
- // operations
- });
Is this possible? Any help is definitely appreciated.- I am stumped and would like some insight into a problem I am encountering when attempting to utilize the ui.tabs functionality of jquery.
I currently have a master template file which looks like the following:- <script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function(){
var loading = '<img src="{$templates}/images/loading.gif" width="20" height="20" alt="Loading content..." title="Loading content..." />';
var tabID=$j.cookie("tabID")||0;
$j("#tabs").tabs({
cache: false,
fxAutoHeight: true,
fxSlide: true,
fxFade: true,
fxSpeed: 'fast',
selected: tabID,
show: function(junk,ui){
$j.cookie("tabID",ui.index);
},
spinner: loading
});
$j('.auth-form').live('submit', function() {
$j('.ui-tabs-panel:visible').html(loading);
$j.ajax({
data: $j(this).serialize(),
type: $j(this).attr('method'),
url: $j(this).attr('action'),
success: function(response) {
$j('.ui-tabs-panel:visible').html(response);
}
});
return false;
})
});
</script> - <div id="tabs" class="tabs ui-corners-all">
<ul id="tabID">
<li><a href="content.php?do=0x00e0"><span><img src="images/icons/icon-tools.png"/></span> <strong>Options</strong></a></li> - </ul>
</div>
- <script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function(){
var loading = '<img src="{$templates}/images/loading.gif" width="20" height="20" alt="Loading content..." title="Loading content..." />';
var tabIDConfig=$j.cookie("tabIDConfig")||0;
$j("#tabsConfig").tabs({
cache: false,
fxAutoHeight: true,
fxSlide: true,
fxFade: true,
fxSpeed: 'fast',
selected: tabIDConfig,
load: function(junk,ui){
//$j('a', ui.panel).click(function() {
$j(ui.panel).load($j(this).href);
return false;
//});
},
show: function(junk,ui){
$j.cookie("tabIDConfig",ui.index);
},
spinner: loading
});
$j('.auth-form').live('submit', function() {
$j('.ui-tabs-panel:visible').html(loading);
$j.ajax({
data: $j(this).serialize(),
type: $j(this).attr('method'),
url: $j(this).attr('action'),
success: function(response) {
$j('.ui-tabs-panel:visible').html(response);
}
});
return false;
})
});
</script>
<div id="tabsConfig" class="tabs ui-corners-all">
<ul id="tabIDConfig" class="tabID">
<li><a href="content.php?do=0x00ea"><span><img src="/images/icons/icon-users.png" /></span> <strong>Groups</strong></a></li>
</ul>
</div>
Any help or pointers is appreciated. Oh yeah the ajax stuff is used to hijack the submit of forms within either the primary tab or the nested tab. Thanks in advance.- 19-Apr-2010 04:30 PM
- Forum: Using jQuery
I am not sure if this is a bug or a behavior or my code causing the problem.
Because of limitations with tabs in the UI the following bit of code essentially hijacks the forms submit button and dynamically serializes and submits data while ensuring the response goes to the correct or active tab.- $j('.auth-form').live('submit', function() {
$j('.ui-tabs-panel:visible').html(loading);
$j.ajax({
data: $j(this).serialize(),
type: $j(this).attr('method'),
url: $j(this).attr('action'),
success: function(response) {
$j('.ui-tabs-panel:visible').html(response);
}
});
return false;
})
Any help or insight is appreciated.- 12-Apr-2010 06:46 PM
- Forum: Developing jQuery Plugins
In regards to the 'autocomplete' plugin available from Jörn Zaefferer. I needed some added functionality to query a server after a user selected an item from your autopopulate list to then populate an existing form. Here is my solution...
Added functionality of a callBack option Add the following three lines on or near line 235- $input.trigger("result", [selected.data, selected.value]);
- +if(options.callBack){
+ options.callBack(selected.value);
+}
- $j("#autoOrders").autocomplete(orders, {
callBack: queryOrders
});
- function queryOrders(data)
{
var x = data.split(" ");
var y = '?date='+x[0]+'&number='+x[1]+'&account='+x[2]+'&eta='+x[3];
return mySearches(y);
}
function mySearches(data)
{
$j.ajax({
data: data,
type: 'post',
url: 'ajaxSearch.php',
success: function(response) {
var myObj = JSON.parse(response, function(key, value) {
$j('#'+key).val(value);
});
}
});
Just in case I didn't explain it right.
By adding an option for a post selected autocomplete function you can auto-populate a form based on your own custom callback.- I am not quite certain I am doing this correctly however from everything I have read/researched from the jquery howto's, forums and example pages my code should work correctly.
First I am attempting to load a json response generated from a php file on another server using the jquery.getJSON function.- <script>
$("#permissions").click(function() {
$.getJSON({
dataType: 'json',
url: "http://server/file.php?callback=?",
data: ({ token: "12345", resource: "abcde" }),
success: function(XMLHttpRequest,textStatus, errorThrown) {
alert(textStatus);
alert(errorThrown);
alert(XMLHttpRequest.responseText);
},
error: function(XMLHttpRequest,textStatus, errorThrown) {
alert(textStatus);
alert(errorThrown);
alert(XMLHttpRequest.responseText);
}
});
});
</script>
The contents of 'http://server/file.php?callback=?' are as follows:- $arrGetDataResponse = array( "resource" => 0, "uid" => 0, "gid" => 0 );
- if( function_exists( "json_encode" ) ) {
$jsonGetData = json_encode( $arrPostDataResponse );
}
return $jsonGetData;
I cannot get the getJSON function to actually query the server and recieve 404 errors in the raw header output.
Am I doing something wrong? Could SSL be a problem?- «Prev
- Next »
- <script>
- <script type="text/javascript">
Moderate user : zerointeger
- var $j = jQuery.noConflict();
- var $m = {'id1':'page1.html','id2':'page2.html'};
© 2013 jQuery Foundation
Sponsored by
and others.