Skip to content

Commit

Permalink
Rework plugin for remove dependency on Ultimate.Backbone.View, instea…
Browse files Browse the repository at this point in the history
…d use Ultimate.Plugin class. Usage example in stylesheets/ultimate/flash.scss. Bump version to 0.6.1
  • Loading branch information
KODerFunk committed Sep 27, 2012
1 parent cc48607 commit 82c54f9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
PATH
remote: .
specs:
ultimate-flash (0.6.0)
ultimate-flash (0.6.1)
ultimate-base (~> 0.2)

GEM
remote: http://rubygems.org/
specs:
ultimate-base (0.2.4)
ultimate-base (0.3.1)

PLATFORMS
ruby
Expand Down
24 changes: 12 additions & 12 deletions app/assets/javascripts/ultimate/flash.js.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###*
* Ultimate Flash 0.6.0 - Ruby on Rails oriented jQuery plugin based on Ultimate Backbone
* Ultimate Flash 0.6.1 - Ruby on Rails oriented jQuery plugin
*
* Copyright 2011-2012 Karpunin Dmitry (KODer) / Evrone.com
*
Expand Down Expand Up @@ -32,12 +32,12 @@
# TODO improve English
# TODO jGrowl features

#= require ultimate/backbone/view
#= require ultimate/backbone/extra/jquery-plugin-adapter
#= require ultimate/jquery-plugin-class
#= require ultimate/jquery-plugin-adapter

Ultimate.Backbone.Plugins ||= {}
Ultimate.Plugins ||= {}

class Ultimate.Backbone.Plugins.Flash extends Ultimate.Backbone.View
class Ultimate.Plugins.Flash extends Ultimate.Plugin

el: ".l-page__flashes"

Expand Down Expand Up @@ -79,13 +79,13 @@ class Ultimate.Backbone.Plugins.Flash extends Ultimate.Backbone.View
@$el.ajaxError =>
if @showAjaxErrors
a = @_ajaxSuccessParseArguments(arguments)
Ultimate.Backbone.debug ".Plugins.Flash.ajaxError", a
Ultimate.debug(".Plugins.Flash.ajaxError", a) if _.isFunction(Ultimate.debug)
@ajaxError a.data, a.jqXHR
# binding hook ajaxSuccess handler
@$el.ajaxSuccess =>
if @showAjaxSuccesses
a = @_ajaxSuccessParseArguments(arguments)
Ultimate.Backbone.debug ".Plugins.Flash.ajaxSuccess", a
Ultimate.debug(".Plugins.Flash.ajaxSuccess", a) if _.isFunction(Ultimate.debug)
@ajaxSuccess a.data, a.jqXHR

# delegate event for hide on click
Expand Down Expand Up @@ -143,7 +143,7 @@ class Ultimate.Backbone.Plugins.Flash extends Ultimate.Backbone.View
# detect event as first element
if successArgs[0] instanceof jQuery.Event
# convert arguments to Array
successArgs = args(successArgs)
successArgs = _.toArray(successArgs)
# remove event
successArgs.shift()
# arrange arguments
Expand Down Expand Up @@ -215,21 +215,21 @@ class Ultimate.Backbone.Plugins.Flash extends Ultimate.Backbone.View
if jqXHR.status >= 400 and jqXHR.responseText
# try detect Rails raise message
if raiseMatches = jqXHR.responseText.match(/<\/h1>\n<pre>(.+?)<\/pre>/)
Ultimate.Backbone.debug "replace thrownError = \"#{thrownError}\" with raiseMatches[1] = \"#{raiseMatches[1]}\""
Ultimate.debug("replace thrownError = \"#{thrownError}\" with raiseMatches[1] = \"#{raiseMatches[1]}\"") if _.isFunction(Ultimate.debug)
thrownError = raiseMatches[1]
else
# try detect short text message as error
if jqXHR.responseText.length <= @detectPlainTextMaxLength
Ultimate.Backbone.debug "replace thrownError = \"#{thrownError}\" with jqXHR.responseText = \"#{jqXHR.responseText}\""
Ultimate.debug("replace thrownError = \"#{thrownError}\" with jqXHR.responseText = \"#{jqXHR.responseText}\"") if _.isFunction(Ultimate.debug)
thrownError = jqXHR.responseText
else
if _.isString(thrownError) and not _.isBlank(thrownError)
Ultimate.Backbone.debug "replace thrownError = \"#{thrownError}\" with @translations.defaultThrownError = \"#{@translations.defaultThrownError}\""
Ultimate.debug("replace thrownError = \"#{thrownError}\" with @translations.defaultThrownError = \"#{@translations.defaultThrownError}\"") if _.isFunction(Ultimate.debug)
thrownError = @translations.defaultThrownError
text += ": " if text
text += "#{thrownError} [#{jqXHR.status}]"
return @alert(text)



Ultimate.Backbone.createJQueryPlugin "ultimateFlash", Ultimate.Backbone.Plugins.Flash
Ultimate.createJQueryPlugin "ultimateFlash", Ultimate.Plugins.Flash
9 changes: 9 additions & 0 deletions app/assets/stylesheets/ultimate/flash.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
// Usage:
// .l-page__flashes {
// @include ultimate-flash($background-alpha: 0.7);
// @include font_custom;
// > .flash {
// &.custom-type { }
// }
// }

@mixin ultimate-flash(
$notice-background: #393,
$notice-border-color: #6c6,
Expand Down
2 changes: 1 addition & 1 deletion lib/ultimate-flash/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Ultimate
module Flash
VERSION = "0.6.0"
VERSION = "0.6.1"
end
end

0 comments on commit 82c54f9

Please sign in to comment.