jQuery page-flip animation - javascript

I am using a pageflip script called Moleskine Notebook. Inside the jquery.booklet.1.1.0.js file there is a function called next which turns the page. I want to call this function from my html file.
I tried "$mybook.next();" but it didn't work, I think I have to do something with jQuery.data() as it states on jquery.booklet.1.1.0.js file (lines 100-103)
//store data for api calls
b.data('booklet',true);
b.data('id', id);
b.data('total', src.children().length);
Here is the script:
http://tympanus.net/Tutorials/MoleskineNotebook/

Read the API docs:
$('#mybook').booklet('next');

Related

call back function after file read in Phonegap

I am dealing with this problem from quite a while, please suggest me a solution:
For android app development, I am using phonegap framework.
I have a async function readFromFile() which reads the json file (which is updated using a user data everytime) stored in SD card, and stores the text result into the global variable, Next I have a function populatePageContents() which reads the global variable, and populates the page's html from the json data.
I want the populatePageContents() function to be called after readFromFile() function has finished reading the file data into global variable.
I tried using someting like this:
<script type="text/javascript">
globalVariable = '';
readFromFile(); // Uses phonegap's file API to read file and puts result into global variable
setTimeout(function() { populatePageContents(JSON.parse(globalVariable)); } , 500);
</script>
The above method works sometimes, but not always. Please suggest some better use of callback functions. Thanks!
Please use callbacks for making it work everytime
U can use something like this:
readFromFile(function(data){
populatePageContents(JSON.parse(data));
});
And your readFromFile function should look like this :
readFromFile(callback){
/***read file phonegap code***//
callback();
}

How to call a controller action using Javascript $.get - Yii?

So, recently I've been trying to call a controller action via javascript $.get. I was suggested by a fellow Stack Overflow member to use
$.get("custom/balance", function(){ });
Where custom is the name of the controller that I am using and balance is actionBalance()—a function that I have declared inside of that controller. I have tried to do so but it seems that the function is not being called. I have placed intentional errors inside of that function so I am sure it is not being called via the $.get function.
previously, I had directed $.get to a file in assets like so
$.get("assets/balance.php, function() { });
This had worked perfectly.
Finally, here is the actionBalance that I have declared - is it possible that I need to then call that function? I'm not sure why custom/balance is not calling the action itself.
public function actionBalance() {
// Return a string
echo '7000';
}
I apologize for the previously incomplete answer which left you confused, as I assumed everyone would want to remove the index.php script name from the URL.
If you are using the default settings, yes, you should add the index.php?r= before the path. index.php is called the entry script in Yii. Other files are hidden/protected from the public in the protected folder.
To hide this entry script from the URL, please follow this tutorial on Yii's website:
Yii 1.1: Url: hide index.php

HTML5 drag event using a $(function() { ... } library

I have been playing around with HTML5 and Javascript for the first time and I am stuck. My question in short is how do I call a method (in html) inside a JS file which starts with
$(function() { ... }
Basically I used azure which gives you a code project to start but when it gave me the files there was a page.js which started with:
$(function() {
var client = new WindowsAzure.MobileServiceClient('[...]', '[...]'),
todoItemTable = client.getTable('todoitem');
...
The azure service has a very simple database which I need to use to create a Kanban boardesc webpage.
I made my task element draggable and added events to handle it but I am unable to create the event method in this JS file and if I have it in my HTML I am unable to call any of the methods in the .js
I have asked around work and no one seems to have seen the $(function() { ... } thing before and I can't find the info that I need anywhere.
Thanks
You do not call this method directly; the syntax you're looking at is JQuery's document.ready in other words this function gets called when your document is finished loading.
JQuery Link - Document.Ready
That is the jQuery shorthand for the $(document).ready(handler) function. Anything you put in the function will be executed when the document is finished loading.
jQuery ready function
That syntax is jQuery - specifically an an alias of the "DOMReady" function
( http://api.jquery.com/ready/ ) which is called after the DOM has finished loading.
Try looking at this question's suggested answer by Derick Bailey.
Why define an anonymous function and pass it jQuery as the argument?
He includes some sample code of how to write a code using a JavaScript Module pattern.
Good luck!
Anthony

Including javascript file dynamically and then calling function dynamically

I've included a javascript file dynamically, here is the file http://www.zaarly.com/anywhere.js
When I call the Zaarly.Anywhere.Open() function I get this error
Zaarly.Anywhere is undefined
If I replace contents of the javascript with a simple function and then call that function it works fine, for example this function works fine:
function simpleFunc() {
alert("called");
}
What could be the problem? The javascript file has no errors, I think it's because of including the file dynamically because it works fine if I include it normally in html file.
Any suggestions
EDIT:
Here is the html that is calling the function
Request on Zaarly
If a call a simple function function such as the on above it works fine
Be sure that you will call Zaarly.Anywhere.Open() only after the script was loaded on page.

Javascript "<body onload=...>" in Drupal

I'm trying to integrate a javascript library for drag&drop on tables into one page of my custom Drupal module. I've included the js file using drupal_add_js, but I don't know how to initialize it.
The documentation for that library states that an init function should be called like
<body onload="REDIPS.drag.init()">
How would I do that in Drupal? Or has Drupal some better way of initializing the script?
Drupal has its own mechanism for this, involving adding a property to Drupal.behaviors. See this page: http://drupal.org/node/205296
Drupal.behaviors.redipsDragBehavior = function() {
REDIPS.drag.init();
};
From the linked page:
Any function defined as a property of
Drupal.behaviors will get called when
the DOM has loaded.
You could try adding another drupal_add_js call in the same function as your other add_js:
drupal_add_js('REDIPS.drag.init();','inline','header',true);
The last param "true" is to defer the execution of the script.
I hope that helps in some way!

Categories

Resources