lib/assets/javascripts/up/flow.js.coffee in upjs-rails-0.6.2 vs lib/assets/javascripts/up/flow.js.coffee in upjs-rails-0.6.3
- old
+ new
@@ -96,11 +96,20 @@
promise.fail(u.error)
promise
###*
- Replaces the given selector with the same CSS selector from the given HTML string.
+ Updates a selector on the current page with the
+ same selector from the given HTML string.
+
+ Example:
+
+ html = '<div class="before">new-before</div>' +
+ '<div class="middle">new-middle</div>' +
+ '<div class="after">new-after</div>';
+
+ up.flow.implant('.middle', html):
@method up.flow.implant
@protected
@param {String} selector
@param {String} html
@@ -137,12 +146,18 @@
findOldFragment = (selector) ->
selectorWithExcludes = "#{selector}:not(.up-ghost, .up-destroying)"
# Prefer to replace fragments in an open popup or modal
u.presence($(".up-popup #{selectorWithExcludes}")) ||
- u.presence($(".up-modal #{selectorWithExcludes}")) ||
- u.presence($(selectorWithExcludes)) ||
- u.error('Could not find selector %o in current body HTML', selector)
+ u.presence($(".up-modal #{selectorWithExcludes}")) ||
+ u.presence($(selectorWithExcludes)) ||
+ fragmentNotFound(selector)
+
+ fragmentNotFound = (selector) ->
+ message = 'Could not find selector %o in current body HTML'
+ if message[0] == '#'
+ message += ' (avoid using IDs)'
+ u.error(message, selector)
parseResponse = (html) ->
# jQuery cannot construct transient elements that contain <html> or <body> tags,
# so we're using the native browser API to grep through the HTML
htmlElement = u.createElementFromHtml(html)