/*
Allow JS and CSS to be deferred even when called via ajax
@todo Does not work in CMS, which uses jquery ondemand anyway
187852
protected function attachCustomScriptsToResponse()
    {
        if (!$this->_response) {
            return;
        }

        if (!$this->customScript || empty($this->customScript)) {
            $this->_response = null;

            return;
        }

        $scripts = '';

        foreach (array_diff_key($this->customScript, $this->blocked,
            singleton('require')->getBlockAjax()) as $name => $script) {
            $scripts .= "<script type=\"text/javascript\">\n";
            $scripts .= "$script\n";
            $scripts .= "</script>\n";
        }

        $body = $this->_response->getBody();

        $end = stripos($body, '</body>');

        if ($end !== false) {
            $body = preg_replace("/(<\/body[^>]*>)/i", $scripts . "\\1", $body);
        } elseif (!$this->_response->getHeader('X-Pjax') && !$this->_response->getHeader('X-DisableDeferred') && strpos($this->_response->getHeader('Content-Type'),
                'text/html') !== false
        ) {
            $body .= $scripts;
        }

        $this->_response->setBody($body);

        $this->_response = null;
    }
463521
function(done) {
    var isSync = (typeof done !== 'function');
    var sass = require('node-sass');
    var opts = this.sassCSSOptions();

    if (isSync) {
      try {
        return sass.renderSync(opts).css.toString();
      } catch (err) {
        throw formatSassError(err, opts.data);
      }
    }

    sass.render(opts, function(err, result) {
      if (err) return done(formatSassError(err, opts.data));
      done(null, result.css.toString());
    });
  }
873417
function (requested) {
    // No postMessage? Don't render – the event-stream will handle it.
    if (!window.postMessage) { return; }

    // Inform other pages event streaming render to reload
    if (requested) {
      sendReload();
      jsbin.state.hasBody = false;
    }
    getPreparedCode().then(function (source) {
      var includeJsInRealtime = jsbin.settings.includejs;

      // Tell the iframe to reload
      var visiblePanels = jsbin.panels.getVisible();
      var outputPanelOpen = visiblePanels.indexOf(jsbin.panels.panels.live) > -1;
      var consolePanelOpen = visiblePanels.indexOf(jsbin.panels.panels.console) > -1;
      if (!outputPanelOpen && !consolePanelOpen) {
        return;
      }
      // this is a flag that helps detect crashed runners
      if (jsbin.settings.includejs) {
        store.sessionStorage.setItem('runnerPending', 1);
      }

      renderer.postMessage('render', {
        source: source,
        options: {
          injectCSS: jsbin.state.hasBody && jsbin.panels.focused.id === 'css',
          requested: requested,
          debug: jsbin.settings.debug,
          includeJsInRealtime: jsbin.settings.includejs,
        },
      });

      jsbin.state.hasBody = true;

    });
  }
72865
function domReady() {
        // Make sure body exists, at least, in case IE gets a little overzealous (jQuery ticket #5443).
        if (!doc.body) {
            // let's not get nasty by setting a timeout too small.. (loop mania guaranteed if assets are queued)
            win.clearTimeout(api.readyTimeout);
            api.readyTimeout = win.setTimeout(domReady, 50);
            return;
        }

        if (!isDomReady) {
            isDomReady = true;

            init();
            each(domWaiters, function (fn) {
                one(fn);
            });
        }
    }
561041
function(options){
			options = options || {};
			
			var message = options.message || messages["loadingDeploymentSettings..."];
			var showMessage = options.showMessage;
			var hideMessage = options.hideMessage;
			
			var preferences = options.preferences;
			var fileClient = options.fileClient;
			var resource = options.resource;
			
			var d = new Deferred();
			showMessage(message);

			fileClient.read(resource.ContentLocation, true).then(
				function(result){
					mCfUtil.getTargets(preferences, result).then(function(result){
					hideMessage();
					d.resolve(result);
				}, d.reject);
			}, d.reject);
			
			return d;
		}
471692
function(ac) {
            var data = {},
                selectedmojit = ac.params.getFromRoute('mojit') || 'none';
            data[selectedmojit] = true;
            ac.assets.addCss('./index.css');
            ac.done(data);
        }
27147
function () {
            var result = new $.Deferred();
            var path = this.path;
            var createIfMissing = this.createIfMissing;
            var recreateIfInvalid = this.recreateIfInvalid;
            var self = this;

            if (path) {
                var prefFile = FileSystem.getFileForPath(path);
                prefFile.read({}, function (err, text) {
                    if (err) {
                        if (createIfMissing) {
                            // Unreadable file is also unwritable -- delete so get recreated
                            if (recreateIfInvalid && (err === FileSystemError.NOT_READABLE || err === FileSystemError.UNSUPPORTED_ENCODING)) {
                                appshell.fs.moveToTrash(path, function (err) {
                                    if (err) {
                                        console.log("Cannot move unreadable preferences file " + path + " to trash!!");
                                    } else {
                                        console.log("Brackets has recreated the unreadable preferences file " + path + ". You may refer to the deleted file in trash in case you need it!!");
                                    }
                                }.bind(this));
                            }
                            result.resolve({});
                        } else {
                            result.reject(new Error("Unable to load preferences at " + path + " " + err));
                        }
                        return;
                    }

                    self._lineEndings = FileUtils.sniffLineEndings(text);

                    // If the file is empty, turn it into an empty object
                    if (/^\s*$/.test(text)) {
                        result.resolve({});
                    } else {
                        try {
                            result.resolve(JSON.parse(text));
                        } catch (e) {
                            if (recreateIfInvalid) {
                                // JSON parsing error -- recreate the preferences file
                                appshell.fs.moveToTrash(path, function (err) {
                                    if (err) {
                                        console.log("Cannot move unparseable preferences file " + path + " to trash!!");
                                    } else {
                                        console.log("Brackets has recreated the Invalid JSON preferences file " + path + ". You may refer to the deleted file in trash in case you need it!!");
                                    }
                                }.bind(this));
                                result.resolve({});
                            } else {
                                result.reject(new ParsingError("Invalid JSON settings at " + path + "(" + e.toString() + ")"));
                            }
                        }
                    }
                });
            } else {
                result.resolve({});
            }

            return result.promise();
        }
773485
function(e, cal) {
        Event.preventDefault(e);
        setTimeout(function() {
            cal.nextMonth();
            var navs = Dom.getElementsByClassName(cal.Style.CSS_NAV_RIGHT, "a", cal.oDomContainer);
            if (navs && navs[0]) {
                try {
                    navs[0].focus();
                } catch (ex) {
                    // ignore
                }
            }
        }, 0);
    }
1035384
function(selector, from, doc, root) {
      if (isEnabled && !isPaused) {
        if (!isExpired) {
          if (Results[selector] && Contexts[selector] === from) {
            return Results[selector];
          }
        } else {
          // pause caching while we are getting
          // hammered by dom mutations (jdalton)
          now = (new Date).getTime();
          if ((now - lastCalled) < minCacheRest) {
            isPaused = isExpired = true;
            setTimeout(function() { isPaused = false; }, minCacheRest);
          } else setCache(true, doc);
          lastCalled = now;
        }
      }
      return undefined;
    }
519211
function( wait ) {

		// Abort if there are pending holds or we're already ready
		if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
			return;
		}

		// Remember that the DOM is ready
		jQuery.isReady = true;

		// If a normal DOM Ready event fired, decrement, and wait if need be
		if ( wait !== true && --jQuery.readyWait > 0 ) {
			return;
		}

		// If there are functions bound, to execute
		readyList.resolveWith( document, [ jQuery ] );
	}
2127
function( cb ){
			var resolvedHref = ss.href;
			var i = sheets.length;
			while( i-- ){
				if( sheets[ i ].href === resolvedHref ){
					return cb();
				}
			}
			setTimeout(function() {
				onloadcssdefined( cb );
			});
		}
316684
function (opts) {
            var that = this;

            return function () {
                return this.thenOpen(globals.adminPagesUrl)
                    .waitUntilVisible('.js-cms-pagetree-options')
                    .then(that.expandPageTree())
                    .then(function () {
                        var pageId;
                        var pageNodeId;
                        var data = '';
                        var href = '';

                        if (opts && opts.title) {
                            pageId = that.getPageId(opts.title);
                            pageNodeId = that.getPageNodeId(opts.title);
                        }

                        if (pageId) {
                            data = '[data-node-id="' + pageNodeId + '"]';
                            href = '[href*="' + pageId + '"]';
                        }

                        return this.then(function () {
                            this.click('.cms-pagetree-jstree .js-cms-pagetree-options' + data);
                        })
                        .then(that.waitUntilActionsDropdownLoaded())
                        .then(function () {
                            this.click('.cms-pagetree-jstree [href*="delete"]' + href);
                        });
                    })
                    .waitForUrl(/delete/)
                    .waitUntilVisible('input[type=submit]')
                    .then(function () {
                        this.click('input[type=submit]');
                    })
                    .wait(1000)
                    .then(that.waitUntilAllAjaxCallsFinish());
            };
        }
1192355
function() {
                        var args = Array.prototype.slice.call(arguments, 0);
                        deferredObject.reject.apply(null, ctxArgs.concat(args));
                    }
1057595
function(event){
			var self = this,
				deferred = $.Deferred();

			if(self.beforeClose(event) === false) {
				deferred.reject();
			} else {

				if (0 === pruneOpened(self).length) {
					toggleGlobalEvents(false);
				}

				self.$instance.fadeOut(self.closeSpeed,function(){
					self.$instance.detach();
					self.afterClose(event);
					deferred.resolve();
				});
			}
			return deferred.promise();
		}
710303
function(location) {
		var deferred = new Deferred();
		this._busyWhile(deferred, messages["Loading..."]);
		this._siteClient.loadSiteConfiguration(location).then(
			function(siteConfig) {
				this._setSiteConfiguration(siteConfig);
				this.setDirty(false);
				deferred.resolve(siteConfig);
			}.bind(this),
			function(error) {
				deferred.reject(error);
			});
		return deferred;
	}
837627
function documentReady(callback) {
  document.readyState === "interactive" || document.readyState === "complete" ? callback() : document.addEventListener("DOMContentLoaded", callback);
}
855808
function(index) {
        if (this.animating) {
            return;
        }

        index = $.bound(index, this.data.length);

        // Exit since transitions don't occur
        if (index === this.index) {
            return;
        }

        var self = this,
            element = this.element,
            caption = this.caption,
            list = this.items,
            listItems = list.children('li'),
            listItem = listItems.eq(index),
            items = this.data,
            item = items[index],
            deferred = $.Deferred();

        this.fireEvent('jumping', [this.index]);

        // Update tabs
        this.tabs.find('a')
            .removeClass('is-active')
            .eq(index)
                .addClass('is-active');

        // Reset previous styles
        listItems.conceal(true);
        caption.conceal(true);
        element
            .addClass('is-loading')
            .aria('busy', true)
            .reveal();

        // Setup deferred callbacks
        this.animating = true;

        deferred.always(function(width, height) {
            list.transitionend(function() {
                caption.html(item.title).reveal(true);
                listItem.reveal(true);
                self.position();
                self.animating = false;
            });

            self._resize(width, height);

            element
                .removeClass('is-loading')
                .aria('busy', false);

            listItem
                .data('width', width)
                .data('height', height);
        });

        deferred.fail(function() {
            element.addClass('has-failed');
            listItem.html(Toolkit.messages.error);
        });

        // Image already exists
        if (listItem.data('width')) {
            deferred.resolve(listItem.data('width'), listItem.data('height'));

        // Create image and animate
        } else {
            var img = new Image();
                img.src = item.image;
                img.onerror = function() {
                    deferred.reject(150, 150);
                };
                img.onload = function() {
                    deferred.resolve(this.width, this.height);
                    listItem.append(img);
                };
        }

        // Hide loader
        if (this.blackout) {
            this.blackout.hideLoader();
        }

        // Save state
        this.index = index;

        this.fireEvent('jumped', [index]);
    }