Browse files

init - sample code

  • Loading branch information...
0 parents commit ae2906b0fb81028d6b2d95f3edeefcb5cf8ba11d @jcleblanc jcleblanc committed Jul 23, 2009
Showing with 240 additions and 0 deletions.
  1. +22 −0 form_submit_forward_external.html
  2. +31 −0 gadgets_io_makeRequest.js
  3. +42 −0 gadgets_json.html
  4. +23 −0 license.txt
  5. +70 −0 tooltip_popup.html
  6. +52 −0 update_small_from_cron.php
22 form_submit_forward_external.html
@@ -0,0 +1,22 @@
+<!--
+form_submit_forward_external.html
+Form Submit and Forward to External Site
+
+Created by Jonathan LeBlanc on 06/08/09.
+Copyright (c) 2009 Yahoo! Inc. All rights reserved.
+The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
+-->
+
+<!-- Form to add search value - link will update to pass search as GET param -->
+<form name="myForm">
+ <input type="text" id="search" name="search" onKeyUp="alterLink()">
+ <a href="http://www.yahoo.com" id="link">Run Request</a>
+</form>
+
+<script type="text/javascript">
+//on search input key up, change the href to pass the new value on the query string
+function alterLink(){
+ document.getElementById('link').href = "http://www.yahoo.com?search=" + document.getElementById('search').value;
+}
+</script>
+
31 gadgets_io_makeRequest.js
@@ -0,0 +1,31 @@
+/*************************************************************************************************************
+* gadgets_io_makeRequest.js
+* OpenSocial Gadgets IO MakeRequest Examples
+*
+* Created by Jonathan LeBlanc on 06/08/09.
+* Copyright (c) 2009 Yahoo! Inc. All rights reserved.
+*
+* The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
+*************************************************************************************************************/
+
+//run ajax request using OpenSocial gagets.io.makeRequest
+function runXHR(){
+ var url = "URL HERE";
+ //define callback function
+ var callback = xhrCallback;
+ var params = {};
+ //define content type of return value
+ params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
+ //define method type (e.g. GET / POST)
+ params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
+ //run ajax request
+ gadgets.io.makeRequest(encodeURI(url), callback, params);
+}
+
+//ajax request callback
+function xhrCallback(response){
+ //check if data is returned from the request
+ if (response.text){
+ //do something
+ }
+}
42 gadgets_json.html
@@ -0,0 +1,42 @@
+<!--
+gadgets_json.html
+OpenSocial Gadgets JSON Examples
+
+Created by Jonathan LeBlanc on 06/08/09.
+Copyright (c) 2009 Yahoo! Inc. All rights reserved.
+
+The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
+-->
+
+<div id='objectDisplay'></div>
+<div id='textDisplay'></div>
+<script>
+/******************** START JSON STRINGIFY ********************/
+//define object
+var myJSONObject = {"bindings": [
+ {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
+ {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
+ {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}]
+};
+
+//use the gadgets.json.stringify OpenSocial method to convert the JSON object to a string
+var jsonString = gadgets.json.stringify(myJSONObject);
+
+//insert the defined 'ircEvent' value of the first object element into the
+//div defined with the id 'objectDisplay'
+document.getElementById('objectDisplay').innerHTML = jsonString;
+/********************* END JSON STRINGIFY *********************/
+
+/********************** START JSON PARSE **********************/
+//define json text - may also be server side serialized json string
+var jsontext = '{"firstname":"Jonathan","surname":"LeBlanc","phone":["111-1234","222-3456"]}';
+
+//use the gadgets.json.parse OpenSocial method to convert the json string to an object
+//replaces the traditional JSON.parse JavaScript method
+var jsonTextData = gadgets.json.parse(jsontext);
+
+//insert the defined 'surname' value of the json object into the
+//div defined with the id 'textDisplay'
+document.getElementById('textDisplay').innerHTML = jsonTextData.surname;
+/*********************** END JSON PARSE ***********************/
+</script>
23 license.txt
@@ -0,0 +1,23 @@
+Yahoo! Application Platform (YAP) Samples Copyright License Agreement (BSD License)
+
+Copyright (c) 2009, Yahoo! Inc.
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+
+* Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+* Neither the name of Yahoo! Inc. nor the names of its
+ contributors may be used to endorse or promote products
+ derived from this software without specific prior
+ written permission of Yahoo! Inc.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
70 tooltip_popup.html
@@ -0,0 +1,70 @@
+<!--
+tooltip_popup.html
+Tooltip With Popup
+
+Created by Jonathan LeBlanc on 06/08/09.
+Copyright (c) 2009 Yahoo! Inc. All rights reserved.
+
+The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
+-->
+
+<div id="tooltip" style="display:none;position:absolute;background-color:#000;color:#fff;padding:10px;"></div>
+<div style="position:relative; margin:50px;">
+ <div id="myContainer" style="position:absolute; top:50px; left:50px; border:1px solid #000; padding:10px; width:200px">Container</div>
+</div>
+
+<script type="text/javascript">
+//assign mouse over handler to container
+var myDiv = document.getElementById('myContainer');
+if (myDiv.addEventListener) {
+ myDiv.addEventListener('mouseover', overCallback, false);
+ myDiv.addEventListener('mouseout', outCallback, false);
+} else if (myDiv.attachEvent) {
+ myDiv.attachEvent('mouseover', overCallback);
+ myDiv.attachEvent('mouseout', outCallback);
+}
+
+//callback for mouseover - sender is the triggering event
+function overCallback(sender){
+ var target;
+
+ // capture the object that the mouse over event was from
+ if (window.event) {
+ target = window.event.srcElement;
+ } else if (sender) {
+ target = sender.target;
+ } else { return; }
+
+ //get the top and left x / y coords of the target
+ var nodeTop = target.offsetTop;
+ var nodeLeft = target.offsetLeft;
+
+ //if the node is within a parent container, loop through each parent
+ //and add their height / width offsets to the top / left
+ nodeParent = target.offsetParent;
+ if (nodeParent != target) {
+ while (nodeParent) {
+ nodeLeft += nodeParent.offsetLeft;
+ nodeTop += nodeParent.offsetTop;
+ nodeParent = nodeParent.offsetParent;
+ }
+ }
+
+ //set tooltip data and display
+ var tooltip = document.getElementById('tooltip');
+ tooltip.innerHTML = "This is a tooltip";
+ tooltip.style.display = "block";
+
+ //set the tooltip top positioning to the same as the container moused over
+ tooltip.style.top = nodeTop + "px";
+
+ //set the tooltip left positioning to the end of the container moused over (left location + width of the container)
+ tooltip.style.left = (nodeLeft + target.offsetWidth) + "px";
+}
+
+//callback for mouseout
+function outCallback(sender){
+ //hide the tooltip
+ document.getElementById('tooltip').style.display = "none";
+}
+</script>
52 update_small_from_cron.php
@@ -0,0 +1,52 @@
+<?php
+/*************************************************************************************************************
+* update_small_from_cron.php
+* Update Small YAP View From Cron Job Sample
+*
+* Created by Jonathan LeBlanc on 06/08/09.
+* Copyright (c) 2009 Yahoo! Inc. All rights reserved.
+*
+* The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
+*************************************************************************************************************/
+
+require_once('apis/Yahoo.inc');
+
+//session information
+define('API_KEY', 'KEY HERE');
+define('SHARED_SECRET', 'KEY HERE');
+define('APP_ID', 'APP ID HERE');
+
+//instantiate session
+$session = new YahooApplication(API_KEY, SHARED_SECRET, APP_ID);
+
+//db information
+$dbhostname = '###';
+$dbusername = '###';
+$dbpassword = '###';
+$dbname = '###';
+
+//connect to database and get all users
+mysql_connect($dbhostname, $dbusername, $dbpassword) OR DIE ('Unable to connect to database. Please try again later.');
+mysql_select_db($dbname);
+$query = "SELECT * FROM user_store";
+$result = mysql_query($query);
+$j = 1;
+
+//for each database user, update the small view
+while (($row = mysql_fetch_assoc($result)) !== false) {
+ if ($row['uid']){
+ $html = '';
+
+ ##################################
+ #CREATE HTML CODE FOR CURRENT USER
+ ##################################
+
+ if (!$session->setSmallView($row['uid'], $html)){
+ echo "$j : NO SESSION SET FOR {$row['uid']}<br />\n";
+ } else {
+ echo "$j : SESSION SET FOR {$row['uid']}<br />\n";
+ }
+ $j++;
+ }
+}
+?>

0 comments on commit ae2906b

Please sign in to comment.