Permalink
Browse files

Added sample to printElement (still in draft), and minified version o…

…f the late loader
  • Loading branch information...
erikzaadi committed Aug 2, 2009
1 parent d54578f commit 7ac06e28d1fb6a0706b9cbba3052317196138db9
@@ -1,3 +1,15 @@
+/*
+* jQuery Late Loader
+*
+* Copyright (c) 2009 Erik Zaadi
+*
+* Plugin home page : http://plugins.jquery.com/project/TODO!
+* Wiki : http://wiki.github.com/erikzaadi/jQueryPlugins/jquerylateloader
+*
+* Dual licensed under the MIT and GPL licenses:
+* http://www.opensource.org/licenses/mit-license.php
+* http://www.gnu.org/licenses/gpl.html
+*/
; (function($) {
$.LateLoader = {
LoadScriptOrCSS: _LoadScriptOrCSS,
@@ -121,8 +133,9 @@
if (!$createdLink.length) {
success = false;
}
- if ($.browser.msie) {
- success = $createdLink.get(0).readyState == "complete";
+ if ($createdLink.get(0).readyState) {
+ var created = $createdLink.get(0).readyState;
+ success = created == "complete" || created == "loaded";
} else {
if (false /*Need to find a non IE solution to validate if the external stylesheet has loaded*/) {
success = false;
@@ -0,0 +1,40 @@
+/*
+* jQuery Late Loader
+*
+* Copyright (c) 2009 Erik Zaadi
+*
+* Plugin home page : http://plugins.jquery.com/project/TODO!
+* Wiki : http://wiki.github.com/erikzaadi/jQueryPlugins/jquerylateloader
+*
+* Dual licensed under the MIT and GPL licenses:
+* http://www.opensource.org/licenses/mit-license.php
+* http://www.gnu.org/licenses/gpl.html
+*/
+;(function($){$.LateLoader={LoadScriptOrCSS:_LoadScriptOrCSS,IsScriptOrCSSLoaded:_IsScriptOrCSSLoaded,GetLoadedScriptOrCSSs:_GetScriptOrCSSArray,GetLoadedScriptOrCSSsByType:_GetScriptOrCSSArrayByType,PluginDefaults:{ArrayDataKey:"LateLoaderDataKey",ElementToAttachDataTo:"body",RemoteTimeout:1500},Defaults:{URL:null,Type:"js",LoadedCallBackFunction:null,ErrorCallBackFunction:null}};
+function _LoadScriptOrCSS(OptionsOrURL){var options;if(typeof(OptionsOrURL)=="string"){options=$.extend({},$.LateLoader.Defaults,{URL:OptionsOrURL});
+}else{options=$.extend({},$.LateLoader.Defaults,OptionsOrURL);}if(_IsScriptOrCSSLoaded(options.URL,options.Type)){_CallFunctionIfAvailable(options.LoadedCallBackFunction,options.URL);
+return;}if(options.Type=="js"){if(_URLIsRemote(options.URL)){setTimeout(function(){if(!_IsScriptOrCSSLoaded(options.URL,options.Type)){_Error(options);
+}},$.LateLoader.PluginDefaults.RemoteTimeout);}$.ajax({dataType:"script",url:options.URL,success:function(){_Success(options);
+},error:function(){_Error(options);},data:{}});}else{_AddCSSFile(options);}}function _IsScriptOrCSSLoaded(URL,Type){var ScriptOrCSSArray=_GetScriptOrCSSArray()||{};
+return(ScriptOrCSSArray[Type]&&($.inArray(URL,ScriptOrCSSArray[Type])!=-1))?true:false;
+}function _GetScriptOrCSSArray(){var ScriptOrCSSData=$($.LateLoader.PluginDefaults.ElementToAttachDataTo).data($.LateLoader.PluginDefaults.ArrayDataKey);
+var ScriptOrCSSArray=ScriptOrCSSData&&ScriptOrCSSData.ScriptOrCSSs?ScriptOrCSSData.ScriptOrCSSs:false;
+if(!ScriptOrCSSArray){return false;}else{return ScriptOrCSSArray;}}function _GetScriptOrCSSArrayByType(Type){var ScriptOrCSSArray=_GetScriptOrCSSArray()||false;
+if(!ScriptOrCSSArray){return false;}if(!ScriptOrCSSArray[Type]){return false;}return ScriptOrCSSArray[Type];
+}function _Error(options){_CallFunctionIfAvailable(options.ErrorCallBackFunction,"error loading "+options.Type+" - "+options.URL);
+}function _Success(options){_AddLoadedScriptOrCSSToArray(options);_CallFunctionIfAvailable(options.LoadedCallBackFunction,options.URL);
+}function _ValidateCSSFileLoaded(options){var $createdLink=$("link[href='"+options.URL+"']");
+var success=true;if(!$createdLink.length){success=false;}if($createdLink.get(0).readyState){var created=$createdLink.get(0).readyState;
+success=created=="complete"||created=="loaded";}else{if(false){success=false;}}if(success){_Success(options);
+}else{_Error(options);}}function _AddCSSFile(options){if(!_URLIsRemote(options.URL)){$.ajax({url:options.URL,dataType:"text",success:function(data){var randID=Math.round(Math.random()*321312);
+var $link=$("<style />").attr({rel:"stylesheet",type:"text/css",id:randID.toString()});
+$link.appendTo("head");setTimeout(function(){var created=$("#"+randID.toString());
+if($.browser.msie){created.get(0).styleSheet.cssText=data;}else{created.text(data);
+}_Success(options);},15);},error:function(){_Error(options);},data:{}});}else{$("<link />").ready(function(){setTimeout(function(){_ValidateCSSFileLoaded(options);
+},15);}).attr({rel:"stylesheet",type:"text/css",href:options.URL}).appendTo("head");
+}}function _AddLoadedScriptOrCSSToArray(options){var ScriptOrCSSArray=_GetScriptOrCSSArray()||{};
+if(!ScriptOrCSSArray[options.Type]){ScriptOrCSSArray[options.Type]=new Array();}ScriptOrCSSArray[options.Type].push(options.URL);
+$($.LateLoader.PluginDefaults.ElementToAttachDataTo).data($.LateLoader.PluginDefaults.ArrayDataKey,{ScriptOrCSSs:ScriptOrCSSArray});
+}function _CallFunctionIfAvailable(method,param){if(method&&$.isFunction(method)){method(param);
+}}function _URLIsRemote(url){return url.indexOf("http")>-1&&(url.indexOf("http://"+window.location.host)==-1&&url.indexOf("https://"+window.location.host)==-1);
+}})(jQuery);
@@ -0,0 +1,11 @@
+.Fuchsia
+{
+ background-color: Fuchsia !important;
+}
+
+hr
+{
+ color: #f00;
+ background-color: #f00;
+ height: 5px;
+}
@@ -0,0 +1,23 @@
+<html>
+<head>
+ <title>jQuery Print Element Tester</title>
+
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
+
+ <script type="text/javascript" src="../jquery.printElement.min.js"></script>
+
+ <script type="text/javascript">
+ $(document).ready(function() {
+ $("#simplePrint").click(function(){
+ $('#toPrint').printElement();
+ });
+ });
+ </script>
+
+</head>
+<body>
+ <input type="button" value="$('#toPrint').printElement()" id="simplePrint" />
+ <hr />
+ <div id="toPrint"> hmm , need some more printable samples here</div>
+</body>
+</html>
@@ -0,0 +1,11 @@
+.Fuchsia
+{
+ background-color: Fuchsia !important;
+}
+
+hr
+{
+ color: #f00;
+ background-color: #f00;
+ height: 5px;
+}
@@ -6,8 +6,9 @@
* Inspired by PrintArea (http://plugins.jquery.com/project/PrintArea) and
* http://stackoverflow.com/questions/472951/how-do-i-print-an-iframe-from-javascript-in-safari-chrome
*
-* $Id: jquery.printElement.js PENDING ID ErikZ $
-*
+* Plugin home page : http://plugins.jquery.com/project/printElement
+* Wiki : http://wiki.github.com/erikzaadi/jQueryPlugins/jqueryprintelement
+*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 7ac06e2

Please sign in to comment.