Created
November 23, 2011 22:10
-
-
Save voidfiles/1390075 to your computer and use it in GitHub Desktop.
Flickr's Pre-script loading event handler code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function(F) { | |
| var registered_ids = {}, | |
| id_to_module_map = {}, | |
| interim_actions = {}, | |
| cleanup_actions = {}, | |
| clicked_ids = {}, | |
| queueing = true; | |
| function register_id(id, callbacks, required_module) { | |
| id = id.replace('*', '.*'); | |
| registered_ids[id] = true; | |
| id_to_module_map[id] = required_module; | |
| interim_actions[id] = callbacks.interim; | |
| cleanup_actions[id] = callbacks.cleanup; | |
| } | |
| function rectify_id(actual_id) { | |
| for (var key_id in registered_ids) { | |
| if (registered_ids.hasOwnProperty(key_id) && actual_id.search(key_id) !== -1) { | |
| return key_id; | |
| } | |
| } | |
| return actual_id; | |
| } | |
| F.actionQueue = { | |
| register: function(id, callbacks, required_module) { | |
| if (id instanceof Array) { | |
| for (var n = 0, len = id.length; n < len; n++) { | |
| register_id(id[n], callbacks, required_module); | |
| } | |
| } else { | |
| register_id(id, callbacks, required_module); | |
| } | |
| }, | |
| queue_click: function(id) { | |
| var id_key = rectify_id(id); | |
| if (queueing && id && id_key && registered_ids[id_key]) { | |
| clicked_ids[id_key] = true; | |
| if (typeof interim_actions[id_key] === 'function') { | |
| interim_actions[id_key].apply(this, arguments); | |
| } | |
| return false; | |
| } else if (queueing) { | |
| return false; | |
| } | |
| return true; | |
| }, | |
| module_loaded: function(module_name, id_to_restrict_to) { | |
| queueing = false; | |
| for (var id in id_to_module_map) { | |
| if (id_to_module_map.hasOwnProperty(id) && clicked_ids[id] && id_to_module_map[id] === module_name) { | |
| cleanup_actions[id](id_to_restrict_to ? id_to_restrict_to : id); | |
| } | |
| } | |
| }, | |
| get_viewport_dimensions: function() { | |
| var doc = window.document, | |
| win = doc.defaultView || doc.parentWindow, | |
| mode = doc['compatMode'], | |
| h = win.innerHeight, | |
| w = win.innerWidth, | |
| root = doc['documentElement']; | |
| if (mode && navigator.userAgent.search(/Opera[\s\/]([^\s]*)/) === -1) { | |
| if (mode != 'CSS1Compat') { | |
| root = doc.body; | |
| } | |
| h = root.clientHeight; | |
| w = root.clientWidth; | |
| } | |
| return { | |
| height: h, | |
| width: w | |
| }; | |
| } | |
| }; | |
| }(F)); | |
| (function(F) { | |
| var geoOverlay1, geoOverlay2, last_context_clicked; | |
| F.actionQueue.register('button-bar-fave', { | |
| interim: function(id) { | |
| var fave_button = document.getElementById(id); | |
| if (fave_button.className.search(/fave/) === -1) { | |
| fave_button.className = 'Butt ywa-track fave-button fave'; | |
| } else { | |
| fave_button.className = 'Butt ywa-track fave-button'; | |
| } | |
| }, | |
| cleanup: function(id) { | |
| F.actionQueue['photo-button-bar'].toggle_fave(); | |
| } | |
| }, 'photo-button-bar'); | |
| F.actionQueue.register('context-link-*', { | |
| interim: function(id) { | |
| last_context_clicked = id; | |
| }, | |
| cleanup: function(id) { | |
| if (last_context_clicked === id) { | |
| F.actionQueue['photo-filmstrip'][last_context_clicked].display(); | |
| } | |
| } | |
| }, 'photo-filmstrip'); | |
| F.actionQueue.register('add-a-tag', { | |
| interim: function(id) {}, | |
| cleanup: function(id) {} | |
| }, 'flickr-tagrs'); | |
| F.actionQueue.register('add-a-person', { | |
| interim: function(id) {}, | |
| cleanup: function(id) {} | |
| }, 'photo-people'); | |
| F.actionQueue.register('photoGeolocationEdit-addbutton', { | |
| interim: function(id) {}, | |
| cleanup: function(id) {} | |
| }, 'mapr'); | |
| F.actionQueue.register(['edit-privacy', 'edit-viewgeo', 'edit-comment-perm', 'edit-addmeta', 'edit-nipsa', 'edit-safety-level', 'edit-content-type'], { | |
| interim: function(id) {}, | |
| cleanup: function(id) {} | |
| }, 'photo-sidebar-owner'); | |
| F.actionQueue.register('photoGeopanel-*', { | |
| interim: function(id) { | |
| var viewport_dimensions = F.actionQueue.get_viewport_dimensions(); | |
| photoGeopanel = document.createElement('div'); | |
| photoGeopanel.className = "interim-spinner-transparent"; | |
| document.body.appendChild(photoGeopanel); | |
| }, | |
| cleanup: function(id) { | |
| if (typeof F.actionQueue.photoGeopanel.display === 'function') { | |
| F.actionQueue.photoGeopanel.display(); | |
| } | |
| if (photoGeopanel) { | |
| photoGeopanel.parentNode.removeChild(photoGeopanel); | |
| } | |
| } | |
| }, 'photoGeopanel'); | |
| F.actionQueue.register('photoGeolocation-*', { | |
| interim: function(id) { | |
| var viewport_dimensions = F.actionQueue.get_viewport_dimensions(); | |
| geoOverlay1 = document.createElement('div'); | |
| geoOverlay1.className = "interim-spinner-transparent"; | |
| document.body.appendChild(geoOverlay1); | |
| }, | |
| cleanup: function(id) { | |
| if (F.actionQueue.photoGeolocation && typeof F.actionQueue.photoGeolocation.display === 'function') { | |
| F.actionQueue.photoGeolocation.display(); | |
| } | |
| if (geoOverlay1) { | |
| geoOverlay1.parentNode.removeChild(geoOverlay1); | |
| } | |
| } | |
| }, 'photoGeolocation'); | |
| F.actionQueue.register('photoGeolocationEdit-*', { | |
| interim: function(id) { | |
| var viewport_dimensions = F.actionQueue.get_viewport_dimensions(); | |
| geoOverlay2 = document.createElement('div'); | |
| geoOverlay2.className = "interim-spinner-transparent"; | |
| document.body.appendChild(geoOverlay2); | |
| }, | |
| cleanup: function(id) { | |
| if (F.actionQueue.photoGeolocationEdit && typeof F.actionQueue.photoGeolocationEdit.display === 'function') { | |
| F.actionQueue.photoGeolocationEdit.display(); | |
| } | |
| if (geoOverlay2) { | |
| geoOverlay2.parentNode.removeChild(geoOverlay2); | |
| } | |
| } | |
| }, 'photoGeolocationEdit'); | |
| }(F)); | |
| (function(F) { | |
| F.actionQueue.register('button-bar-options', { | |
| interim: function(id) { | |
| var button = document.getElementById(id); | |
| if (button.className.search(/ActiveButt/) === -1) { | |
| button.className = button.className + ' ActiveButt'; | |
| } | |
| button.blur(); | |
| if (!document.getElementById('interim-menu-action')) { | |
| var fake_menu = document.createElement('div'); | |
| fake_menu.id = 'interim-menu-action'; | |
| fake_menu.className = (document.getElementById('button-bar-fave')) ? ((document.getElementById('button-bar-fave').className.replace(/fave-button/, '').search(/fave/) !== -1) ? 'interim-menu interim-menu-fave' : 'interim-menu') : 'interim-menu interim-menu-owner'; | |
| fake_menu.innerHTML = '<div class="yui3-popover-arrow yui3-popover-arrow-t interim-menu-arrow">◣</div>' + '<div class="interim-menu-arrow-mask"></div>'; | |
| document.getElementById('nav').appendChild(fake_menu); | |
| } | |
| if (document.getElementById('interim-menu-share')) { | |
| var fake_share_menu = document.getElementById('interim-menu-share'); | |
| fake_share_menu.parentNode.removeChild(fake_share_menu); | |
| if (document.getElementById('button-bar-share')) { | |
| document.getElementById('button-bar-share').className = document.getElementById('button-bar-share').className.replace(/ActiveButt/, ''); | |
| } | |
| } | |
| }, | |
| cleanup: function(id) { | |
| var fake_menu = document.getElementById('interim-menu-action'); | |
| if (fake_menu) { | |
| fake_menu.parentNode.removeChild(fake_menu); | |
| } | |
| F.actionQueue['photo-button-bar'].display_action(); | |
| } | |
| }, 'photo-button-bar'); | |
| }(F)); | |
| (function(F) { | |
| F.actionQueue.register('share-this-v3-more-button', { | |
| interim: function(id) { | |
| var button = document.getElementById(id); | |
| if (button.className.search(/ActiveButt/) === -1) { | |
| button.className = button.className + ' ActiveButt'; | |
| } | |
| button.blur(); | |
| if (!document.getElementById('interim-menu-share')) { | |
| var fake_menu = document.createElement('div'); | |
| fake_menu.id = 'interim-menu-share'; | |
| fake_menu.className = (document.getElementById('button-bar-fave')) ? ((document.getElementById('button-bar-fave').className.replace(/fave-button/, '').search(/fave/) !== -1) ? 'interim-menu interim-menu-fave' : 'interim-menu') : 'interim-menu interim-menu-owner'; | |
| fake_menu.innerHTML = '<div class="yui3-popover-arrow yui3-popover-arrow-t interim-menu-arrow">◣</div>' + '<div class="interim-menu-arrow-mask"></div>'; | |
| document.getElementById('nav').appendChild(fake_menu); | |
| } | |
| if (document.getElementById('interim-menu-action')) { | |
| var fake_action_menu = document.getElementById('interim-menu-action'); | |
| fake_action_menu.parentNode.removeChild(fake_action_menu); | |
| if (document.getElementById('button-bar-options')) { | |
| document.getElementById('button-bar-options').className = document.getElementById('button-bar-options').className.replace(/ActiveButt/, ''); | |
| } | |
| } | |
| }, | |
| cleanup: function(id) { | |
| var fake_menu = document.getElementById('interim-menu-share'); | |
| if (fake_menu) { | |
| fake_menu.parentNode.removeChild(fake_menu); | |
| } | |
| F.actionQueue['share-this-v3-more-button'].display_share(); | |
| } | |
| }, 'share-this-v3-more-button'); | |
| }(F)); | |
| (function(F) { | |
| var nav; | |
| function hasClass(o, cStr) { | |
| return (o ? new RegExp('(^|\\s)' + cStr + '(\\s|$)').test(o.className) : false); | |
| }; | |
| function addClass(o, cStr) { | |
| if (!o || !cStr || hasClass(o, cStr)) { | |
| return false; | |
| } | |
| o.className = (o.className ? o.className + ' ' : '') + cStr; | |
| }; | |
| function removeClass(o, cStr) { | |
| if (!o || !cStr || !hasClass(o, cStr)) { | |
| return false; | |
| } | |
| o.className = o.className.replace(new RegExp('( ' + cStr + ')|(' + cStr + ')', 'g'), ''); | |
| }; | |
| function toggleClass(o, sClass) { | |
| if (hasClass(o, sClass)) { | |
| removeClass(o, sClass); | |
| } else { | |
| addClass(o, sClass); | |
| } | |
| } | |
| function getParentByNodeName(oChild, sParentNodeName) { | |
| if (!oChild || !sParentNodeName) { | |
| return false; | |
| } | |
| sParentNodeName = sParentNodeName.toLowerCase(); | |
| while (oChild.parentNode && sParentNodeName !== oChild.parentNode.nodeName.toLowerCase()) { | |
| oChild = oChild.parentNode; | |
| } | |
| return (oChild.parentNode && sParentNodeName === oChild.parentNode.nodeName.toLowerCase() ? oChild.parentNode : null); | |
| }; | |
| F.actionQueue.register('flickr-nav', { | |
| interim: function(id, e) { | |
| var oClicked = (e ? (e.target ? e.target : e.srcElement) : null), | |
| oLI; | |
| if (!oClicked) { | |
| return false; | |
| } | |
| oLI = getParentByNodeName(oClicked, 'li'); | |
| }, | |
| cleanup: function(id) {} | |
| }, 'flickr-nav'); | |
| }(F)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment