Thursday, 12 September 2013

jQuery image slide not working?

jQuery image slide not working?

I am new to jQuery and trying to play around with it to get some practice.
I have inserted a jQuery image slider on my local website by using a
source code provided at slidesjs.com but it's not working.
Also, I like to make it more organise so how can I link my jQuery page
with the html if I were to separate all the jQuery out into a new file?
http://jsfiddle.net/3WaWf/1/
Following is what i attempted:
<html>
<header>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="jquery.slides.min.js"></script>
<link rel="stylesheet" type="text/css" href="style2.css"></header>
<style>
/* Prevents slides from flashing */
#slides {
display:none;
}
</style>
<script>
$(function(){
$("#slides").slidesjs({
width: 940,
height: 528
});
});
</script>
<body>
<div class="nav-bar">
<h1 class="logo" style="vertical-align:middle">LogoHere</h1>
<ul class="nav-menu">
<li><a href="index.html" class="action">Action</a></li>
<li><a href="about.html" class="about">Who we are</a></li>
<li><a href="blog.html" class="blog">Blog</a></li>
<li><a href="services.html"
class="services">Services</a></li>
<li><a href="contact.html" class="contact">Get in
touch</a></li>
</ul>
<div id="slides">
<img src="hkslide1.jpg">
<img src="hkslide2.jpeg">
<img src="hkslide3.jpg">
</div>
</div>

Javascript denying user input into a field on keydown

Javascript denying user input into a field on keydown

I have a field with a set number of digits to be allowed. This field has a
mask to add commas in the appropriate places. However if the max number if
digits is allowed and the user highlights a comma, they can replace the
comma with a digit - then the mask is applied and the field ends up adding
extra digits. I have a function that catches this on keydown and does an
e.preventDefault(); when the value length is >= allowedDigits for that
field.
The problem is that when the user keys down the number gets placed into
the field then it checks it. Is there any way to remove what the user
pressed or check before the input gets placed into the field?

Deriving generic type from generic ArrayList

Deriving generic type from generic ArrayList

I have two types that extend the generic ArrayList type.
public class BuyersGuideResponse extends ArrayList {
private void checkStatusAttributes(){ ... }
private void addItems(){ ... }
}
public class CatalogEngineTypeResponse extends ArrayList {
private void checkStatusAttributes(){ ... }
private void addItems(){ ... }
}
The checkStatusAttributes method is identical in both types so I'd like to
create a abstract generic intermediate type. I currently have
public class ArrayListResponse extends ArrayList {
// no implementation
}
public class BuyersGuideResponse extends ArrayListResponse
{
// implementation unchanged
...
private void addItems()
{
NodeList nodes =
doc.getElementsByTagName(CatalogConst.BUYERS_GUIDE_ITEM_NODE_NAME);
for(int i = 0; i < nodes.getLength(); i++)
{
add(new BuyersGuideItem(nodes.item(i)));
}
...
}
...
}
When compiling the following error is generated :
quote - BuyersGuideResponse.java:51: error: unexpected type
add(new BuyersGuideItem(nodes.item(i)));
^
required: class
found: type parameter BuyersGuideItem
where BuyersGuideItem is a type-variable
BuyersGuideItem extends Object declared in BuyersGuideItem.java
end quote -
Where am I going wrong?

Wednesday, 11 September 2013

Restrict php file in .htaccess based on mode/query string

Restrict php file in .htaccess based on mode/query string

I want to restrict access to a specific file (ucp.php), but ONLY in
registration mode. Ie, someone will have to authenticate in order to
register, but once registered will be able to access other ucp.php
functions (profile editing, for example), without being required to
authenticate again.
Since ucp.php is the only file with a "register" mode, I've tried:
<Files "^(.*)mode=register$">
require valid-user
</Files>
So far, I've only been able to restrict access no matter the function, or
not at all. I'm open to any alternative suggestions for how to do this.
Thanks!
EDIT
I also tried:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*)mode=register(.*)$ [NC]
RewriteRule require valid-user
That didn't work either, but as you can probably tell, I'm just kind of
stitching things together trying to get it to work.
Any suggestions?

Replace textfield with select CKEditor 4 image dialog box

Replace textfield with select CKEditor 4 image dialog box

I'm trying to replace the default text field for the URL with a select
drop down populated with images from a database; however I managed to get
everything working besides actually placing the image into the editor. I
wrote a little adaption that does the desired effect within the dialog
box, however when I press "OK" it still fails to place the image within
the textarea. Any ideas?
Current adaptation:
CKEDITOR.on("dialogDefinition", function(ev){
var d_name = ev.data.name, d_def = ev.data.definition, info = null,
preview = null;
if(d_name == "image") {
info = d_def.getContents("info");
info.remove("txtHSpace");
info.remove("txtVSpace");
info.remove("txtUrl");
info.add({
id: "txtUrl",
type: "select",
label: "Site Images",
items: images,
onChange: function(){
preview = $("#cke_66_previewImage"), val = this.getValue();
if(val) {
preview.attr("src", val).removeAttr("style");
} else {
preview.removeAttr("src").css("display", "none");
}
},
validate: function(){
val = this.getValue();
return(val != "" && val != null);
}
});
}
});

Requirejs module called before calling FB.init() error

Requirejs module called before calling FB.init() error

I have two require.js modules. In module A there is a function with an
asynchronous call to Facebook, the function is also attempting to
initialize module B.
Module B will only run properly if it is initialized on return of init.
Otherwise, it will return the following error:
FB.getLoginStatus() called before calling FB.init().
Why is it that the module will only load and run properly on return of init?
Here is the code in module A:
:::Working:::
/*global define */
define(['facebookSDK','getstuff'], function (FB,getstuff) {
'use strict';
var init = function() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID,
accessToken = response.authResponse.accessToken;
console.log(uid + ' ' + accessToken);
} else if (response.status === 'not_authorized') {
console.log('User has not authorized this App');
} else {
window.top.location = 'https://www.facebook.com/index.php';
}
});
return getstuff.initialize();
};
return {initialize:init};
});
:::Error:::
/*global define */
define(['facebookSDK','getstuff'], function (FB,getstuff) {
'use strict';
var init = function() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID,
accessToken = response.authResponse.accessToken;
console.log(uid + ' ' + accessToken);
} else if (response.status === 'not_authorized') {
console.log('User has not authorized this App');
} else {
window.top.location = 'https://www.facebook.com/index.php';
}
});
getstuff.initialize();
};
return {initialize:init};
});

cannot install pycurl - get errors 1 and 2

cannot install pycurl - get errors 1 and 2

I am attempting to install pycurl-7.19.0 on my Mac OSX 10.8.4.
The error I get when compiling:
py setup.py install
The results:
Using curl-config (libcurl 7.24.0)
running install
running build
running build_py
running build_ext
building 'pycurl' extension
clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common
-fno-strict- aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE
-DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g
-Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64
-pipe -DHAVE_CURL_SSL=1
-I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
-c src/pycurl.c -o build/temp.macosx-10.8-intel-2.7/src/pycurl.o
clang: warning: argument unused during compilation: '-mno-fused-madd'
In file included from src/pycurl.c:50:
In file included from /usr/local/include/curl/curl.h:35:
/usr/local/include/curl/curlrules.h:143:6: error: '__curl_rule_01__'
declared as an array with a negative size
[CurlchkszEQ(long, CURL_SIZEOF_LONG)];
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/curl/curlrules.h:132:27: note: expanded from macro
'CurlchkszEQ'
#define CurlchkszEQ(t, s) sizeof(t) == s ? 1 : -1
^~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/curl/curlrules.h:153:6: error: '__curl_rule_02__'
declared as an array with a negative size
[CurlchkszEQ(curl_off_t, CURL_SIZEOF_CURL_OFF_T)];
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/curl/curlrules.h:132:27: note: expanded from macro
'CurlchkszEQ'
#define CurlchkszEQ(t, s) sizeof(t) == s ? 1 : -1
^~~~~~~~~~~~~~~~~~~~~~~
src/pycurl.c:85:4: warning: "libcurl was compiled with SSL support, but
configure could not determine which " "library
was used; thus no SSL crypto locking callbacks will be set, which may "
"cause random crashes on SSL requests"
[-W#warnings]
# warning \
^
1 warning and 2 errors generated.
error: command 'clang' failed with exit status 1
I currently have curl-7.32.0 installed and am running Python 2.7.2 and GCC
4.2.1.