From f070bbe69eea69bcd34108c898e64e87a505ec9d Mon Sep 17 00:00:00 2001 From: Shish Moom Date: Tue, 7 Jul 2009 06:48:59 -0700 Subject: [PATCH] auto-include library scripts --- core/page.class.php | 4 + lib/jquery.auto-complete.pack.js | 11 +++ lib/jquery.cookie.js | 97 ++++++++++++++++++++++ themes/default/script.js => lib/shimmie.js | 0 themes/default/layout.class.php | 13 ++- themes/default/sidebar.js | 83 ------------------ 6 files changed, 121 insertions(+), 87 deletions(-) create mode 100644 lib/jquery.auto-complete.pack.js create mode 100644 lib/jquery.cookie.js rename themes/default/script.js => lib/shimmie.js (100%) delete mode 100644 themes/default/sidebar.js diff --git a/core/page.class.php b/core/page.class.php index a38f3f5f..c765b763 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -80,6 +80,10 @@ class GenericPage { case "page": header("Cache-control: no-cache"); usort($this->blocks, "blockcmp"); + $data_href = get_base_href(); + foreach(glob("lib/*.js") as $js) { + $this->add_header(""); + } $layout = new Layout(); $layout->display_page($page); break; diff --git a/lib/jquery.auto-complete.pack.js b/lib/jquery.auto-complete.pack.js new file mode 100644 index 00000000..571a81cc --- /dev/null +++ b/lib/jquery.auto-complete.pack.js @@ -0,0 +1,11 @@ +/** + * Auto Complete v2.1 + * June 11, 2009 + * Corey Hart @ http://www.codenothing.com + * + * Auto Complete takes input from the user and runs a check through PHP to find what the user + * is looking for. This test case runs a limited search on words that begin with the letter 'a'. + * + * @css: Optional class for list rollovers, defaults to 'non-404' + */ +;(function($){$.fn.autoComplete=function(css){this.each(function(){var $obj=$(this),$input=$("input[type='text']",$obj),settings={opt:-1,inputval:"",css:(css)?css:"non-404",ajax:$("input[name='href']",$obj).val()};$input.keyup(function(e){var key=e.keyCode;if((key>47&&key<91)||key==8){settings.opt=-1;settings.inputval=$input.val();sendRequest(settings.inputval)}else{if(key==37||key==39){settings.opt=-1;$("ul",$obj).html("")}else{if(key==38){if(settings.opt>=0){settings.opt--;var val=$("ul li",$obj).removeClass(settings.css).eq(settings.opt).addClass(settings.css).attr("rel");val=(settings.opt<0)?settings.inputval:val;if(val){$input.val(val)}}}else{if(key==40){if(settings.opt<$("ul li",$obj).length-1){settings.opt++;var val=$("ul li",$obj).removeClass(settings.css).eq(settings.opt).addClass(settings.css).attr("rel");if(val){$input.val(val)}}}}}}}).blur(function(){settings.opt=-1;$("ul",$obj).html("")});var sendRequest=function(val){$.post(settings.ajax,{value:val},function(json){$("ul",$obj).html("");json=eval(json);if(json&&json.length>0){for(i in json){$("ul",$obj).append('
  • '+json[i].display+"
  • ")}mouseaction()}})};function mouseaction(){$("ul li",$obj).mouseover(function(){$("ul li",$obj).removeClass(settings.css);$input.val($(this).addClass(settings.css).attr("rel"))}).click(function(){$("ul",$obj).html("")});$("ul",$obj).mouseout(function(){$input.val(settings.inputval)})}})}})(jQuery); diff --git a/lib/jquery.cookie.js b/lib/jquery.cookie.js new file mode 100644 index 00000000..a80bfa29 --- /dev/null +++ b/lib/jquery.cookie.js @@ -0,0 +1,97 @@ +/** + * Cookie plugin + * + * Copyright (c) 2006 Klaus Hartl (stilbuero.de) + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + * + */ + +/** + * Create a cookie with the given name and value and other optional parameters. + * + * @example $.cookie('the_cookie', 'the_value'); + * @desc Set the value of a cookie. + * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true }); + * @desc Create a cookie with all available options. + * @example $.cookie('the_cookie', 'the_value'); + * @desc Create a session cookie. + * @example $.cookie('the_cookie', null); + * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain + * used when the cookie was set. + * + * @param String name The name of the cookie. + * @param String value The value of the cookie. + * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. + * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. + * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. + * If set to null or omitted, the cookie will be a session cookie and will not be retained + * when the the browser exits. + * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). + * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). + * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will + * require a secure protocol (like HTTPS). + * @type undefined + * + * @name $.cookie + * @cat Plugins/Cookie + * @author Klaus Hartl/klaus.hartl@stilbuero.de + */ + +/** + * Get the value of a cookie with the given name. + * + * @example $.cookie('the_cookie'); + * @desc Get the value of a cookie. + * + * @param String name The name of the cookie. + * @return The value of the cookie. + * @type String + * + * @name $.cookie + * @cat Plugins/Cookie + * @author Klaus Hartl/klaus.hartl@stilbuero.de + */ +jQuery.cookie = function(name, value, options) { + if (typeof value != 'undefined') { // name and value given, set cookie + options = options || {}; + if (value === null) { + value = ''; + options = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed + options.expires = -1; + } + var expires = ''; + if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { + var date; + if (typeof options.expires == 'number') { + date = new Date(); + date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); + } else { + date = options.expires; + } + expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE + } + // NOTE Needed to parenthesize options.path and options.domain + // in the following expressions, otherwise they evaluate to undefined + // in the packed version for some reason... + var path = options.path ? '; path=' + (options.path) : ''; + var domain = options.domain ? '; domain=' + (options.domain) : ''; + var secure = options.secure ? '; secure' : ''; + document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); + } else { // only name given, get cookie + var cookieValue = null; + if (document.cookie && document.cookie != '') { + var cookies = document.cookie.split(';'); + for (var i = 0; i < cookies.length; i++) { + var cookie = jQuery.trim(cookies[i]); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) == (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; + } +}; \ No newline at end of file diff --git a/themes/default/script.js b/lib/shimmie.js similarity index 100% rename from themes/default/script.js rename to lib/shimmie.js diff --git a/themes/default/layout.class.php b/themes/default/layout.class.php index b928e38a..d6723ff2 100644 --- a/themes/default/layout.class.php +++ b/themes/default/layout.class.php @@ -49,10 +49,6 @@ class Layout { $header_html - - - - @@ -92,7 +88,16 @@ EOD; $(document).ready(function() { $(\"#$i-toggle\").click(function() { $(\"#$i\").slideToggle(\"slow\"); + if($(\"#$i\").is(\":hidden\")) { + $.cookie(\"$i-hidden\", true); + } + else { + $.cookie(\"$i-hidden\", false); + } }); + if($.cookie(\"$i-hidden\")) { + $(\"#$i\").hide(); + } });
    diff --git a/themes/default/sidebar.js b/themes/default/sidebar.js deleted file mode 100644 index 585f8ca8..00000000 --- a/themes/default/sidebar.js +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This script shamelessly stolen from wakachan.org d(^_^)b - */ - -var cookie_name="shimmie_sidebar"; -var default_sections=["upload", "edit_tags"]; - -function toggle(id) -{ - var e=document.getElementById(id); - if(!e) return; - if(e.style.display) - { - remove_section(id); - e.style.display=""; - - var e2 = document.getElementById(id+"-toggle"); - if(e2) { - e2.style.color = "#000"; - } - } - else - { - add_section(id); - e.style.display="none"; - - var e2 = document.getElementById(id+"-toggle"); - if(e2) { - e2.style.color = "#AAA"; - } - } -} - -function add_section(id) -{ - var sections=get_sections(); - for(var i=0;i